ERP5Site.py 46.3 KB
Newer Older
1
##############################################################################
Jean-Paul Smets's avatar
Jean-Paul Smets committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
""" Portal class

$Id$
"""

import Globals
from Globals import package_home
#from Products.ERP5 import content_classes
from AccessControl import ClassSecurityInfo
from Products.CMFDefault.Portal import CMFSite, PortalGenerator
from Products.CMFCore.utils import getToolByName, _getAuthenticatedUser
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
Jean-Paul Smets's avatar
Jean-Paul Smets committed
25
from Products.ERP5Type.Document.Folder import FolderMixIn
26
from Products.ERP5Type.Document import addFolder
Jean-Paul Smets's avatar
Jean-Paul Smets committed
27
from Acquisition import aq_base, aq_parent, aq_inner, aq_acquire
28
from Products.ERP5Type import allowClassTool
29
from Products.ERP5Type.Cache import CachingMethod
30 31
from Products.ERP5Type.ERP5Type import ERP5TypeInformation
from Products.ERP5.Document.BusinessTemplate import BusinessTemplate
32

33
import ERP5Defaults
34
from os import path
Jean-Paul Smets's avatar
Jean-Paul Smets committed
35 36

from zLOG import LOG
Sebastien Robin's avatar
Sebastien Robin committed
37
from string import join
Jean-Paul Smets's avatar
Jean-Paul Smets committed
38 39 40 41

import os

# Site Creation DTML
42 43
manage_addERP5SiteForm = Globals.HTMLFile('dtml/addERP5Site', globals())
manage_addERP5SiteForm.__name__ = 'addERP5Site'
Jean-Paul Smets's avatar
Jean-Paul Smets committed
44 45 46 47

# ERP5Site Constructor
def manage_addERP5Site(self, id, title='ERP5', description='',
                         create_userfolder=1,
48
                         create_activities=1,
Jean-Paul Smets's avatar
Jean-Paul Smets committed
49 50
                         email_from_address='postmaster@localhost',
                         email_from_name='Portal Administrator',
51
                         validate_email=0,
52 53 54 55
                         erp5_sql_connection_type='Z MySQL Database Connection',
                         erp5_sql_connection_string='test test',
                         cmf_activity_sql_connection_type='Z MySQL Database Connection',
                         cmf_activity_sql_connection_string='test test',
Sebastien Robin's avatar
Sebastien Robin committed
56
                         light_install=0,reindex=1,
57
                         RESPONSE=None):
Jean-Paul Smets's avatar
Jean-Paul Smets committed
58 59 60
    '''
    Adds a portal instance.
    '''
61 62
    #LOG('manage_addERP5Site, create_activities',0,create_activities)
    #LOG('manage_addERP5Site, create_activities==1',0,create_activities==1)
Jean-Paul Smets's avatar
Jean-Paul Smets committed
63 64 65
    gen = ERP5Generator()
    from string import strip
    id = strip(id)
66 67 68
    p = gen.create(self, id, create_userfolder,
                   erp5_sql_connection_type,erp5_sql_connection_string,
                   cmf_activity_sql_connection_type,cmf_activity_sql_connection_string,
Sebastien Robin's avatar
Sebastien Robin committed
69 70
                   create_activities=create_activities,light_install=light_install,
                   reindex=reindex)
Jean-Paul Smets's avatar
Jean-Paul Smets committed
71 72 73 74
    gen.setupDefaultProperties(p, title, description,
                               email_from_address, email_from_name,
                               validate_email)
    if RESPONSE is not None:
75
        RESPONSE.redirect(p.absolute_url())
Jean-Paul Smets's avatar
Jean-Paul Smets committed
76

77
class ERP5Site ( FolderMixIn, CMFSite ):
Jean-Paul Smets's avatar
Jean-Paul Smets committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
    """
        The *only* function this class should have is to help in the setup
        of a new ERP5.  It should not assist in the functionality at all.
    """
    meta_type = 'ERP5 Site'
    constructors = (manage_addERP5SiteForm, manage_addERP5Site, )
    uid = 0
    last_id = 0
    icon = 'portal.gif'

    _properties = (
        {'id':'title', 'type':'string'},
        {'id':'description', 'type':'text'},
        )
    title = ''
    description = ''

    # Declarative security
    security = ClassSecurityInfo()
97
    security.declareObjectProtected(Permissions.AccessContentsInformation)
Jean-Paul Smets's avatar
Jean-Paul Smets committed
98

Yoshinori Okuji's avatar
Yoshinori Okuji committed
99
    security.declareProtected(Permissions.View, 'view')
Jean-Paul Smets's avatar
Jean-Paul Smets committed
100 101 102 103 104 105 106
    def view(self):
        """
          Returns the default view.
          Implemented for consistency
        """
        return self.index_html()

107 108 109 110
    def hasObject(self, id):
      """Check if the portal has an id.
      """
      return id in self.objectIds()
111

Jean-Paul Smets's avatar
Jean-Paul Smets committed
112 113 114 115
    security.declareProtected(Permissions.AccessContentsInformation, 'getPortalObject')
    def getPortalObject(self):
      return self

116 117 118 119 120 121 122
    security.declareProtected(Permissions.AccessContentsInformation, 'getTitle')
    def getTitle(self):
      """
        Return the title.
      """
      return self.title

Jean-Paul Smets's avatar
Jean-Paul Smets committed
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
    security.declareProtected(Permissions.AccessContentsInformation, 'getUid')
    def getUid(self):
      """
        Returns the UID of the object. Eventually reindexes
        the object in order to make sure there is a UID
        (useful for import / export).

        WARNING : must be updates for circular references issues
      """
      #if not hasattr(self, 'uid'):
      #  self.reindexObject()
      return getattr(self, 'uid', 0)

    security.declareProtected(Permissions.AccessContentsInformation, 'getParentUid')
    def getParentUid(self):
      """
        A portal has no parent
      """
      return self.getUid()

Jean-Paul Smets's avatar
Jean-Paul Smets committed
143 144 145 146 147 148
    # Required to allow content creation outside folders
    security.declareProtected(Permissions.View, 'getIdGroup')
    def getIdGroup(self):
      return None

    # Required to allow content creation outside folders
