-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add contact creation in POI form #3196
Open
jarlhengstmengel
wants to merge
1
commit into
develop
Choose a base branch
from
feature/add_contact_creation_in_poi_form
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
integreat_cms/cms/templates/ajax_contact_form/_contact_form_widget.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{% load i18n %} | ||
{% load widget_tweaks %} | ||
<div> | ||
<label for="{{ contact_form.title.id_for_label }}"> | ||
{{ contact_form.point_of_contact_for.label }} | ||
</label> | ||
{% render_field contact_form.point_of_contact_for|append_attr:"form:ajax_contact_form" %} | ||
<label for="{{ contact_form.name.id_for_label }}"> | ||
{{ contact_form.name.label }} | ||
</label> | ||
{% render_field contact_form.name|append_attr:"form:ajax_contact_form" %} | ||
<label for="{{ contact_form.email.id_for_label }}"> | ||
{{ contact_form.email.label }} | ||
</label> | ||
{% render_field contact_form.email|append_attr:"form:ajax_contact_form" %} | ||
<label for="{{ contact_form.phone_number.id_for_label }}"> | ||
{{ contact_form.phone_number.label }} | ||
</label> | ||
{% render_field contact_form.phone_number|append_attr:"form:ajax_contact_form" %} | ||
<label for="{{ contact_form.website.id_for_label }}"> | ||
{{ contact_form.website.label }} | ||
</label> | ||
{% render_field contact_form.website|append_attr:"form:ajax_contact_form" %} | ||
<button id="submit-contact-form-button" | ||
name="location" | ||
value="{{ poi_id }}" | ||
form="ajax_contact_form" | ||
data-btn-save-contact-form | ||
class="btn w-full mt-4 mb-2" | ||
data-url="{% url 'create_contact_ajax' region_slug=request.region.slug %}"> | ||
{% translate "Submit" %} | ||
</button> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
integreat_cms/cms/views/contacts/contact_form_ajax_view.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from django.http import JsonResponse | ||
from django.shortcuts import render | ||
from django.utils.decorators import method_decorator | ||
from django.views.generic import TemplateView | ||
|
||
from ...decorators import permission_required | ||
from ...forms import ContactForm | ||
from ...models import Contact | ||
from .contact_context_mixin import ContactContextMixin | ||
|
||
if TYPE_CHECKING: | ||
from typing import Any | ||
|
||
from django.http import HttpRequest, HttpResponse | ||
|
||
|
||
@method_decorator(permission_required("cms.view_contact"), name="dispatch") | ||
@method_decorator(permission_required("cms.change_contact"), name="post") | ||
class ContactFormAjaxView(TemplateView, ContactContextMixin): | ||
""" | ||
View for the ajax contact widget | ||
""" | ||
|
||
#: Template for ajax POI widget | ||
template = "ajax_contact_form/_contact_form_widget.html" | ||
|
||
def get(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse: | ||
r"""Render a contact form widget template | ||
|
||
:param request: The current request | ||
:param \*args: The supplied arguments | ||
:param \**kwargs: The supplied keyword arguments | ||
:return: The html template of a POI form | ||
""" | ||
contact_form = ContactForm( | ||
additional_instance_attributes={"region": request.region} | ||
) | ||
|
||
return render( | ||
request, | ||
"ajax_contact_form/_contact_form_widget.html", | ||
{ | ||
**self.get_context_data(**kwargs), | ||
"contact_form": contact_form, | ||
"poi_id": kwargs.get( | ||
"poi_id", | ||
), | ||
}, | ||
) | ||
|
||
def post(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse: | ||
r"""Add a new POI to the database | ||
|
||
:param request: The current request | ||
:param \*args: The supplied arguments | ||
:param \**kwargs: The supplied keyword arguments | ||
:raises ~django.http.Http404: If no language for the given language slug was found | ||
|
||
:return: A status message, either a success or an error message | ||
""" | ||
|
||
contact_instance = Contact.objects.filter(id=None).first() | ||
|
||
data = request.POST.dict() | ||
|
||
contact_form = ContactForm( | ||
data=data, | ||
files=request.FILES, | ||
instance=contact_instance, | ||
additional_instance_attributes={ | ||
"region": request.region, | ||
}, | ||
) | ||
|
||
if not contact_form.is_valid(): | ||
return JsonResponse( | ||
data={ | ||
"contact_form": contact_form.get_error_messages(), | ||
} | ||
) | ||
|
||
contact = contact_form.save() | ||
|
||
return JsonResponse( | ||
data={ | ||
"success": "Successfully created location", | ||
"contact_label": contact.label_in_reference_list(), | ||
"edit_url": contact.backend_edit_link, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4890,7 +4890,9 @@ msgstr "Faxnummer" | |||||
msgid "Update" | ||||||
msgstr "Aktualisieren" | ||||||
|
||||||
#: cms/templates/_tinymce_config.html cms/views/media/media_context_mixin.py | ||||||
#: cms/templates/_tinymce_config.html | ||||||
#: cms/templates/ajax_contact_form/_contact_form_widget.html | ||||||
#: cms/views/media/media_context_mixin.py | ||||||
msgid "Submit" | ||||||
msgstr "Speichern" | ||||||
|
||||||
|
@@ -4980,6 +4982,7 @@ msgid "The new location was successfully created." | |||||
msgstr "Ein neuer Ort wurde erfolgreich erstellt." | ||||||
|
||||||
#: cms/templates/ajax_poi_form/poi_box.html | ||||||
#: cms/templates/pois/poi_form_sidebar/related_contacts_box.html | ||||||
msgid "An error occurred." | ||||||
msgstr "Es ist ein Fehler aufgetreten." | ||||||
|
||||||
|
@@ -7802,6 +7805,14 @@ msgstr "Dieser Ort wird in folgenden Kontakten verwendet." | |||||
msgid "This location is not currently referred to in any contact." | ||||||
msgstr "Zur Zeit gibt es keine Kontakte zu diesem Ort." | ||||||
|
||||||
#: cms/templates/pois/poi_form_sidebar/related_contacts_box.html | ||||||
msgid "Create a new contact" | ||||||
msgstr "Kontakt erstellen" | ||||||
|
||||||
#: cms/templates/pois/poi_form_sidebar/related_contacts_box.html | ||||||
msgid "The new contact was successfully created." | ||||||
msgstr "Ein neuer Kontakt wurde erfolgreich erstellt." | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This is very nit picky, but I think we should keep the definitive article to stay consistent to the English version, but yes, it doesn't sound as good |
||||||
|
||||||
#: cms/templates/pois/poi_list.html cms/templates/pois/poi_list_archived.html | ||||||
msgid "Archived locations" | ||||||
msgstr "Archivierte Orte" | ||||||
|
@@ -11185,6 +11196,16 @@ msgstr "" | |||||
"Diese Seite konnte nicht importiert werden, da sie zu einer anderen Region " | ||||||
"gehört ({})." | ||||||
|
||||||
#~ msgid "Here you can create a new contact with this location." | ||||||
#~ msgstr "Hier können Sie einen neuen Kontakt mit diesem Ort erstellen." | ||||||
|
||||||
#~ msgid "" | ||||||
#~ "Add missing data or change existing data. Select the data you want to " | ||||||
#~ "import." | ||||||
#~ msgstr "" | ||||||
#~ "Ergänzen Sie fehlende Daten oder ändern bestehende Daten. Wählen Sie die " | ||||||
#~ "Daten aus, die übernommen werden sollen." | ||||||
|
||||||
#~ msgid "An error occurred while importing events from this external calendar" | ||||||
#~ msgstr "Ein Fehler mit dem Import von Veranstaltungen ist aufgetreten" | ||||||
|
||||||
|
@@ -11232,13 +11253,6 @@ msgstr "" | |||||
#~ msgid "Created by" | ||||||
#~ msgstr "Erstellt von" | ||||||
|
||||||
#~ msgid "" | ||||||
#~ "Add missing data or change existing data. Select the data you want to " | ||||||
#~ "import." | ||||||
#~ msgstr "" | ||||||
#~ "Ergänzen Sie fehlende Daten oder ändern bestehende Daten. Wählen Sie die " | ||||||
#~ "Daten aus, die übernommen werden sollen." | ||||||
|
||||||
#~ msgid "E-mail from location" | ||||||
#~ msgstr "E-mail des Ortes" | ||||||
|
||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -104,6 +104,8 @@ import "./js/menu"; | |||
import "./js/poi-categories/poicategory-colors-icons"; | ||||
import "./js/dashboard/broken-links"; | ||||
|
||||
import "./js/contact_box"; | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
// IE11: fetch | ||||
/* eslint-disable-next-line @typescript-eslint/no-var-requires */ | ||||
require("element-closest").default(window); | ||||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least for the list views we changed the icon to the pencil, but maybe it's okay for this view because the context is slightly different? (And also: we still use this icon still in a few places)