diff options
Diffstat (limited to 'ishtar_common/models.py')
| -rw-r--r-- | ishtar_common/models.py | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 9509b36a6..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): @@ -475,6 +480,33 @@ class GeneralType(models.Model, Cached): item.generate_key() +class Basket(models.Model): + """ + Abstract class for a basket + Subclass must be defined with an "items" ManyToManyField + """ + IS_BASKET = True + label = models.CharField(_(u"Label"), max_length=1000) + comment = models.TextField(_(u"Comment"), blank=True, null=True) + user = models.ForeignKey('IshtarUser', blank=True, null=True) + available = models.BooleanField(_(u"Available"), default=True) + + class Meta: + abstract = True + unique_together = (('label', 'user'),) + + def __unicode__(self): + return self.label + + def get_short_menu_class(self): + return 'basket' + + @property + def associated_filename(self): + return "{}-{}".format(datetime.date.today().strftime( + "%Y-%m-%d"), slugify(self.label)) + + class ItemKey(models.Model): key = models.CharField(_(u"Key"), max_length=100) content_type = models.ForeignKey(ContentType) @@ -551,6 +583,7 @@ class HistoryError(Exception): class BaseHistorizedItem(Imported): + IS_BASKET = False history_modifier = models.ForeignKey( User, related_name='+', on_delete=models.SET_NULL, verbose_name=_(u"Last editor"), blank=True, null=True) |
