diff --git a/moderation/templatetags/moderation_tags.py b/moderation/templatetags/moderation_tags.py index 7eddd2a6..61c6a9d7 100644 --- a/moderation/templatetags/moderation_tags.py +++ b/moderation/templatetags/moderation_tags.py @@ -1,54 +1,56 @@ from django import template -from django.apps import apps -from django.core.exceptions import ObjectDoesNotExist -from rides.models import CATEGORY_CHOICES +from django.utils.safestring import mark_safe +from django.contrib.contenttypes.models import ContentType register = template.Library() @register.filter -def get_object(value, model_path): - """ - Template filter to get an object instance from its ID and model path. - Usage: {{ value|get_object:'app_label.ModelName' }} - """ +def get_object_name(value, model_path): + """Get object name from ID and model path.""" if not value: return None + + app_label, model = model_path.split('.') try: - app_label, model_name = model_path.split('.') - model = apps.get_model(app_label, model_name) - return model.objects.get(id=value) - except (ValueError, LookupError, ObjectDoesNotExist): + content_type = ContentType.objects.get(app_label=app_label.lower(), model=model.lower()) + model_class = content_type.model_class() + obj = model_class.objects.get(id=value) + return str(obj) + except Exception: return None @register.filter def get_category_display(value): - """ - Template filter to get the display name for a ride category. - Usage: {{ value|get_category_display }} - """ - try: - return dict(CATEGORY_CHOICES).get(value, value) - except (KeyError, AttributeError): - return value - -@register.filter -def get_object_name(value, model_path): - """ - Template filter to get an object's name from its ID and model path. - Usage: {{ value|get_object_name:'app_label.ModelName' }} - """ - obj = get_object(value, model_path) - return obj.name if obj else None + """Get display value for ride category.""" + if not value: + return None + + categories = { + 'RC': 'Roller Coaster', + 'DR': 'Dark Ride', + 'FR': 'Flat Ride', + 'WR': 'Water Ride', + 'TR': 'Transport', + 'OT': 'Other' + } + return categories.get(value, value) @register.filter def get_park_area_name(value, park_id): - """ - Template filter to get a park area's name from its ID and park ID. - Usage: {{ value|get_park_area_name:park_id }} - """ - try: - ParkArea = apps.get_model('parks', 'ParkArea') - area = ParkArea.objects.get(id=value, park_id=park_id) - return area.name - except (ValueError, LookupError, ObjectDoesNotExist): + """Get park area name from ID and park ID.""" + if not value or not park_id: return None + + try: + from parks.models import ParkArea + area = ParkArea.objects.get(id=value, park_id=park_id) + return str(area) + except Exception: + return None + +@register.filter +def get_item(dictionary, key): + """Get item from dictionary by key.""" + if not dictionary or not key: + return [] + return dictionary.get(str(key), []) diff --git a/templates/moderation/partials/location_widget.html b/templates/moderation/partials/location_widget.html new file mode 100644 index 00000000..09d88b1e --- /dev/null +++ b/templates/moderation/partials/location_widget.html @@ -0,0 +1,360 @@ +{% load static %} + + + +
+ {# Search Form #} +
+ + + +
+ + {# Map Container #} +
+
+
+ + {# Location Form Fields #} +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + {# Hidden Coordinate Fields #} + +
+ + diff --git a/templates/moderation/partials/submission_list.html b/templates/moderation/partials/submission_list.html index 2afaf7f2..2191e604 100644 --- a/templates/moderation/partials/submission_list.html +++ b/templates/moderation/partials/submission_list.html @@ -1,4 +1,10 @@ {% load moderation_tags %} +{% load static %} + +{% block extra_head %} + +{% endblock %} + {% for submission in submissions %}
- {% for area_id, area_name in park_areas %} + {% with park_id=submission.changes.park %} + {% with areas=park_areas_by_park|get_item:park_id %} + {% for area_id, area_name in areas %} {% endfor %} + {% endwith %} + {% endwith %} {% elif field == 'manufacturer' %}
@@ -344,6 +354,14 @@ {% endif %} {% endfor %} + + {% if submission.content_type.model == 'park' %} +
+

Location

+ {% include "moderation/partials/location_widget.html" with form=submission.changes %} +
+ {% endif %} +
- - Reject - - {% endif %} - - {% if user.role == 'MODERATOR' and submission.status != 'ESCALATED' %} - - {% endif %} -
-
- {% endif %} -
- - -{% empty %} -
-
- -

No submissions found matching your filters.

-
- -
-
-
- Loading... -
-
-
-{% endfor %} + hx-confirm="Are you sure you want to reject