ERP5Site.py 46 KB
Newer Older
1
##############################################################################
Jean-Paul Smets's avatar
Jean-Paul Smets committed
2 3 4 5 6 7 8 9 10 11 12
#
# 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
#
##############################################################################
13 14
"""
  Portal class
Jean-Paul Smets's avatar
Jean-Paul Smets committed
15 16 17 18
"""

import Globals
from Globals import package_home
19

Jean-Paul Smets's avatar
Jean-Paul Smets committed
20 21 22 23
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
24
from Products.ERP5Type.Document.Folder import FolderMixIn
25
from Products.ERP5Type.Document import addFolder
Jean-Paul Smets's avatar
Jean-Paul Smets committed
26
from Acquisition import aq_base, aq_parent, aq_inner, aq_acquire
27
from Products.ERP5Type import allowClassTool
28
from Products.ERP5Type.Cache import CachingMethod
29 30
from Products.ERP5Type.ERP5Type import ERP5TypeInformation
from Products.ERP5.Document.BusinessTemplate import BusinessTemplate
31

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

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

import os
39 40
MARKER = []

41

Jean-Paul Smets's avatar
Jean-Paul Smets committed
42 43

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

# ERP5Site Constructor
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
def manage_addERP5Site( self
                      , id
                      , title                               = 'ERP5'
                      , description                         = ''
                      , create_userfolder                   = 1
                      , create_activities                   = 1
                      , email_from_address                  = 'postmaster@localhost'
                      , email_from_name                     = 'Portal Administrator'
                      , validate_email                      = 0
                      , erp5_sql_connection_type            = 'Z MySQL Database Connection'
                      , erp5_sql_connection_string          = 'test test'
                      , erp5_sql_deferred_connection_type   = 'Z MySQL Deferred Database Connection'
                      , erp5_sql_deferred_connection_string = 'test test'
                      , cmf_activity_sql_connection_type    = 'Z MySQL Database Connection'
                      , cmf_activity_sql_connection_string  = 'test test'
63
                      , light_install                       = 0
64 65 66
                      , reindex                             = 1
                      , RESPONSE                            = None
                      ):
67
  """
Jean-Paul Smets's avatar
Jean-Paul Smets committed
68
    Adds a portal instance.
69 70
  """
  gen = ERP5Generator()
71 72 73 74 75 76 77 78 79 80 81
  id = str(id).strip()
  p = gen.create( self
                , id
                , create_userfolder
                , erp5_sql_connection_type
                , erp5_sql_connection_string
                , erp5_sql_deferred_connection_type
                , erp5_sql_deferred_connection_string
                , cmf_activity_sql_connection_type
                , cmf_activity_sql_connection_string
                , create_activities
82 83
                , light_install = light_install
                , reindex       = reindex
84 85 86 87 88 89 90 91
                )
  gen.setupDefaultProperties( p
                            , title
                            , description
                            , email_from_address
                            , email_from_name
                            , validate_email
                            )
92
  if RESPONSE is not None:
93 94 95
    RESPONSE.redirect(p.absolute_url())


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

97
class ERP5Site(FolderMixIn, CMFSite):
98 99
  """
    The *only* function this class should have is to help in the setup
100
    of a new ERP5. It should not assist in the functionality at all.
101
  """
102
  meta_type    = 'ERP5 Site'
103
  constructors = (manage_addERP5SiteForm, manage_addERP5Site, )
104 105 106 107 108 109 110 111 112 113 114
  uid          = 0
  last_id      = 0
  icon         = 'portal.gif'

  _properties = ( { 'id'  : 'title'
                  , 'type': 'string'
                  }
                , { 'id'  : 'description'
                  , 'type': 'text'
                  }
                )
115 116 117 118 119 120 121
  title = ''
  description = ''

  # Declarative security
  security = ClassSecurityInfo()
  security.declareObjectProtected(Permissions.AccessContentsInformation)

122

123 124
  security.declareProtected(Permissions.View, 'view')
  def view(self):
125 126 127 128 129 130
    """
      Returns the default view.
      Implemented for consistency
    """
    return self.index_html()

131 132

  def hasObject(self, id):
133 134
    """
      Check if the portal has an id.
Jean-Paul Smets's avatar
Jean-Paul Smets committed
135
    """
136
    return id in self.objectIds()
137

138

139 140 141
  security.declareProtected(Permissions.AccessContentsInformation, 'getPortalObject')
  def getPortalObject(self):
    return self
Jean-Paul Smets's avatar
Jean-Paul Smets committed
142

143

144 145 146 147 148 149
  security.declareProtected(Permissions.AccessContentsInformation, 'getTitle')
  def getTitle(self):
    """
      Return the title.
    """
    return self.title
