diff options
| -rw-r--r-- | archaeological_operations/models.py | 22 | ||||
| -rw-r--r-- | archaeological_operations/urls.py | 11 | ||||
| -rw-r--r-- | archaeological_operations/views.py | 21 | ||||
| -rw-r--r-- | ishtar_common/wizards.py | 5 | 
4 files changed, 55 insertions, 4 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 091e1e60c..ee2023f5c 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -470,6 +470,14 @@ class ArchaeologicalSite(          QA_EDIT,          QA_LOCK,          QuickAction( +            url="site-add-operation", +            icon_class="fa fa-plus", +            text=_("Create associated operation"), +            target="many", +            rights=["change_operation"], +            is_popup=False +        ), +        QuickAction(              url="site-qa-duplicate",              icon_class="fa fa-clone",              text=_("Duplicate"), @@ -620,10 +628,22 @@ class ArchaeologicalSite(              actions.append(self.get_add_geo_action())          can_create_operation = self.can_do(request, "change_operation") +        if can_create_operation and not self.operations.count(): +            actions.append( +                ( +                    reverse("site-add-operation", args=[self.pk]), +                    _("Create an operation associated to this site"), +                    "fa fa-plus", +                    _("ope."), +                    "", +                    False +                ) +            ) +          if can_create_operation and self.operations.count():              actions.append(                  ( -                    reverse("site-qa-top-operation", args=[self.pk]), +                    reverse("site-add-top-operation", args=[self.pk]),                      _("Create a cluster operation for site associated to many operations"),                      "fa fa-plus",                      _("top ope."), diff --git a/archaeological_operations/urls.py b/archaeological_operations/urls.py index cf4ab6489..7e2b71589 100644 --- a/archaeological_operations/urls.py +++ b/archaeological_operations/urls.py @@ -356,11 +356,18 @@ urlpatterns = [          kwargs={"confirm": True},      ),      url( -        r"^site-qa-top-operation/(?P<pks>\d+)?/$", +        r"^site-add-operation/(?P<pks>[0-9-]+)?/$", +        check_rights(["change_operation"])( +            views.site_add_operation +        ), +        name="site-add-operation", +    ), +    url( +        r"^site-add-top-operation/(?P<pks>\d+)?/$",          check_rights(["change_operation"])(              views.site_add_top_operation          ), -        name="site-qa-top-operation", +        name="site-add-top-operation",      ),      url(          r"generate-stats-operation/(?P<pk>.+)/", diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py index 7bbc4c0b4..8fa7e08c0 100644 --- a/archaeological_operations/views.py +++ b/archaeological_operations/views.py @@ -584,6 +584,27 @@ def site_delete(request, pk):      return redirect(reverse(wizard_url, kwargs={"step": "final-" + wizard_url})) +def site_add_operation(request, pks, current_right=None): +    pks = [int(p) for p in pks.split("-")] +    for pk in pks: +        q = models.ArchaeologicalSite.objects.filter(pk=pk) +        if not q.count(): +            raise Http404() +        site = q.all()[0] +        if not site.can_do(request, "view_archaeologicalsite") \ +                or site.operations.count(): +            raise Http404() +    # operation add permission checked on view call +    operation_creation_wizard(request) +    wizards.OperationWizard.session_set_value( +            request, "general-operation_creation", "archaeological_site", pks, +            reset=True +    ) +    return redirect( +        reverse("operation_creation", kwargs={"step": "general-operation_creation"}) +    ) + +  def site_add_top_operation(request, pks, current_right=None):      q = models.ArchaeologicalSite.objects.filter(pk=pks)      if not q.count(): diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index c2383e2de..fa14d9827 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -1334,7 +1334,10 @@ class Wizard(IshtarWizard):          if not data:              data = MultiValueDict()          key = key if key.startswith(form_key) else form_key + "-" + key -        data[key] = value +        if isinstance(value, list): +            data.setlist(key, value) +        else: +            data[key] = value          storage.set_step_data(form_key, data)      @classmethod  | 
