diff --git a/src/c3nav/mapdata/models/report.py b/src/c3nav/mapdata/models/report.py index f3b94dea..a37a1fa3 100644 --- a/src/c3nav/mapdata/models/report.py +++ b/src/c3nav/mapdata/models/report.py @@ -6,10 +6,14 @@ from django.core.cache import cache from django.core.exceptions import ObjectDoesNotExist from django.db import models from django.db.models import Q +from django.urls import reverse from django.utils.crypto import get_random_string +from django.utils.functional import cached_property from django.utils.translation import ugettext_lazy as _ from c3nav.mapdata.fields import I18nField +from c3nav.mapdata.models.geometry.level import LevelGeometryMixin +from c3nav.mapdata.models.geometry.space import SpaceGeometryMixin from c3nav.mapdata.models.locations import SpecificLocation from c3nav.mapdata.utils.locations import get_location_by_id_for_request from c3nav.mapdata.utils.models import get_submodels @@ -98,6 +102,10 @@ class Report(models.Model): from c3nav.site.forms import ReportMissingLocationForm, ReportIssueForm return ReportMissingLocationForm if self.category == 'missing-location' else ReportIssueForm + @cached_property + def location_specific(self): + return self.location.get_child() + @classmethod def qs_for_request(cls, request): if request.user_permissions.review_all_reports: @@ -154,6 +162,27 @@ class Report(models.Model): cache.set('user:has-reports:%d' % user.pk, result, 900) return result + @cached_property + def editor_url(self): + if self.category == 'missing-location': + return None + elif self.category == 'location-issue': + location = self.location_specific + url_name = 'editor.%s.edit' % location.__class__._meta.default_related_name + if isinstance(location, SpaceGeometryMixin): + return reverse(url_name, kwargs={ + 'pk': location.pk, + 'space': location.space.pk + }) + if isinstance(location, LevelGeometryMixin): + return reverse(url_name, kwargs={ + 'pk': location.pk, + 'space': location.level.pk + }) + return reverse(url_name, kwargs={ + 'pk': location.pk, + }) + def save(self, *args, **kwargs): created = self.pk is None if self.author: diff --git a/src/c3nav/site/templates/site/fragment_report_meta.html b/src/c3nav/site/templates/site/fragment_report_meta.html index 8a1e8155..8ceb8efe 100644 --- a/src/c3nav/site/templates/site/fragment_report_meta.html +++ b/src/c3nav/site/templates/site/fragment_report_meta.html @@ -1,10 +1,22 @@ {% load i18n %} {% if report.category == 'location-issue' %}

{% trans 'You are reporting an issue with the following location:' %}

- {% include 'site/fragment_location.html' with form_value=1 location=report.location %} + {% include 'site/fragment_location.html' with form_value=1 location=report.location_specific %} +

+ {% trans 'open in c3nav' %} + {% if report.editor_url %} + – {% trans 'open in editor' %} + {% endif %} +

{% elif report.category == 'missing-location' %}

{% trans 'You are reporting an missing location at the following position:' %}

{% include 'site/fragment_location.html' with form_value=1 location=report.coordinates add_subtitle=report.coordinates_id %} +

+ {% trans 'open in c3nav' %} – + {% if report.editor_url %} + – {% trans 'open in editor' %} + {% endif %} +

{% elif report.category == 'route-issue' %}

{% trans 'You are reporting an issue with the following route:' %}