Skip to content

Commit

Permalink
App Datenmanagement: kleine Bugfixes und Bereinigungsarbeiten im Code
Browse files Browse the repository at this point in the history
  • Loading branch information
gdmhrogut committed Sep 22, 2023
1 parent a26d0c6 commit f7cb656
Show file tree
Hide file tree
Showing 14 changed files with 658 additions and 656 deletions.
20 changes: 10 additions & 10 deletions datenmanagement/templates/datenmanagement/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{{ block.super }}
{% leaflet_css plugins="geoman,locatecontrol" %}
<link rel="stylesheet" type="text/css" href="{% static 'datenmanagement/css/form.css' %}">
{% if forms_in_mobile_mode or request.user_agent.is_mobile or request.user_agent.is_tablet %}
{% if forms_in_mobile_mode or is_mobile %}
<link rel="stylesheet" type="text/css" href="{% static 'datenmanagement/css/form-mobile.css' %}">
{% if forms_in_mobile_mode %}
<link rel="stylesheet" type="text/css" href="{% static 'datenmanagement/css/form-mobile-mode.css' %}">
Expand Down Expand Up @@ -174,7 +174,7 @@ <h5 class="alert-heading">assoziierte Datensätze</h5>
{% elif address_type == 'Straße' %}
<button disabled id="mapToStreet" class="btn btn-primary" type="button"><i class="fas fa-road"></i> Straße übernehmen</button>
{% elif address_type == 'Gemeindeteil' %}
<button disabled id="mapToQuarter" class="btn btn-primary" type="button"><i class="fas fa-circle-dot"></i> Gemeindeteil übernehmen</button>
<button disabled id="mapToDistrict" class="btn btn-primary" type="button"><i class="fas fa-circle-dot"></i> Gemeindeteil übernehmen</button>
{% endif %}
{% endif %}
</div>
Expand Down Expand Up @@ -223,13 +223,13 @@ <h5 class="alert-heading">assoziierte Datensätze</h5>
<div id="buttons">
<div class="d-grid mt-5 mb-3 gap-2 d-md-block">
{% 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 %}
<button class="btn btn-primary" type="submit" onclick="setFinalArrayFields(); setFinalGeometry();"><i class="fas fa-floppy-disk"></i> {% if not forms_in_mobile_mode and not request.user_agent.is_mobile and not request.user_agent.is_tablet %}{% if object %}Änderungen{% else %}neuen Datensatz{% endif %} {% endif %}speichern</button>
<button class="btn btn-primary" type="submit" onclick="setFinalArrayFields(); setFinalGeometry();"><i class="fas fa-floppy-disk"></i> {% if not forms_in_mobile_mode and not is_mobile %}{% if object %}Änderungen{% else %}neuen Datensatz{% endif %} {% endif %}speichern</button>
{% endif %}
{% if object and user|user_has_model_add_permission:model_name_lower %}
<button class="btn btn-primary" type="submit" onclick="cloneObject(); setFinalArrayFields(); setFinalGeometry();"><i class="fas fa-clone"></i> {% if not forms_in_mobile_mode and not request.user_agent.is_mobile and not request.user_agent.is_tablet %}als neuen Datensatz {% endif %}klonen</button>
<button class="btn btn-primary" type="submit" onclick="cloneObject(); setFinalArrayFields(); setFinalGeometry();"><i class="fas fa-clone"></i> {% if not forms_in_mobile_mode and not is_mobile %}als neuen Datensatz {% endif %}klonen</button>
{% endif %}
{% if object and user|user_has_model_delete_permission:model_name_lower %}
<a class="btn btn-danger" role="button" href="{% url 'datenmanagement:'|add:model_name|add:'_delete' object.pk %}"><i class="fas fa-trash"></i> {% if not forms_in_mobile_mode and not request.user_agent.is_mobile and not request.user_agent.is_tablet %}Datensatz {% endif %}löschen</a>
<a class="btn btn-danger" role="button" href="{% url 'datenmanagement:'|add:model_name|add:'_delete' object.pk %}"><i class="fas fa-trash"></i> {% if not forms_in_mobile_mode and not is_mobile %}Datensatz {% endif %}löschen</a>
{% endif %}
<a class="btn btn-warning" role="button" href="{% url 'datenmanagement:'|add:model_name|add:'_start' %}"><i class="fas fa-hand"></i> abbrechen</a>
</div>
Expand Down Expand Up @@ -278,7 +278,7 @@ <h5 class="alert-heading">assoziierte Datensätze</h5>
window.currMap = map;

