Skip to content
Snippets Groups Projects
Commit 3246148c authored by Benjamin Hättasch's avatar Benjamin Hättasch
Browse files

Allow creating and setting a previously unknown owner from AK editing form

Add a new link to edit form leading to owner creation form and passing the primary key of the edited AK/wish to that view
To realize that link, the corresponding field is excluded from the default form rendering and the rendering is triggered manually for that field (and the name field that should still appear on top)
When user is successfully created, they is set as owner of an AK, the user is redirect to the detail page of that AK and a message is displayed
Add corresponding test
This implements #96 and #86
parent f38542a7
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-12-27 00:42+0100\n"
"POT-Creation-Date: 2023-01-01 16:07+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
......@@ -258,10 +258,17 @@ msgid "AKs"
msgstr "AKs"
#: AKSubmission/templates/AKSubmission/ak_edit.html:8
#: AKSubmission/templates/AKSubmission/ak_edit.html:21
#: AKSubmission/templates/AKSubmission/ak_edit.html:32
msgid "Edit AK"
msgstr "AK bearbeiten"
#: AKSubmission/templates/AKSubmission/ak_edit.html:24
msgid ""
"Add person not in the list yet. Unsaved changes in this form will be lost."
msgstr ""
"Person hinzufügen, die noch nicht in der Liste ist. Ungespeicherte "
"Änderungen in diesem Formular gehen verloren."
#: AKSubmission/templates/AKSubmission/ak_history.html:27
msgid "Back"
msgstr "Zurück"
......@@ -316,7 +323,7 @@ msgstr "Senden"
#: AKSubmission/templates/AKSubmission/akmessage_add.html:32
#: AKSubmission/templates/AKSubmission/akowner_create_update.html:27
#: AKSubmission/templates/AKSubmission/akslot_add_update.html:30
#: AKSubmission/templates/AKSubmission/submit_new.html:54
#: AKSubmission/templates/AKSubmission/submit_new.html:56
msgid "Reset Form"
msgstr "Formular leeren"
......@@ -324,7 +331,7 @@ msgstr "Formular leeren"
#: AKSubmission/templates/AKSubmission/akowner_create_update.html:31
#: AKSubmission/templates/AKSubmission/akslot_add_update.html:34
#: AKSubmission/templates/AKSubmission/akslot_delete.html:46
#: AKSubmission/templates/AKSubmission/submit_new.html:58
#: AKSubmission/templates/AKSubmission/submit_new.html:60
msgid "Cancel"
msgstr "Abbrechen"
......@@ -407,7 +414,7 @@ msgstr ""
"Dieses Event is nicht aktiv. Es können keine AKs hinzugefügt oder bearbeitet "
"werden"
#: AKSubmission/templates/AKSubmission/submit_new.html:50
#: AKSubmission/templates/AKSubmission/submit_new.html:52
msgid "Submit"
msgstr "Eintragen"
......@@ -437,35 +444,40 @@ msgstr "AK erfolgreich angelegt"
msgid "AK successfully updated"
msgstr "AK erfolgreich aktualisiert"
#: AKSubmission/views.py:344
#: AKSubmission/views.py:310
#, python-brace-format
msgid "Added '{owner}' as new owner of '{ak.name}'"
msgstr "'{owner}' als neue Leitung von '{ak.name}' hinzugefügt"
#: AKSubmission/views.py:351
msgid "Person Info successfully updated"
msgstr "Personen-Info erfolgreich aktualisiert"
#: AKSubmission/views.py:364
#: AKSubmission/views.py:371
msgid "No user selected"
msgstr "Keine Person ausgewählt"
#: AKSubmission/views.py:391
#: AKSubmission/views.py:398
msgid "AK Slot successfully added"
msgstr "AK-Slot erfolgreich angelegt"
#: AKSubmission/views.py:405
#: AKSubmission/views.py:412
msgid "You cannot edit a slot that has already been scheduled"
msgstr "Bereits geplante AK-Slots können nicht mehr bearbeitet werden"
#: AKSubmission/views.py:415
#: AKSubmission/views.py:422
msgid "AK Slot successfully updated"
msgstr "AK-Slot erfolgreich aktualisiert"
#: AKSubmission/views.py:428
#: AKSubmission/views.py:435
msgid "You cannot delete a slot that has already been scheduled"
msgstr "Bereits geplante AK-Slots können nicht mehr gelöscht werden"
#: AKSubmission/views.py:438
#: AKSubmission/views.py:445
msgid "AK Slot successfully deleted"
msgstr "AK-Slot erfolgreich angelegt"
#: AKSubmission/views.py:460
#: AKSubmission/views.py:467
msgid "Message to organizers successfully saved"
msgstr "Nachricht an die Organisator*innen erfolgreich gespeichert"
......
......@@ -16,6 +16,17 @@
<li class="breadcrumb-item active">{% trans "Edit" %}</li>
{% endblock %}
{% block form_contents %}
{% bootstrap_field form.name %}
<div class="form-group">
{% bootstrap_field form.owners form_group_class="" %}
<a href="{% url 'submit:akowner_create' event_slug=event.slug %}?add_to_existing_ak={{ ak.pk }}">
{% fa5_icon "plus" "fas" %} {% trans "Add person not in the list yet. Unsaved changes in this form will be lost." %}
</a>
</div>
{% bootstrap_form form exclude='name,owners' %}
{% endblock %}
{% block headline %}
<h2>{% trans 'Edit AK' %}</h2>
......
......@@ -44,7 +44,9 @@
<h2>{% trans 'New AK' %}</h2>
{% endblock %}
<form method="POST" class="post-form">{% csrf_token %}
{% bootstrap_form form %}
{% block form_contents %}
{% bootstrap_form form %}
{% endblock %}
{% buttons %}
<button type="submit" class="save btn btn-primary float-right">
{% fa5_icon "check" 'fas' %} {% trans "Submit" %}
......
......@@ -159,4 +159,21 @@ class ModelViewTests(BasicViewTests, TestCase):
response = self.client.post(invalid_interest_api_url)
self.assertEqual(response.status_code, 404, f"Invalid URL reachable ({interest_api_url})")
def test_adding_of_unknown_user(self):
detail_url = reverse_lazy(f"{self.APP_NAME}:ak_detail", kwargs={'event_slug': 'kif42', 'pk': 1})
response = self.client.get(detail_url)
self.assertEqual(response.status_code, 200, msg="Could not load ak detail view")
edit_url = reverse_lazy(f"{self.APP_NAME}:ak_edit", kwargs={'event_slug': 'kif42', 'pk': 1})
response = self.client.get(edit_url)
self.assertEqual(response.status_code, 200, msg="Could not load ak detail view")
self.assertContains(response, "Add person not in the list yet",
msg_prefix="Link to add unknown user not contained")
self.assertEqual(AK.objects.get(pk=1).owners.count(), 1)
add_new_user_to_ak_url = reverse_lazy(f"{self.APP_NAME}:akowner_create", kwargs={'event_slug': 'kif42'}) + f"?add_to_existing_ak=1"
response = self.client.post(add_new_user_to_ak_url, {'name': 'New test owner', 'event': Event.get_by_slug('kif42').pk})
self.assertRedirects(response, detail_url,
msg_prefix=f"No correct redirect: {add_new_user_to_ak_url} (POST) -> {detail_url}")
self._assert_message(response, "Added 'New test owner' as new owner of 'Test AK Inhalt'")
self.assertEqual(AK.objects.get(pk=1).owners.count(), 2)
......@@ -302,6 +302,13 @@ class AKOwnerCreateView(EventSlugMixin, EventInactiveRedirectMixin, CreateView):
form_class = AKOwnerForm
def get_success_url(self):
if "add_to_existing_ak" in self.request.GET:
ak_pk = self.request.GET['add_to_existing_ak']
ak = get_object_or_404(AK, pk=ak_pk)
ak.owners.add(self.object)
messages.add_message(self.request, messages.SUCCESS,
_("Added '{owner}' as new owner of '{ak.name}'").format(owner=self.object, ak=ak))
return reverse_lazy('submit:ak_detail', kwargs={'event_slug': self.kwargs['event_slug'], 'pk': ak.pk})
return reverse_lazy('submit:submit_ak',
kwargs={'event_slug': self.kwargs['event_slug'], 'owner_slug': self.object.slug})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment