diff options
Diffstat (limited to 'archaeological_operations/models.py')
| -rw-r--r-- | archaeological_operations/models.py | 64 | 
1 files changed, 59 insertions, 5 deletions
| diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 402f45485..8a415c0c5 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -180,6 +180,11 @@ class ArchaeologicalSite(DocumentItem, BaseHistorizedItem, QRCodeItem,      }      # alternative names of fields for searches +    REVERSED_BOOL_FIELDS = [ +        'documents__image__isnull', +        'documents__associated_file__isnull', +        'documents__associated_url__isnull', +    ]      ALT_NAMES = {          'reference': SearchAltName(              pgettext_lazy("key for text search", "reference"), @@ -264,6 +269,7 @@ class ArchaeologicalSite(DocumentItem, BaseHistorizedItem, QRCodeItem,          ),      }      ALT_NAMES.update(BaseHistorizedItem.ALT_NAMES) +    ALT_NAMES.update(DocumentItem.ALT_NAMES)      UP_MODEL_QUERY = {          "operation": (pgettext_lazy("key for text search", "operation"), @@ -278,12 +284,25 @@ class ArchaeologicalSite(DocumentItem, BaseHistorizedItem, QRCodeItem,      DOWN_MODEL_UPDATE = ["context_records"]      QA_LOCK = QuickAction( -        url="operation-qa-lock", icon_class="fa fa-lock", +        url="site-qa-lock", icon_class="fa fa-lock",          text=_(u"Lock/Unlock"), target="many", -        rights=['change_operation', 'change_own_operation'] +        rights=['change_archaeologicalsite', +                'change_own_archaeologicalsite'] +    ) +    QA_EDIT = QuickAction( +        url="site-qa-bulk-update", icon_class="fa fa-pencil", +        text=_(u"Bulk update"), target="many", +        rights=['change_archaeologicalsite', +                'change_own_archaeologicalsite']      )      QUICK_ACTIONS = [ -        QA_LOCK +        QA_EDIT, +        QA_LOCK, +        QuickAction( +            url="site-qa-duplicate", icon_class="fa fa-clone", +            text=_("Duplicate"), target="one", +            rights=['change_archaeologicalsite', +                    'change_own_archaeologicalsite']),      ]      objects = SiteManager() @@ -409,6 +428,22 @@ class ArchaeologicalSite(DocumentItem, BaseHistorizedItem, QRCodeItem,          return Find.objects.filter(              base_finds__context_record__archaeological_site__pk=self.pk) +    def get_extra_actions(self, request): +        """ +        For sheet template +        """ +        # url, base_text, icon, extra_text, extra css class, is a quick action +        actions = super(ArchaeologicalSite, self).get_extra_actions(request) +        # is_locked = self.is_locked(request.user) + +        can_edit_site = self.can_do(request, 'change_archaeologicalsite') +        if can_edit_site: +            actions += [ +                (reverse("site-qa-duplicate", args=[self.pk]), +                 _("Duplicate"), "fa fa-clone", "", "", True), +            ] +        return actions +      @classmethod      def _get_query_owns_dicts(cls, ishtaruser, no_rel=False):          profile = ishtaruser.current_profile @@ -665,6 +700,11 @@ class Operation(ClosedItem, DocumentItem, BaseHistorizedItem, QRCodeItem,      # search parameters      BOOL_FIELDS = ['end_date__isnull', 'virtual_operation',                     'documentation_received', 'finds_received'] +    REVERSED_BOOL_FIELDS = [ +        'documents__image__isnull', +        'documents__associated_file__isnull', +        'documents__associated_url__isnull', +    ]      DATED_FIELDS = [          'start_date__lte', 'start_date__gte', 'excavation_end_date__lte',          'excavation_end_date__gte', 'documentation_deadline__lte', @@ -922,9 +962,12 @@ class Operation(ClosedItem, DocumentItem, BaseHistorizedItem, QRCodeItem,          ),      }      ALT_NAMES.update(BaseHistorizedItem.ALT_NAMES) +    ALT_NAMES.update(DocumentItem.ALT_NAMES) +      QA_EDIT = QuickAction(          url="operation-qa-bulk-update", icon_class="fa fa-pencil",          text=_(u"Bulk update"), target="many", +        rights=['change_operation', 'change_own_operation']      )      QA_LOCK = QuickAction(          url="operation-qa-lock", icon_class="fa fa-lock", @@ -932,7 +975,11 @@ class Operation(ClosedItem, DocumentItem, BaseHistorizedItem, QRCodeItem,          rights=['change_operation', 'change_own_operation']      )      QUICK_ACTIONS = [ -        QA_EDIT, QA_LOCK +        QA_EDIT, QA_LOCK, +        QuickAction( +            url="operation-qa-duplicate", icon_class="fa fa-clone", +            text=_("Duplicate"), target="one", +            rights=['change_operation', 'change_own_operation']),      ]      UP_MODEL_QUERY = { @@ -1352,9 +1399,16 @@ class Operation(ClosedItem, DocumentItem, BaseHistorizedItem, QRCodeItem,          """          # url, base_text, icon, extra_text, extra css class, is a quick action          actions = super(Operation, self).get_extra_actions(request) +        is_locked = self.is_locked(request.user) +        can_edit_operation = self.can_do(request, 'change_operation') +        if can_edit_operation: +            actions += [ +                (reverse("operation-qa-duplicate", args=[self.pk]), +                 _("Duplicate"), "fa fa-clone", "", "", True), +            ]          can_add_cr = self.can_do(request, 'add_contextrecord') -        if can_add_cr and not self.is_locked(request.user): +        if can_add_cr and not is_locked:              actions += [                  (reverse('operation-qa-contextrecord', args=[self.pk]),                   _("Add context record"), "fa fa-plus", | 
