diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-11-02 12:04:26 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-11-16 17:04:41 +0100 |
commit | 46ee7a1ad70b77a7548914ea2d85dab15db8edcd (patch) | |
tree | 01eefca20cbe21bcb99eb682d1c23f10b78a79eb | |
parent | a72adcf584bd6aa1508df6dbcbdffddd6ab6c930 (diff) | |
download | Ishtar-46ee7a1ad70b77a7548914ea2d85dab15db8edcd.tar.bz2 Ishtar-46ee7a1ad70b77a7548914ea2d85dab15db8edcd.zip |
Context record: bulk update - add relations
-rw-r--r-- | CHANGES-DEV.md | 7 | ||||
-rw-r--r-- | archaeological_context_records/forms.py | 55 | ||||
-rw-r--r-- | archaeological_context_records/models.py | 8 | ||||
-rw-r--r-- | archaeological_context_records/urls.py | 15 | ||||
-rw-r--r-- | archaeological_context_records/views.py | 6 |
5 files changed, 91 insertions, 0 deletions
diff --git a/CHANGES-DEV.md b/CHANGES-DEV.md new file mode 100644 index 000000000..7465816e8 --- /dev/null +++ b/CHANGES-DEV.md @@ -0,0 +1,7 @@ +Ishtar changelog +================ + +### Features ### +- Context record: bulk update + +### Bugs ### diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py index 6d48aba4f..594ed1346 100644 --- a/archaeological_context_records/forms.py +++ b/archaeological_context_records/forms.py @@ -53,6 +53,7 @@ from ishtar_common.forms import ( MultiSearchForm, LockForm, DocumentItemSelect, + QAForm, ) from ishtar_common.forms_common import get_town_field from archaeological_operations.forms import ( @@ -688,3 +689,57 @@ class QAContextRecordDuplicateForm(IshtarForm): except Parcel.DoesNotExist: pass return self.context_record.duplicate(self.user, data=data) + + +class QAContextRecordFormMulti(QAForm): + form_admin_name = _("Context record - Quick action - Modify") + form_slug = "contextrecord-quickaction-modify" + + base_models = ["qa_relation_type"] + associated_models = { + "qa_relation_type": models.RelationType, + } + + MULTI = True + qa_relation_type = forms.ChoiceField( + label=_("Relation type"), + required=False, + ) + qa_related_to = forms.IntegerField( + label=_("Related to"), + widget=widgets.JQueryAutoComplete( + reverse_lazy("autocomplete-contextrecord"), + associated_model=models.ContextRecord, + ), + validators=[valid_id(models.ContextRecord)], + required=False, + ) + + TYPES = [ + FieldType("qa_relation_type", models.RelationType), + ] + + def clean(self): + cleaned_data = super().clean() + r_type = cleaned_data.get("qa_relation_type") + r_related = cleaned_data.get("qa_related_to") + if (r_type and not r_related) or (not r_type and r_related): + raise forms.ValidationError( + _( + "To add relations, you must fill relation type and related to fields." + ) + ) + + def _set_qa_related_to(self, item, __): + r_type = self.cleaned_data.get("qa_relation_type", None) + r_related = self.cleaned_data.get("qa_related_to", None) + if not r_type or not r_related: + return + models.RecordRelations.objects.get_or_create( + left_record=item, + right_record_id=r_related, + relation_type_id=r_type + ) + + def _set_qa_relation_type(self, item, __): + pass diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 151446c2d..71adcb219 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -589,7 +589,15 @@ class ContextRecord( target="many", rights=["change_contextrecord", "change_own_contextrecord"], ) + QA_EDIT = QuickAction( + url="contextrecord-qa-bulk-update", + icon_class="fa fa-pencil", + text=_("Bulk update"), + target="many", + rights=["change_contextrecord", "change_own_contextrecord"], + ) QUICK_ACTIONS = [ + QA_EDIT, QA_LOCK, QuickAction( url="contextrecord-qa-duplicate", diff --git a/archaeological_context_records/urls.py b/archaeological_context_records/urls.py index be3994821..3db2cf9aa 100644 --- a/archaeological_context_records/urls.py +++ b/archaeological_context_records/urls.py @@ -169,4 +169,19 @@ urlpatterns = [ ), name="contextrecord-qa-duplicate", ), + url( + r"^contextrecord-qa-bulk-update/(?P<pks>[0-9-]+)?/$", + check_rights(["change_contextrecord", "change_own_contextrecord"])( + views.QAContextRecordForm.as_view() + ), + name="contextrecord-qa-bulk-update", + ), + url( + r"^contextrecord-qa-bulk-update/(?P<pks>[0-9-]+)?/confirm/$", + check_rights(["change_contextrecord", "change_own_contextrecord"])( + views.QAContextRecordForm.as_view() + ), + name="contextrecord-qa-bulk-update-confirm", + kwargs={"confirm": True}, + ), ] diff --git a/archaeological_context_records/views.py b/archaeological_context_records/views.py index 568d2a4f2..8d6030af3 100644 --- a/archaeological_context_records/views.py +++ b/archaeological_context_records/views.py @@ -40,6 +40,7 @@ from ishtar_common.views import ( QAItemForm, QABaseLockView, wizard_is_available, + QAItemEditForm, ) from ishtar_common.views_item import display_item, get_item, show_item, revert_item from archaeological_context_records import wizards @@ -286,3 +287,8 @@ class QAContextRecordDuplicateFormView(QAItemForm): data["action_name"] = _("Duplicate") data["operation"] = self.items[0].operation return data + + +class QAContextRecordForm(QAItemEditForm): + model = models.ContextRecord + form_class = forms.QAContextRecordFormMulti |