2016-10-13 15:55:15 +02:00
|
|
|
import json
|
2017-07-10 16:00:43 +02:00
|
|
|
import operator
|
2018-11-16 01:26:44 +01:00
|
|
|
import os
|
2018-12-25 23:11:56 +01:00
|
|
|
from django.core.validators import validate_slug
|
2017-07-10 16:00:43 +02:00
|
|
|
from functools import reduce
|
2017-12-19 01:49:54 +01:00
|
|
|
from itertools import chain
|
2016-09-23 17:02:17 +02:00
|
|
|
|
2018-11-16 01:26:44 +01:00
|
|
|
from django.conf import settings
|
2017-12-19 01:49:54 +01:00
|
|
|
from django.core.cache import cache
|
2017-07-10 19:03:24 +02:00
|
|
|
from django.core.exceptions import FieldDoesNotExist
|
2018-11-18 02:00:27 +01:00
|
|
|
from django.core.serializers.json import DjangoJSONEncoder
|
2017-12-19 01:49:54 +01:00
|
|
|
from django.db.models import Q
|
2018-11-17 01:40:57 +01:00
|
|
|
from django.forms import (BooleanField, CharField, ChoiceField, DecimalField, Form, ModelChoiceField, ModelForm,
|
|
|
|
MultipleChoiceField, Select, ValidationError)
|
2016-09-23 15:23:02 +02:00
|
|
|
from django.forms.widgets import HiddenInput
|
2016-12-01 12:25:02 +01:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2016-10-13 15:55:15 +02:00
|
|
|
from shapely.geometry.geo import mapping
|
2016-09-23 15:23:02 +02:00
|
|
|
|
2017-07-05 19:40:35 +02:00
|
|
|
from c3nav.editor.models import ChangeSet, ChangeSetUpdate
|
2017-12-08 00:36:12 +01:00
|
|
|
from c3nav.mapdata.fields import GeometryField
|
|
|
|
from c3nav.mapdata.forms import I18nModelFormMixin
|
2017-08-06 16:52:08 +02:00
|
|
|
from c3nav.mapdata.models import GraphEdge
|
2017-12-19 01:49:54 +01:00
|
|
|
from c3nav.mapdata.models.access import AccessPermission
|
2017-06-29 15:53:26 +02:00
|
|
|
|
2016-09-23 15:23:02 +02:00
|
|
|
|
2017-12-08 00:36:12 +01:00
|
|
|
class EditorFormBase(I18nModelFormMixin, ModelForm):
|
2018-12-09 21:26:01 +01:00
|
|
|
def __init__(self, *args, space_id=None, request=None, geometry_editable=False, is_json=False, **kwargs):
|
2016-09-26 17:23:08 +02:00
|
|
|
self.request = request
|
2016-09-23 15:23:02 +02:00
|
|
|
super().__init__(*args, **kwargs)
|
2016-10-13 15:55:15 +02:00
|
|
|
creating = not self.instance.pk
|
2016-09-23 15:23:02 +02:00
|
|
|
|
2017-12-21 02:35:36 +01:00
|
|
|
if hasattr(self.instance, 'author_id'):
|
|
|
|
if self.instance.author_id is None:
|
|
|
|
self.instance.author = request.user
|
|
|
|
|
2016-11-28 15:46:58 +01:00
|
|
|
if 'geometry' in self.fields:
|
2018-12-09 21:26:01 +01:00
|
|
|
if not geometry_editable:
|
2018-11-20 22:54:29 +01:00
|
|
|
# can't see this geometry in editor
|
|
|
|
self.fields.pop('geometry')
|
|
|
|
else:
|
|
|
|
# hide geometry widget
|
|
|
|
self.fields['geometry'].widget = HiddenInput()
|
|
|
|
if not creating:
|
|
|
|
self.initial['geometry'] = json.dumps(mapping(self.instance.geometry), separators=(',', ':'))
|
2016-10-13 15:55:15 +02:00
|
|
|
|
2018-11-16 01:26:44 +01:00
|
|
|
if self._meta.model.__name__ == 'Source' and self.request.user.is_superuser:
|
|
|
|
Source = self.request.changeset.wrap_model('Source')
|
|
|
|
|
2018-11-18 02:00:27 +01:00
|
|
|
sources = {s['name']: s for s in Source.objects.all().values('name', 'access_restriction_id',
|
|
|
|
'left', 'bottom', 'right', 'top')}
|
|
|
|
used_names = set(sources.keys())
|
2018-12-13 04:05:23 +01:00
|
|
|
all_names = set(os.listdir(settings.SOURCES_ROOT))
|
2018-12-13 03:57:03 +01:00
|
|
|
if not creating:
|
|
|
|
used_names.remove(self.instance.name)
|
2018-12-13 04:05:23 +01:00
|
|
|
all_names.add(self.instance.name)
|
2018-11-16 01:26:44 +01:00
|
|
|
self.fields['name'].widget = Select(choices=tuple((s, s) for s in sorted(all_names-used_names)))
|
|
|
|
|
2018-11-18 02:00:27 +01:00
|
|
|
if creating:
|
|
|
|
for s in sources.values():
|
|
|
|
s['access_restriction'] = s['access_restriction_id']
|
|
|
|
del s['access_restriction_id']
|
|
|
|
self.fields['copy_from'] = ChoiceField(
|
|
|
|
choices=tuple((('', '---------'), ))+tuple(
|
|
|
|
(json.dumps(sources[name], separators=(',', ':'), cls=DjangoJSONEncoder), name)
|
|
|
|
for name in sorted(used_names)
|
|
|
|
),
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
|
2018-11-17 01:40:57 +01:00
|
|
|
self.fields['fixed_x'] = DecimalField(label='fixed x', required=False,
|
|
|
|
max_digits=7, decimal_places=3, initial=0)
|
|
|
|
self.fields['fixed_y'] = DecimalField(label='fixed y', required=False,
|
|
|
|
max_digits=7, decimal_places=3, initial=0)
|
|
|
|
self.fields['scale_x'] = DecimalField(label='scale x (m/px)', required=False,
|
|
|
|
max_digits=7, decimal_places=3, initial=1)
|
|
|
|
self.fields['scale_y'] = DecimalField(label='scale y (m/px)', required=False,
|
|
|
|
max_digits=7, decimal_places=3, initial=1)
|
|
|
|
self.fields['lock_aspect'] = BooleanField(label='lock aspect ratio', required=False, initial=True)
|
|
|
|
self.fields['lock_scale'] = BooleanField(label='lock scale (for moving)', required=False, initial=True)
|
|
|
|
|
|
|
|
self.fields.move_to_end('lock_scale', last=False)
|
|
|
|
self.fields.move_to_end('lock_aspect', last=False)
|
|
|
|
self.fields.move_to_end('scale_y', last=False)
|
|
|
|
self.fields.move_to_end('scale_x', last=False)
|
|
|
|
self.fields.move_to_end('fixed_y', last=False)
|
|
|
|
self.fields.move_to_end('fixed_x', last=False)
|
|
|
|
self.fields.move_to_end('access_restriction', last=False)
|
2018-11-18 02:00:27 +01:00
|
|
|
if creating:
|
|
|
|
self.fields.move_to_end('copy_from', last=False)
|
2018-11-17 01:40:57 +01:00
|
|
|
self.fields.move_to_end('name', last=False)
|
|
|
|
|
2017-12-20 20:54:58 +01:00
|
|
|
if self._meta.model.__name__ == 'AccessRestriction':
|
|
|
|
AccessRestrictionGroup = self.request.changeset.wrap_model('AccessRestrictionGroup')
|
|
|
|
|
|
|
|
self.fields['groups'].label_from_instance = lambda obj: obj.title
|
|
|
|
self.fields['groups'].queryset = AccessRestrictionGroup.qs_for_request(self.request)
|
|
|
|
|
|
|
|
elif 'groups' in self.fields:
|
2017-07-10 16:00:43 +02:00
|
|
|
LocationGroupCategory = self.request.changeset.wrap_model('LocationGroupCategory')
|
|
|
|
|
2017-07-10 19:04:35 +02:00
|
|
|
kwargs = {'allow_'+self._meta.model._meta.default_related_name: True}
|
2018-12-21 19:07:28 +01:00
|
|
|
categories = LocationGroupCategory.objects.filter(**kwargs).prefetch_related('groups')
|
2017-07-10 19:18:44 +02:00
|
|
|
if self.instance.pk:
|
|
|
|
instance_groups = tuple(self.instance.groups.values_list('pk', flat=True))
|
|
|
|
else:
|
|
|
|
instance_groups = ()
|
2017-07-10 16:00:43 +02:00
|
|
|
|
|
|
|
self.fields.pop('groups')
|
|
|
|
|
|
|
|
for category in categories:
|
2018-12-21 20:00:52 +01:00
|
|
|
choices = tuple((str(group.pk), group.title)
|
|
|
|
for group in sorted(category.groups.all(), key=self.sort_group))
|
2017-07-10 19:18:44 +02:00
|
|
|
category_groups = set(group.pk for group in category.groups.all())
|
|
|
|
initial = tuple(str(pk) for pk in instance_groups if pk in category_groups)
|
|
|
|
if category.single:
|
|
|
|
name = 'group_'+category.name
|
|
|
|
initial = initial[0] if initial else ''
|
2017-07-11 18:04:22 +02:00
|
|
|
choices = (('', '---'), )+choices
|
2018-12-23 17:52:15 +01:00
|
|
|
field = ChoiceField(label=category.title, required=False, initial=initial, choices=choices,
|
|
|
|
help_text=category.help_text)
|
2017-07-10 19:18:44 +02:00
|
|
|
else:
|
|
|
|
name = 'groups_'+category.name
|
2017-11-30 16:51:28 +01:00
|
|
|
field = MultipleChoiceField(label=category.title_plural, required=False,
|
2018-12-23 17:52:15 +01:00
|
|
|
initial=initial, choices=choices,
|
|
|
|
help_text=category.help_text)
|
2017-07-10 19:18:44 +02:00
|
|
|
self.fields[name] = field
|
2017-05-16 14:50:36 +02:00
|
|
|
|
2017-07-10 14:10:48 +02:00
|
|
|
if 'category' in self.fields:
|
|
|
|
self.fields['category'].label_from_instance = lambda obj: obj.title
|
|
|
|
|
2017-07-13 18:54:49 +02:00
|
|
|
if 'access_restriction' in self.fields:
|
|
|
|
AccessRestriction = self.request.changeset.wrap_model('AccessRestriction')
|
|
|
|
|
|
|
|
self.fields['access_restriction'].label_from_instance = lambda obj: obj.title
|
|
|
|
self.fields['access_restriction'].queryset = AccessRestriction.qs_for_request(self.request)
|
|
|
|
|
2018-11-20 23:06:49 +01:00
|
|
|
if 'base_mapdata_accessible' in self.fields:
|
|
|
|
if not request.user.is_superuser:
|
|
|
|
self.fields['base_mapdata_accessible'].disabled = True
|
|
|
|
|
2017-12-19 01:49:54 +01:00
|
|
|
if space_id and 'target_space' in self.fields:
|
2017-12-19 00:56:12 +01:00
|
|
|
Space = self.request.changeset.wrap_model('Space')
|
2017-12-19 01:49:54 +01:00
|
|
|
|
|
|
|
GraphNode = self.request.changeset.wrap_model('GraphNode')
|
|
|
|
GraphEdge = self.request.changeset.wrap_model('GraphEdge')
|
|
|
|
|
|
|
|
cache_key = 'editor:neighbor_spaces:%s:%s%d' % (
|
|
|
|
self.request.changeset.raw_cache_key_by_changes,
|
|
|
|
AccessPermission.cache_key_for_request(request, with_update=False),
|
|
|
|
space_id
|
|
|
|
)
|
|
|
|
other_spaces = cache.get(cache_key, None)
|
|
|
|
if other_spaces is None:
|
|
|
|
AccessPermission.cache_key_for_request(request, with_update=False) + ':' + str(request.user.pk or 0)
|
|
|
|
space_nodes = set(GraphNode.objects.filter(space_id=space_id).values_list('pk', flat=True))
|
|
|
|
space_edges = GraphEdge.objects.filter(
|
|
|
|
Q(from_node_id__in=space_nodes) | Q(to_node_id__in=space_nodes)
|
|
|
|
).values_list('from_node_id', 'to_node_id')
|
|
|
|
other_nodes = set(chain(*space_edges)) - space_nodes
|
|
|
|
other_spaces = set(GraphNode.objects.filter(pk__in=other_nodes).values_list('space_id', flat=True))
|
|
|
|
other_spaces.discard(space_id)
|
|
|
|
cache.set(cache_key, other_spaces, 900)
|
|
|
|
|
|
|
|
for space_field in ('origin_space', 'target_space'):
|
|
|
|
other_space_id = getattr(self.instance, space_field+'_id', None)
|
|
|
|
if other_space_id:
|
|
|
|
other_spaces.add(other_space_id)
|
|
|
|
|
|
|
|
space_qs = Space.qs_for_request(self.request).filter(pk__in=other_spaces)
|
|
|
|
|
2017-12-19 00:56:12 +01:00
|
|
|
for space_field in ('origin_space', 'target_space'):
|
|
|
|
if space_field in self.fields:
|
|
|
|
self.fields[space_field].label_from_instance = lambda obj: obj.title
|
|
|
|
self.fields[space_field].queryset = space_qs
|
2017-12-19 00:50:40 +01:00
|
|
|
|
2017-05-27 18:29:36 +02:00
|
|
|
self.redirect_slugs = None
|
|
|
|
self.add_redirect_slugs = None
|
|
|
|
self.remove_redirect_slugs = None
|
|
|
|
if 'slug' in self.fields:
|
2018-12-25 23:11:56 +01:00
|
|
|
self.fields['slug'].validators.append(validate_slug)
|
2017-05-27 18:29:36 +02:00
|
|
|
self.redirect_slugs = sorted(self.instance.redirects.values_list('slug', flat=True))
|
|
|
|
self.fields['redirect_slugs'] = CharField(label=_('Redirecting Slugs (comma seperated)'), required=False,
|
|
|
|
initial=','.join(self.redirect_slugs))
|
|
|
|
self.fields.move_to_end('redirect_slugs', last=False)
|
|
|
|
self.fields.move_to_end('slug', last=False)
|
|
|
|
|
2017-07-19 18:02:40 +02:00
|
|
|
if 'from_node' in self.fields:
|
|
|
|
self.fields['from_node'].widget = HiddenInput()
|
|
|
|
|
|
|
|
if 'to_node' in self.fields:
|
|
|
|
self.fields['to_node'].widget = HiddenInput()
|
|
|
|
|
2017-12-21 03:32:03 +01:00
|
|
|
if 'data' in self.fields and 'data' in self.initial:
|
2017-12-21 02:58:13 +01:00
|
|
|
self.initial['data'] = json.dumps(self.initial['data'])
|
|
|
|
|
2018-11-22 19:14:36 +01:00
|
|
|
self.is_json = is_json
|
|
|
|
self.missing_fields = tuple((name, field) for name, field in self.fields.items()
|
|
|
|
if name not in self.data and not field.required)
|
|
|
|
|
2018-12-21 20:00:52 +01:00
|
|
|
@staticmethod
|
|
|
|
def sort_group(group):
|
|
|
|
return (-group.priority, group.title)
|
|
|
|
|
2017-05-27 18:29:36 +02:00
|
|
|
def clean_redirect_slugs(self):
|
|
|
|
old_redirect_slugs = set(self.redirect_slugs)
|
|
|
|
new_redirect_slugs = set(s for s in (s.strip() for s in self.cleaned_data['redirect_slugs'].split(',')) if s)
|
|
|
|
|
|
|
|
self.add_redirect_slugs = new_redirect_slugs - old_redirect_slugs
|
|
|
|
self.remove_redirect_slugs = old_redirect_slugs - new_redirect_slugs
|
|
|
|
|
|
|
|
for slug in self.add_redirect_slugs:
|
|
|
|
self.fields['slug'].run_validators(slug)
|
2017-06-12 18:01:51 +02:00
|
|
|
|
2017-06-27 03:20:50 +02:00
|
|
|
LocationSlug = self.request.changeset.wrap_model('LocationSlug')
|
2017-07-06 12:26:19 +02:00
|
|
|
qs = LocationSlug.objects.filter(slug__in=self.add_redirect_slugs)
|
|
|
|
|
2017-08-04 20:17:08 +02:00
|
|
|
if 'slug' in self.cleaned_data and self.cleaned_data['slug'] in self.add_redirect_slugs:
|
2017-07-06 12:26:19 +02:00
|
|
|
raise ValidationError(
|
|
|
|
_('Can not add redirecting slug “%s”: it\'s the slug of this object.') % self.cleaned_data['slug']
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
qs = qs.exclude(pk=self.instance.pk)
|
|
|
|
|
|
|
|
for slug in qs.values_list('slug', flat=True)[:1]:
|
2017-06-12 18:01:51 +02:00
|
|
|
raise ValidationError(
|
|
|
|
_('Can not add redirecting slug “%s”: it is already used elsewhere.') % slug
|
|
|
|
)
|
2017-05-27 18:29:36 +02:00
|
|
|
|
2017-12-21 03:32:03 +01:00
|
|
|
def clean_data(self):
|
|
|
|
try:
|
|
|
|
data = json.loads(self.cleaned_data['data'])
|
|
|
|
except json.JSONDecodeError:
|
|
|
|
raise ValidationError(_('Invalid JSON.'))
|
2017-12-25 16:41:59 +01:00
|
|
|
|
|
|
|
from c3nav.routing.locator import LocatorPoint
|
2017-12-26 02:12:44 +01:00
|
|
|
LocatorPoint.clean_scans(data)
|
2017-12-25 16:41:59 +01:00
|
|
|
|
2017-12-21 03:32:03 +01:00
|
|
|
return data
|
|
|
|
|
2016-11-28 15:46:58 +01:00
|
|
|
def clean(self):
|
2018-11-22 19:14:36 +01:00
|
|
|
if self.is_json:
|
|
|
|
for name, field in self.missing_fields:
|
|
|
|
self.add_error(name, field.error_messages['required'])
|
|
|
|
|
2016-11-28 15:46:58 +01:00
|
|
|
if 'geometry' in self.fields:
|
|
|
|
if not self.cleaned_data.get('geometry'):
|
|
|
|
raise ValidationError('Missing geometry.')
|
2016-12-12 13:21:09 +01:00
|
|
|
|
2016-12-04 14:16:05 +01:00
|
|
|
super().clean()
|
2016-11-28 15:46:58 +01:00
|
|
|
|
2017-07-10 16:00:43 +02:00
|
|
|
def _save_m2m(self):
|
|
|
|
super()._save_m2m()
|
2017-12-20 22:44:45 +01:00
|
|
|
if self._meta.model.__name__ != 'AccessRestriction':
|
|
|
|
try:
|
|
|
|
field = self._meta.model._meta.get_field('groups')
|
|
|
|
except FieldDoesNotExist:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
if field.many_to_many:
|
|
|
|
groups = reduce(operator.or_, (set(value) for name, value in self.cleaned_data.items()
|
|
|
|
if name.startswith('groups_')), set())
|
|
|
|
groups |= set(value for name, value in self.cleaned_data.items()
|
|
|
|
if name.startswith('group_') and value)
|
|
|
|
groups = tuple((int(val) if val.isdigit() else val) for val in groups)
|
|
|
|
self.instance.groups.set(groups)
|
2017-07-10 16:00:43 +02:00
|
|
|
|
2016-11-28 15:46:58 +01:00
|
|
|
|
2017-05-16 14:10:50 +02:00
|
|
|
def create_editor_form(editor_model):
|
2018-12-23 17:52:15 +01:00
|
|
|
possible_fields = ['slug', 'name', 'title', 'title_plural', 'help_text', 'icon', 'join_edges', 'up_separate',
|
|
|
|
'walk', 'ordering', 'category', 'width', 'groups', 'color', 'priority', 'icon_name',
|
2017-11-30 15:05:32 +01:00
|
|
|
'base_altitude', 'waytype', 'access_restriction', 'height', 'default_height', 'door_height',
|
2017-12-11 15:34:07 +01:00
|
|
|
'outside', 'can_search', 'can_describe', 'geometry', 'single', 'altitude', 'short_label',
|
2017-12-22 15:16:28 +01:00
|
|
|
'origin_space', 'target_space', 'data', 'comment', 'slow_down_factor',
|
2017-12-22 16:14:35 +01:00
|
|
|
'extra_seconds', 'speed', 'description', 'speed_up', 'description_up', 'enter_description',
|
2018-11-20 23:06:49 +01:00
|
|
|
'level_change_description', 'base_mapdata_accessible',
|
2017-11-14 22:24:29 +01:00
|
|
|
'allow_levels', 'allow_spaces', 'allow_areas', 'allow_pois', 'left', 'top', 'right', 'bottom']
|
2017-07-10 14:10:48 +02:00
|
|
|
field_names = [field.name for field in editor_model._meta.get_fields() if not field.one_to_many]
|
2017-05-26 20:40:20 +02:00
|
|
|
existing_fields = [name for name in possible_fields if name in field_names]
|
2016-10-13 15:55:15 +02:00
|
|
|
|
2017-07-10 19:03:45 +02:00
|
|
|
class EditorForm(EditorFormBase, ModelForm):
|
2016-10-13 15:55:15 +02:00
|
|
|
class Meta:
|
2017-05-16 14:10:50 +02:00
|
|
|
model = editor_model
|
2016-11-28 15:46:58 +01:00
|
|
|
fields = existing_fields
|
2016-10-13 15:55:15 +02:00
|
|
|
|
2017-06-21 12:47:28 +02:00
|
|
|
EditorForm.__name__ = editor_model.__name__+'EditorForm'
|
|
|
|
return EditorForm
|
2017-06-29 15:53:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ChangeSetForm(ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = ChangeSet
|
|
|
|
fields = ('title', 'description')
|
2017-07-05 19:40:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
class RejectForm(ModelForm):
|
|
|
|
final = BooleanField(label=_('Final rejection'), required=False)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ChangeSetUpdate
|
|
|
|
fields = ('comment', )
|
2017-07-19 18:02:40 +02:00
|
|
|
|
|
|
|
|
2017-07-26 13:20:55 +02:00
|
|
|
class GraphEdgeSettingsForm(ModelForm):
|
2017-11-22 23:13:12 +01:00
|
|
|
oneway = BooleanField(label=_('create one way edges'), required=False)
|
2017-11-25 16:25:50 +01:00
|
|
|
activate_next = BooleanField(label=_('activate next node after connecting'), required=False)
|
2017-11-22 23:13:12 +01:00
|
|
|
|
2017-07-26 13:20:55 +02:00
|
|
|
class Meta:
|
|
|
|
model = GraphEdge
|
|
|
|
fields = ('waytype', 'access_restriction', )
|
|
|
|
|
|
|
|
def __init__(self, *args, request=None, **kwargs):
|
|
|
|
self.request = request
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
2017-07-27 18:58:40 +02:00
|
|
|
WayType = self.request.changeset.wrap_model('WayType')
|
|
|
|
self.fields['waytype'].label_from_instance = lambda obj: obj.title
|
|
|
|
self.fields['waytype'].queryset = WayType.objects.all()
|
|
|
|
self.fields['waytype'].to_field_name = None
|
|
|
|
|
2017-07-26 13:20:55 +02:00
|
|
|
AccessRestriction = self.request.changeset.wrap_model('AccessRestriction')
|
|
|
|
self.fields['access_restriction'].label_from_instance = lambda obj: obj.title
|
|
|
|
self.fields['access_restriction'].queryset = AccessRestriction.qs_for_request(self.request)
|
|
|
|
|
|
|
|
|
|
|
|
class GraphEditorActionForm(Form):
|
|
|
|
def __init__(self, *args, request=None, allow_clicked_position=False, **kwargs):
|
|
|
|
self.request = request
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
GraphNode = self.request.changeset.wrap_model('GraphNode')
|
|
|
|
graph_node_qs = GraphNode.objects.all()
|
2017-07-26 13:30:08 +02:00
|
|
|
self.fields['active_node'] = ModelChoiceField(graph_node_qs, widget=HiddenInput(), required=False)
|
2017-07-26 13:20:55 +02:00
|
|
|
self.fields['clicked_node'] = ModelChoiceField(graph_node_qs, widget=HiddenInput(), required=False)
|
|
|
|
|
|
|
|
if allow_clicked_position:
|
|
|
|
self.fields['clicked_position'] = CharField(widget=HiddenInput(), required=False)
|
|
|
|
|
2017-07-26 15:28:08 +02:00
|
|
|
Space = self.request.changeset.wrap_model('Space')
|
|
|
|
space_qs = Space.objects.all()
|
|
|
|
self.fields['goto_space'] = ModelChoiceField(space_qs, widget=HiddenInput(), required=False)
|
|
|
|
|
2017-07-26 13:20:55 +02:00
|
|
|
def clean_clicked_position(self):
|
|
|
|
return GeometryField(geomtype='point').to_python(self.cleaned_data['clicked_position'])
|