Yoshinori Okuji's avatar
Yoshinori Okuji committed
149
    security.declareProtected(Permissions.View, 'setLastId')
Jean-Paul Smets's avatar
Jean-Paul Smets committed
150 151 152
    def setLastId(self, id):
      self.last_id = id

Sebastien Robin's avatar
Sebastien Robin committed
153 154 155 156 157 158 159
    security.declareProtected(Permissions.AccessContentsInformation, 'getPath')
    def getPath(self, REQUEST=None):
      """
        Returns the absolute path of an object
      """
      return join(self.getPhysicalPath(),'/')

Jean-Paul Smets's avatar
Jean-Paul Smets committed
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
    security.declareProtected(Permissions.AccessContentsInformation, 'searchFolder')
    def searchFolder(self, **kw):
      """
        Search the content of a folder by calling
        the portal_catalog.
      """
      if not kw.has_key('parent_uid'):
        kw['parent_uid'] = self.uid
      kw2 = {}
      # Remove useless matter before calling the
      # catalog. In particular, consider empty
      # strings as None values
      for cname in kw.keys():
        if kw[cname] != '' and kw[cname]!=None:
          kw2[cname] = kw[cname]
      # The method to call to search the folder
      # content has to be called z_search_folder
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
      method = self.portal_catalog.searchResults
      return method(**kw2)

    security.declareProtected(Permissions.AccessContentsInformation, 'countFolder')
    def countFolder(self, **kw):
      """
        Count the content of a folder by calling
        the portal_catalog.
      """
      if not kw.has_key('parent_uid'):
        kw['parent_uid'] = self.uid
      kw2 = {}
      # Remove useless matter before calling the
      # catalog. In particular, consider empty
      # strings as None values
      for cname in kw.keys():
        if kw[cname] != '' and kw[cname]!=None:
          kw2[cname] = kw[cname]
      # The method to call to search the folder
      # content has to be called z_search_folder
      method = self.portal_catalog.countResults
Jean-Paul Smets's avatar
Jean-Paul Smets committed
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
      return method(**kw2)

    # Proxy methods for security reasons
    def getOwnerInfo(self):
      return self.owner_info()

    # Make sure fixConsistency is recursive - ERROR - this creates recursion errors
    # checkConsistency = Folder.checkConsistency
    # fixConsistency = Folder.fixConsistency

    security.declarePublic('getOrderedGlobalActionList')
    def getOrderedGlobalActionList(self, action_list):
      """
      Returns a dictionnary of actions, sorted by type of object

      This should absolutely be rewritten by using clean concepts to separate worklists XXX
      """
      #LOG("getOrderedGlobalActionList", 0, str(action_list))
      sorted_workflow_actions = {}
      sorted_global_actions = []
      other_global_actions = []
      for action in action_list:
        action['disabled'] = 0
        if action.has_key('workflow_title'):
          if not sorted_workflow_actions.has_key(action['workflow_title']):
            sorted_workflow_actions[action['workflow_title']] = []
          sorted_workflow_actions[action['workflow_title']].append(action)
        else:
          other_global_actions.append(action)
      workflow_title_list = sorted_workflow_actions.keys()
      workflow_title_list.sort()
      for key in workflow_title_list:
        sorted_global_actions.append({'title': key, 'disabled': 1})
        sorted_global_actions.extend(sorted_workflow_actions[key])
232
      sorted_global_actions.append({'title': 'Others', 'disabled': 1})
Jean-Paul Smets's avatar
Jean-Paul Smets committed
233 234 235
      sorted_global_actions.extend(other_global_actions)
      return sorted_global_actions

236 237 238 239 240 241 242 243
    def setupDefaultProperties(self, p, title, description,
                               email_from_address, email_from_name,
                               validate_email
                               ):
        CMFSite.setupDefaultProperties(self, p, title, description,
                               email_from_address, email_from_name,
                               validate_email)

244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
    # Portal methods are based on the concept of having portal-specific parameters
    # for customization. In the past, we used global parameters, but it was not very good
    # because it was very difficult to customize the settings for each portal site.
    def _getPortalConfiguration(self, id):
      """
        Get a portal-specific configuration.

        Current implementation is using properties in a portal object.
        If not found, try to get a default value for backward compatibility.

        This implementation can be improved by gathering information from appropriate places,
        such as portal_types, portal_categories and portal_workflow.
      """
      if self.hasProperty(id):
        return self.getProperty(id)

      # Fall back to the default.
      return getattr(ERP5Defaults, id, None)

263 264 265 266 267 268 269 270 271
    def _getPortalGroupedTypeList(self, group):
      """Return a list of portal types classified to a specific group.
      """
      def getTypeList(group):
        type_list = []
        for pt in self.portal_types.objectValues():
          if group in getattr(pt, 'group_list', ()):
            type_list.append(pt.getId())
        return tuple(type_list)
272

273 274
      getTypeList = CachingMethod(getTypeList,
          id=('_getPortalGroupedTypeList', group), cache_duration=3600)
275
      return getTypeList(group)
276

277 278 279 280 281 282 283 284 285
    def _getPortalGroupedCategoryList(self, group):
      """Return a list of base categories classified to a specific group.
      """
      def getCategoryList(group):
        category_list = []
        for bc in self.portal_categories.objectValues():
          if group in bc.getCategoryTypeList():
            category_list.append(bc.getId())
        return tuple(category_list)
286

287 288
      getCategoryList = CachingMethod(getCategoryList,
            id=('_getPortalGroupedCategoryList', group), cache_duration=3600)
289
      return getCategoryList(group)
290 291 292 293 294 295 296

    def _getPortalGroupedStateList(self, group):
      """Return a list of workflow states classified to a specific group.
      """
      def getStateList(group):
        state_dict = {}
        for wf in self.portal_workflow.objectValues():
297
          if getattr(wf, 'states', None):
298 299 300 301
            for state in wf.states.objectValues():
              if group in getattr(state, 'type_list', ()):
                state_dict[state.getId()] = None
        return tuple(state_dict.keys())
302

303 304
      getStateList = CachingMethod(getStateList,
          id=('_getPortalGroupedStateList', group), cache_duration=3600)
305
      return getStateList(group)
306

307 308
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalDefaultSectionCategory')
309 310 311 312
    def getPortalDefaultSectionCategory(self):
      """
        Return a default section category. This method is deprecated.
      """
313 314
      LOG('ERP5Site', 0, 'getPortalDefaultSectionCategory is deprecated;'+
          ' use portal_preferences.getPreferredSectionCategory instead.')
315
      section_category = self.portal_preferences.getPreferredSectionCategory()
316

317 318
      # XXX This is only for backward-compatibility.
      if not section_category:
319 320
        section_category = self._getPortalConfiguration(
                                  'portal_default_section_category')
321

322 323
      return section_category

324 325
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalResourceTypeList')
326 327 328 329
    def getPortalResourceTypeList(self):
      """
        Return resource types.
      """
330 331
      return self._getPortalGroupedTypeList('resource') or\
             self._getPortalConfiguration('portal_resource_type_list')
332

333 334
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalSubVariationTypeList')
335 336 337 338 339 340
    def getPortalSubVariationTypeList(self):
      """
        Return resource types.
      """
      return self._getPortalGroupedTypeList('sub_variation')

341
    security.declareProtected(Permissions.AccessContentsInformation,
342
                              'getPortalSubVariationBaseCategoryList')
343 344 345 346 347 348
    def getPortalSubVariationBaseCategoryList(self):
      """
        Return variation base categories.
      """
      return self._getPortalGroupedCategoryList('sub_variation')

349 350
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalVariationTypeList')
351 352 353 354
    def getPortalVariationTypeList(self):
      """
        Return variation types.
      """
355 356
      return self._getPortalGroupedTypeList('variation') or\
             self._getPortalConfiguration('portal_variation_type_list')
357

358 359
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalNodeTypeList')
360 361 362 363
    def getPortalNodeTypeList(self):
      """
        Return node types.
      """
364 365 366 367 368 369 370 371 372 373 374
      return self._getPortalGroupedTypeList('node') or\
             self._getPortalConfiguration('portal_node_type_list')

    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalPaymentNodeTypeList')
    def getPortalPaymentNodeTypeList(self):
      """
        Return payment node types.
      """
      return self._getPortalGroupedTypeList('payment_node') or\
             self._getPortalConfiguration('portal_payment_node_type_list')
375

376 377
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalInvoiceTypeList')
378 379 380 381
    def getPortalInvoiceTypeList(self):
      """
        Return invoice types.
      """
382 383
      return self._getPortalGroupedTypeList('invoice') or\
             self._getPortalConfiguration('portal_invoice_type_list')
384

385 386
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalOrderTypeList')
387 388 389 390
    def getPortalOrderTypeList(self):
      """
        Return order types.
      """
391 392
      return self._getPortalGroupedTypeList('order') or\
             self._getPortalConfiguration('portal_order_type_list')
393

394 395
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalDeliveryTypeList')
396 397 398 399
    def getPortalDeliveryTypeList(self):
      """
        Return delivery types.
      """
400 401
      return self._getPortalGroupedTypeList('delivery') or\
             self._getPortalConfiguration('portal_delivery_type_list')
402

403
    security.declareProtected(Permissions.AccessContentsInformation,
404 405 406 407 408
                              'getPortalTransformationTypeList')
    def getPortalTransformationTypeList(self):
      """
        Return transformation types.
      """
409 410
      return self._getPortalGroupedTypeList('transformation') or\
             self._getPortalConfiguration('portal_transformation_type_list')
411

412 413
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalVariationBaseCategoryList')
414 415 416 417
    def getPortalVariationBaseCategoryList(self):
      """
        Return variation base categories.
      """
418 419
      return self._getPortalGroupedCategoryList('variation') or\
             self._getPortalConfiguration('portal_variation_base_category_list')
420

421 422 423 424 425 426
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalOptionBaseCategoryList')
    def getPortalOptionBaseCategoryList(self):
      """
        Return option base categories.
      """
427 428
      return self._getPortalGroupedCategoryList('option') or\
             self._getPortalConfiguration('portal_option_base_category_list')
429

430 431
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalInvoiceMovementTypeList')
432 433 434 435
    def getPortalInvoiceMovementTypeList(self):
      """
        Return invoice movement types.
      """
436 437
      return self._getPortalGroupedTypeList('invoice_movement') or\
             self._getPortalConfiguration('portal_invoice_movement_type_list')
438

439 440
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalOrderMovementTypeList')
441 442 443 444
    def getPortalOrderMovementTypeList(self):
      """
        Return order movement types.
      """
445 446
      return self._getPortalGroupedTypeList('order_movement') or\
             self._getPortalConfiguration('portal_order_movement_type_list')
447

448 449
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalDeliveryMovementTypeList')
450 451 452 453
    def getPortalDeliveryMovementTypeList(self):
      """
        Return delivery movement types.
      """
454 455
      return self._getPortalGroupedTypeList('delivery_movement') or\
             self._getPortalConfiguration('portal_delivery_movement_type_list')
456

457 458
    security.declareProtected(Permissions.AccessContentsInformation,
                               'getPortalSupplyTypeList')
459 460
    def getPortalSupplyTypeList(self):
      """
Sebastien Robin's avatar
Sebastien Robin committed
461
        Return supply types.
462
      """
463 464
      return self._getPortalGroupedTypeList('supply') or\
             self._getPortalConfiguration('portal_supply_type_list')
465

466
    security.declareProtected(Permissions.AccessContentsInformation,
467 468
                               'getPortalSupplyPathTypeList')
    def getPortalSupplyPathTypeList(self):
469 470 471
      """
        Return supply movement types.
      """
472 473
      return self._getPortalGroupedTypeList('supply_path') or\
             self._getPortalConfiguration('portal_supply_path_type_list')
474

475 476
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalAcquisitionMovementTypeList')
477 478 479 480
    def getPortalAcquisitionMovementTypeList(self):
      """
        Return acquisition movement types.
      """
