Ignore:
Timestamp:
18 Dec 2014, 14:44:30 (10 years ago)
Author:
Henrik Bettermann
Message:

Change contract_id generation algorithm. Use Universally Unique IDentifiers instead of consecutive numbers.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/app.py

    r12256 r12258  
    4242    grok.implements(ICompany)
    4343
    44     _curr_con_id = 101
    45 
    4644    # Setup authentication for this app. Note: this is only
    4745    # initialized, when a new instance of this app is created.
     
    5452        self.setup()
    5553        return
    56 
    57     @property
    58     def unique_contract_id(self):
    59         """A unique contract id for all contract objects in customers.
    60 
    61         The contract id returned is guaranteed to be unique.
    62 
    63         Once a contract id was issued, it won't be issued again.
    64 
    65         Obtaining an contract id is currently not thread-safe but can be
    66         made easily by enabling commented lines.
    67         """
    68         # lock.acquire() # lock data
    69         new_id = u'c%s' % (self._curr_con_id)
    70         self._curr_con_id += 1
    71         # self._p_changed = True
    72         # commit()
    73         # lock.release() # end of lock
    74         return new_id
    7554
    7655    def setup(self):
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/batching.py

    r12256 r12258  
    406406        return None
    407407
    408         #documents = self.getParent(row, site)
    409         #if documents is None:
    410         #    return None
    411         #document_id = row.get('document_id', None)
    412         #if document_id is None:
    413         #    return None
    414         #entry = documents.get(document_id)
    415         #return entry
    416 
    417408    def updateEntry(self, obj, row, site, filename):
    418409        """Update obj to the values given in row.
     
    496487        if contract_id is None:
    497488            return None
    498         entry = contracts.get(contract_id)
    499         return entry
     489        cat = queryUtility(ICatalog, name='contracts_catalog')
     490        results = list(cat.searchResults(contract_id=(contract_id, contract_id)))
     491        if results:
     492            return results[0]
     493        return None
    500494
    501495    def updateEntry(self, obj, row, site, filename):
    502496        """Update obj to the values given in row.
    503497        """
     498        # Remove contract_id from row if empty
     499        if 'contract_id' in row and row['contract_id'] in (None, IGNORE_MARKER):
     500            row.pop('contract_id')
    504501        items_changed = super(ContractProcessor, self).updateEntry(
    505502            obj, row, site, filename)
    506503        customer = self.getParent(row, site).__parent__
    507504        customer.__parent__.logger.info(
    508             '%s - %s - %s - updated: %s'
    509             % (self.name, filename, customer.customer_id, items_changed))
     505            '%s - %s - %s - %s - updated: %s'
     506            % (self.name, filename, customer.customer_id, obj.contract_id,
     507               items_changed))
    510508        return
    511509
    512510    def addEntry(self, obj, row, site):
    513511        parent = self.getParent(row, site)
    514         contract_id = row['contract_id'].strip('#')
    515         parent[contract_id] = obj
    516         # Reset _curr_con_id if contract_id has been imported
    517         site = grok.getSite()
    518         if row.get('contract_id', None) not in (None, IGNORE_MARKER):
    519             site._curr_con_id -= 1
     512        parent.addContract(obj)
    520513        return
    521514
     
    541534            if class_name != self.factory_name.strip('waeup.'):
    542535                errs.append(('class_name','wrong processor'))
    543         try:
    544             # Correct con_id counter. As the IConverter for contracts
    545             # creates contract objects that are not used afterwards, we
    546             # have to fix the site-wide con_id counter.
    547             site = grok.getSite()
    548             site._curr_con_id -= 1
    549         except (KeyError, TypeError, AttributeError):
    550                 pass
    551         # We have to check contract_id.
    552         contract_id = row.get('contract_id', None)
    553         if mode == 'create':
    554             if not contract_id:
    555                 contract_id = generate_contract_id()
    556                 conv_dict['contract_id'] = contract_id
    557                 return errs, inv_errs, conv_dict
    558             cat = queryUtility(ICatalog, name='contracts_catalog')
    559             results = list(
    560                 cat.searchResults(contract_id=(contract_id, contract_id)))
    561             if results:
    562                 # contract_id must not exist.
    563                 errs.append(('contract_id','id exists'))
    564         else:
    565             if not contract_id.startswith('c'):
    566                 errs.append(('contract_id','invalid format'))
    567536        return errs, inv_errs, conv_dict
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser.py

    r12256 r12258  
    11651165    pnav = 4
    11661166
    1167     form_fields = grok.AutoFields(IContract).omit('product_object')
     1167    form_fields = grok.AutoFields(IContract).omit(
     1168        'product_object', 'contract_id')
    11681169
    11691170    @property
     
    11801181        # classes depending on the contype parameter given in form.
    11811182        contract = createObject('waeup.%s' % contype)
     1183        self.applyData(contract, **data)
    11821184        self.context.addContract(contract)
    11831185        contype = getUtility(ICustomersUtils).SELECTABLE_CONTYPES_DICT[contype]
     
    12271229    @property
    12281230    def form_fields(self):
    1229         return grok.AutoFields(self.context.form_fields_interface)
     1231        return grok.AutoFields(self.context.form_fields_interface).omit(
     1232            'contract_id')
    12301233
    12311234    @property
     
    12471250    @property
    12481251    def form_fields(self):
    1249         return grok.AutoFields(self.context.edit_form_fields_interface)
     1252        return grok.AutoFields(self.context.edit_form_fields_interface).omit(
     1253            'contract_id')
    12501254
    12511255    def update(self):
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/contracts.py

    r12210 r12258  
    2727from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
    2828from waeup.ikoba.interfaces import MessageFactory as _
    29 from waeup.ikoba.interfaces import IIkobaUtils, IObjectHistory, VERIFIED
     29from waeup.ikoba.interfaces import (
     30    IIkobaUtils, IObjectHistory, VERIFIED, IIDSource)
    3031from waeup.ikoba.customers.interfaces import (
    3132    IContractsContainer, ICustomerNavigation,
     
    7576        super(ContractBase, self).__init__()
    7677        # The site doesn't exist in unit tests
    77         try:
    78             self.contract_id = generate_contract_id()
    79         except AttributeError:
    80             self.contract_id = u'c999'
     78        source = getUtility(IIDSource)
     79        self.contract_id = unicode(source.get_hex_uuid())
    8180        self.last_product_id = None
    8281        return
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/interfaces.py

    r12214 r12258  
    265265
    266266    """
    267     contract_id = Attribute('Contract Identifier')
    268267    history = Attribute('Object history, a list of messages')
    269268    state = Attribute('Returns the contract state')
     
    280279    translated_class_name = Attribute('Translatable class name')
    281280
     281    contract_id = schema.TextLine(
     282        title = _(u'Contract Id'),
     283        required = False,
     284        )
     285
    282286    title = schema.TextLine(
    283287        title = _(u'Contract Title'),
  • main/waeup.ikoba/trunk/src/waeup/ikoba/utils/batching.py

    r12250 r12258  
    227227                # Computed attributes can't be set.
    228228                continue
    229             log_value = getattr(value, 'any_id', value)
     229            log_value = getattr(value, 'product_id', value)
     230            log_value = getattr(value, 'document_id', log_value)
    230231            changed.append('%s=%s' % (key, log_value))
    231232
Note: See TracChangeset for help on using the changeset viewer.