diff --git a/datenmanagement/static/datenmanagement/js/map.js b/datenmanagement/static/datenmanagement/js/map.js index 8a6e50b1..7d5e3e00 100644 --- a/datenmanagement/static/datenmanagement/js/map.js +++ b/datenmanagement/static/datenmanagement/js/map.js @@ -224,7 +224,7 @@ function filterGeoJsonFeatures(filterObjectsList, layer, isSubLayer, clusterLaye * @param {Object} layer - GeoJSON map layer */ function setGeoJsonFeaturePropertiesAndActions(feature, layer) { - // if feature has a link to its viewing/changing page... + // if feature has a link to its form page... if (feature.properties.link) { // open link when clicking on feature layer.on('click', function () { diff --git a/datenmanagement/templates/datenmanagement/form.html b/datenmanagement/templates/datenmanagement/form.html index 1fad6324..8e28fa11 100644 --- a/datenmanagement/templates/datenmanagement/form.html +++ b/datenmanagement/templates/datenmanagement/form.html @@ -84,7 +84,7 @@
assoziierte Datensätze
{% endif %}
{% csrf_token %} -
+
{% for field in form %} {% if not field|is_field_address_related_field and not field|is_field_geometry_field %} @@ -107,7 +107,7 @@
assoziierte Datensätze
{% endwith %} {% endif %} {% with foreign_model=field.name|get_foreign_key_field_class_name:model_name %} - {% if geometry_type and foreign_model|has_model_geometry_field %} + {% if model_geometry_type and foreign_model|has_model_geometry_field %} {% endif %} {% endwith %} @@ -153,19 +153,19 @@
assoziierte Datensätze
{% endif %}
- {% if geometry_type %} + {% if model_geometry_type %}
{% if geometry %} {% else %} - + {% endif %} {% leaflet_map "leaflet-map" callback="window.mapCallbackFunction" %} {% if not object and user|user_has_model_add_permission:model_name_lower or object and user|user_has_model_change_permission:model_name_lower %} - {% if geometry_type == 'Point' or address_type and not address_mandatory %} + {% if model_geometry_type == 'Point' or address_type and not address_mandatory %}
- {% if geometry_type == 'Point' %} + {% if model_geometry_type == 'Point' %} {% endif %} {% if not address_mandatory %} @@ -231,7 +231,7 @@
assoziierte Datensätze
{% if object and user|user_has_model_delete_permission:model_name_lower %} {% if not forms_in_mobile_mode and not is_mobile %}Datensatz {% endif %}löschen {% endif %} - abbrechen + abbrechen
{% include "modal-error.html" %} @@ -315,10 +315,10 @@
assoziierte Datensätze
// Leaflet-Geoman konfigurieren {% if not gpx_input %} - {% if 'LineString' in geometry_type %} + {% if 'LineString' in model_geometry_type %} configureLeafletGeoman(map, 'LineString') - {% elif geometry_type == 'Point' or geometry_type == 'Polygon' or geometry_type == 'MultiPolygon' %} - configureLeafletGeoman(map, '{{ geometry_type }}') + {% elif model_geometry_type == 'Point' or model_geometry_type == 'Polygon' or model_geometry_type == 'MultiPolygon' %} + configureLeafletGeoman(map, '{{ model_geometry_type }}') {% else %} configureLeafletGeoman(map) {% endif %} @@ -478,7 +478,7 @@
assoziierte Datensätze
* prüft beim Start des Modus „Zeichnen“, ob es bereits einen Leaflet-Geoman-Layer gibt, und löscht diesen gegebenenfalls */ map.on('pm:drawstart', function () { - {% if geometry_type == 'Point' or geometry_type == 'LineString' or geometry_type == 'Polygon' %} + {% if model_geometry_type == 'Point' or model_geometry_type == 'LineString' or model_geometry_type == 'Polygon' %} if (map.pm.getGeomanLayers().length > 0) { map.pm.getGeomanLayers().forEach((item) => { if (item._drawnByGeoman === true) @@ -504,7 +504,7 @@
assoziierte Datensätze
// Adressenbezug für gesetze Geometrie setzen setAddressReference('{{ address_type }}', layer); // bei Bewegungs-Event Adressenbezug neu setzen - {% if geometry_type == 'Point' %} + {% if model_geometry_type == 'Point' %} layer.on('pm:dragend', (e) => { setAddressReference('{{ address_type }}', e.layer); }); @@ -741,7 +741,7 @@
assoziierte Datensätze
// bei Desktop und bei vorhandener Karte: // vertikale Position der Buttons dynamisch setzen anhand von Position und Größe des Formulars (plus „Puffer“ von 20 Pixeln) - {% if not forms_in_mobile_mode and not is_mobile and geometry_type %} + {% if not forms_in_mobile_mode and not is_mobile and model_geometry_type %} setButtonsPosition(); {% endif %} @@ -768,7 +768,7 @@
assoziierte Datensätze
link.prop('hidden', false); } else link.prop('hidden', true); - {% if geometry_type and foreign_model|has_model_geometry_field %} + {% if model_geometry_type and foreign_model|has_model_geometry_field %} currMap.pm.getGeomanLayers().forEach((layer) => { if (layer.toGeoJSON().properties.foreignkey === '{{ foreign_model }}') { layer.remove(); @@ -870,7 +870,7 @@
assoziierte Datensätze
addDeleteFieldButton(field); // bei Desktop und bei vorhandener Karte: // vertikale Position der Buttons dynamisch setzen anhand von Position und Größe des Formulars (plus „Puffer“ von 20 Pixeln) - {% if not forms_in_mobile_mode and not is_mobile and geometry_type %} + {% if not forms_in_mobile_mode and not is_mobile and model_geometry_type %} setButtonsPosition(); {% endif %} } @@ -953,7 +953,7 @@
assoziierte Datensätze
layer.setLatLng(latLng); } } else { - {% if geometry_type == 'Point' %} + {% if model_geometry_type == 'Point' %} let layer = new L.Marker(getFeatureGeometryLatLng(featureGeometry), { icon: redMarker }); @@ -990,7 +990,7 @@
assoziierte Datensätze
*/ function setAddressReference(addressType, layer) { let geoJson = layer.toGeoJSON(); - let geometryType = '{{ geometry_type|lower }}'; + let geometryType = '{{ model_geometry_type|lower }}'; if (geometryType.indexOf('point') !== -1) geometryType = 'Point'; else if (geometryType.indexOf('line') !== -1) @@ -1079,23 +1079,23 @@
assoziierte Datensätze
* übernimmt erstellte Geometrie(n) aus der Karte final in Feld #id_geometry */ function setFinalGeometry() { - {% if geometry_type %} + {% if model_geometry_type %} let jsonGeometrie; if (currMap.pm.getGeomanDrawLayers().length < 1) { let coordinates; - {% if geometry_type == 'Point' %} + {% if model_geometry_type == 'Point' %} coordinates = [0, 0]; - {% elif geometry_type == 'Polygon' %} + {% elif model_geometry_type == 'Polygon' %} coordinates = [[]]; {% else %} coordinates = []; {% endif %} jsonGeometrie = { - 'type': '{{ geometry_type }}', + 'type': '{{ model_geometry_type }}', 'coordinates': coordinates }; } else { - {% if geometry_type == 'MultiPolygon' or geometry_type == 'MultiPoint' or geometry_type == 'MultiLineString' %} + {% if model_geometry_type == 'MultiPolygon' or model_geometry_type == 'MultiPoint' or model_geometry_type == 'MultiLineString' %} let coordinates = []; let temp; currMap.pm.getGeomanDrawLayers().forEach(function (layer) { @@ -1109,7 +1109,7 @@
assoziierte Datensätze
} }); jsonGeometrie = { - 'type': '{{ geometry_type }}', + 'type': '{{ model_geometry_type }}', 'coordinates': coordinates, }; {% else %} @@ -1255,7 +1255,7 @@
assoziierte Datensätze
// und die Geometrie auf die Karte gezeichnet $('#postcode-assigner').parent('span').click(function () { let geoJson = currMap.pm.getGeomanLayers()[0].toGeoJSON(); - let geometryType = '{{ geometry_type|lower }}'; + let geometryType = '{{ model_geometry_type|lower }}'; if (geometryType.indexOf('point') !== -1) geometryType = 'Point'; else if (geometryType.indexOf('line') !== -1) diff --git a/datenmanagement/views/functions.py b/datenmanagement/views/functions.py index 46ffd665..243b078f 100644 --- a/datenmanagement/views/functions.py +++ b/datenmanagement/views/functions.py @@ -23,40 +23,14 @@ def add_basic_model_context_elements(context, model): :param model: model :return: context with basic model related elements added """ - context['model_name'] = model.__name__ - context['model_verbose_name_plural'] = model._meta.verbose_name_plural - context['model_description'] = model.BasemodelMeta.description - context['model_is_editable'] = model.BasemodelMeta.editable - context['model_geometry_type'] = model.BasemodelMeta.geometry_type - context['model_pk_field_name'] = model._meta.pk.name - return context - - -def add_model_context_elements(context, model, kwargs=None): - """ - adds model related elements to the passed context and returns the context - - :param context: context - :param model: model - :param kwargs: kwargs of the view calling this function - :return: context with model related elements added - """ model_name = model.__name__ context['model_name'] = model_name context['model_name_lower'] = model_name.lower() - context['model_pk_field'] = model._meta.pk.name - context['model_verbose_name'] = model._meta.verbose_name context['model_verbose_name_plural'] = model._meta.verbose_name_plural context['model_description'] = model.BasemodelMeta.description - context['editable'] = model.BasemodelMeta.editable - context['geometry_type'] = model.BasemodelMeta.geometry_type - context['subset_id'] = None - if kwargs and kwargs['subset_id']: - subset_id = int(kwargs['subset_id']) - context['subset_id'] = subset_id - context['objects_count'] = get_model_objects(model, subset_id, True) - else: - context['objects_count'] = get_model_objects(model, None, True) + context['model_is_editable'] = model.BasemodelMeta.editable + context['model_geometry_type'] = model.BasemodelMeta.geometry_type + context['model_pk_field_name'] = model._meta.pk.name return context diff --git a/datenmanagement/views/views_form.py b/datenmanagement/views/views_form.py index 209f0b47..2f775ad8 100644 --- a/datenmanagement/views/views_form.py +++ b/datenmanagement/views/views_form.py @@ -13,78 +13,75 @@ from datenmanagement.utils import get_field_name_for_address_type, get_thumb_url, \ is_address_related_field, is_geometry_field from .forms import GenericForm -from .functions import add_user_agent_context_elements, assign_widgets, set_form_attributes, \ - add_model_form_context_elements, add_model_context_elements +from .functions import add_basic_model_context_elements, add_model_form_context_elements, \ + add_user_agent_context_elements, assign_widgets, set_form_attributes class DataAddView(CreateView): """ - erstellt ein neues Datenbankobjekt eines Datensatzes - - :param model: Datenmodell - :param template_name: Name des Templates - :param success_url: Success-URL + view for form page for creating an object of a model """ - def __init__(self, model=None, template_name=None, success_url=None): + def __init__(self, model=None, *args, **kwargs): self.model = model - self.template_name = template_name - self.success_url = success_url self.form_class = modelform_factory( self.model, form=GenericForm, fields='__all__', - formfield_callback=assign_widgets) + formfield_callback=assign_widgets + ) self.multi_foto_field = None self.multi_files = None self.file = None - super(DataAddView, self).__init__() + super().__init__(*args, **kwargs) def get_form_kwargs(self): """ - liefert **kwargs als Dictionary mit Formularattributen + returns ``**kwargs`` as a dictionary with form attributes - :return: **kwargs als Dictionary mit Formularattributen + :return: ``**kwargs`` as a dictionary with form attributes """ - kwargs = super(DataAddView, self).get_form_kwargs() + kwargs = super().get_form_kwargs() self = set_form_attributes(self) if self.model.BasemodelMeta.multi_foto_field and self.request.method == 'POST': self.multi_files = self.request.FILES if self.request.method == 'POST': self.file = self.request.FILES - kwargs[ - 'fields_with_foreign_key_to_linkify'] = self.fields_with_foreign_key_to_linkify - kwargs[ - 'choices_models_for_choices_fields'] = self.choices_models_for_choices_fields - kwargs[ - 'group_with_users_for_choice_field'] = self.group_with_users_for_choice_field + kwargs['request'] = self.request + kwargs['model'] = self.model + kwargs['fields_with_foreign_key_to_linkify'] = self.fields_with_foreign_key_to_linkify + kwargs['choices_models_for_choices_fields'] = self.choices_models_for_choices_fields + kwargs['group_with_users_for_choice_field'] = self.group_with_users_for_choice_field kwargs['multi_foto_field'] = self.model.BasemodelMeta.multi_foto_field - kwargs['multi_files'] = self.multi_files kwargs['file'] = self.file - kwargs['model'] = self.model - kwargs['request'] = self.request + kwargs['multi_files'] = self.multi_files return kwargs def get_context_data(self, **kwargs): """ - liefert Dictionary mit Kontextelementen des Views + returns a dictionary with all context elements for this view :param kwargs: - :return: Dictionary mit Kontextelementen des Views + :return: dictionary with all context elements for this view """ + model_name = self.model.__name__ context = super().get_context_data(**kwargs) # add user agent related elements to context context = add_user_agent_context_elements(context, self.request) - context = add_model_context_elements(context, self.model) + # add basic model related elements to context + context = add_basic_model_context_elements(context, self.model) + # add model form related elements to context context = add_model_form_context_elements(context, self.model) + # add further elements to context context['multi_foto_field'] = self.model.BasemodelMeta.multi_foto_field + context['url_back'] = reverse('datenmanagement:' + model_name + '_start') return context def get_initial(self): """ - setzt initiale Feldwerte im View + conditionally sets initial field values for this view - :return: Dictionary mit initialen Feldwerten im View + :return: dictionary with initial field values for this view """ ansprechpartner = None bearbeiter = None @@ -113,10 +110,10 @@ def get_initial(self): def form_valid(self, form): """ - sendet eine HTTP-Response, wenn Formular valide ist + sends HTTP response if passed form is valid - :param form: Formular, das geprüft werden soll - :return: Success-URL als HTTP-Response, falls Formular valide + :param form: form + :return: HTTP response if passed form is valid """ form.instance.user = self.request.user success( @@ -124,7 +121,7 @@ def form_valid(self, form): 'Der neue Datensatz %s ' 'wurde erfolgreich angelegt!' % str(form.instance) ) - return super(DataAddView, self).form_valid(form) + return super().form_valid(form) def form_invalid(self, form, **kwargs): """ @@ -157,55 +154,45 @@ def form_invalid(self, form, **kwargs): class DataChangeView(UpdateView): """ - ändert ein vorhandenes Datenbankobjekt eines Datensatzes - - :param model: Datenmodell - :param template_name: Name des Templates - :param success_url: Success-URL + view for form page for updating an object of a model """ - def __init__(self, model=None, template_name=None, success_url=None): + def __init__(self, model=None, *args, **kwargs): self.model = model - self.template_name = template_name - self.success_url = success_url self.form_class = modelform_factory( - self.model, - form=GenericForm, - fields='__all__', - formfield_callback=assign_widgets) - self.associated_models = None + self.model, + form=GenericForm, + fields='__all__', + formfield_callback=assign_widgets + ) self.file = None - self.associated_new = None self.associated_objects = None - super(DataChangeView, self).__init__() + self.associated_new = None + self.associated_models = None + super().__init__(*args, **kwargs) def get_form_kwargs(self): """ - liefert **kwargs als Dictionary mit Formularattributen + returns ``**kwargs`` as a dictionary with form attributes - :return: **kwargs als Dictionary mit Formularattributen + :return: ``**kwargs`` as a dictionary with form attributes """ - kwargs = super(DataChangeView, self).get_form_kwargs() + kwargs = super().get_form_kwargs() self = set_form_attributes(self) self.associated_objects = None self.associated_new = None self.associated_models = self.model.BasemodelMeta.associated_models if self.request.method == 'POST': self.file = self.request.FILES + kwargs['request'] = self.request + kwargs['model'] = self.model kwargs['associated_objects'] = self.associated_objects kwargs['associated_new'] = self.associated_new - kwargs[ - 'fields_with_foreign_key_to_linkify'] = self.fields_with_foreign_key_to_linkify - kwargs[ - 'choices_models_for_choices_fields'] = self.choices_models_for_choices_fields - kwargs[ - 'group_with_users_for_choice_field'] = self.group_with_users_for_choice_field + kwargs['fields_with_foreign_key_to_linkify'] = self.fields_with_foreign_key_to_linkify + kwargs['choices_models_for_choices_fields'] = self.choices_models_for_choices_fields + kwargs['group_with_users_for_choice_field'] = self.group_with_users_for_choice_field kwargs['file'] = self.file - kwargs['model'] = self.model - kwargs['request'] = self.request - - # assoziierte Modelle für die Bereitstellung entsprechender Links - # heranziehen + # use associated models to provide corresponding links if self.associated_models: self.associated_new = [] self.associated_objects = [] @@ -231,26 +218,21 @@ def get_form_kwargs(self): '?preselect_field=' + associated_model_foreign_key_field + '&preselect_value=' + - str( - self.object.pk)} + str(self.object.pk) + } self.associated_new.append(associated_new_dict) curr_filter = { associated_model_foreign_key_field: self.object.pk } - for associated_object in associated_model_model.objects.filter( - **curr_filter): - foto = ( - associated_object.foto if hasattr( - associated_object, - 'foto') else None) + for associated_object in associated_model_model.objects.filter(**curr_filter): + foto = associated_object.foto if hasattr(associated_object, 'foto') else None preview_img_url = '' preview_thumb_url = '' if foto: try: preview_img_url = foto.url + '?' + str(time()) if associated_model_model.BasemodelMeta.thumbs: - preview_thumb_url = get_thumb_url( - foto.url) + '?' + str(time()) + preview_thumb_url = get_thumb_url(foto.url) + '?' + str(time()) except ValueError: pass associated_object_dict = { @@ -258,37 +240,37 @@ def get_form_kwargs(self): 'name': str(associated_object), 'id': associated_object.pk, 'link': reverse( - 'datenmanagement:' + associated_model + '_change', - args=[associated_object.pk]), + 'datenmanagement:' + associated_model + '_change', args=[associated_object.pk]), 'preview_img_url': preview_img_url, 'preview_thumb_url': preview_thumb_url } self.associated_objects.append(associated_object_dict) kwargs['associated_objects'] = self.associated_objects kwargs['associated_new'] = self.associated_new - return kwargs def get_context_data(self, **kwargs): """ - liefert Dictionary mit Kontextelementen des Views + returns a dictionary with all context elements for this view :param kwargs: - :return: Dictionary mit Kontextelementen des Views + :return: dictionary with all context elements for this view """ + model_name = self.model.__name__ context = super().get_context_data(**kwargs) # add user agent related elements to context context = add_user_agent_context_elements(context, self.request) - context = add_model_context_elements(context, self.model) + # add basic model related elements to context + context = add_basic_model_context_elements(context, self.model) + # add model form related elements to context context = add_model_form_context_elements(context, self.model) - context['associated_objects'] = ( - self.associated_objects if self.associated_objects else None) - context['associated_new'] = ( - self.associated_new if self.associated_new else None) + # add further elements to context + context['associated_objects'] = self.associated_objects if self.associated_objects else None + context['associated_new'] = self.associated_new if self.associated_new else None if self.model.BasemodelMeta.geometry_type: with connections['datenmanagement'].cursor() as cursor: cursor.execute( - 'SELECT st_asgeojson(st_transform(geometrie, 4326)) FROM ' + + 'SELECT ST_AsGeoJSON(ST_Transform(geometrie, 4326)) FROM ' + self.model._meta.db_table.replace('"', '') + ' WHERE UUID=%s;', [self.kwargs['pk']] @@ -305,44 +287,42 @@ def get_context_data(self, **kwargs): context['current_' + field_name_for_address_type] = self.object.strasse.pk elif field_name_for_address_type == 'gemeindeteil' and self.object.gemeindeteil: context['current_' + field_name_for_address_type] = self.object.gemeindeteil.pk - # Dictionary für alle Array-Felder und deren Inhalte vorbereiten, - # die als Inhalt mehr als einen Wert umfassen + # prepare a dictionary for all array fields and their contents that contain more than one value array_fields_values = {} for field in self.model._meta.get_fields(): - # bei Array-Feld... if field.__class__.__name__ == 'ArrayField': - # Werte auslesen + # read values values = getattr(self.model.objects.get(pk=self.object.pk), field.name) - # sofern dieses mehr als einen Wert umfasst... + # if more than one value... if values is not None and len(values) > 1: - # Liste für dieses Feld aus allen Array-Inhalten ab dem zweiten zusammenstellen + # compile the list for this field from all array contents starting from the second one array_field_values = values[1:] - # falls Basisfeld des Array-Felds vom Typ Datum ist... + # if base field of array field is of type Date... if field.base_field.__class__.__name__ == 'DateField': - # Listeninhalte formatieren + # format list contents cleaned_array_field_values = [] for array_field_value in array_field_values: cleaned_array_field_values.append(array_field_value.strftime('%Y-%m-%d')) array_field_values = cleaned_array_field_values - # Liste in vorbereitetes Dictionary einfügen + # insert list into prepared dictionary array_fields_values[field.name] = array_field_values - # neuen Kontext anlegen und Dictionary für alle Array-Felder und deren Inhalte - # dort JSON-serialisiert einfügen, die als Inhalt mehr als einen Wert umfassen + # create a new context and insert a JSON-serialized dictionary for all array fields + # and their contents that contain more than one value context['array_fields_values'] = dumps(array_fields_values) + context['url_back'] = reverse('datenmanagement:' + model_name + '_start') return context def get_initial(self): """ - setzt initiale Feldwerte im View + conditionally sets initial field values for this view - :return: Dictionary mit initialen Feldwerten im View + :return: dictionary with initial field values for this view """ - # leeres Dictionary für initiale Feldwerte im View definieren + # declare empty dictionary for initial field values in the view curr_dict = {} - # falls Adresse, Straße oder Gemeindeteil existiert... + # if address, street or district exists... if self.model.BasemodelMeta.address_type: - # Dictionary um entsprechenden initialen Feldwert - # für Adresse, Straße oder Gemeindeteil ergänzen + # add the appropriate initial field value for address, street or district to the dictionary field_name_for_address_type = get_field_name_for_address_type(self.model) if field_name_for_address_type == 'adresse' and self.object.adresse: curr_dict[field_name_for_address_type] = self.object.adresse @@ -351,23 +331,21 @@ def get_initial(self): elif field_name_for_address_type == 'gemeindeteil' and self.object.gemeindeteil: curr_dict[field_name_for_address_type] = self.object.gemeindeteil for field in self.model._meta.get_fields(): - # bei Array-Feld... if field.__class__.__name__ == 'ArrayField': values = getattr(self.model.objects.get(pk=self.object.pk), field.name) - # sofern dieses nicht leer ist... if values is not None and len(values) > 0 and values[0] is not None: - # initialen Wert für dieses Feld auf ersten Wert des Arrays des Objektes setzen + # set initial value for this field to first array element + # and add it to prepared dictionary initial_value = values[0] - # Dictionary um den initialen Wert für dieses Feld ergänzen curr_dict[field.name] = initial_value return curr_dict def form_valid(self, form): """ - sendet eine HTTP-Response, wenn Formular valide ist + sends HTTP response if passed form is valid - :param form: Formular, das geprüft werden soll - :return: Success-URL als HTTP-Response, falls Formular valide + :param form: form + :return: HTTP response if passed form is valid """ form.instance.user = self.request.user success( @@ -375,7 +353,7 @@ def form_valid(self, form): 'Der Datensatz %s ' 'wurde erfolgreich geändert!' % str(form.instance) ) - return super(DataChangeView, self).form_valid(form) + return super().form_valid(form) def form_invalid(self, form, **kwargs): """ @@ -411,59 +389,58 @@ def form_invalid(self, form, **kwargs): def get_object(self, *args, **kwargs): """ - liefert Objekt zurück, das geändert werden soll; - bei fehlenden Rechten wird PermissionDenied()-Exeption geworfen + returns object to be changed; + if rights are missing, a ``PermissionDenied()`` exception is thrown :param args: :param kwargs: - :return: Objekt, das geändert werden soll + :return: object to be changed """ - obj = super(DataChangeView, self).get_object(*args, **kwargs) + obj = super().get_object(*args, **kwargs) return obj class DataDeleteView(SuccessMessageMixin, DeleteView): """ - löscht ein vorhandenes Datenbankobjekt eines Datensatzes + view for form page for deleting an object of a model """ def get_context_data(self, **kwargs): """ - liefert Dictionary mit Kontextelementen des Views + returns a dictionary with all context elements for this view :param kwargs: - :return: Dictionary mit Kontextelementen des Views + :return: """ context = super().get_context_data(**kwargs) - context['model_verbose_name_plural'] = self.model._meta.verbose_name_plural + # add basic model related elements to context + context = add_basic_model_context_elements(context, self.model) return context def get_object(self, *args, **kwargs): """ - liefert Objekt zurück, das gelöscht werden soll; - bei fehlenden Rechten wird PermissionDenied()-Exeption geworfen + returns object to be deleted; + if rights are missing, a ``PermissionDenied()`` exception is thrown :param args: :param kwargs: - :return: Objekt, das gelöscht werden soll + :return: object to be deleted """ - obj = super(DataDeleteView, self).get_object(*args, **kwargs) - userperm_delete = self.request.user.has_perm( - 'datenmanagement.delete_' + self.model.__name__.lower()) - if not userperm_delete: + obj = super().get_object(*args, **kwargs) + if not self.request.user.has_perm('datenmanagement.delete_' + self.model.__name__.lower()): raise PermissionDenied() return obj def form_valid(self, form): """ - sendet eine HTTP-Response, wenn Formular valide ist + sends HTTP response if passed form is valid - :param form: Formular, das geprüft werden soll - :return: Success-URL als HTTP-Response, falls Formular valide + :param form: form + :return: HTTP response if passed form is valid """ success( self.request, 'Der Datensatz %s ' 'wurde erfolgreich gelöscht!' % str(self.object) ) - return super(DataDeleteView, self).form_valid(form) + return super().form_valid(form) diff --git a/datenmanagement/views/views_list_map.py b/datenmanagement/views/views_list_map.py index 1fdf13ef..76876af8 100644 --- a/datenmanagement/views/views_list_map.py +++ b/datenmanagement/views/views_list_map.py @@ -155,7 +155,7 @@ def prepare_results(self, qs): else: data = escape(value) item_data.append(data) - # append links for changing, viewing and/or deleting + # append links for updating, viewing and/or deleting if self.model_is_editable: links = '' if self.request.user.has_perm('datenmanagement.change_' + self.model_name_lower):