481 482
      return tuple(list(self.getPortalOrderMovementTypeList()) +
                   list(self.getPortalDeliveryMovementTypeList()) +
483
                   list(self.getPortalInvoiceMovementTypeList()))
484

485 486
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalMovementTypeList')
487 488 489 490
    def getPortalMovementTypeList(self):
      """
        Return movement types.
      """
491 492 493 494
      return tuple(list(self.getPortalOrderMovementTypeList()) +
                   list(self.getPortalDeliveryMovementTypeList()) +
                   list(self.getPortalInvoiceMovementTypeList()) +
                   ['Simulation Movement'])
495

496 497
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalSimulatedMovementTypeList')
498 499 500 501
    def getPortalSimulatedMovementTypeList(self):
      """
        Return simulated movement types.
      """
502 503
      return tuple([x for x in self.getPortalMovementTypeList()\
                     if x not in self.getPortalContainerTypeList()])
504

505 506
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalContainerTypeList')
507 508 509 510
    def getPortalContainerTypeList(self):
      """
        Return container types.
      """
511 512
      return self._getPortalGroupedTypeList('container') or\
             self._getPortalConfiguration('portal_container_type_list')
513

514 515
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalContainerLineTypeList')
516 517 518 519
    def getPortalContainerLineTypeList(self):
      """
        Return container line types.
      """
520 521
      return self._getPortalGroupedTypeList('container_line') or\
             self._getPortalConfiguration('portal_container_line_type_list')
522

523 524
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalItemTypeList')
525 526 527 528
    def getPortalItemTypeList(self):
      """
        Return item types.
      """
529 530
      return self._getPortalGroupedTypeList('item') or\
             self._getPortalConfiguration('portal_item_type_list')
531

532 533
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalDiscountTypeList')
534 535 536 537
    def getPortalDiscountTypeList(self):
      """
        Return discount types.
      """
538 539
      return self._getPortalGroupedTypeList('discount') or\
             self._getPortalConfiguration('portal_discount_type_list')
540

541 542
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalAlarmTypeList')
543 544 545 546
    def getPortalAlarmTypeList(self):
      """
        Return alarm types.
      """
547 548
      return self._getPortalGroupedTypeList('alarm') or\
             self._getPortalConfiguration('portal_alarm_type_list')
549

550 551
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalPaymentConditionTypeList')
552 553 554 555
    def getPortalPaymentConditionTypeList(self):
      """
        Return payment condition types.
      """
556 557
      return self._getPortalGroupedTypeList('payment_condition') or\
             self._getPortalConfiguration('portal_payment_condition_type_list')
558

559 560
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalBalanceTransactionLineTypeList')
561 562 563 564
    def getPortalBalanceTransactionLineTypeList(self):
      """
        Return balance transaction line types.
      """
565 566 567
      return self._getPortalGroupedTypeList('balance_transaction_line') or\
             self._getPortalConfiguration(
                    'portal_balance_transaction_line_type_list')
568

569 570
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalCurrentInventoryStateList')
571 572 573 574
    def getPortalCurrentInventoryStateList(self):
      """
        Return current inventory states.
      """
575 576
      return self._getPortalGroupedStateList('current_inventory') or\
            self._getPortalConfiguration('portal_current_inventory_state_list')
577

578 579
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalDraftOrderStateList')
580 581 582 583
    def getPortalDraftOrderStateList(self):
      """
        Return draft order states.
      """
584 585
      return self._getPortalGroupedStateList('draft_order') or\
             self._getPortalConfiguration('portal_draft_order_state_list')
586

587 588
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalPlannedOrderStateList')
589 590 591 592
    def getPortalPlannedOrderStateList(self):
      """
        Return planned order states.
      """
593 594
      return self._getPortalGroupedStateList('planned_order') or\
             self._getPortalConfiguration('portal_planned_order_state_list')
595

596 597
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalReservedInventoryStateList')
598 599 600 601
    def getPortalReservedInventoryStateList(self):
      """
        Return reserved inventory states.
      """
602 603
      return self._getPortalGroupedStateList('reserved_inventory') or\
          self._getPortalConfiguration('portal_reserved_inventory_state_list')
604

605 606
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalFutureInventoryStateList')
607 608 609 610
    def getPortalFutureInventoryStateList(self):
      """
        Return future inventory states.
      """
611 612
      return self._getPortalGroupedStateList('future_inventory') or\
             self._getPortalConfiguration('portal_future_inventory_state_list')
613

614 615 616 617 618 619 620
    security.declareProtected(Permissions.AccessContentsInformation, 'getPortalUpdatableAmortisationTransactionStateList')
    def getPortalUpdatableAmortisationTransactionStateList(self):
      """
        Return states when Amortisation Transaction can be updated by amortisation_transaction_builder.
      """
      return self._getPortalConfiguration('portal_updatable_amortisation_transaction_state_list')

621 622
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalColumnBaseCategoryList')
623 624 625 626
    def getPortalColumnBaseCategoryList(self):
      """
        Return column base categories.
      """
627 628
      return self._getPortalGroupedCategoryList('column') or\
             self._getPortalConfiguration('portal_column_base_category_list')
629

630 631
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalLineBaseCategoryList')
632 633 634 635
    def getPortalLineBaseCategoryList(self):
      """
        Return line base categories.
      """
636 637
      return self._getPortalGroupedCategoryList('line') or\
             self._getPortalConfiguration('portal_line_base_category_list')
638

639 640
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalTabBaseCategoryList')
641 642 643 644
    def getPortalTabBaseCategoryList(self):
      """
        Return tab base categories.
      """
645 646
      return self._getPortalGroupedCategoryList('tab') or\
             self._getPortalConfiguration('portal_tab_base_category_list')
647

648 649 650 651
    def getPortalDefaultGapRoot(self):
      """
        Return the Accounting Plan to use by default (return the root node)
      """
652 653
      LOG('ERP5Site', 0, 'getPortalDefaultGapRoot is deprecated;'+
       ' use portal_preferences.getPreferredAccountingTransactionGap instead.')
654

