summaryrefslogtreecommitdiff
path: root/ishtar_common/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-06-03 22:23:46 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-06-03 22:23:46 +0200
commitfc835921567bde864b158f0a26a9461334b8facd (patch)
tree15c53d3ee13d79e72be949dc98d5c31195338a59 /ishtar_common/models.py
parent7f481fdfc8ce76e70bb4496c63770f8b5a9255b6 (diff)
parentba25fffca393f1a92d9e91422532a1da177b9e97 (diff)
downloadIshtar-fc835921567bde864b158f0a26a9461334b8facd.tar.bz2
Ishtar-fc835921567bde864b158f0a26a9461334b8facd.zip
Merge branch 'v0.9' into wheezy
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r--ishtar_common/models.py35
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)