150

151

152 153 154 155 156 157
  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).
Jean-Paul Smets's avatar
Jean-Paul Smets committed
158

159 160 161
      WARNING : must be updates for circular references issues
    """
    return getattr(self, 'uid', 0)
Jean-Paul Smets's avatar
Jean-Paul Smets committed
162

163

164 165 166 167 168 169
  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
170

171

172 173 174 175
  # Required to allow content creation outside folders
  security.declareProtected(Permissions.View, 'getIdGroup')
  def getIdGroup(self):
    return None
Jean-Paul Smets's avatar
Jean-Paul Smets committed
176

177

178 179 180 181
  # Required to allow content creation outside folders
  security.declareProtected(Permissions.ModifyPortalContent, 'setLastId')
  def setLastId(self, id):
    self.last_id = id
Jean-Paul Smets's avatar
Jean-Paul Smets committed
182

183

184 185 186 187 188 189
  security.declareProtected(Permissions.AccessContentsInformation, 'getPath')
  def getPath(self, REQUEST=None):
    """
      Returns the absolute path of an object
    """
    return join(self.getPhysicalPath(),'/')
Sebastien Robin's avatar
Sebastien Robin committed
190

191

192 193 194 195 196 197 198 199 200
  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 = {}
201 202
    # Remove useless matter before calling the catalog. In particular, consider empty
    #   strings as None values.
203
    for cname in kw.keys():
204
      if kw[cname] not in ('', None):
205
        kw2[cname] = kw[cname]
206
    # The method to call to search the folder content has to be called z_search_folder.
207 208 209
    method = self.portal_catalog.searchResults
    return method(**kw2)

210

211 212 213 214 215 216 217 218 219
  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 = {}
220 221
    # Remove useless matter before calling the catalog. In particular, consider empty
    #   strings as None values
222
    for cname in kw.keys():
223
      if kw[cname] not in ('', None):
224
        kw2[cname] = kw[cname]
225
    # The method to call to search the folder content has to be called z_search_folder.
226 227 228
    method = self.portal_catalog.countResults
    return method(**kw2)

229

230 231 232 233 234 235 236 237
  # Proxy methods for security reasons
  def getOwnerInfo(self):
    return self.owner_info()


  security.declarePublic('getOrderedGlobalActionList')
  def getOrderedGlobalActionList(self, action_list):
    """
238 239
      Returns a dictionnary of actions, sorted by type of object.
      TODO: This should absolutely be rewritten by using clean concepts to separate worklists.
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
    """
    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])
    sorted_global_actions.append({'title': 'Others', 'disabled': 1})
    sorted_global_actions.extend(other_global_actions)
    return sorted_global_actions

261

262 263 264 265
  def setupDefaultProperties(self, p, title, description,
                              email_from_address, email_from_name,
                              validate_email
                              ):
266 267 268 269
    CMFSite.setupDefaultProperties(self, p, title, description,
                            email_from_address, email_from_name,
                            validate_email)

270 271

  # Portal methods are based on the concept of having portal-specific parameters
272 273
  #   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.
274 275 276
  def _getPortalConfiguration(self, id):
    """
      Get a portal-specific configuration.
277

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

281 282 283 284 285
      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)
286

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

290

291
  def _getPortalGroupedTypeList(self, group):
292 293
    """
      Return a list of portal types classified to a specific group.
294 295 296 297 298 299 300 301
    """
    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)

302 303 304 305
    getTypeList = CachingMethod( getTypeList
                               , id             = ('_getPortalGroupedTypeList', group)
                               , cache_duration = 3600
                               )
306 307
    return getTypeList(group)

308

309
  def _getPortalGroupedCategoryList(self, group):
310 311
    """
      Return a list of base categories classified to a specific group.
312 313 314 315 316 317 318 319
    """
    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)

320 321 322 323
    getCategoryList = CachingMethod( getCategoryList
                                   , id             = ('_getPortalGroupedCategoryList', group)
                                   , cache_duration = 3600
                                   )
324 325
    return getCategoryList(group)

326

327
  def _getPortalGroupedStateList(self, group):
328 329
    """
      Return a list of workflow states classified to a specific group.
330 331 332 333 334 335 336 337 338 339
    """
    def getStateList(group):
      state_dict = {}
      for wf in self.portal_workflow.objectValues():
        if getattr(wf, 'states', None):
          for state in wf.states.objectValues():
            if group in getattr(state, 'type_list', ()):
              state_dict[state.getId()] = None
      return tuple(state_dict.keys())