655 656
      return self.portal_preferences.getPreferredAccountingTransactionGap() or\
             self._getPortalConfiguration('portal_default_gap_root')
657

658
    def getPortalAccountingMovementTypeList(self) :
659 660 661
      """
        Return accounting movement type list.
      """
662 663
      return self._getPortalGroupedTypeList('accounting_movement') or\
          self._getPortalConfiguration('portal_accounting_movement_type_list')
664

665 666 667 668
    def getPortalAccountingTransactionTypeList(self) :
      """
        Return accounting transaction movement type list.
      """
669 670
      return self._getPortalGroupedTypeList('accounting_transaction') or\
        self._getPortalConfiguration('portal_accounting_transaction_type_list')
671

672
    def getPortalAssignmentBaseCategoryList(self):
673
      """
674 675
        Return List of category values to generate security groups.
      """
676
      ### Here is the filter patch waiting bug #124 to be corrected
677 678
      category_list = self._getPortalGroupedCategoryList('assignment') or\
          self._getPortalConfiguration('portal_assignment_base_category_list')
679 680 681 682 683
      clean_list = []
      for cat in category_list:
        if cat.find("_btsave") == -1:
          clean_list.append(cat)
      return clean_list
684

685 686
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getDefaultModuleId')
687 688
    def getDefaultModuleId(self, portal_type):
      """
689
        Return default module id where a object with portal_type can
Romain Courteaud's avatar
Romain Courteaud committed
690
        be created.
691
      """
Romain Courteaud's avatar
Romain Courteaud committed
692
      # Very dummy method, but it works with today name convention.
693 694 695 696 697
      module_name = portal_type.lower().replace(' ','_')
      portal_object = self
      if not hasattr(portal_object, module_name):
        module_name += '_module'
        if not hasattr(portal_object, module_name):
Romain Courteaud's avatar
Romain Courteaud committed
698 699 700
          LOG('ERP5Site, getDefaultModuleId', 0,
              'Unable to find default module for portal_type: %s' % \
                  portal_type)
701 702
          raise ValueError, 'Unable to find module for portal_type: %s' % \
                            portal_type
703 704
      return module_name

705 706
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getDefaultModule')
707 708 709 710 711 712
    def getDefaultModule(self, portal_type):
      """
        Return default module where a object with portal_type can be created
      """
      return getattr(self, self.getDefaultModuleId(portal_type), None)

713 714 715 716 717 718 719
    security.declareProtected(Permissions.AddPortalContent, 'newContent')
    def newContent(self, id=None, portal_type=None, immediate_reindex=0, **kw):
      """
        Creates a new content
      """
      if id is None:
        raise ValueError, 'The id should not be None'
720
      if portal_type is None:
721 722 723 724 725 726 727 728 729 730
        raise ValueError, 'The portal_type should not be None'
      self.portal_types.constructContent(type_name=portal_type,
                                         container=self,
                                         id=id,
                                         ) # **kw) removed due to CMF bug
      new_instance = self[id]
      if kw is not None: new_instance._edit(force_update=1, **kw)
      if immediate_reindex: new_instance.immediateReindexObject()
      return new_instance

731 732 733 734 735 736
    def log(self,description,content):
      """
      Put a log message
      """
      LOG(description,0,content)

737

Jean-Paul Smets's avatar
Jean-Paul Smets committed
738 739 740 741 742 743
Globals.InitializeClass(ERP5Site)

class ERP5Generator(PortalGenerator):

    klass = ERP5Site

744 745 746 747 748 749 750
    def getBootstrapDirectory(self):
        """
          Return the name of the bootstrap directory
        """
        product_path = package_home(globals())
        return os.path.join(product_path, 'bootstrap')

751 752 753
    def create(self, parent, id, create_userfolder,
               erp5_sql_connection_type, erp5_sql_connection_string,
               cmf_activity_sql_connection_type,cmf_activity_sql_connection_string,
Sebastien Robin's avatar
Sebastien Robin committed
754
               reindex=1,**kw):
755
        LOG('setupTools, create',0,kw)
756 757
        id = str(id)
        portal = self.klass(id=id)
Sebastien Robin's avatar
Sebastien Robin committed
758 759
        if reindex==0:
          setattr(portal,'isIndexable',0)
760 761 762
        parent._setObject(id, portal)
        # Return the fully wrapped object.
        p = parent.this()._getOb(id)
763 764 765 766
        p._setProperty('erp5_sql_connection_type', erp5_sql_connection_type, 'string')
        p._setProperty('erp5_sql_connection_string', erp5_sql_connection_string, 'string')
        p._setProperty('cmf_activity_sql_connection_type', cmf_activity_sql_connection_type, 'string')
        p._setProperty('cmf_activity_sql_connection_string', cmf_activity_sql_connection_string, 'string')
767
        p._setProperty('management_page_charset', 'UTF-8', 'string') # XXX hardcoded charset
768
        self.setup(p, create_userfolder,**kw)
769 770
        return p

771
    def setupLastTools(self, p, **kw):
772 773 774 775 776
        """Set up finals tools
           We want to set the activity tool only at the end to
           make sure that we do not put un the queue the full reindexation
        """
        # Add Activity Tool
777
        #LOG('setupTools, kw',0,kw)
778
        if kw.has_key('create_activities') and int(kw['create_activities'])==1:
779 780 781
          if not p.hasObject('portal_activities'):
            addTool = p.manage_addProduct['CMFActivity'].manage_addTool
            addTool('CMF Activity Tool', None) # Allow user to select active/passive
782 783 784 785 786 787 788 789
          # Initialize Activities
          portal_activities = getToolByName(p, 'portal_activities', None)
          if portal_activities is not None:
            if kw.get('update', 0):
              keep = 1
            else:
              keep = 0
            portal_activities.manageClearActivities(keep=keep)
790

Yoshinori Okuji's avatar
Yoshinori Okuji committed
791 792 793 794 795 796 797 798 799
    def setupTemplateTool(self, p, **kw):
      """Setup the Template Tool. Security must be set strictly.
      """
      addTool = p.manage_addProduct['ERP5'].manage_addTool
      addTool('ERP5 Template Tool', None)
      context = p.portal_templates
      permission_list = context.possible_permissions()
      for permission in permission_list:
        context.manage_permission(permission, ['Manager'], 0)
