Skip to content

Commit

Permalink
App Datenmanagement: Navigation überarbeitet
Browse files Browse the repository at this point in the history
  • Loading branch information
gdmhrogut committed Dec 19, 2023
1 parent 2616594 commit 84c8567
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 10 deletions.
31 changes: 31 additions & 0 deletions datenmanagement/templates/datenmanagement/add_another.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% extends "navbar.html" %}
{% load datenmanagement_tags %}

{% block title %}{{ model_verbose_name_plural }} – weiterer Datensatz? | {% endblock %}

{% block content %}
{% if messages %}
{% for message in messages %}
{% if message.tags and message.tags == 'success' %}
<div class="alert alert-success" role="alert">
<i class="fa-solid fa-circle-check"></i>
{{ message|safe }}
</div>
{% endif %}
{% endfor %}
{% endif %}
<h5>
<small>
Möchten Sie den soeben erfolgreich angelegten Datensatz <strong><em>{{ object }}</em></strong> nochmal bearbeiten oder ihn als Vorlage für einen weiteren Datensatz zum Datenthema <strong>{{ model_verbose_name_plural }}</strong> verwenden?
</small>
</h5>
<div class="d-grid mt-4 gap-2 d-md-block">
<a class="btn btn-success" role="button" href="{{ url_yes }}"><i class="fas fa-clone"></i> ja</a>
<a class="btn btn-warning" role="button" href="{{ url_no }}"><i class="fas fa-hand"></i> nein</a>
</div>
<script>
setTimeout(function () {
$('.alert-success').alert('close');
}, 3000);
</script>
{% endblock %}
6 changes: 4 additions & 2 deletions datenmanagement/templates/datenmanagement/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,14 @@ <h4 class="mt-3">
$('#action-count').text('1 Datensatz ausgewählt');
$('#action-select option[value="delete-selected"]').text('ausgewählten Datensatz löschen');
$('#action-delete-modal-title').text('Ausgewählten Datensatz löschen?');
$('#action-delete-modal-body p').text('Sie haben 1 Datensatz ausgewählt. Soll dieser wirklich gelöscht werden?');
$('#action-delete-modal-body').html('');
$('#action-delete-modal-body').append('<p>Sie haben 1 Datensatz ausgewählt. Soll dieser wirklich gelöscht werden?</p>');
} else if (actionCheckboxes.length > 1) {
$('#action-count').text(actionCheckboxes.length + ' Datensätze ausgewählt');
$('#action-select option[value="delete-selected"]').text('ausgewählte Datensätze löschen');
$('#action-delete-modal-title').text('Ausgewählte Datensätze löschen?');
$('#action-delete-modal-body p').text('Sie haben ' + actionCheckboxes.length + ' Datensätze ausgewählt. Sollen diese wirklich gelöscht werden?');
$('#action-delete-modal-body').html('');
$('#action-delete-modal-body').append('<p>Sie haben ' + actionCheckboxes.length + ' ' + 'Datensätze ausgewählt. Sollen diese wirklich gelöscht werden?</p>');
}
});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ <h5 id="action-delete-modal-title" class="modal-title"></h5>
</div>
<div id="action-delete-modal-body" class="modal-body">
<div class="text-center">
<p></p>
</div>
</div>
<div class="modal-footer">
Expand Down
14 changes: 13 additions & 1 deletion datenmanagement/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from .views.api import DatenmanagementViewSet
from .views.functions import assign_object_value, delete_object_immediately
from .views.views_form import DataAddView, DataChangeView, DataDeleteView
from .views.views_general import GeometryView, GISFiletoGeoJSON, IndexView, StartView
from .views.views_general import GeometryView, GISFiletoGeoJSON, IndexView, StartView, \
AddAnotherView
from .views.views_list_map import MapDataCompositionView, MapListView, TableDataCompositionView, \
TableListView

Expand Down Expand Up @@ -205,6 +206,17 @@ def permission_required(*perms):
)
)

