diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-07-27 11:49:04 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-07-27 11:49:04 +0200 | 
| commit | 4ad9278e67d8fb024c685df03812c2e1d8313aa1 (patch) | |
| tree | dde04c38350d5952174ae29f189c132e56061b3b /ishtar_common/models.py | |
| parent | 1b754a300be8844e2e0b45839639cb92002d5d5e (diff) | |
| download | Ishtar-4ad9278e67d8fb024c685df03812c2e1d8313aa1.tar.bz2 Ishtar-4ad9278e67d8fb024c685df03812c2e1d8313aa1.zip | |
Sync external ID on manual insert (refs #3161)
Diffstat (limited to 'ishtar_common/models.py')
| -rw-r--r-- | ishtar_common/models.py | 65 | 
1 files changed, 65 insertions, 0 deletions
| diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 5b5bd8f4e..3c46573dd 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -832,6 +832,35 @@ class LightHistorizedItem(BaseHistorizedItem):          super(LightHistorizedItem, self).save(*args, **kwargs)          return True +PARSE_FORMULA = re.compile("{([^}]*)}") + + +def get_external_id(key, item): +    profile = get_current_profile() +    if not hasattr(profile, key): +        return +    formula = getattr(profile, key) +    dct = {} +    for fkey in PARSE_FORMULA.findall(formula): +        if fkey.startswith('settings__'): +            dct[fkey] = getattr(settings, fkey[len('settings__'):]) or '' +            continue +        obj = item +        for k in fkey.split('__'): +            try: +                obj = getattr(obj, k) +            except ObjectDoesNotExist: +                obj = None +            if callable(obj): +                obj = obj() +            if obj is None: +                break +        if obj is None: +            dct[fkey] = '' +        else: +            dct[fkey] = obj +    return formula.format(**dct) +  class IshtarSiteProfile(models.Model, Cached):      slug_field = 'slug' @@ -850,6 +879,42 @@ class IshtarSiteProfile(models.Model, Cached):          _(u"Home page"), null=True, blank=True,          help_text=_(u"Homepage of Ishtar - if not defined a default homepage "                      u"will appear. Use the markdown syntax.")) +    file_external_id = models.TextField( +        _(u"File external id"), +        default="{settings__ISHTAR_LOCAL_PREFIX}{year}-{numeric_reference}", +        help_text=_(u"Formula to manage file external ID. " +                    u"Change this with care. With incorrect formula, the " +                    u"application might be unusable and import of external " +                    u"data can be destructive.")) +    parcel_external_id = models.TextField( +        _(u"Parcel external id"), +        default="{associated_file__external_id}{operation__code_patriarche}-" +                "{town__numero_insee}-{section}{parcel_number}", +        help_text=_(u"Formula to manage parcel external ID. " +                    u"Change this with care. With incorrect formula, the " +                    u"application might be unusable and import of external " +                    u"data can be destructive.")) +    context_record_external_id = models.TextField( +        _(u"Context record external id"), +        default="{parcel__external_id}-{label}", +        help_text=_(u"Formula to manage context record external ID. " +                    u"Change this with care. With incorrect formula, the " +                    u"application might be unusable and import of external " +                    u"data can be destructive.")) +    base_find_external_id = models.TextField( +        _(u"Base find external id"), +        default="{context_record__external_id}-{label}", +        help_text=_(u"Formula to manage base find external ID. " +                    u"Change this with care. With incorrect formula, the " +                    u"application might be unusable and import of external " +                    u"data can be destructive.")) +    find_external_id = models.TextField( +        _(u"Find external id"), +        default="{get_first_base_find__context_record__external_id}-{label}", +        help_text=_(u"Formula to manage find external ID. " +                    u"Change this with care. With incorrect formula, the " +                    u"application might be unusable and import of external " +                    u"data can be destructive."))      active = models.BooleanField(_(u"Current active"), default=False)      class Meta: | 