800

801
    def setupTools(self, p,**kw):
Jean-Paul Smets's avatar
Jean-Paul Smets committed
802
        """Set up initial tools"""
803

804 805
        if not 'portal_actions' in p.objectIds():
          PortalGenerator.setupTools(self, p)
Jean-Paul Smets's avatar
Jean-Paul Smets committed
806

807
        # It is better to remove portal_catalog which is ZCatalog as soon as possible,
808
        # because the API is not the completely same as ERP5Catalog, and ZCatalog is
809
        # useless for ERP5 after all.
810
        update = kw.get('update', 0)
811
        portal_catalog = getToolByName(p, 'portal_catalog', None)
812
        if portal_catalog is not None and portal_catalog.meta_type != 'ZSQLCatalog' and not update:
813
          p._delObject('portal_catalog')
814

Yoshinori Okuji's avatar
Yoshinori Okuji committed
815
        # Add CMF Report Tool
Aurel's avatar
Aurel committed
816 817 818
        if not p.hasObject('portal_report'):
          addTool = p.manage_addProduct['CMFReportTool'].manage_addTool
          addTool('CMF Report Tool', None)
Yoshinori Okuji's avatar
Yoshinori Okuji committed
819

Jean-Paul Smets's avatar
Jean-Paul Smets committed
820 821
        # Add ERP5 Tools
        addTool = p.manage_addProduct['ERP5'].manage_addTool
822 823 824 825 826 827 828 829 830 831 832 833
        if not p.hasObject('portal_categories'):
          addTool('ERP5 Categories', None)
        if not p.hasObject('portal_rules'):
          addTool('ERP5 Rule Tool', None)
        if not p.hasObject('portal_ids'):
          addTool('ERP5 Id Tool', None)
        if not p.hasObject('portal_simulation'):
          addTool('ERP5 Simulation Tool', None)
        if not p.hasObject('portal_templates'):
          self.setupTemplateTool(p)
        if not p.hasObject('portal_trash'):
          addTool('ERP5 Trash Tool', None)
Aurel's avatar
Aurel committed
834
        if not p.hasObject('portal_alarms'):
835 836 837 838 839 840 841
          addTool('ERP5 Alarm Tool', None)
        if not p.hasObject('portal_domains'):
          addTool('ERP5 Domain Tool', None)
        if not p.hasObject('portal_deliveries'):
          addTool('ERP5 Delivery Tool', None)
        if not p.hasObject('portal_orders'):
          addTool('ERP5 Order Tool', None)
842 843 844

        # Add ERP5Type Tools
        addTool = p.manage_addProduct['ERP5Type'].manage_addTool
845 846 847 848 849
        if not p.hasObject('portal_classes'):
          if allowClassTool():
            addTool('ERP5 Class Tool', None)
          else:
            addTool('ERP5 Dummy Class Tool', None)
850

Jean-Paul Smets's avatar
Jean-Paul Smets committed
851 852
        # Add ERP5 SQL Catalog Tool
        addTool = p.manage_addProduct['ERP5Catalog'].manage_addTool
853 854
        if not p.hasObject('portal_catalog'):
          addTool('ERP5 Catalog', None)
Jean-Paul Smets's avatar
Jean-Paul Smets committed
855
        # Add Default SQL connection
856
        if p.erp5_sql_connection_type == 'Z MySQL Database Connection':
857 858 859
          if not p.hasObject('erp5_sql_connection'):
            addSQLConnection = p.manage_addProduct['ZSQLMethods'].manage_addZMySQLConnection
            addSQLConnection('erp5_sql_connection', 'ERP5 SQL Server Connection', p.erp5_sql_connection_string)
860 861 862
        elif p.erp5_sql_connection_type == 'Z Gadfly':
          pass
        if p.cmf_activity_sql_connection_type == 'Z MySQL Database Connection':
863 864 865
          if not p.hasObject('cmf_activity_sql_connection'):
            addSQLConnection = p.manage_addProduct['ZSQLMethods'].manage_addZMySQLConnection
            addSQLConnection('cmf_activity_sql_connection', 'CMF Activity SQL Server Connection', p.cmf_activity_sql_connection_string)
866
        elif p.cmf_activity_sql_connection_type == 'Z Gadfly':
867
          pass
Jean-Paul Smets's avatar
Jean-Paul Smets committed
868 869
        # Create default methods in Catalog XXX
        portal_catalog = getToolByName(p, 'portal_catalog')
870 871 872
        if not portal_catalog.getSQLCatalog('erp5_mysql') and not update:
            # FIXME: addDefaultSQLMethods should be removed.
            portal_catalog.addDefaultSQLMethods('erp5_mysql')
873

Sebastien Robin's avatar
Sebastien Robin committed
874 875
            # Clear Catalog
            portal_catalog.manage_catalogClear()
876

877
        # Add ERP5Form Tools
Jean-Paul Smets's avatar
Jean-Paul Smets committed
878
        addTool = p.manage_addProduct['ERP5Form'].manage_addTool
879 880 881 882
        if not p.hasObject('portal_selections'):
          addTool('ERP5 Selections', None)
        if not p.hasObject('portal_preferences'):
          addTool('ERP5 Preference Tool', None)
883

Jean-Paul Smets's avatar
Jean-Paul Smets committed
884 885
        # Add ERP5SyncML Tools
        addTool = p.manage_addProduct['ERP5SyncML'].manage_addTool
886 887
        if not p.hasObject('portal_synchronizations'):
          addTool('ERP5 Synchronizations', None)
Jean-Paul Smets's avatar
Jean-Paul Smets committed
888

889
        # Add Message Catalog
Sebastien Robin's avatar
Sebastien Robin committed
890 891 892 893 894 895
        #if 'Localizer' in p.objectIds():
          #p._delObject('Localizer') # Why delete it, we should keep for ERP5/CPS
        if not 'Localizer' in p.objectIds():
          #p._delObject('Localizer') # Why delete it, we should keep for ERP5/CPS
          addLocalizer = p.manage_addProduct['Localizer'].manage_addLocalizer
          addLocalizer('', ('en',))
896 897
        localizer = getToolByName(p, 'Localizer')
        addMessageCatalog = localizer.manage_addProduct['Localizer'].manage_addMessageCatalog
898 899 900 901 902 903
        if 'erp5_ui' not in localizer.objectIds():
          if 'default' in localizer.objectIds():
            localizer.manage_delObjects('default')
          addMessageCatalog('default', 'ERP5 Localized Messages', ('en',))
          addMessageCatalog('erp5_ui', 'ERP5 Localized Interface', ('en',))
          addMessageCatalog('erp5_content', 'ERP5 Localized Content', ('en',))
904

Jean-Paul Smets's avatar
Jean-Paul Smets committed
905

906 907 908 909 910 911 912 913 914 915 916
    def setupMembersFolder(self, p):
        """
          ERP5 is not a CMS
        """
        pass

    def setupDefaultSkins(self, p):
        from Products.CMFCore.DirectoryView import addDirectoryViews
        from Products.CMFDefault import cmfdefault_globals
        from Products.CMFActivity import cmfactivity_globals
        ps = getToolByName(p, 'portal_skins')
917 918 919
        # Do not use filesystem skins for ERP5 any longer.
        # addDirectoryViews(ps, 'skins', globals())
        # addDirectoryViews(ps, path.join('skins','pro'), globals())
920 921 922
        addDirectoryViews(ps, 'skins', cmfdefault_globals)
        addDirectoryViews(ps, 'skins', cmfactivity_globals)
        ps.manage_addProduct['OFSP'].manage_addFolder(id='external_method')
923
        ps.manage_addProduct['OFSP'].manage_addFolder(id='custom')
924
        # set the 'custom' layer a high priority, so it remains the first
925 926 927
        # layer when installing new business templates
        ps['custom'].manage_addProperty(
            "business_template_skin_layer_priority", 100.0, "float")
928
        ps.addSkinSelection('View', 'custom, external_method, activity, '
929
                                  + 'zpt_content, zpt_generic,'
930
                                  + 'zpt_control, content, generic, control, Images',
931
                            make_default=1)
932 933 934
        ps.addSkinSelection('Print', 'custom, external_method, activity, '
                                  + 'zpt_content, zpt_generic,'
                                  + 'zpt_control, content, generic, control, Images',
Romain Courteaud's avatar
Romain Courteaud committed
935 936 937 938
                            make_default=0)
        ps.addSkinSelection('CSV', 'custom, external_method, activity, '
                                  + 'zpt_content, zpt_generic,'
                                  + 'zpt_control, content, generic, control, Images',
939
                            make_default=0)
940 941 942 943
        p.setupCurrentSkin()

    def setupWorkflow(self, p):
        """
944
          Set up workflows for business templates
945
        """
946 947 948
        tool = getToolByName(p, 'portal_workflow', None)
        if tool is None:
            return
949 950 951
        for wf_id in ('business_template_building_workflow', 'business_template_installation_workflow'):
          if wf_id in tool.objectIds():
            tool.manage_delObjects([wf_id])
952 953 954 955 956 957 958 959 960 961
        bootstrap_dir = self.getBootstrapDirectory()
        business_template_building_workflow = os.path.join(bootstrap_dir,
                                                           'business_template_building_workflow.xml')
        tool._importObjectFromFile(business_template_building_workflow)
        business_template_installation_workflow = os.path.join(bootstrap_dir,
                                                               'business_template_installation_workflow.xml')
        tool._importObjectFromFile(business_template_installation_workflow)
        tool.setChainForPortalTypes( ( 'Business Template', ),
                                     ( 'business_template_building_workflow',
                                       'business_template_installation_workflow' ) )
962 963
        pass

964
    def setupIndex(self, p, **kw):
965
        # Make sure all tools and folders have been indexed
Sebastien Robin's avatar
Sebastien Robin committed
966 967
        if kw.has_key('reindex') and kw['reindex']==0:
          return
968 969 970
        skins_tool = getToolByName(p, 'portal_skins', None)
        if skins_tool is None:
          return
971
        portal_catalog = p.portal_catalog
Sebastien Robin's avatar
Sebastien Robin committed
972
        portal_catalog.manage_catalogClear()
973
        skins_tool["erp5_core"].ERP5Site_reindexAll()
974

975
    def setupUserFolder(self, p):
976
        # We use if possible ERP5Security, then NuxUserGroups
977
        try:
978
          from Products import ERP5Security
979
          from Products import PluggableAuthService
980 981 982 983 984 985 986
        except ImportError:
          ERP5Security = None
          try:
            import Products.NuxUserGroups
            withnuxgroups = 1
          except:
            withnuxgroups = 0
Jean-Paul Smets's avatar
Jean-Paul Smets committed
987
        if ERP5Security is not None:
988 989
          # Use Pluggable Auth Service instead of the standard acl_users.
          p.manage_addProduct['PluggableAuthService'].addPluggableAuthService()
990 991 992 993
          # Add legacy ZODB support
          p.acl_users.manage_addProduct['PluggableAuthService'].addZODBUserManager('zodb_users')
          p.acl_users.manage_addProduct['PluggableAuthService'].addZODBGroupManager('zodb_groups')
          p.acl_users.manage_addProduct['PluggableAuthService'].addZODBRoleManager('zodb_roles')
994 995 996 997
          # Add CMF Portal Roles
          #XXX Maybe it will no longer be required once PAS is the standard
          p.acl_users.zodb_roles.addRole('Member')
          p.acl_users.zodb_roles.addRole('Reviewer')
998 999 1000 1001 1002 1003 1004
          # Register ZODB Interface
          p.acl_users.zodb_users.manage_activateInterfaces(('IAuthenticationPlugin',
                                                        'IUserEnumerationPlugin','IUserAdderPlugin'))
          p.acl_users.zodb_groups.manage_activateInterfaces(('IGroupsPlugin',
                                                        'IGroupEnumerationPlugin'))
          p.acl_users.zodb_roles.manage_activateInterfaces(('IRoleEnumerationPlugin',
                                                        'IRolesPlugin', 'IRoleAssignerPlugin'))
