diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-02-14 12:39:03 +0100 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-02-15 17:20:19 +0100 | 
| commit | 32b9575cefa9eede2be68ea8464a7c70d52e4105 (patch) | |
| tree | df7cf20de56e13c9660d14219d7ee5d825bb2909 /ishtar_common/models.py | |
| parent | 5bbafc5b1a398afa4cd37acf20293eddb8c12f9b (diff) | |
| download | Ishtar-32b9575cefa9eede2be68ea8464a7c70d52e4105.tar.bz2 Ishtar-32b9575cefa9eede2be68ea8464a7c70d52e4105.zip  | |
Archaeological site: search view (refs #3913)
- add site to profile
- allow alternate label in menus for sites
- add entry in menu
- basic configuration of site model
Diffstat (limited to 'ishtar_common/models.py')
| -rw-r--r-- | ishtar_common/models.py | 70 | 
1 files changed, 29 insertions, 41 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 674e42538..74b2f4221 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1464,6 +1464,7 @@ CURRENCY = ((u"€", _(u"Euro")),              (u"$", _(u"US dollar")))  FIND_INDEX_SOURCE = ((u"O", _(u"Operations")),                       (u"CR", _(u"Context records"))) +SITE_LABELS = [('site', _(u"Site")), ('entity', _(u"Archaeological entity"))]  class IshtarSiteProfile(models.Model, Cached): @@ -1471,18 +1472,16 @@ class IshtarSiteProfile(models.Model, Cached):      label = models.TextField(_(u"Name"))      slug = models.SlugField(_(u"Slug"), unique=True)      description = models.TextField(_(u"Description"), null=True, blank=True) -    base_color = models.CharField( -        _(u"CSS color code for base module"), -        default=u'rgba(0, 0, 0, 0)', max_length=200)      files = models.BooleanField(_(u"Files module"), default=False) -    files_color = models.CharField( -        _(u"CSS color code for files module"), -        default=u'rgba(0, 32, 210, 0.1)', max_length=200) +    archaeological_site = models.BooleanField( +        _(u"Archaeological site module"), default=False) +    archaeological_site_label = models.CharField( +        _(u"Archaeological site type"), max_length=200, +        choices=SITE_LABELS, +        default='site' +    )      context_record = models.BooleanField(_(u"Context records module"),                                           default=False) -    context_record_color = models.CharField( -        _(u"CSS color code for context record module"), -        default=u'rgba(210,200,0,0.2)', max_length=200)      find = models.BooleanField(_(u"Finds module"), default=False,                                 help_text=_(u"Need context records module"))      find_index = models.CharField( @@ -1490,21 +1489,12 @@ class IshtarSiteProfile(models.Model, Cached):          choices=FIND_INDEX_SOURCE,          help_text=_(u"To prevent irrelevant indexes, change this parameter "                      u"only if there is no find in the database")) -    find_color = models.CharField( -        _(u"CSS color code for find module"), -        default=u'rgba(210,0,0,0.15)', max_length=200)      warehouse = models.BooleanField(          _(u"Warehouses module"), default=False,          help_text=_(u"Need finds module")) -    warehouse_color = models.CharField( -        _(u"CSS code for warehouse module"), default=u'rgba(10,20,200,0.15)', -        max_length=200)      preservation = models.BooleanField(_(u"Preservation module"),                                         default=False)      mapping = models.BooleanField(_(u"Mapping module"), default=False) -    mapping_color = models.CharField( -        _(u"CSS code for mapping module"), default=u'rgba(72, 236, 0, 0.15)', -        max_length=200)      homepage = models.TextField(          _(u"Home page"), null=True, blank=True,          help_text=_(u"Homepage of Ishtar - if not defined a default homepage " @@ -1579,18 +1569,26 @@ class IshtarSiteProfile(models.Model, Cached):      def __unicode__(self):          return unicode(self.label) -    def get_raw_css(self): -        css = '' -        for attr, css_name in (('base_color', 'operation'), -                               ('files_color', 'file'), -                               ('context_record_color', 'context-record'), -                               ('find_color', 'find'), -                               ('warehouse_color', 'warehouse')): -            css += ''' -.menu-%s{ -    background-color: %s; -}''' % (css_name, getattr(self, attr)) -        return css +    @classmethod +    def get_current_profile(cls, force=False): +        cache_key, value = get_cache(cls, ['is-current-profile']) +        if value and not force: +            return value +        q = cls.objects.filter(active=True) +        if not q.count(): +            obj = cls.objects.create( +                label="Default profile", slug='default', active=True) +        else: +            obj = q.all()[0] +        cache.set(cache_key, obj, settings.CACHE_TIMEOUT) +        return obj + +    @classmethod +    def get_default_site_label(cls): +        return cls.get_current_profile().get_site_label() + +    def get_site_label(self): +        return unicode(dict(SITE_LABELS)[self.archaeological_site_label])      def save(self, *args, **kwargs):          raw = False @@ -1621,17 +1619,7 @@ class IshtarSiteProfile(models.Model, Cached):  def get_current_profile(force=False): -    cache_key, value = get_cache(IshtarSiteProfile, ['is-current-profile']) -    if value and not force: -        return value -    q = IshtarSiteProfile.objects.filter(active=True) -    if not q.count(): -        obj = IshtarSiteProfile.objects.create( -            label="Default profile", slug='default', active=True) -    else: -        obj = q.all()[0] -    cache.set(cache_key, obj, settings.CACHE_TIMEOUT) -    return obj +    return IshtarSiteProfile.get_current_profile(force=force)  def cached_site_changed(sender, **kwargs):  | 
