diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-06-10 12:29:37 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-06-12 10:46:13 +0200 | 
| commit | 4649cf3fcfd901dfd099355a29b664a450966823 (patch) | |
| tree | 6964cba3625130b7336075f01b4f2d678517e20a /ishtar_common/models.py | |
| parent | ef4a039625f5f68f8e16ec5f1737f31da85fdaa5 (diff) | |
| download | Ishtar-4649cf3fcfd901dfd099355a29b664a450966823.tar.bz2 Ishtar-4649cf3fcfd901dfd099355a29b664a450966823.zip | |
Quick action to add a document from a sheet (refs #4107)
Diffstat (limited to 'ishtar_common/models.py')
| -rw-r--r-- | ishtar_common/models.py | 44 | 
1 files changed, 33 insertions, 11 deletions
| diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 3715c0326..bc0cb7b09 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1216,9 +1216,34 @@ class DocumentItem(object):              return Document.objects.none()          return self.documents.filter(image__isnull=False).exclude(image="") +    def get_extra_actions(self, request): +        """ +        For sheet template: return "Add document / image" action +        """ +        # url, base_text, icon, extra_text, extra css class +        actions = [] +        can_add_doc = request.user.ishtaruser.has_right( +            'add_document', request.session) or ( +                request.user.ishtaruser.has_right( +                    'add_own_document', request.session) and +                self.is_own(request.user.ishtaruser) +        ) +        if can_add_doc: +            actions = [ +                ( +                    reverse("create-document") + "?{}={}".format(self.SLUG, +                                                                 self.pk), +                    _(u"Add document/image"), +                    "fa fa-plus", +                    _(u"doc./image"), +                    "" +                ) +            ] +        return actions + -class BaseHistorizedItem(FullSearch, Imported, JsonData, FixAssociated, -                         DocumentItem): +class BaseHistorizedItem(DocumentItem, FullSearch, Imported, JsonData, +                         FixAssociated):      """      Historized item with external ID management.      All historized items are searcheable and have a data json field @@ -2707,19 +2732,16 @@ class Person(Address, Merge, OwnPerms, ValueGetter):          return slugify(u"-".join(values))      def operation_docs_q(self): -        from archaeological_operations.models import OperationSource -        return OperationSource.objects.filter( -            authors__person=self) +        return Document.objects.filter( +            authors__person=self, operations__pk__isnull=False)      def contextrecord_docs_q(self): -        from archaeological_context_records.models import ContextRecordSource -        return ContextRecordSource.objects.filter( -            authors__person=self) +        return Document.objects.filter( +            authors__person=self, context_records__pk__isnull=False)      def find_docs_q(self): -        from archaeological_finds.models import FindSource -        return FindSource.objects.filter( -            authors__person=self) +        return Document.objects.filter( +            authors__person=self, finds__pk__isnull=False)      def save(self, *args, **kwargs):          super(Person, self).save(*args, **kwargs) | 