340 341 342 343
    getStateList = CachingMethod( getStateList
                                , id             = ('_getPortalGroupedStateList', group)
                                , cache_duration = 3600
                                )
344 345
    return getStateList(group)

346 347 348

  security.declareProtected( Permissions.AccessContentsInformation
                           , 'getPortalDefaultSectionCategory')
349 350 351 352 353 354 355 356 357 358 359 360
  def getPortalDefaultSectionCategory(self):
    """
      Return a default section category. This method is deprecated.
    """
    LOG('ERP5Site', 0, 'getPortalDefaultSectionCategory is deprecated;'+
        ' use portal_preferences.getPreferredSectionCategory instead.')
    section_category = self.portal_preferences.getPreferredSectionCategory()
    # XXX This is only for backward-compatibility.
    if not section_category:
      section_category = self._getPortalConfiguration(
                                'portal_default_section_category')
    return section_category
361

362

363 364 365 366 367 368
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalResourceTypeList')
  def getPortalResourceTypeList(self):
    """
      Return resource types.
    """
369 370 371
    return self._getPortalGroupedTypeList('resource') or \
           self._getPortalConfiguration('portal_resource_type_list')

372

373 374 375 376 377 378 379
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalSubVariationTypeList')
  def getPortalSubVariationTypeList(self):
    """
      Return resource types.
    """
    return self._getPortalGroupedTypeList('sub_variation')
380

381

382 383 384 385 386 387 388
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalSubVariationBaseCategoryList')
  def getPortalSubVariationBaseCategoryList(self):
    """
      Return variation base categories.
    """
    return self._getPortalGroupedCategoryList('sub_variation')
389

390

391 392 393 394 395 396
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalVariationTypeList')
  def getPortalVariationTypeList(self):
    """
      Return variation types.
    """
397 398 399
    return self._getPortalGroupedTypeList('variation') or \
           self._getPortalConfiguration('portal_variation_type_list')

400

401 402 403 404 405 406
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalNodeTypeList')
  def getPortalNodeTypeList(self):
    """
      Return node types.
    """
407 408 409
    return self._getPortalGroupedTypeList('node') or \
           self._getPortalConfiguration('portal_node_type_list')

410

411 412 413 414 415 416
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalPaymentNodeTypeList')
  def getPortalPaymentNodeTypeList(self):
    """
      Return payment node types.
    """
417 418 419
    return self._getPortalGroupedTypeList('payment_node') or \
           self._getPortalConfiguration('portal_payment_node_type_list')

420

421 422 423 424 425 426
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalInvoiceTypeList')
  def getPortalInvoiceTypeList(self):
    """
      Return invoice types.
    """
427 428 429
    return self._getPortalGroupedTypeList('invoice') or \
           self._getPortalConfiguration('portal_invoice_type_list')

430

431 432 433 434 435 436
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalOrderTypeList')
  def getPortalOrderTypeList(self):
    """
      Return order types.
    """
437 438 439
    return self._getPortalGroupedTypeList('order') or \
           self._getPortalConfiguration('portal_order_type_list')

440

441 442 443 444 445 446
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalDeliveryTypeList')
  def getPortalDeliveryTypeList(self):
    """
      Return delivery types.
    """
447 448 449
    return self._getPortalGroupedTypeList('delivery') or \
           self._getPortalConfiguration('portal_delivery_type_list')

450

451 452 453 454 455 456
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalTransformationTypeList')
  def getPortalTransformationTypeList(self):
    """
      Return transformation types.
    """
457 458 459
    return self._getPortalGroupedTypeList('transformation') or \
           self._getPortalConfiguration('portal_transformation_type_list')

460

461 462 463 464 465 466
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalVariationBaseCategoryList')
  def getPortalVariationBaseCategoryList(self):
    """
      Return variation base categories.
    """
467 468 469
    return self._getPortalGroupedCategoryList('variation') or \
           self._getPortalConfiguration('portal_variation_base_category_list')

470

471 472 473 474 475 476
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalOptionBaseCategoryList')
  def getPortalOptionBaseCategoryList(self):
    """
      Return option base categories.
    """
477 478 479
    return self._getPortalGroupedCategoryList('option') or \
           self._getPortalConfiguration('portal_option_base_category_list')

480

481 482 483 484 485 486
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalInvoiceMovementTypeList')
  def getPortalInvoiceMovementTypeList(self):
    """
      Return invoice movement types.
    """
487 488 489
    return self._getPortalGroupedTypeList('invoice_movement') or \
           self._getPortalConfiguration('portal_invoice_movement_type_list')

490

491 492 493 494 495 496
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalOrderMovementTypeList')
  def getPortalOrderMovementTypeList(self):
    """
      Return order movement types.
    """