# page for creating another object of a model, based on the object just created
urlpatterns.append(
path(
model_name + '/add_another',
view=permission_required(
'datenmanagement.add_' + model_name_lower
)(AddAnotherView.as_view(model=model)),
name=model_name + '_add_another'
)
)

# form page for updating an object of a model
urlpatterns.append(
path(
Expand Down
6 changes: 4 additions & 2 deletions datenmanagement/views/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,15 @@ def get_model_objects(model, subset_id=None, count_only=False):
def get_url_back(referer, fallback, lazy=False):
"""
returns URL used for buttons leading "back" (to somewehere)
and/or used in case of successfully submitted forms
:param referer: referer
:param fallback: fallback
:param lazy: lazy?
:return: URL used for cancel buttons
:return: URL used for buttons leading "back" (to somewehere)
and/or used in case of successfully submitted forms
"""
if referer and '/delete' not in referer:
if referer and '/add_another' not in referer and '/delete' not in referer:
return referer
return reverse_lazy(fallback) if lazy else reverse(fallback)

Expand Down
18 changes: 14 additions & 4 deletions datenmanagement/views/views_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,24 @@ def form_valid(self, form):
:return: HTTP response if passed form is valid
"""
form.instance.user = self.request.user
referer = form.data.get('original_url_back', None)
object_just_created = form.instance
# return to the page for creating another object of this model,
# based on the object just created
self.success_url = get_url_back(
referer if referer else None,
'datenmanagement:' + self.model.__name__ + '_start',
None,
'datenmanagement:' + self.model.__name__ + '_add_another',
True
)
# store object just created and original referer in session
# for usage in next view
if hasattr(self.request, 'session'):
self.request.session['object_just_created'] = str(object_just_created)
self.request.session['object_just_created_pk'] = str(object_just_created.pk)
self.request.session['original_url_back'] = form.data.get('original_url_back', None)
success(
self.request,
'Der neue Datensatz <strong><em>%s</em></strong> '
'wurde erfolgreich angelegt!' % str(form.instance)
'wurde erfolgreich angelegt!' % str(object_just_created)
)
response = super().form_valid(form)
return response
Expand Down Expand Up @@ -362,6 +370,7 @@ def form_valid(self, form):
:return: HTTP response if passed form is valid
"""
form.instance.user = self.request.user
# return to either the original referer or a default page
referer = form.data.get('original_url_back', None)
self.success_url = get_url_back(
referer if referer and '/list' in referer else None,
Expand Down Expand Up @@ -461,6 +470,7 @@ def form_valid(self, form, **kwargs):
:param form: form
:return: HTTP response if passed form is valid
"""
# return to either the original referer or a default page
referer = form.data.get('original_url_back', None)
self.success_url = get_url_back(
referer if referer and '/list' in referer else None,
Expand Down
31 changes: 31 additions & 0 deletions datenmanagement/views/views_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,34 @@ def get_context_data(self, **kwargs):
context['url_model_map'] = reverse('datenmanagement:' + model_name + '_map')
context['url_back'] = reverse('datenmanagement:index')
return context


class AddAnotherView(TemplateView):
"""
view for page for creating another object of a model, based on the object just created
:param model: model
"""

model = None
template_name = 'datenmanagement/add_another.html'

def __init__(self, model=None):
self.model = model
super().__init__()

def get_context_data(self, **kwargs):
"""
returns a dictionary with all context elements for this view
:param kwargs:
:return: dictionary with all context elements for this view
"""
context = super().get_context_data(**kwargs)
# add basic model related elements to context
context = add_basic_model_context_elements(context, self.model)
context['object'] = self.request.session.get('object_just_created', None)
pk = self.request.session.get('object_just_created_pk', None)
context['url_yes'] = reverse('datenmanagement:' + self.model.__name__ + '_change', args=[pk])
context['url_no'] = self.request.session.get('original_url_back', None)
return context

0 comments on commit 84c8567

Please sign in to comment.