Skip to content

Commit

Permalink
refactor: EPSG settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias84 committed Feb 22, 2020
1 parent 36218df commit fd181b3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
3 changes: 3 additions & 0 deletions cleanship/settings/example.py
Expand Up @@ -26,6 +26,9 @@

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

EPSG_WIDGET = 4326
EPSG_INTERNAL = 25833

LEAFLET_CONFIG = {
'SPATIAL_EXTENT': (11.681900024414062, 54.037618883628134, 12.448196411132812, 54.26161470169560),
'TILES': [
Expand Down
7 changes: 4 additions & 3 deletions common/models.py
@@ -1,3 +1,4 @@
from django.conf import settings
from django.contrib.auth.models import AbstractUser
from django.contrib.auth.models import Group
from django.contrib.gis.db import models
Expand Down Expand Up @@ -86,7 +87,7 @@ def validate_in_municipality(value):
"""Check if map point is within boundary"""
# TODO: Extract validators, switch datasource #56
position = value
position.transform(4326)
position.transform(settings.EPSG_WIDGET)
logger.debug('Checking issue position ({})'.format(position))
ds = DataSource('municipality_area.json')
poly = ds[0].get_geoms(geos=True)[0]
Expand Down Expand Up @@ -125,7 +126,7 @@ class Issue(models.Model):
description = models.TextField(max_length=500, verbose_name=_('description'), help_text=_('Notes describing further details.')) # BUG: Could be empty, whats the right way?
author_email = models.EmailField(null=True, blank=False, verbose_name=_('author'), help_text=_('eMail alias of the author.'))
author_trust = models.IntegerField(choices=TrustTypes.choices(), default=TrustTypes.EXTERNAL, verbose_name = _('trust'), help_text=_('Trust level of the author.'))
position = models.PointField(srid=25833, verbose_name=_('position'), help_text=_('Georeference for this issue. (might be inaccurate)'), validators=[validate_in_municipality]) # TODO: Extract srid to settings
position = models.PointField(srid=settings.EPSG_INTERNAL, verbose_name=_('position'), help_text=_('Georeference for this issue. (might be inaccurate)'), validators=[validate_in_municipality]) # TODO: Extract srid to settings
category = TreeForeignKey('Category', on_delete=models.CASCADE, null=False, blank=False, verbose_name=_('category'), help_text=_('Multi-level selection of which kind of note this issue comes closest.'), validators=[validate_is_subcategory])
photo = models.ImageField(upload_to='', null=True, blank=True, verbose_name=_('photo'), help_text=_('Photo that show the spot. (unprocessed, might include metadata)'))
created_at = models.DateTimeField(default=timezone.now, verbose_name=_('creation date'), help_text=_('Date of submission.'))
Expand Down Expand Up @@ -158,7 +159,7 @@ def get_responsible_candidates(self):

def get_position_WGS84(self):
positionWGS84 = self.position
positionWGS84.transform(4326)
positionWGS84.transform(settings.EPSG_WIDGET)
return positionWGS84

def __str__(self):
Expand Down
15 changes: 8 additions & 7 deletions office/views.py
@@ -1,3 +1,4 @@
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpResponseRedirect
Expand Down Expand Up @@ -52,10 +53,10 @@ def get_context_data(self, **kwargs):
StatusTypes.IMPOSSIBLE: "impossible",
StatusTypes.DUBLICATE: "dublicate"}
context['status_string'] = statusMapping[issue.status]
positionWGS84 = issue.position
positionWGS84.transform(4326)
positionWGS84 = positionWGS84.geojson
context['position_geojson'] = positionWGS84
positionWidget = issue.position
positionWidget.transform(settings.EPSG_WIDGET)
positionWidget = positionWidget.geojson
context['position_geojson'] = positionWidget
return context

class IssueListView(LoginRequiredMixin, SingleTableMixin, FilterView):
Expand All @@ -73,9 +74,9 @@ def get_context_data(self,**kwargs):
context = super().get_context_data(**kwargs)
# reproject
for issue in context['object_list']:
positionWGS84 = issue.position
positionWGS84.transform(4326)
issue.position_webmap = positionWGS84.geojson
positionWidget = issue.position
positionWidget.transform(settings.EPSG_WIDGET)
issue.position_webmap = positionWidget.geojson
return context

class IssueCreateView(LoginRequiredMixin, generic.CreateView):
Expand Down

0 comments on commit fd181b3

Please sign in to comment.