497 498 499
    return self._getPortalGroupedTypeList('order_movement') or \
           self._getPortalConfiguration('portal_order_movement_type_list')

500

501 502 503 504 505 506
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalDeliveryMovementTypeList')
  def getPortalDeliveryMovementTypeList(self):
    """
      Return delivery movement types.
    """
507 508 509
    return self._getPortalGroupedTypeList('delivery_movement') or \
           self._getPortalConfiguration('portal_delivery_movement_type_list')

510

511 512 513 514 515 516
  security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalSupplyTypeList')
  def getPortalSupplyTypeList(self):
    """
      Return supply types.
    """
517 518 519
    return self._getPortalGroupedTypeList('supply') or \
           self._getPortalConfiguration('portal_supply_type_list')

520

521 522 523 524 525 526
  security.declareProtected(Permissions.AccessContentsInformation,
                              'getPortalSupplyPathTypeList')
  def getPortalSupplyPathTypeList(self):
    """
      Return supply movement types.
    """
527 528 529
    return self._getPortalGroupedTypeList('supply_path') or \
           self._getPortalConfiguration('portal_supply_path_type_list')

530

531 532 533 534 535 536 537
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalAcquisitionMovementTypeList')
  def getPortalAcquisitionMovementTypeList(self):
    """
      Return acquisition movement types.
    """
    return tuple(list(self.getPortalOrderMovementTypeList()) +
538 539 540
                 list(self.getPortalDeliveryMovementTypeList()) +
                 list(self.getPortalInvoiceMovementTypeList()))

541

542 543 544 545 546 547 548
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalMovementTypeList')
  def getPortalMovementTypeList(self):
    """
      Return movement types.
    """
    return tuple(list(self.getPortalOrderMovementTypeList()) +
549 550
                 list(self.getPortalDeliveryMovementTypeList()) +
                 list(self.getPortalInvoiceMovementTypeList()) +
551 552
                  ['Simulation Movement'])

553

554 555 556 557 558 559
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalSimulatedMovementTypeList')
  def getPortalSimulatedMovementTypeList(self):
    """
      Return simulated movement types.
    """
560
    return tuple([x for x in self.getPortalMovementTypeList() \
561
                    if x not in self.getPortalContainerTypeList()])
562

563

564 565 566 567 568 569
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalContainerTypeList')
  def getPortalContainerTypeList(self):
    """
      Return container types.
    """
570 571 572
    return self._getPortalGroupedTypeList('container') or \
           self._getPortalConfiguration('portal_container_type_list')

573

574 575 576 577 578 579
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalContainerLineTypeList')
  def getPortalContainerLineTypeList(self):
    """
      Return container line types.
    """
580 581 582
    return self._getPortalGroupedTypeList('container_line') or \
           self._getPortalConfiguration('portal_container_line_type_list')

583

584 585 586 587 588 589
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalItemTypeList')
  def getPortalItemTypeList(self):
    """
      Return item types.
    """
590 591 592
    return self._getPortalGroupedTypeList('item') or \
           self._getPortalConfiguration('portal_item_type_list')

593

594 595 596 597 598 599
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalDiscountTypeList')
  def getPortalDiscountTypeList(self):
    """
      Return discount types.
    """
600 601 602
    return self._getPortalGroupedTypeList('discount') or \
           self._getPortalConfiguration('portal_discount_type_list')

603

604 605 606 607 608 609
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalAlarmTypeList')
  def getPortalAlarmTypeList(self):
    """
      Return alarm types.
    """
610 611 612
    return self._getPortalGroupedTypeList('alarm') or \
           self._getPortalConfiguration('portal_alarm_type_list')

613

614 615 616 617 618 619
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalPaymentConditionTypeList')
  def getPortalPaymentConditionTypeList(self):
    """
      Return payment condition types.
    """
620 621 622
    return self._getPortalGroupedTypeList('payment_condition') or \
           self._getPortalConfiguration('portal_payment_condition_type_list')

623

624 625 626 627 628 629
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalBalanceTransactionLineTypeList')
  def getPortalBalanceTransactionLineTypeList(self):
    """
      Return balance transaction line types.
    """
630 631 632
    return self._getPortalGroupedTypeList('balance_transaction_line') or \
           self._getPortalConfiguration('portal_balance_transaction_line_type_list')

633

634 635 636 637 638 639
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalCurrentInventoryStateList')
  def getPortalCurrentInventoryStateList(self):
    """
      Return current inventory states.
    """
640 641 642
    return self._getPortalGroupedStateList('current_inventory') or \
           self._getPortalConfiguration('portal_current_inventory_state_list')

