Changeset 1195 in main


Ignore:
Timestamp:
06/07/12 15:37:29 (7 years ago)
Author:
pcosquer
Message:

models: adds a new field reference_number to PLMObject in order to fix #108
/!\ manage.py migrate plmapp is required
new tests: SuggestedReferenceTestCase? to test if it is fixed

Location:
trunk/openPLM/plmapp
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/openPLM/plmapp/controllers/plmobject.py

    r1167 r1195  
    9191            raise ValueError("Incorrect type") 
    9292        # create an object 
     93        try: 
     94            start = "PART_"  if issubclass(models.Part, class_) else "DOC_" 
     95            reference_number = int(re.search(r"^%s(\d+)$" % start, reference).group(1))  
     96        except: 
     97            reference_number = 0 
    9398        obj = class_(reference=reference, type=type, revision=revision, 
    94                      owner=user, creator=user) 
     99                     owner=user, creator=user, reference_number=reference_number) 
    95100        if no_index: 
    96101            obj.no_index = True 
  • trunk/openPLM/plmapp/forms.py

    r1173 r1195  
    9595    else: 
    9696        base_cls, name = m.Document, "DOC" 
    97     nb = base_cls.objects.count() + start + 1 
    98     reference = "%s_%05d" % (name, nb) 
    99     while base_cls.objects.filter(reference=reference).exists(): 
    100         nb += 1 
    101         reference = "%s_%05d" % (name, nb) 
    102     return reference 
     97    try: 
     98        max_ref = base_cls.objects.order_by("-reference_number")\ 
     99            .values_list("reference_number", flat=True)[0] 
     100    except IndexError: 
     101        max_ref = 0 
     102    nb = max_ref + start + 1 
     103    return "%s_%05d" % (name, nb) 
    103104 
    104105def get_initial_creation_data(cls, start=0): 
  • trunk/openPLM/plmapp/models.py

    r1192 r1195  
    485485 
    486486            True if the object is published (accessible to anonymous user) 
     487        .. attribute:: reference_number 
     488 
     489            .. versionadded:: 1.1 
     490 
     491            number found in the reference if it matches ``PART_|DOC_\d+``             
    487492 
    488493    .. note:: 
     
    491496        :class:`Document`. 
    492497 
     498    .. versionchanged:: 1.1 
     499        :attr:`published` and :attr:`reference_number` added. 
    493500    """ 
    494501 
     
    498505    type = models.CharField(_("type"), max_length=50) 
    499506    revision = models.CharField(_("revision"), max_length=50) 
     507     
     508    # hidden field to get a valid new reference 
     509    reference_number = models.IntegerField(default=0) 
    500510 
    501511    # other attributes 
  • trunk/openPLM/plmapp/tests/__init__.py

    r864 r1195  
    4242from openPLM.plmapp.tests.gestion_document_native import * 
    4343from openPLM.plmapp.tests.navigate import * 
     44from openPLM.plmapp.tests.reference import * 
    4445 
    4546import openPLM.plmapp.models 
Note: See TracChangeset for help on using the changeset viewer.