Skip to content

Commit

Permalink
BEMAS: Verbesserungen Benutzerführung
Browse files Browse the repository at this point in the history
  • Loading branch information
gdmhrogut committed Feb 14, 2024
1 parent 4099375 commit 40f11ac
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 56 deletions.
7 changes: 7 additions & 0 deletions bemas/templates/bemas/generic-objectclass-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
{% if form.errors %}
{% include "bemas/container-errors.html" %}
{% endif %}
{% if messages %}
{% include "bemas/container-messages.html" %}
{% endif %}
<h2><i class="fas fa-{{ objectclass_name|lower|get_icon }}"></i> <em>{{ objectclass_verbose_name }}</em></h2>
{% if objectclass_logentry_url %}
<a href="{{ objectclass_logentry_url }}"><i class="fas fa-{{ 'logentry'|get_icon }}"></i> Einträge im Bearbeitungsverlauf anzeigen</a>
Expand Down Expand Up @@ -110,6 +113,10 @@ <h2><i class="fas fa-{{ objectclass_name|lower|get_icon }}"></i> <em>{{ objectcl
{% include "modal-error.html" %}
</form>
<script>
setTimeout(function () {
$('.alert-success').alert('close');
}, 3000);

/**
* @function
* @name mapCallbackFunction
Expand Down
15 changes: 7 additions & 8 deletions bemas/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
from .views.views_codelist import CodelistCreateView, CodelistDeleteView, CodelistTableView, \
CodelistUpdateView
from .views.views_general import CodelistsIndexView, IndexView, MapView, OrphanedDataView
from .views.views_objectclass import ComplaintDeleteView, ContactDeleteView, ContactCreateView, \
ContactUpdateView, GenericObjectclassCreateView, GenericObjectclassDeleteView, \
GenericObjectclassTableView, GenericObjectclassUpdateView, OrganizationDeleteView, \
PersonDeleteView
from .views.views_objectclass import ComplaintDeleteView, GenericObjectclassCreateView, \
GenericObjectclassDeleteView, GenericObjectclassTableView, GenericObjectclassUpdateView, \
OrganizationDeleteView, PersonDeleteView

router = routers.DefaultRouter()

Expand Down Expand Up @@ -255,7 +254,7 @@
urlpatterns.append(
path(
'contact/create',
view=login_required(ContactCreateView.as_view(
view=login_required(GenericObjectclassCreateView.as_view(
model=model
)),
name='contact_create'
Expand All @@ -266,7 +265,7 @@
urlpatterns.append(
path(
'contact/update/<pk>',
view=login_required(ContactUpdateView.as_view(
view=login_required(GenericObjectclassUpdateView.as_view(
model=model
)),
name='contact_update'
Expand All @@ -277,7 +276,7 @@
urlpatterns.append(
path(
'contact/delete/<pk>',
view=login_required(ContactDeleteView.as_view(
view=login_required(GenericObjectclassDeleteView.as_view(
model=model
)),
name='contact_delete'
Expand Down Expand Up @@ -650,7 +649,7 @@
urlpatterns.append(
path(
'event/delete/<pk>',
view=login_required(ComplaintDeleteView.as_view(
view=login_required(GenericObjectclassDeleteView.as_view(
model=model
)),
name='event_delete'
Expand Down
8 changes: 7 additions & 1 deletion bemas/views/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,13 @@ def get_referer_url(referer, fallback, lazy=False):
:return: URL used for "cancel" buttons
and/or used in case of successfully submitted forms
"""
if referer and '/delete' not in referer:
if (
referer
and '/contact' not in referer
and '/event' not in referer
and '/logentry' not in referer
and '/delete' not in referer
):
return referer
return reverse_lazy(fallback) if lazy else reverse(fallback)

Expand Down
73 changes: 26 additions & 47 deletions bemas/views/views_objectclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.db.models import ProtectedError
from django.forms.models import modelform_factory
from django.http import HttpResponseRedirect
from django.urls import reverse, reverse_lazy
from django.urls import reverse
from django.views.generic.base import TemplateView
from django.views.generic.edit import CreateView, DeleteView, UpdateView
from json import dumps
Expand Down Expand Up @@ -71,8 +71,11 @@ def get_context_data(self, **kwargs):
:return: dictionary with all context elements for this view
"""
# set generic object class context for create, update and/or delete views
cancel_url = get_referer_url(
get_referer(self.request), 'bemas:' + self.model.__name__.lower() + '_table')
if issubclass(self.model, Contact):
fallback_url = 'bemas:organization_table'
else:
fallback_url = 'bemas:' + self.model.__name__.lower() + '_table'
cancel_url = get_referer_url(get_referer(self.request), fallback_url)
context = set_generic_objectclass_create_update_delete_context(
super().get_context_data(**kwargs),
self.request,
Expand Down Expand Up @@ -122,11 +125,11 @@ def form_valid(self, form):
"""
# return to either the original referer or a default page
referer = form.data.get('original_referer', None)
self.success_url = get_referer_url(
referer if referer else None,
'bemas:' + self.model.__name__.lower() + '_table',
True
)
if issubclass(self.model, Contact):
fallback_url = 'bemas:organization_table'
else:
fallback_url = 'bemas:' + self.model.__name__.lower() + '_table'
self.success_url = get_referer_url(referer if referer else None, fallback_url, True)
# string representation of new complaint equals its primary key
# (which is not yet available) and thus use its description here
if issubclass(self.model, Complaint):
Expand Down Expand Up @@ -203,8 +206,11 @@ def get_context_data(self, **kwargs):
:return: dictionary with all context elements for this view
"""
# set generic object class context for create, update and/or delete views
cancel_url = get_referer_url(
get_referer(self.request), 'bemas:' + self.model.__name__.lower() + '_table')
if issubclass(self.model, Contact):
fallback_url = 'bemas:organization_table'
else:
fallback_url = 'bemas:' + self.model.__name__.lower() + '_table'
cancel_url = get_referer_url(get_referer(self.request), fallback_url)
context = set_generic_objectclass_create_update_delete_context(
super().get_context_data(**kwargs),
self.request,
Expand Down Expand Up @@ -306,11 +312,11 @@ def form_valid(self, form):
"""
# return to either the original referer or a default page
referer = form.data.get('original_referer', None)
self.success_url = get_referer_url(
referer if referer else None,
'bemas:' + self.model.__name__.lower() + '_table',
True
)
if issubclass(self.model, Contact):
fallback_url = 'bemas:organization_table'
else:
fallback_url = 'bemas:' + self.model.__name__.lower() + '_table'
self.success_url = get_referer_url(referer if referer else None, fallback_url, True)
success(
self.request,
'{} {} <strong><em>{}</em></strong> wurde erfolgreich geändert!'.format(
Expand Down Expand Up @@ -381,8 +387,11 @@ def get_context_data(self, **kwargs):
:return: dictionary with all context elements for this view
"""
# set generic object class context for create, update and/or delete views
cancel_url = get_referer_url(
get_referer(self.request), 'bemas:' + self.model.__name__.lower() + '_table')
if issubclass(self.model, Contact):
fallback_url = 'bemas:organization_table'
else:
fallback_url = 'bemas:' + self.model.__name__.lower() + '_table'
cancel_url = get_referer_url(get_referer(self.request), fallback_url)
context = set_generic_objectclass_create_update_delete_context(
super().get_context_data(**kwargs),
self.request,
Expand Down Expand Up @@ -561,33 +570,3 @@ def get_context_data(self, **kwargs):
# add custom deletion hints (shown as text to user) to context
context['deletion_hints'] = self.deletion_hints
return context


class ContactCreateView(GenericObjectclassCreateView):
"""
view for form page for creating an instance of object class contact
:param cancel_url: custom cancel URL
"""

cancel_url = reverse_lazy('bemas:organization_table')


class ContactUpdateView(GenericObjectclassUpdateView):
"""
view for form page for updating an instance of object class contact
:param cancel_url: custom cancel URL
"""

cancel_url = reverse_lazy('bemas:organization_table')


class ContactDeleteView(GenericObjectclassDeleteView):
"""
view for form page for deleting an instance of object class contact
:param cancel_url: custom cancel URL
"""

cancel_url = reverse_lazy('bemas:organization_table')

0 comments on commit 40f11ac

Please sign in to comment.