643

644 645 646 647 648 649
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalDraftOrderStateList')
  def getPortalDraftOrderStateList(self):
    """
      Return draft order states.
    """
650 651 652
    return self._getPortalGroupedStateList('draft_order') or \
           self._getPortalConfiguration('portal_draft_order_state_list')

653

654 655 656 657 658 659
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalPlannedOrderStateList')
  def getPortalPlannedOrderStateList(self):
    """
      Return planned order states.
    """
660 661 662
    return self._getPortalGroupedStateList('planned_order') or \
           self._getPortalConfiguration('portal_planned_order_state_list')

663

664 665 666 667 668 669
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalReservedInventoryStateList')
  def getPortalReservedInventoryStateList(self):
    """
      Return reserved inventory states.
    """
670 671 672
    return self._getPortalGroupedStateList('reserved_inventory') or \
           self._getPortalConfiguration('portal_reserved_inventory_state_list')

673

674 675 676 677 678 679
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalFutureInventoryStateList')
  def getPortalFutureInventoryStateList(self):
    """
      Return future inventory states.
    """
680 681 682
    return self._getPortalGroupedStateList('future_inventory') or \
           self._getPortalConfiguration('portal_future_inventory_state_list')

683

684 685 686 687 688 689
  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')
690

691

692 693 694 695 696 697
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalColumnBaseCategoryList')
  def getPortalColumnBaseCategoryList(self):
    """
      Return column base categories.
    """
698 699 700
    return self._getPortalGroupedCategoryList('column') or \
           self._getPortalConfiguration('portal_column_base_category_list')

701

702 703 704 705 706 707
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalLineBaseCategoryList')
  def getPortalLineBaseCategoryList(self):
    """
      Return line base categories.
    """
708 709 710
    return self._getPortalGroupedCategoryList('line') or \
           self._getPortalConfiguration('portal_line_base_category_list')

711

712 713 714 715 716 717
  security.declareProtected(Permissions.AccessContentsInformation,
                            'getPortalTabBaseCategoryList')
  def getPortalTabBaseCategoryList(self):
    """
      Return tab base categories.
    """
718 719 720
    return self._getPortalGroupedCategoryList('tab') or \
           self._getPortalConfiguration('portal_tab_base_category_list')

721

722 723 724 725 726
  def getPortalDefaultGapRoot(self):
    """
      Return the Accounting Plan to use by default (return the root node)
    """
    LOG('ERP5Site', 0, 'getPortalDefaultGapRoot is deprecated;'+
727 728 729
        ' use portal_preferences.getPreferredAccountingTransactionGap instead.')
    return self.portal_preferences.getPreferredAccountingTransactionGap() or \
           self._getPortalConfiguration('portal_default_gap_root')
730

731

732 733 734 735
  def getPortalAccountingMovementTypeList(self) :
    """
      Return accounting movement type list.
    """
736 737 738
    return self._getPortalGroupedTypeList('accounting_movement') or \
           self._getPortalConfiguration('portal_accounting_movement_type_list')

739

740 741 742 743
  def getPortalAccountingTransactionTypeList(self) :
    """
      Return accounting transaction movement type list.
    """
744 745 746
    return self._getPortalGroupedTypeList('accounting_transaction') or \
           self._getPortalConfiguration('portal_accounting_transaction_type_list')

747

748 749 750 751
  def getPortalAssignmentBaseCategoryList(self):
    """
      Return List of category values to generate security groups.
    """
752 753
    return self._getPortalGroupedCategoryList('assignment') or \
           self._getPortalConfiguration('portal_assignment_base_category_list')
754

755 756

  security.declareProtected(Permissions.AccessContentsInformation, 'getPortalTicketTypeList')
757 758 759 760 761
  def getPortalTicketTypeList(self):
    """
    Return ticket types.
    """
    return self._getPortalGroupedTypeList('ticket')
762

763 764

  security.declareProtected(Permissions.AccessContentsInformation, 'getPortalEventTypeList')
765 766 767 768 769
  def getPortalEventTypeList(self):
    """
    Return event types.
    """
    return self._getPortalGroupedTypeList('event')
770

771 772

  security.declareProtected(Permissions.AccessContentsInformation, 'getDefaultModuleId')
773 774 775 776 777 778 779 780 781 782
  def getDefaultModuleId(self, portal_type, default=MARKER):
    """
      Return default module id where a object with portal_type can
      be created.
    """
    # Very dummy method, but it works with today name convention.
    module_name = portal_type.lower().replace(' ','_')
    portal_object = self
    if not hasattr(portal_object, module_name):
      module_name += '_module'