1005 1006 1007 1008
          # Add ERP5UserManager
          p.acl_users.manage_addProduct['ERP5Security'].addERP5UserManager('erp5_users')
          p.acl_users.manage_addProduct['ERP5Security'].addERP5GroupManager('erp5_groups')
          p.acl_users.manage_addProduct['ERP5Security'].addERP5RoleManager('erp5_roles')
1009
          # Register ERP5UserManager Interface
1010
          p.acl_users.erp5_users.manage_activateInterfaces(('IAuthenticationPlugin',
1011 1012 1013
                                                            'IUserEnumerationPlugin',))
          p.acl_users.erp5_groups.manage_activateInterfaces(('IGroupsPlugin',))
          p.acl_users.erp5_roles.manage_activateInterfaces(('IRolesPlugin',))
1014 1015
        elif withnuxgroups:
          # NuxUserGroups user folder
1016
          p.manage_addProduct['NuxUserGroups'].addUserFolderWithGroups()
1017 1018
        else:
          # Standard user folder
1019 1020
          PortalGenerator.setupUserFolder(self, p)

1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039
    def setupPermissions(self, p):
      permission_dict = {
        'Access Transient Objects'     : ('Manager', 'Anonymous'),
        'Access contents information'  : ('Manager', 'Member', 'Anonymous'),
        'Access future portal content' : ('Manager', 'Reviewer'),
        'Access session data'          : ('Manager', 'Anonymous'),
        'AccessContentsInformation'    : ('Manager', 'Member'),
        'Add portal content'           : ('Manager', 'Owner'),
        'Add portal folders'           : ('Manager', 'Owner'),
        'Delete objects'               : ('Manager', 'Owner'),
        'FTP access'                   : ('Manager', 'Owner'),
        'List folder contents'         : ('Manager', 'Member'),
        'List portal members'          : ('Manager', 'Member'),
        'List undoable changes'        : ('Manager', 'Member'),
        'Manage properties'            : ('Manager', 'Owner'),
        'Modify portal content'        : ('Manager', 'Owner'),
        'Reply to item'                : ('Manager', 'Member'),
        'Review portal content'        : ('Manager', 'Reviewer'),
        'Search ZCatalog'              : ('Manager', 'Member'),
1040
        'Set own password'             : ('Manager',),
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
        'Set own properties'           : ('Manager', 'Member'),
        'Undo changes'                 : ('Manager', 'Owner'),
        'View'                         : ('Manager', 'Member', 'Owner', 'Anonymous'),
        'View management screens'      : ('Manager', 'Owner')
      }

      for permission in p.ac_inherited_permissions(1):
        name = permission[0]
        role_list = permission_dict.get(name, ('Manager',))
        p.manage_permission(name, roles=role_list, acquire=0)

1052 1053
    def setup(self, p, create_userfolder, **kw):
        update = kw.get('update', 0)
Aurel's avatar
Aurel committed
1054

1055
        self.setupTools(p, **kw)
1056

1057 1058
        if not p.hasObject('MailHost'):
          self.setupMailHost(p)
1059

1060
        if int(create_userfolder) != 0 and not p.hasObject('acl_users'):
1061 1062
            self.setupUserFolder(p)

1063 1064 1065 1066 1067
        if not p.hasObject('cookie_authentication'):
          self.setupCookieAuth(p)

        if 'Member' not in getattr(p, '__ac_roles__', ()):
          self.setupRoles(p)
1068

1069 1070 1071 1072 1073
        if not update:
          self.setupPermissions(p)
          self.setupDefaultSkins(p)

        self.setupLastTools(p, **kw)
1074

1075
        # Finish setup
1076 1077
        if not p.hasObject('Members'):
          self.setupMembersFolder(p)
1078 1079 1080

        # ERP5 Design Choice is that all content should be user defined
        # Content is disseminated through business templates
1081
        self.setupBusinessTemplate(p)
1082

1083 1084
        if not p.hasObject('content_type_registry'):
          self.setupMimetypes(p)
Aurel's avatar
Aurel committed
1085 1086
        if not update:
          self.setupWorkflow(p)
1087

1088 1089
        if not update:
          self.setupERP5Core(p,**kw)
1090

1091 1092
        # Make sure tools are cleanly indexed with a uid before creating children
        # XXX for some strange reason, member was indexed 5 times
1093 1094
        if not update:
          self.setupIndex(p, **kw)
Jean-Paul Smets's avatar
Jean-Paul Smets committed
1095

1096 1097 1098 1099
    def setupBusinessTemplate(self,p):
        """
        Install the portal_type of Business Template
        """
1100 1101 1102
        tool = getToolByName(p, 'portal_types', None)
        if tool is None:
          return
1103 1104 1105 1106
        if 'Business Template' not in tool.objectIds():
          t = BusinessTemplate.factory_type_information
          ti = apply(ERP5TypeInformation, (), t)
          tool._setObject(t['id'], ti)
1107

Sebastien Robin's avatar
Sebastien Robin committed
1108
    def setupERP5Core(self,p,**kw):
1109 1110 1111 1112 1113 1114
        """
        Install the core part of ERP5
        """
        template_tool = getToolByName(p, 'portal_templates', None)
        if template_tool is None:
          return
1115 1116
        if template_tool.getInstalledBusinessTemplate('erp5_core') is None:
          bootstrap_dir = self.getBootstrapDirectory()
1117 1118 1119 1120 1121 1122 1123 1124
          for bt in ('erp5_core','erp5_html_style'):
            template = os.path.join(bootstrap_dir, bt)
            if not os.path.exists(template):
              template = os.path.join(bootstrap_dir, '%s.bt5' % bt)

            id = template_tool.generateNewId()
            template_tool.download(template, id=id)
            template_tool[id].install(**kw)
1125

Jean-Paul Smets's avatar
Jean-Paul Smets committed
1126
# Patch the standard method
Sebastien Robin's avatar
Sebastien Robin committed
1127
CMFSite.getPhysicalPath = ERP5Site.getPhysicalPath