summaryrefslogtreecommitdiff
path: root/ishtar_common/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-06-03 22:05:13 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-06-03 22:05:13 +0200
commitdd098e6bab668d5d602b2d5c4dd64af3d0aa62b4 (patch)
tree4fdfe0c828e975812fdc6a8ededba4995300ecc2 /ishtar_common/models.py
parent5f77b4d18fdd1f4b8c6e967d65dc949197a28243 (diff)
parent6bcaf64532e8b1ea76e5e74e3291fac2b238f838 (diff)
downloadIshtar-dd098e6bab668d5d602b2d5c4dd64af3d0aa62b4.tar.bz2
Ishtar-dd098e6bab668d5d602b2d5c4dd64af3d0aa62b4.zip
Merge branch 'master' into v0.9
Conflicts: ishtar_common/views.py
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)