783
      if not hasattr(portal_object, module_name):
784 785 786
        if default is not MARKER:
          return default
        LOG('ERP5Site, getDefaultModuleId', 0,
787 788
            'Unable to find default module for portal_type: %s' % portal_type)
        raise ValueError, 'Unable to find module for portal_type: %s' % portal_type
789 790
    return module_name

791 792

  security.declareProtected(Permissions.AccessContentsInformation, 'getDefaultModule')
793 794 795 796 797
  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)
798

799

800 801 802 803 804 805 806 807 808
  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'
    if portal_type is None:
      raise ValueError, 'The portal_type should not be None'
809 810 811 812
    self.portal_types.constructContent( type_name = portal_type
                                      , container = self
                                      , id        = id
                                      ) # **kw) removed due to CMF bug
813
    new_instance = self[id]
814 815 816 817
    if kw is not None:
      new_instance._edit(force_update=1, **kw)
    if immediate_reindex:
      new_instance.immediateReindexObject()
818 819
    return new_instance

820

821 822
  def log(self,description,content):
    """
823
      Put a log message
824
    """
825 826
    LOG(description, 0, content)

827

828

Jean-Paul Smets's avatar
Jean-Paul Smets committed
829 830 831 832
Globals.InitializeClass(ERP5Site)

class ERP5Generator(PortalGenerator):

833
  klass = ERP5Site
834

835 836 837 838 839 840 841
  def getBootstrapDirectory(self):
    """
      Return the name of the bootstrap directory
    """
    product_path = package_home(globals())
    return os.path.join(product_path, 'bootstrap')

842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857

  def create( self
            , parent
            , id
            , create_userfolder
            , erp5_sql_connection_type
            , erp5_sql_connection_string
            , erp5_sql_deferred_connection_type
            , erp5_sql_deferred_connection_string
            , cmf_activity_sql_connection_type
            , cmf_activity_sql_connection_string
            , create_activities=1
            , reindex=1
            , **kw
            ):
    LOG('setupTools, create', 0, kw)
858 859
    id = str(id)
    portal = self.klass(id=id)
860 861
    # Make sure reindex will not be called until business templates will be installed
    setattr(portal, 'isIndexable', 0)
862 863 864 865 866
    parent._setObject(id, portal)
    # Return the fully wrapped object.
    p = parent.this()._getOb(id)
    p._setProperty('erp5_sql_connection_type', erp5_sql_connection_type, 'string')
    p._setProperty('erp5_sql_connection_string', erp5_sql_connection_string, 'string')
867 868
    p._setProperty('erp5_sql_deferred_connection_type', erp5_sql_deferred_connection_type, 'string')
    p._setProperty('erp5_sql_deferred_connection_string', erp5_sql_deferred_connection_string, 'string')
869 870
    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')
871 872
    p._setProperty('management_page_charset', 'UTF-8', 'string')
    self.setup(p, create_userfolder, **kw)
873 874
    return p

875

