summaryrefslogtreecommitdiff
path: root/ishtar_common/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-11-30 18:47:14 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-11-30 18:48:21 +0100
commiteddd946150bcd9d4ddb05000806cc2cdfb9af60d (patch)
treee091e17882ca67be8e6040e938439fa5a5e6bc5a /ishtar_common/models.py
parentafd7fb9c2be01a44a45f582eebdf02632a10be99 (diff)
downloadIshtar-eddd946150bcd9d4ddb05000806cc2cdfb9af60d.tar.bz2
Ishtar-eddd946150bcd9d4ddb05000806cc2cdfb9af60d.zip
Manage basket to treatment file association
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)