// bei mobilen Geräten: Standortbestimmung hinzufügen
{% if request.user_agent.is_mobile or request.user_agent.is_tablet %}
{% if is_mobile %}
enableMapLocate(map)
{% endif %}

Expand Down Expand Up @@ -730,7 +730,7 @@ <h5 class="alert-heading">assoziierte Datensätze</h5>
});

// bei Klick auf Button „Gemeindeteil übernehmen“...
$('#mapToQuarter').on('click', function () {
$('#mapToDistrict').on('click', function () {
// aktuellen Gemeindeteil der Geometrie in der Karte übernehmen
setAddressReference(window.addressType, window.currMap.pm.getGeomanLayers()[0]);
$('#addressToMap').prop('disabled', false);
Expand All @@ -741,7 +741,7 @@ <h5 class="alert-heading">assoziierte Datensätze</h5>

// 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 request.user_agent.is_mobile and not request.user_agent.is_tablet and geometry_type %}
{% if not forms_in_mobile_mode and not is_mobile and geometry_type %}
setButtonsPosition();
{% endif %}

Expand Down Expand Up @@ -870,7 +870,7 @@ <h5 class="alert-heading">assoziierte Datensätze</h5>
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 request.user_agent.is_mobile and not request.user_agent.is_tablet and geometry_type %}
{% if not forms_in_mobile_mode and not is_mobile and geometry_type %}
setButtonsPosition();
{% endif %}
}
Expand Down Expand Up @@ -975,7 +975,7 @@ <h5 class="alert-heading">assoziierte Datensätze</h5>
{% elif address_type == 'Straße' %}
$('#mapToStreet').prop('disabled', false);
{% elif address_type == 'Gemeindeteil' %}
$('#mapToQuarter').prop('disabled', false);
$('#mapToDistrict').prop('disabled', false);
{% endif %}
}

Expand Down
8 changes: 4 additions & 4 deletions datenmanagement/templates/datenmanagement/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h2>Datenthemen, die Ihnen zur Verfügung stehen:</h2>
<h3 class="mt-3">Meta-Datenthemen</h3>
<div class="list-group mb-3">
{% for model in models_meta %}
<a class="list-group-item list-group-item-action list-group-item-info" href="{% url 'datenmanagement:'|add:model.name|add:'_start' %}">
<a class="list-group-item list-group-item-action list-group-item-info" href="{{ model.url_start }}">
<h4>{{ model.verbose_name_plural }}</h4>
<h5><small>{{ model.description }}</small></h5>
</a>
Expand All @@ -22,7 +22,7 @@ <h5><small>{{ model.description }}</small></h5>
<h3 class="mt-3">Codelisten</h3>
<div class="list-group mb-3">
{% for model in models_codelist %}
<a class="list-group-item list-group-item-action list-group-item-secondary" href="{% url 'datenmanagement:'|add:model.name|add:'_start' %}">
<a class="list-group-item list-group-item-action list-group-item-secondary" href="{{ model.url_start }}">
<h4>{{ model.verbose_name_plural }}</h4>
<h5><small>{{ model.description }}</small></h5>
</a>
Expand All @@ -33,7 +33,7 @@ <h5><small>{{ model.description }}</small></h5>
<h3 class="mt-3">Komplexe Datenthemen</h3>
<div class="list-group mb-3">
{% for model in models_complex %}
<a class="list-group-item list-group-item-action list-group-item-primary" href="{% url 'datenmanagement:'|add:model.name|add:'_start' %}">
<a class="list-group-item list-group-item-action list-group-item-primary" href="{{ model.url_start }}">
<h4>{{ model.verbose_name_plural }}</h4>
<h5><small>{{ model.description }}</small></h5>
</a>
Expand All @@ -44,7 +44,7 @@ <h5><small>{{ model.description }}</small></h5>
<h3 class="mt-3">Einfache Datenthemen</h3>
<div class="list-group mb-3">
{% for model in models_simple %}
<a class="list-group-item list-group-item-action list-group-item-primary" href="{% url 'datenmanagement:'|add:model.name|add:'_start' %}">
<a class="list-group-item list-group-item-action list-group-item-primary" href="{{ model.url_start }}">
<h4>{{ model.verbose_name_plural }}</h4>
<h5><small>{{ model.description }}</small></h5>
</a>
Expand Down
2 changes: 1 addition & 1 deletion datenmanagement/templates/datenmanagement/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h4 class="mt-3">
{% endif %}
</em>
</h4>
<div class="d-grid gap-2{% if not request.user_agent.is_mobile and not request.user_agent.is_tablet %} d-md-block{% endif %}">
<div class="d-grid gap-2{% if not is_mobile %} d-md-block{% endif %}">
{% if editable and user|user_has_model_add_permission:model_name_lower %}
<a class="btn btn-primary" role="button" href="{% url 'datenmanagement:'|add:model_name|add:'_add' %}"><i class="fas fa-circle-plus"></i> neuen Datensatz anlegen</a>
{% endif %}
Expand Down
18 changes: 8 additions & 10 deletions datenmanagement/templates/datenmanagement/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{{ block.super }}
{% leaflet_css plugins="locatecontrol,markercluster" %}
<link rel="stylesheet" type="text/css" href="{% static 'datenmanagement/css/map.css' %}">
{% if request.user_agent.is_mobile or request.user_agent.is_tablet %}
{% if is_mobile %}
<link rel="stylesheet" type="text/css" href="{% static 'datenmanagement/css/map-mobile.css' %}">
{% else %}
<link rel="stylesheet" type="text/css" href="{% static 'datenmanagement/css/map-desktop.css' %}">
Expand Down Expand Up @@ -41,7 +41,7 @@ <h4 class="mt-3">
{% endif %}
</em>
</h4>
<div class="d-grid mb-3 gap-2{% if not request.user_agent.is_mobile and not request.user_agent.is_tablet %} d-md-block{% endif %}">
<div class="d-grid mb-3 gap-2{% if not is_mobile %} d-md-block{% endif %}">
{% if user|user_has_model_add_permission:model_name_lower %}
<a class="btn btn-primary" role="button" href="{% url 'datenmanagement:'|add:model_name|add:'_add' %}"><i class="fas fa-circle-plus"></i> neuen Datensatz anlegen</a>
{% endif %}
Expand All @@ -61,7 +61,7 @@ <h4 class="mt-3">
<div id="map-side-container" class="mb-3">
{% leaflet_map "map" callback="window.mapCallbackFunction" %}
{% if map_filters_enabled %}
<div id="filter"{% if not request.user_agent.is_mobile and not request.user_agent.is_tablet %} class="side"{% endif %}>
<div id="filter"{% if not is_mobile %} class="side"{% endif %}>
<h5>Filter für Kartenobjekte</h5>
<div id="filter-alert" class="alert alert-warning" role="alert">Filter wirken <strong>additiv</strong> (wie „UND“)</div>
{% if map_one_click_filters %}
Expand Down Expand Up @@ -190,14 +190,14 @@ <h6>Ein-Klick-Filter</h6>
</div>
</div>
{% endif %}
<div {% if map_filters_enabled %}id="map-control"{% endif %}{% if not request.user_agent.is_mobile and not request.user_agent.is_tablet %} class="side"{% endif %}>
<div {% if map_filters_enabled %}id="map-control"{% endif %}{% if not is_mobile %} class="side"{% endif %}>
<h5>Kartenausschnitt</h5>
<div class="d-grid mt-2 gap-2 d-md-block">
<button id="map-extent-filter" class="btn btn-success"><i class="fas fa-map-location"></i> {% if map_filters_enabled %}aktuelle Filtermenge{% else %}alle Objekte{% endif %}</button>
<button id="map-extent-initial" class="btn btn-warning"><i class="fas fa-map"></i> gesamt</button>
</div>
</div>
<div id="address-search"{% if not request.user_agent.is_mobile and not request.user_agent.is_tablet %} class="side"{% endif %}>
<div id="address-search"{% if not is_mobile %} class="side"{% endif %}>
<h5>Adressensuche</h5>
<div class="form-floating">
<input id="searchtext" type="text" class="form-control" name="searchtext" autocapitalize="off" autocomplete="off" placeholder="Adresse, Straße oder Gemeindeteil eingeben…">
Expand Down Expand Up @@ -229,9 +229,6 @@ <h5>Adressensuche</h5>
window.currMap = map;

// define several globally available variables
{% if request.user_agent.is_mobile or request.user_agent.is_tablet %}
window.mobile = true
{% endif %}
window.geometryType = '{{ geometry_type }}';
{% if heavy_load_limit %}
window.heavyLoadLimit = true
Expand All @@ -247,8 +244,9 @@ <h5>Adressensuche</h5>
{% endif %}

// bei mobilen Geräten: Standortbestimmung hinzufügen
if (window.mobile)
enableMapLocate(map);
{% if is_mobile %}
enableMapLocate(map)
{% endif %}

/**
* @function
Expand Down
16 changes: 8 additions & 8 deletions datenmanagement/templates/datenmanagement/start.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ <h2>{{ model_verbose_name_plural }}</h2>
<h4><small>{{ model_description }}</small></h4>
<h4 class="mt-3"><em>Was möchten Sie tun?</em></h4>
<div class="d-grid mt-3 gap-3 mx-auto">
{% if model_is_editable and user|user_has_model_add_permission:model_name_lower %}
<a class="btn btn-lg btn-primary" role="button" href="{% url 'datenmanagement:'|add:model_name|add:'_add' %}"><i class="fas fa-circle-plus"></i> neuen Datensatz anlegen</a>
{% if url_model_add %}
<a class="btn btn-lg btn-primary" role="button" href="{{ url_model_add }}"><i class="fas fa-circle-plus"></i> neuen Datensatz anlegen</a>
{% endif %}
{% if user|user_has_model_change_permission:model_name_lower or user|user_has_model_delete_permission:model_name_lower or user|user_has_model_view_permission:model_name_lower %}
<a class="btn btn-lg btn-secondary" role="button" href="{% url 'datenmanagement:'|add:model_name|add:'_list' %}"><i class="fas fa-table"></i> alle Datensätze in Tabelle auflisten</a>
{% if model_has_geometry %}
<a class="btn btn-lg btn-secondary" role="button" href="{% url 'datenmanagement:'|add:model_name|add:'_map' %}"><i class="fas fa-map"></i> alle Datensätze auf Karte anzeigen</a>
{% endif %}
{% if url_model_list %}
<a class="btn btn-lg btn-secondary" role="button" href="{{ url_model_list }}"><i class="fas fa-table"></i> alle Datensätze in Tabelle auflisten</a>
{% endif %}
{% if url_model_map %}
<a class="btn btn-lg btn-secondary" role="button" href="{{ url_model_map }}"><i class="fas fa-map"></i> alle Datensätze auf Karte anzeigen</a>
{% endif %}
<a class="btn btn-lg btn-warning" role="button" href="{% url 'datenmanagement:index' %}"><i class="fas fa-backward"></i> zurück</a>
<a class="btn btn-lg btn-warning" role="button" href="{{ url_back }}"><i class="fas fa-backward"></i> zurück</a>
</div>
<script>
setTimeout(function () {
Expand Down
3 changes: 1 addition & 2 deletions datenmanagement/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
from .views.api import DatenmanagementViewSet
from .views.functions import delete_object_immediately
from .views.views_form import DataAddView, DataChangeView, DataDeleteView
from .views.views_helpers import GeometryView, GISFiletoGeoJSON
from .views.views_general import IndexView, StartView
from .views.views_general import GeometryView, GISFiletoGeoJSON, IndexView, StartView
from .views.views_list_map import DataListView, DataMapListView, DataMapView, DataView


Expand Down
62 changes: 60 additions & 2 deletions datenmanagement/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import date
from datetime import date, datetime
from django.conf import settings
from django.contrib.gis.db.models.fields import LineStringField as ModelLineStringField
from django.contrib.gis.db.models.fields import MultiLineStringField as ModelMultiLineStringField
Expand All @@ -10,6 +10,7 @@
from django.contrib.gis.forms.fields import MultiPolygonField as FormMultiPolygonField
from django.contrib.gis.forms.fields import PointField as FormPointField
from django.contrib.gis.forms.fields import PolygonField as FormPolygonField
from locale import LC_ALL, format_string, setlocale
from pathlib import Path
from uuid import uuid4

Expand All @@ -23,6 +24,22 @@ def get_current_year():
return int(date.today().year)


def get_data(curr_object, field):
"""
returns the data of the passed model field for the passed object
:param curr_object: object
:param field: model field
:return: data of the passed model field for the passed object
"""
data = getattr(curr_object, field)
if isinstance(data, date):
data = data.strftime('%Y-%m-%d')
elif isinstance(data, datetime):
data = data.strftime('%Y-%m-%d %H:%M:%S')
return data


def get_field_name_for_address_type(model, l10n=True):
"""
returns name of address related field depending on address reference type of passed model
Expand Down Expand Up @@ -54,6 +71,17 @@ def get_path(url):
return path


def get_thumb_url(url):
"""
returns the associated thumbnail URL for the passed URL of a photo
:param url: URL of a photo
:return: associated thumbnail URL for the passed URL of a photo
"""
path = Path(url)
return str(path.parent / 'thumbs' / path.name)


def is_address_related_field(field):
"""
checks if passed field is an address related field
Expand Down Expand Up @@ -91,6 +119,17 @@ def is_geometry_field(field):
return False


def localize_number(value):
"""
returns the passed numerical value localized
:param value: numerical value
:return: localized version of the passed numerical value
"""
setlocale(LC_ALL, 'de_DE.UTF-8')
return format_string('%.2f', value, grouping=True)


def path_and_rename(path):
"""
cleans passed path and returns it
Expand All @@ -117,7 +156,7 @@ def wrapper(instance, filename):
return wrapper


def user_has_model_permissions_at_all(user, model):
def user_has_model_permissions_any(user, model):
"""
checks whether the passed user has any rights on the passed model
Expand All @@ -135,3 +174,22 @@ def user_has_model_permissions_at_all(user, model):
return True
else:
return False


def user_has_model_permissions_change_delete_view(user, model):
"""
checks whether the passed user has change, delete or view rights on the passed model
:param user: user
:param model: model
:return: has the passed user change, delete or view rights on the passed model?
"""
model_name_lower = model.__name__.lower()
if (
user.has_perm('datenmanagement.change_' + model_name_lower)
or user.has_perm('datenmanagement.delete_' + model_name_lower)
or user.has_perm('datenmanagement.view_' + model_name_lower)
):
return True
else:
return False
Loading

0 comments on commit f7cb656

Please sign in to comment.