def get_object(self): slug = self.kwargs['slug'] if slug.startswith('p:'): return get_object_or_404(Position, secret=slug[2:]) if slug.isdigit(): location = get_location_by_id_for_request(slug, self.request) if isinstance(location, DynamicLocation): return location raise Http404
def clean_coordinates_id(self): coordinates_id = self.cleaned_data['coordinates_id'] if coordinates_id is None: return coordinates_id if not coordinates_id.startswith('c:'): raise ValidationError(_('Invalid coordinates.')) coordinates = get_location_by_id_for_request( self.cleaned_data['coordinates_id'], self.request) if coordinates is None: raise ValidationError(_('Invalid coordinates.')) return coordinates_id
def __get__(self, instance, owner=None): value_id = getattr(instance, self.name+'_id') if value_id is None: self.cached_pk = None self.cached_value = None return None if value_id == self.cached_id: return self.cached_value from c3nav.mapdata.utils.locations import get_location_by_id_for_request value = get_location_by_id_for_request(value_id, getattr(instance, 'request', None)) if value is None: raise ObjectDoesNotExist self.cached_id = value_id self.cached_value = value return value
def position_set(request, coordinates): coordinates = get_location_by_id_for_request(coordinates, request) if coordinates is None: raise Http404 if request.method == 'POST': form = PositionSetForm(request, data=request.POST) if form.is_valid(): position = form.cleaned_data['position'] position.last_coordinates_update = timezone.now() position.coordinates = coordinates position.save() messages.success(request, _('Position set.')) return redirect( reverse('site.position_detail', kwargs={'pk': position.pk})) else: form = PositionSetForm(request) return render(request, 'site/position_set.html', { 'coordinates': coordinates, 'form': form, })
def get_object(self): return get_location_by_id_for_request(self.kwargs['pk'], self.request)
def get_object(self): return get_location_by_id_for_request(self.kwargs['pk'], self.request)
def get_report_location_for_request(pk, request): location = get_location_by_id_for_request(pk, request) if location is None: raise Http404 return location
def convert_location(data): result = { 'total': 0, 'invalid': 0, 'locations': { 'total': 0, 'by_type': {}, 'by_space': {}, 'by_level': {}, 'by_group': {}, }, 'coordinates': { 'total': 0, 'by_level': {}, 'by_space': {}, 'by_area': {}, 'by_poi': {}, } } # fill up lists with zeros location_slugs = {} level_labels = {} for location in LocationSlug.objects.all(): location = location.get_child() if isinstance(location, LocationRedirect): continue result['locations']['by_type'].setdefault(location.__class__.__name__.lower(), {})[location.get_slug()] = 0 location_slugs[location.pk] = location.get_slug() if isinstance(location, Level): result['locations']['by_level'][location.short_label] = 0 result['coordinates']['by_level'][location.short_label] = 0 level_labels[location.pk] = location.short_label if isinstance(location, Space): result['locations']['by_space'][location.get_slug()] = 0 result['coordinates']['by_space'][location.get_slug()] = 0 if isinstance(location, Area): if getattr(location, 'can_search', False) or getattr(location, 'can_describe', False): result['coordinates']['by_area'][location.get_slug()] = 0 if isinstance(location, POI): if getattr(location, 'can_search', False) or getattr(location, 'can_describe', False): result['coordinates']['by_poi'][location.get_slug()] = 0 if isinstance(location, LocationGroup): result['locations']['by_group'][location.get_slug()] = 0 for name, value in data: if name[0] != 'pk' or name[0] == 'c:anywhere': continue location = get_location_by_id_for_request(name[1], fake_request) result['total'] += value if location is None: result['invalid'] += value continue if isinstance(location, CustomLocation): location.x += 1.5 location.y += 1.5 result['coordinates']['total'] += value result['coordinates']['by_level'][location_slugs[location.level.pk]] += value if location.space is None: continue result['coordinates']['by_space'][location_slugs[location.space.pk]] += value for area in location.areas: result['coordinates']['by_area'][location_slugs[area.pk]] += value if location.near_area: result['coordinates']['by_area'][location_slugs[location.near_area.pk]] += value if location.near_poi: result['coordinates']['by_poi'][location_slugs[location.near_poi.pk]] += value else: result['locations']['total'] += value location = getattr(location, 'target', location) result['locations']['by_type'].setdefault(location.__class__.__name__.lower(), {})[location.get_slug()] += value if hasattr(location, 'space_id'): result['locations']['by_space'][location_slugs[location.space_id]] += value if hasattr(location, 'level_id'): result['locations']['by_level'][level_labels[location.level_id]] += value if hasattr(location, 'groups'): for group in location.groups.all(): result['locations']['by_group'][location_slugs[group.pk]] += value _sort_count(result['locations']['by_type'], 'level') _sort_count(result['locations']['by_type'], 'space') _sort_count(result['locations']['by_type'], 'area') _sort_count(result['locations']['by_type'], 'poi') _sort_count(result['locations']['by_type'], 'locationgroup') _sort_count(result['locations'], 'by_space') _sort_count(result['locations'], 'by_level') _sort_count(result['locations'], 'by_group') _sort_count(result['coordinates'], 'by_level') _sort_count(result['coordinates'], 'by_space') _sort_count(result['coordinates'], 'by_area') _sort_count(result['coordinates'], 'by_poi') return result
def clean_destination(self): location = get_location_by_id_for_request(self.cleaned_data['destination'], self.request) if location is None: raise forms.ValidationError(ugettext_lazy('Unknown destination.')) return location
def convert_location(data): result = { 'total': 0, 'invalid': 0, 'locations': { 'total': 0, 'by_type': {}, 'by_space': {}, 'by_level': {}, 'by_group': {}, }, 'coordinates': { 'total': 0, 'by_level': {}, 'by_space': {}, 'by_area': {}, 'by_poi': {}, } } # fill up lists with zeros location_slugs = {} level_labels = {} for location in LocationSlug.objects.all(): location = location.get_child() if isinstance(location, LocationRedirect): continue result['locations']['by_type'].setdefault( location.__class__.__name__.lower(), {})[location.get_slug()] = 0 location_slugs[location.pk] = location.get_slug() if isinstance(location, Level): result['locations']['by_level'][location.short_label] = 0 result['coordinates']['by_level'][location.short_label] = 0 level_labels[location.pk] = location.short_label if isinstance(location, Space): result['locations']['by_space'][location.get_slug()] = 0 result['coordinates']['by_space'][location.get_slug()] = 0 if isinstance(location, Area): if getattr(location, 'can_search', False) or getattr( location, 'can_describe', False): result['coordinates']['by_area'][location.get_slug()] = 0 if isinstance(location, POI): if getattr(location, 'can_search', False) or getattr( location, 'can_describe', False): result['coordinates']['by_poi'][location.get_slug()] = 0 if isinstance(location, LocationGroup): result['locations']['by_group'][location.get_slug()] = 0 for name, value in data: if name[0] != 'pk' or name[0] == 'c:anywhere': continue location = get_location_by_id_for_request(name[1], fake_request) result['total'] += value if location is None: result['invalid'] += value continue if isinstance(location, CustomLocation): location.x += 1.5 location.y += 1.5 result['coordinates']['total'] += value result['coordinates']['by_level'][location_slugs[ location.level.pk]] += value if location.space is None: continue result['coordinates']['by_space'][location_slugs[ location.space.pk]] += value for area in location.areas: result['coordinates']['by_area'][location_slugs[ area.pk]] += value if location.near_area: result['coordinates']['by_area'][location_slugs[ location.near_area.pk]] += value if location.near_poi: result['coordinates']['by_poi'][location_slugs[ location.near_poi.pk]] += value else: result['locations']['total'] += value location = getattr(location, 'target', location) result['locations']['by_type'].setdefault( location.__class__.__name__.lower(), {})[location.get_slug()] += value if hasattr(location, 'space_id'): result['locations']['by_space'][location_slugs[ location.space_id]] += value if hasattr(location, 'level_id'): result['locations']['by_level'][level_labels[ location.level_id]] += value if hasattr(location, 'groups'): for group in location.groups.all(): result['locations']['by_group'][location_slugs[ group.pk]] += value _sort_count(result['locations']['by_type'], 'level') _sort_count(result['locations']['by_type'], 'space') _sort_count(result['locations']['by_type'], 'area') _sort_count(result['locations']['by_type'], 'poi') _sort_count(result['locations']['by_type'], 'locationgroup') _sort_count(result['locations'], 'by_space') _sort_count(result['locations'], 'by_level') _sort_count(result['locations'], 'by_group') _sort_count(result['coordinates'], 'by_level') _sort_count(result['coordinates'], 'by_space') _sort_count(result['coordinates'], 'by_area') _sort_count(result['coordinates'], 'by_poi') return result