sort locations

This commit is contained in:
Laura Klünder 2016-12-24 21:51:30 +01:00
parent d1534a27e8
commit 517e194c44
3 changed files with 33 additions and 12 deletions

View file

@ -167,14 +167,15 @@ class LocationViewSet(ViewSet):
lookup_field = 'name'
include_package_access = True
@staticmethod
def _filter(queryset):
return queryset.filter(can_search=True).order_by('name')
def list(self, request, **kwargs):
locations = []
locations += list(filter_queryset_by_access(request, LocationGroup.objects.filter(can_search=True,
compiled_room=True)))
locations += sorted(filter_arealocations_by_access(request, AreaLocation.objects.filter(can_search=True)),
locations += list(filter_queryset_by_access(request, self._filter(LocationGroup.objects.all())))
locations += sorted(filter_arealocations_by_access(request, self._filter(AreaLocation.objects.all())),
key=AreaLocation.get_sort_key, reverse=True)
locations += list(filter_queryset_by_access(request, LocationGroup.objects.filter(can_search=True,
compiled_room=False)))
return Response([location.to_location_json() for location in locations])
def retrieve(self, request, name=None, **kwargs):

View file

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.4 on 2016-12-24 18:03
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('mapdata', '0032_auto_20161223_2225'),
]
operations = [
migrations.AddField(
model_name='locationgroup',
name='can_describe',
field=models.BooleanField(default=True, verbose_name='can be used to describe a position'),
),
migrations.AlterField(
model_name='locationgroup',
name='compiled_room',
field=models.BooleanField(default=False, verbose_name='is a compiled room'),
),
]

View file

@ -38,20 +38,15 @@ def search_location(request, search):
words = search.split(' ')[:10]
queryset = LocationGroup.objects.filter(can_seach=True, compiled_room=True)
queryset = LocationGroup.objects.filter(can_seach=True).order_by('name')
if isinstance(location, LocationGroup):
queryset.exclude(name='g:' + location.name)
results += list(filter_words(filter_queryset_by_access(request, queryset), words)[:10])
queryset = AreaLocation.objects.filter(can_seach=True)
queryset = AreaLocation.objects.filter(can_seach=True).order_by('name')
if isinstance(location, AreaLocation):
queryset.exclude(name=location.name)
results += sorted(filter_words(filter_arealocations_by_access(request, queryset), words),
key=AreaLocation.get_sort_key, reverse=True)
queryset = LocationGroup.objects.filter(can_seach=True, compiled_room=False)
if isinstance(location, LocationGroup):
queryset.exclude(name='g:'+location.name)
results += list(filter_words(filter_queryset_by_access(request, queryset), words)[:10])
return results