876 877 878 879 880 881 882
  def setupLastTools(self, p, **kw):
    """
      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
883 884 885 886 887 888 889 890 891 892 893 894
    if not p.hasObject('portal_activities'):
      addTool = p.manage_addProduct['CMFActivity'].manage_addTool
      addTool('CMF Activity Tool', None) # Allow user to select active/passive
    # 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)

895

896 897 898 899 900 901 902 903 904 905 906
  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)

907

908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969
  def setupTools(self, p,**kw):
    """
      Set up initial tools
    """
    if not 'portal_actions' in p.objectIds():
      PortalGenerator.setupTools(self, p)

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

    # Add CMF Report Tool
    if not p.hasObject('portal_report'):
      addTool = p.manage_addProduct['CMFReportTool'].manage_addTool
      addTool('CMF Report Tool', None)

    # Add ERP5 Tools
    addTool = p.manage_addProduct['ERP5'].manage_addTool
    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)
    if not p.hasObject('portal_alarms'):
      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)

    try:
      addTool = p.manage_addProduct['ERP5Subversion'].manage_addTool
      if not p.hasObject('portal_subversion'):
        addTool('ERP5 Subversion Tool', None)
    except AttributeError:
      pass

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

    # Add ERP5 SQL Catalog Tool
    addTool = p.manage_addProduct['ERP5Catalog'].manage_addTool
    if not p.hasObject('portal_catalog'):
      addTool('ERP5 Catalog', None)
970

971 972 973
    # Add Default SQL connection
    if p.erp5_sql_connection_type == 'Z MySQL Database Connection':
      if not p.hasObject('erp5_sql_connection'):
974
        addSQLConnection = p.manage_addProduct['ZMySQLDA'].manage_addZMySQLConnection
975 976 977
        addSQLConnection('erp5_sql_connection', 'ERP5 SQL Server Connection', p.erp5_sql_connection_string)
    elif p.erp5_sql_connection_type == 'Z Gadfly':
      pass
978 979 980 981

    # Add Deferred SQL Connections
    if p.erp5_sql_deferred_connection_type == 'Z MySQL Deferred Database Connection':
      if not p.hasObject('erp5_sql_deferred_connection'):
982
        addSQLConnection = p.manage_addProduct['ZMySQLDDA'].manage_addZMySQLDeferredConnection
983 984 985 986 987
        addSQLConnection('erp5_sql_deferred_connection', 'ERP5 SQL Server Deferred Connection', p.erp5_sql_deferred_connection_string)
    elif p.erp5_sql_deferred_connection_type == 'Z Gadfly':
      pass

    # Add Activity SQL Connections
988 989
    if p.cmf_activity_sql_connection_type == 'Z MySQL Database Connection':
      if not p.hasObject('cmf_activity_sql_connection'):
990
        addSQLConnection = p.manage_addProduct['ZMySQLDA'].manage_addZMySQLConnection
991 992 993 994 995 996 997 998
        addSQLConnection('cmf_activity_sql_connection', 'CMF Activity SQL Server Connection', p.cmf_activity_sql_connection_string)
    elif p.cmf_activity_sql_connection_type == 'Z Gadfly':
      pass

    portal_catalog = getToolByName(p, 'portal_catalog')
    if not portal_catalog.getSQLCatalog('erp5_mysql') and not update:
      portal_catalog.addDefaultSQLMethods()
      portal_catalog.manage_catalogClear()
999 1000 1001 1002 1003 1004
      # TODO: Replace previous lines with the commented below (not working actually).
      #       The goal is to delete addDefaultSQLMethods() method and duplicated zsql
      #         method from /ERP5Catalog/sql/mysql_erp5.
      # addSQLCatalog = portal_catalog.manage_addProduct['ZSQLCatalog'].manage_addSQLCatalog
      # addSQLCatalog('erp5_mysql', '')
      # portal_catalog.default_sql_catalog_id = 'erp5_mysql'
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022

    # Add ERP5Form Tools
    addTool = p.manage_addProduct['ERP5Form'].manage_addTool
    if not p.hasObject('portal_selections'):
      addTool('ERP5 Selections', None)
    if not p.hasObject('portal_preferences'):
      addTool('ERP5 Preference Tool', None)

    # Add ERP5SyncML Tools
    addTool = p.manage_addProduct['ERP5SyncML'].manage_addTool
    if not p.hasObject('portal_synchronizations'):
      addTool('ERP5 Synchronizations', None)

    # Add Message Catalog
    if not 'Localizer' in p.objectIds():
      addLocalizer = p.manage_addProduct['Localizer'].manage_addLocalizer
      addLocalizer('', ('en',))
    localizer = getToolByName(p, 'Localizer')
1023
    addMessageCatalog = localizer.manage_addProduct['Localizer'].manage_addMessageCatalog
1024 1025 1026
    if 'erp5_ui' not in localizer.objectIds():
      if 'default' in localizer.objectIds():
        localizer.manage_delObjects('default')
1027 1028 1029
      addMessageCatalog('default'     , 'ERP5 Localized Messages' , ('en',))
      addMessageCatalog('erp5_ui'     , 'ERP5 Localized Interface', ('en',))
      addMessageCatalog('erp5_content', 'ERP5 Localized Content'  , ('en',))
1030 1031 1032 1033 1034 1035 1036 1037


  def setupMembersFolder(self, p):
    """
      ERP5 is not a CMS
    """
    pass

1038

1039 1040 1041 1042 1043 1044 1045 1046 1047
  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')
    addDirectoryViews(ps, 'skins', cmfdefault_globals)
    addDirectoryViews(ps, 'skins', cmfactivity_globals)
    ps.manage_addProduct['OFSP'].manage_addFolder(id='external_method')
    ps.manage_addProduct['OFSP'].manage_addFolder(id='custom')
1048 1049
    # Set the 'custom' layer a high priority, so it remains the first
    #   layer when installing new business templates
1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065
    ps['custom'].manage_addProperty(
        "business_template_skin_layer_priority", 100.0, "float")
    ps.addSkinSelection('View', 'custom, external_method, activity, '
                              + 'zpt_content, zpt_generic,'
                              + 'zpt_control, content, generic, control, Images',
                        make_default=1)
    ps.addSkinSelection('Print', 'custom, external_method, activity, '
                              + 'zpt_content, zpt_generic,'
                              + 'zpt_control, content, generic, control, Images',
                        make_default=0)
    ps.addSkinSelection('CSV', 'custom, external_method, activity, '
                              + 'zpt_content, zpt_generic,'
                              + 'zpt_control, content, generic, control, Images',
                        make_default=0)
    p.setupCurrentSkin()

1066

1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
  def setupWorkflow(self, p):
    """
      Set up workflows for business templates
    """
    tool = getToolByName(p, 'portal_workflow', None)
    if tool is None:
        return
    for wf_id in ('business_template_building_workflow', 'business_template_installation_workflow'):
      if wf_id in tool.objectIds():
        tool.manage_delObjects([wf_id])
    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' ) )
    pass

1089

1090 1091 1092 1093 1094 1095 1096
  def setupIndex(self, p, **kw):
    # Make sure all tools and folders have been indexed
    if kw.has_key('reindex') and kw['reindex']==0:
      return
    skins_tool = getToolByName(p, 'portal_skins', None)
    if skins_tool is None:
      return
1097
    setattr(p, 'isIndexable', 1)
1098 1099 1100 1101
    portal_catalog = p.portal_catalog
    portal_catalog.manage_catalogClear()
    skins_tool["erp5_core"].ERP5Site_reindexAll()

1102

1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122
  def setupUserFolder(self, p):
    # We use if possible ERP5Security, then NuxUserGroups
    try:
      from Products import ERP5Security
      from Products import PluggableAuthService
    except ImportError:
      ERP5Security = None
      try:
        import Products.NuxUserGroups
        withnuxgroups = 1
      except ImportError:
        withnuxgroups = 0
    if ERP5Security is not None:
      # Use Pluggable Auth Service instead of the standard acl_users.
      p.manage_addProduct['PluggableAuthService'].addPluggableAuthService()
      # 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')
      # Add CMF Portal Roles
1123
      #XXX Maybe it will be no longer required once PAS is the standard
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
      p.acl_users.zodb_roles.addRole('Member')
      p.acl_users.zodb_roles.addRole('Reviewer')
      # 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'))
      # 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')
      # Register ERP5UserManager Interface
      p.acl_users.erp5_users.manage_activateInterfaces(('IAuthenticationPlugin',
                                                        'IUserEnumerationPlugin',))
      p.acl_users.erp5_groups.manage_activateInterfaces(('IGroupsPlugin',))
      p.acl_users.erp5_roles.manage_activateInterfaces(('IRolesPlugin',))
    elif withnuxgroups:
      # NuxUserGroups user folder
      p.manage_addProduct['NuxUserGroups'].addUserFolderWithGroups()
    else:
      # Standard user folder
      PortalGenerator.setupUserFolder(self, p)

1149

1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180
  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'),
      'Set own password'             : ('Manager',),
      '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)

1181

1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218
  def setup(self, p, create_userfolder, **kw):
    update = kw.get('update', 0)

    self.setupTools(p, **kw)

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

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

    if not p.hasObject('cookie_authentication'):
      self.setupCookieAuth(p)

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

    if not update:
      self.setupPermissions(p)
      self.setupDefaultSkins(p)

    # Finish setup
    if not p.hasObject('Members'):
      self.setupMembersFolder(p)

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

    if not p.hasObject('content_type_registry'):
      self.setupMimetypes(p)
    if not update:
      self.setupWorkflow(p)

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

1219 1220
    self.setupLastTools(p, **kw)

1221 1222 1223 1224 1225
    # Make sure tools are cleanly indexed with a uid before creating children
    # XXX for some strange reason, member was indexed 5 times
    if not update:
      self.setupIndex(p, **kw)

1226

1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238
  def setupBusinessTemplate(self,p):
    """
      Install the portal_type of Business Template
    """
    tool = getToolByName(p, 'portal_types', None)
    if tool is None:
      return
    if 'Business Template' not in tool.objectIds():
      t = BusinessTemplate.factory_type_information
      ti = apply(ERP5TypeInformation, (), t)
      tool._setObject(t['id'], ti)

1239 1240

  def setupERP5Core(self, p, **kw):
1241 1242 1243 1244 1245 1246 1247 1248
    """
      Install the core part of ERP5
    """
    template_tool = getToolByName(p, 'portal_templates', None)
    if template_tool is None:
      return
    if template_tool.getInstalledBusinessTemplate('erp5_core') is None:
      bootstrap_dir = self.getBootstrapDirectory()
1249
      for bt in ('erp5_core', 'erp5_html_style'):
1250 1251 1252 1253 1254 1255 1256
        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)