open in editor and open in c3nav
This commit is contained in:
parent
6a91631f9b
commit
e70654b4b7
2 changed files with 42 additions and 1 deletions
|
@ -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:
|
||||
|
|
|
@ -1,10 +1,22 @@
|
|||
{% load i18n %}
|
||||
{% if report.category == 'location-issue' %}
|
||||
<p><strong>{% trans 'You are reporting an issue with the following location:' %}</strong></p>
|
||||
{% 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 %}
|
||||
<p>
|
||||
<a href="/l/{{ report.location_specific.slug }}/">{% trans 'open in c3nav' %}</a>
|
||||
{% if report.editor_url %}
|
||||
– <a href="{{ editor_url }}">{% trans 'open in editor' %}</a>
|
||||
{% endif %}
|
||||
</p>
|
||||
{% elif report.category == 'missing-location' %}
|
||||
<p><strong>{% trans 'You are reporting an missing location at the following position:' %}</strong></p>
|
||||
{% include 'site/fragment_location.html' with form_value=1 location=report.coordinates add_subtitle=report.coordinates_id %}
|
||||
<p>
|
||||
<a href="/l/{{ report.coordinates.pk }}/">{% trans 'open in c3nav' %}</a> –
|
||||
{% if report.editor_url %}
|
||||
– <a href="{{ editor_url }}">{% trans 'open in editor' %}</a>
|
||||
{% endif %}
|
||||
</p>
|
||||
{% elif report.category == 'route-issue' %}
|
||||
<p><strong>{% trans 'You are reporting an issue with the following route:' %}</strong></p>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue