diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-06-02 16:07:31 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-06-02 16:07:31 +0200 | 
| commit | 7868245668607ab9fb618011e4880f15ec1ef7de (patch) | |
| tree | 7c6f95d37fe429c118496e3f797f69df88aa129b | |
| parent | ba13e51cb85b99954570d318e5b9d5174559d9d8 (diff) | |
| download | Ishtar-7868245668607ab9fb618011e4880f15ec1ef7de.tar.bz2 Ishtar-7868245668607ab9fb618011e4880f15ec1ef7de.zip | |
Generic management of baskets in owns items
| -rw-r--r-- | archaeological_files/models.py | 2 | ||||
| -rw-r--r-- | archaeological_finds/models.py | 17 | ||||
| -rw-r--r-- | archaeological_operations/models.py | 2 | ||||
| -rw-r--r-- | ishtar_common/models.py | 7 | 
4 files changed, 14 insertions, 14 deletions
| diff --git a/archaeological_files/models.py b/archaeological_files/models.py index 519d3ced3..0258cb16d 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -331,7 +331,7 @@ class File(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem,      @classmethod      def get_owns(cls, user):          owns = super(File, cls).get_owns(user) -        return sorted(owns.all(), key=lambda x: x.cached_label) +        return sorted(owns, key=lambda x: x.cached_label)      def get_values(self, prefix=''):          values = super(File, self).get_values(prefix=prefix) diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py index 9c972f68c..417dd3929 100644 --- a/archaeological_finds/models.py +++ b/archaeological_finds/models.py @@ -240,6 +240,11 @@ CHECK_CHOICES = (('NC', _(u"Not checked")),                   ) +class FindBasket(Basket): +    items = models.ManyToManyField('Find', blank=True, null=True, +                                   related_name='basket') + +  class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):      CHECK_DICT = dict(CHECK_CHOICES)      SHOW_URL = 'show-find' @@ -329,6 +334,7 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):      check_date = models.DateField(_(u"Check date"),                                    default=datetime.date.today)      history = HistoricalRecords() +    BASKET_MODEL = FindBasket      def __init__(self, *args, **kwargs):          super(Find, self).__init__(*args, **kwargs) @@ -384,12 +390,6 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):              lbl += u' ({})'.format(base)          return lbl -    @classmethod -    def get_owns(cls, user): -        if user.is_anonymous(): -            return FindBasket.objects.none() -        return FindBasket.objects.filter(user=user) -      def get_first_base_find(self):          q = self.base_finds          if not q.count(): @@ -546,11 +546,6 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):              #        idx and idx['material_index__max'] + 1 or 1 -class FindBasket(Basket): -    items = models.ManyToManyField(Find, blank=True, null=True, -                                   related_name='basket') - -  class FindSource(Source):      SHOW_URL = 'show-findsource' diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 253ea7635..e3453f0cf 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -251,7 +251,7 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem,          owns = super(Operation, cls).get_owns(user)          # owns = owns.annotate(null_count=Count('operation_code'))          # return owns.order_by("common_name", "-year", "operation_code") -        return sorted(owns.all(), key=lambda x: x.cached_label) +        return sorted(owns, key=lambda x: x.cached_label)      def __unicode__(self):          if self.cached_label: diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 33ae05369..f3974d04d 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -243,10 +243,15 @@ class OwnPerms:              user = IshtarUser.objects.get(user_ptr=user)          if user.is_anonymous():              return cls.objects.filter(pk__isnull=True) +        items = [] +        if hasattr(cls, 'BASKET_MODEL'): +            items = list(cls.BASKET_MODEL.objects.filter(user=user).all())          query = cls.get_query_owns(user)          if not query:              return cls.objects.filter(pk__isnull=True) -        return cls.objects.filter(query).order_by(*cls._meta.ordering) +        items += list( +            cls.objects.filter(query).order_by(*cls._meta.ordering).all()) +        return items  class Cached(object): | 
