summaryrefslogtreecommitdiff
path: root/ishtar_common/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r--ishtar_common/models.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 1a0d80ac3..219b6b266 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -3432,7 +3432,7 @@ class IshtarUser(FullSearch):
return self.person.full_label()
-class Basket(FullSearch):
+class Basket(FullSearch, OwnPerms):
"""
Abstract class for a basket
Subclass must be defined with an "items" ManyToManyField
@@ -3486,6 +3486,35 @@ class Basket(FullSearch):
return "{}-{}".format(datetime.date.today().strftime(
"%Y-%m-%d"), slugify(self.label))
+ @classmethod
+ def get_query_owns(cls, ishtaruser):
+ return Q(user=ishtaruser) | Q(shared_with=ishtaruser) | Q(
+ shared_write_with=ishtaruser)
+
+ @classmethod
+ def get_write_query_owns(cls, ishtaruser):
+ return Q(user=ishtaruser)
+
+ def duplicate(self, ishtaruser=None):
+ """
+ Duplicate the basket. Items in basket are copied but not shared users
+ :param ishtaruser: if provided an alternate user is used
+ :return: the new basket
+ """
+ items = list(self.items.all())
+ new_item = self
+ new_item.pk = None
+ if ishtaruser:
+ new_item.user = ishtaruser
+ label = new_item.label
+ while self.__class__.objects.filter(
+ label=label, user=new_item.user).count():
+ label += unicode(_(u" - duplicate"))
+ new_item.save()
+ for item in items:
+ new_item.add(item)
+ return new_item
+
class AuthorType(GeneralType):
order = models.IntegerField(_(u"Order"), default=1)