optimised models and views
This commit is contained in:
@ -33,6 +33,11 @@ http {
|
||||
alias /app/static/;
|
||||
}
|
||||
|
||||
location /media/ {
|
||||
alias /app/media/;
|
||||
}
|
||||
|
||||
|
||||
location / {
|
||||
proxy_pass http://app:8000;
|
||||
proxy_set_header Host $host;
|
||||
|
||||
@ -4,7 +4,7 @@ from django.shortcuts import render
|
||||
from leaflet.admin import LeafletGeoAdmin
|
||||
from leaflet.admin import LeafletGeoAdminMixin
|
||||
from leaflet_admin_list.admin import LeafletAdminListMixin
|
||||
from .models import RogUser, Location, SystemSettings, JoinedEvent, Favorite, TravelList, TravelPoint, ShapeLayers, Event, Location_line, Location_polygon, JpnAdminMainPerf, JpnAdminPerf, JpnSubPerf, Useractions, CustomUser, GifuAreas, UserTracks, ShapeFileLocations, templocation, UserUpload, UserUploadUser, EventUser, GoalImages, CheckinImages
|
||||
from .models import RogUser, Location, SystemSettings, JoinedEvent, Favorite, TravelList, TravelPoint, ShapeLayers, Event, Location_line, Location_polygon, JpnAdminMainPerf, Useractions, CustomUser, GifuAreas, UserTracks, templocation, UserUpload, EventUser, GoalImages, CheckinImages
|
||||
from django.contrib.auth.admin import UserAdmin
|
||||
from django.urls import path
|
||||
from django.shortcuts import render
|
||||
@ -210,7 +210,6 @@ admin.site.register(JpnAdminMainPerf, LeafletGeoAdmin)
|
||||
admin.site.register(UserTracks, LeafletGeoAdmin);
|
||||
#admin.site.register(JpnAdminPerf, LeafletGeoAdmin)
|
||||
admin.site.register(GifuAreas, LeafletGeoAdmin)
|
||||
admin.site.register(JpnSubPerf, JpnSubPerfAdmin)
|
||||
admin.site.register(ShapeLayers, admin.ModelAdmin)
|
||||
admin.site.register(UserUpload, admin.ModelAdmin)
|
||||
admin.site.register(EventUser, admin.ModelAdmin)
|
||||
|
||||
49
rog/migrations/0041_auto_20230526_1724.py
Normal file
49
rog/migrations/0041_auto_20230526_1724.py
Normal file
@ -0,0 +1,49 @@
|
||||
# Generated by Django 3.2.9 on 2023-05-26 08:24
|
||||
|
||||
import django.contrib.postgres.indexes
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('rog', '0040_auto_20221105_1939'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.DeleteModel(
|
||||
name='JpnAdminPerf',
|
||||
),
|
||||
migrations.DeleteModel(
|
||||
name='JpnSubPerf',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='location',
|
||||
name='category',
|
||||
field=models.CharField(blank=True, db_index=True, max_length=2048, null=True, verbose_name='Category'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='location',
|
||||
name='event_active',
|
||||
field=models.BooleanField(db_index=True, default=True, verbose_name='Is Event active'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='location',
|
||||
name='event_name',
|
||||
field=models.CharField(blank=True, db_index=True, max_length=2048, null=True, verbose_name='Event name'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='location',
|
||||
name='group',
|
||||
field=models.CharField(blank=True, db_index=True, max_length=2048, null=True, verbose_name='Group'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='location',
|
||||
name='location_id',
|
||||
field=models.IntegerField(blank=True, db_index=True, null=True, verbose_name='Location id'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='location',
|
||||
index=django.contrib.postgres.indexes.GistIndex(fields=['geom'], name='rog_locatio_geom_4793cc_gist'),
|
||||
),
|
||||
]
|
||||
102
rog/models.py
102
rog/models.py
@ -22,6 +22,7 @@ from django.contrib.gis.utils import LayerMapping
|
||||
from django.apps import apps
|
||||
from django.db import transaction
|
||||
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, BaseUserManager
|
||||
from django.contrib.postgres.indexes import GistIndex
|
||||
|
||||
import csv
|
||||
import codecs
|
||||
@ -102,46 +103,58 @@ class JpnAdminMainPerf(models.Model):
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = 'jpn_admin_main_perf'
|
||||
indexes = [
|
||||
models.Index(fields=['geom'], name='jpn_admin_main_perf_geom_idx'),
|
||||
# Add other fields for indexing as per the requirements
|
||||
]
|
||||
|
||||
|
||||
class JpnAdminPerf(models.Model):
|
||||
geom = models.MultiLineStringField(blank=True, null=True)
|
||||
et_id = models.IntegerField(blank=True, null=True)
|
||||
et_right = models.CharField(max_length=80, blank=True, null=True)
|
||||
et_left = models.CharField(max_length=80, blank=True, null=True)
|
||||
adm2_l = models.CharField(max_length=50, blank=True, null=True)
|
||||
adm1_l = models.CharField(max_length=50, blank=True, null=True)
|
||||
adm0_l = models.CharField(max_length=50, blank=True, null=True)
|
||||
adm0_r = models.CharField(max_length=50, blank=True, null=True)
|
||||
adm1_r = models.CharField(max_length=50, blank=True, null=True)
|
||||
adm2_r = models.CharField(max_length=50, blank=True, null=True)
|
||||
admlevel = models.IntegerField(blank=True, null=True)
|
||||
# class JpnAdminPerf(models.Model):
|
||||
# geom = models.MultiLineStringField(blank=True, null=True)
|
||||
# et_id = models.IntegerField(blank=True, null=True)
|
||||
# et_right = models.CharField(max_length=80, blank=True, null=True)
|
||||
# et_left = models.CharField(max_length=80, blank=True, null=True)
|
||||
# adm2_l = models.CharField(max_length=50, blank=True, null=True)
|
||||
# adm1_l = models.CharField(max_length=50, blank=True, null=True)
|
||||
# adm0_l = models.CharField(max_length=50, blank=True, null=True)
|
||||
# adm0_r = models.CharField(max_length=50, blank=True, null=True)
|
||||
# adm1_r = models.CharField(max_length=50, blank=True, null=True)
|
||||
# adm2_r = models.CharField(max_length=50, blank=True, null=True)
|
||||
# admlevel = models.IntegerField(blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = 'jpn_admin_perf'
|
||||
# class Meta:
|
||||
# managed = False
|
||||
# db_table = 'jpn_admin_perf'
|
||||
# indexes = [
|
||||
# models.Index(fields=['geom'], name='jpn_admin_perf_geom_idx'),
|
||||
# # Add other fields for indexing as per the requirements
|
||||
# ]
|
||||
|
||||
###
|
||||
### Cities
|
||||
###
|
||||
class JpnSubPerf(models.Model):
|
||||
geom = models.MultiPolygonField(blank=True, null=True)
|
||||
adm0_en = models.CharField(max_length=254, blank=True, null=True)
|
||||
adm0_ja = models.CharField(max_length=254, blank=True, null=True)
|
||||
adm0_pcode = models.CharField(max_length=254, blank=True, null=True)
|
||||
adm1_en = models.CharField(max_length=254, blank=True, null=True)
|
||||
adm1_ja = models.CharField(max_length=254, blank=True, null=True)
|
||||
adm1_pcode = models.CharField(max_length=254, blank=True, null=True)
|
||||
adm2_ja = models.CharField(max_length=254, blank=True, null=True)
|
||||
adm2_en = models.CharField(max_length=254, blank=True, null=True)
|
||||
adm2_pcode = models.CharField(max_length=254, blank=True, null=True)
|
||||
name_modified = models.CharField(max_length=254, blank=True, null=True)
|
||||
area_name = models.CharField(max_length=254, blank=True, null=True)
|
||||
list_order =models.IntegerField(default=0)
|
||||
# ###
|
||||
# ### Cities
|
||||
# ###
|
||||
# class JpnSubPerf(models.Model):
|
||||
# geom = models.MultiPolygonField(blank=True, null=True)
|
||||
# adm0_en = models.CharField(max_length=254, blank=True, null=True)
|
||||
# adm0_ja = models.CharField(max_length=254, blank=True, null=True)
|
||||
# adm0_pcode = models.CharField(max_length=254, blank=True, null=True)
|
||||
# adm1_en = models.CharField(max_length=254, blank=True, null=True)
|
||||
# adm1_ja = models.CharField(max_length=254, blank=True, null=True)
|
||||
# adm1_pcode = models.CharField(max_length=254, blank=True, null=True)
|
||||
# adm2_ja = models.CharField(max_length=254, blank=True, null=True)
|
||||
# adm2_en = models.CharField(max_length=254, blank=True, null=True)
|
||||
# adm2_pcode = models.CharField(max_length=254, blank=True, null=True)
|
||||
# name_modified = models.CharField(max_length=254, blank=True, null=True)
|
||||
# area_name = models.CharField(max_length=254, blank=True, null=True)
|
||||
# list_order =models.IntegerField(default=0)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = 'jpn_sub_perf'
|
||||
# class Meta:
|
||||
# managed = False
|
||||
# db_table = 'jpn_sub_perf'
|
||||
# indexes = [
|
||||
# models.Index(fields=['geom'], name='jpn_sub_perf_geom_idx'),
|
||||
# # Add other fields for indexing as per the requirements
|
||||
# ]
|
||||
|
||||
###
|
||||
### Gifu Areas
|
||||
@ -162,6 +175,10 @@ class GifuAreas(models.Model):
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = 'gifu_areas'
|
||||
indexes = [
|
||||
models.Index(fields=['geom'], name='gifu_areas_geom_idx'),
|
||||
# Add other fields for indexing as per the requirements
|
||||
]
|
||||
|
||||
|
||||
class UserUpload(models.Model):
|
||||
@ -252,11 +269,11 @@ class SystemSettings(models.Model):
|
||||
last_updated_at=models.DateTimeField(auto_now=True)
|
||||
|
||||
class Location(models.Model):
|
||||
location_id=models.IntegerField(_('Location id'), blank=True, null=True)
|
||||
location_id=models.IntegerField(_('Location id'), blank=True, null=True, db_index=True)
|
||||
sub_loc_id=models.CharField(_('Sub location id'), max_length=2048, blank=True, null=True)
|
||||
cp=models.FloatField(_('Check Point'), blank=False, null=True, default=0)
|
||||
location_name=models.CharField(_('Location Name'), max_length=2048, default="--- 場所をお願いします --")
|
||||
category=models.CharField(_('Category'), max_length=2048, blank=True, null=True)
|
||||
category=models.CharField(_('Category'), max_length=2048, blank=True, null=True, db_index=True)
|
||||
subcategory=models.CharField(_('Sub Category'), max_length=2048, blank=True, null=True)
|
||||
zip=models.CharField(_('Zip code'), max_length=12, blank=True, null=True)
|
||||
address = models.CharField(_('Address'), max_length=2048, blank=True, null=True)
|
||||
@ -270,15 +287,15 @@ class Location(models.Model):
|
||||
webcontents=models.CharField(_('Web Content'), max_length=2048, blank=True, null=True)
|
||||
status=models.CharField(_('Status'),max_length=2048, blank=True, null=True)
|
||||
portal=models.CharField(_('Portal'), max_length=2048,blank=True, null=True)
|
||||
group=models.CharField(_('Group'), max_length=2048,blank=True, null=True)
|
||||
group=models.CharField(_('Group'), max_length=2048,blank=True, null=True, db_index=True)
|
||||
phone=models.CharField(_('Phone'), max_length=2048,blank=True, null=True)
|
||||
fax=models.CharField(_('Fax'), max_length=2048, blank=True, null=True)
|
||||
email=models.EmailField(_('Email'), max_length=2048,blank=True, null=True)
|
||||
facility=models.CharField(_('Facility'), max_length=2048, blank=True, null=True)
|
||||
remark=models.CharField(_('Remarks'), max_length=2048, blank=True, null=True)
|
||||
tags=models.CharField(_('Tags'), max_length=2048, blank=True, null=True)
|
||||
event_name = models.CharField(_('Event name'), max_length=2048, blank=True, null=True)
|
||||
event_active = models.BooleanField(_("Is Event active"),default=True)
|
||||
event_name = models.CharField(_('Event name'), max_length=2048, blank=True, null=True, db_index=True)
|
||||
event_active = models.BooleanField(_("Is Event active"),default=True, db_index=True)
|
||||
hidden_location = models.BooleanField(_("Is Hidden Location"),default=False)
|
||||
auto_checkin = models.BooleanField(_("Is AutoCheckin"),default=False)
|
||||
checkin_radius = models.FloatField(_("Checkin radious"), blank=True, null=True, default=15.0)
|
||||
@ -300,6 +317,11 @@ class Location(models.Model):
|
||||
last_updated_at=models.DateTimeField(auto_now=True)
|
||||
geom=models.MultiPointField(srid=4326)
|
||||
|
||||
class Meta:
|
||||
indexes = [
|
||||
GistIndex(fields=['geom']),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return self.location_name
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
from rest_framework import serializers
|
||||
from rest_framework_gis.serializers import GeoFeatureModelSerializer
|
||||
from sqlalchemy.sql.functions import mode
|
||||
from .models import Location, Location_line, Location_polygon, JpnAdminMainPerf, JpnAdminPerf, JpnSubPerf, Useractions, GifuAreas, RogUser, UserTracks, GoalImages, CheckinImages,CustomUser
|
||||
from .models import Location, Location_line, Location_polygon, JpnAdminMainPerf, Useractions, GifuAreas, RogUser, UserTracks, GoalImages, CheckinImages,CustomUser
|
||||
from drf_extra_fields.fields import Base64ImageField
|
||||
|
||||
#from django.contrib.auth.models import User
|
||||
@ -42,16 +42,16 @@ class JPN_main_perfSerializer(serializers.ModelSerializer):
|
||||
model=JpnAdminMainPerf
|
||||
fields=['id', 'adm0_en', 'adm0_ja', 'adm0_pcode', 'adm1_en', 'adm1_ja', 'adm1_pcode']
|
||||
|
||||
class JPN_sub_perSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model=JpnSubPerf
|
||||
fields=['id', 'adm0_en', 'adm0_ja', 'adm0_pcode', 'adm1_en', 'adm1_ja', 'adm1_pcode', 'adm2_ja', 'adm2_en', 'adm2_pcode']
|
||||
# class JPN_sub_perSerializer(serializers.ModelSerializer):
|
||||
# class Meta:
|
||||
# model=JpnSubPerf
|
||||
# fields=['id', 'adm0_en', 'adm0_ja', 'adm0_pcode', 'adm1_en', 'adm1_ja', 'adm1_pcode', 'adm2_ja', 'adm2_en', 'adm2_pcode']
|
||||
|
||||
|
||||
class JPN_perfSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model=JpnAdminPerf
|
||||
fields=['id','et_id', 'et_right', 'et_left', 'adm2_l', 'adm1_l', 'adm0_l', 'adm0_r', 'adm1_r', 'adm2_r', 'admlevel']
|
||||
# class JPN_perfSerializer(serializers.ModelSerializer):
|
||||
# class Meta:
|
||||
# model=JpnAdminPerf
|
||||
# fields=['id','et_id', 'et_right', 'et_left', 'adm2_l', 'adm1_l', 'adm0_l', 'adm0_r', 'adm1_r', 'adm2_r', 'admlevel']
|
||||
|
||||
|
||||
class GifuAreaSerializer(serializers.ModelSerializer):
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
from sys import prefix
|
||||
from rest_framework import urlpatterns
|
||||
from rest_framework.routers import DefaultRouter
|
||||
from .views import LocationViewSet, Location_lineViewSet, Location_polygonViewSet, Jpn_Main_PerfViewSet, Jpn_PerfViewSet, LocationsInPerf, SubInPerf, ExtentForSubPerf, SubPerfInMainPerf, ExtentForMainPerf, LocationsInSubPerf, CatView, RegistrationAPI, LoginAPI, UserAPI, UserActionViewset, UserMakeActionViewset, UserDestinations, UpdateOrder, LocationInBound, DeleteDestination, CustomAreaLocations, GetAllGifuAreas, CustomAreaNames, userDetials, UserTracksViewSet, CatByCity, ChangePasswordView, GoalImageViewSet, CheckinImageViewSet, ExtentForLocations, DeleteAccount, PrivacyView, RegistrationView
|
||||
from .views import LocationViewSet, Location_lineViewSet, Location_polygonViewSet, Jpn_Main_PerfViewSet, LocationsInPerf, ExtentForSubPerf, SubPerfInMainPerf, ExtentForMainPerf, LocationsInSubPerf, CatView, RegistrationAPI, LoginAPI, UserAPI, UserActionViewset, UserMakeActionViewset, UserDestinations, UpdateOrder, LocationInBound, DeleteDestination, CustomAreaLocations, GetAllGifuAreas, CustomAreaNames, userDetials, UserTracksViewSet, CatByCity, ChangePasswordView, GoalImageViewSet, CheckinImageViewSet, ExtentForLocations, DeleteAccount, PrivacyView, RegistrationView
|
||||
from django.urls import path, include
|
||||
from knox import views as knox_views
|
||||
|
||||
@ -14,7 +14,6 @@ router.register(prefix='location', viewset=LocationViewSet, basename='location')
|
||||
router.register(prefix='location_line', viewset=Location_lineViewSet, basename="location_line")
|
||||
router.register(prefix='location_polygon', viewset=Location_polygonViewSet, basename='location_polygon')
|
||||
router.register(prefix='perf_main', viewset=Jpn_Main_PerfViewSet, basename='main_perf')
|
||||
router.register(prefix='perf', viewset=Jpn_PerfViewSet, basename='perf')
|
||||
router.register(prefix='track', viewset=UserTracksViewSet, basename='track')
|
||||
router.register(prefix='goalimage', viewset=GoalImageViewSet, basename='goalimage')
|
||||
router.register(prefix='checkinimage', viewset=CheckinImageViewSet, basename='checkinimage')
|
||||
|
||||
196
rog/views.py
196
rog/views.py
@ -1,8 +1,8 @@
|
||||
from curses.ascii import NUL
|
||||
from django.core.serializers import serialize
|
||||
from .models import GoalImages, Location, Location_line, Location_polygon, JpnAdminMainPerf, JpnAdminPerf, JpnSubPerf, Useractions, GifuAreas, RogUser, CustomUser, UserTracks, GoalImages, CheckinImages
|
||||
from .models import GoalImages, Location, Location_line, Location_polygon, JpnAdminMainPerf, Useractions, GifuAreas, RogUser, CustomUser, UserTracks, GoalImages, CheckinImages
|
||||
from rest_framework import viewsets
|
||||
from .serializers import LocationSerializer, Location_lineSerializer, Location_polygonSerializer, JPN_main_perfSerializer, JPN_perfSerializer, JPN_sub_perSerializer, LocationCatSerializer, CreateUserSerializer, UserSerializer, LoginUserSerializer, UseractionsSerializer, UserDestinationSerializer, GifuAreaSerializer, LocationEventNameSerializer, RogUserSerializer, UserTracksSerializer, ChangePasswordSerializer, GolaImageSerializer, CheckinImageSerializer, RegistrationSerializer
|
||||
from .serializers import LocationSerializer, Location_lineSerializer, Location_polygonSerializer, JPN_main_perfSerializer, LocationCatSerializer, CreateUserSerializer, UserSerializer, LoginUserSerializer, UseractionsSerializer, UserDestinationSerializer, GifuAreaSerializer, LocationEventNameSerializer, RogUserSerializer, UserTracksSerializer, ChangePasswordSerializer, GolaImageSerializer, CheckinImageSerializer, RegistrationSerializer
|
||||
from knox.models import AuthToken
|
||||
|
||||
from rest_framework import viewsets, generics, status
|
||||
@ -53,9 +53,9 @@ class Jpn_Main_PerfViewSet(viewsets.ModelViewSet):
|
||||
serializer_class=JPN_main_perfSerializer
|
||||
filter_fields = ["adm1_ja"]
|
||||
|
||||
class Jpn_PerfViewSet(viewsets.ModelViewSet):
|
||||
queryset=JpnAdminPerf.objects.all()
|
||||
serializer_class=JPN_perfSerializer
|
||||
# class Jpn_PerfViewSet(viewsets.ModelViewSet):
|
||||
# queryset=JpnAdminPerf.objects.all()
|
||||
# serializer_class=JPN_perfSerializer
|
||||
|
||||
class UserTracksViewSet(viewsets.ModelViewSet):
|
||||
queryset = UserTracks.objects.all()
|
||||
@ -126,51 +126,56 @@ def LocationsInSubPerf(request):
|
||||
return JsonResponse(serializer.data, safe=False)
|
||||
|
||||
|
||||
def LocationInBound(request):
|
||||
lat1 = float(request.GET.get('la1'))
|
||||
lon1 = float(request.GET.get('ln1'))
|
||||
lat2 = float(request.GET.get('la2'))
|
||||
lon2 = float(request.GET.get('ln2'))
|
||||
lat3 = float(request.GET.get('la3'))
|
||||
lon3 = float(request.GET.get('ln3'))
|
||||
lat4 = float(request.GET.get('la4'))
|
||||
lon4 = float(request.GET.get('ln4'))
|
||||
cat = request.GET.get('cat')
|
||||
grp = request.GET.get('grp')
|
||||
from rest_framework.pagination import PageNumberPagination
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
|
||||
is_rog = request.GET.get('rog')
|
||||
class StandardResultsSetPagination(PageNumberPagination):
|
||||
page_size = 100
|
||||
page_size_query_param = 'page_size'
|
||||
max_page_size = 1000
|
||||
|
||||
class LocationInBound(APIView):
|
||||
pagination_class = StandardResultsSetPagination
|
||||
|
||||
def get(self, request, format=None):
|
||||
lats = [request.GET.get(f'la{i}') for i in range(1, 5)]
|
||||
lons = [request.GET.get(f'ln{i}') for i in range(1, 5)]
|
||||
cat = request.GET.get('cat')
|
||||
grp = request.GET.get('grp')
|
||||
is_rog = request.GET.get('rog')
|
||||
|
||||
if all(lats) and all(lons):
|
||||
pl = geos.Polygon(((lons[i], lats[i]) for i in range(4)), srid=4326)
|
||||
locs = Location.objects.filter(geom__within=pl, event_name__isnull=True)
|
||||
|
||||
if cat:
|
||||
locs = locs.filter(category=cat)
|
||||
|
||||
if(lat1 != None and lon1 != None and lat2 != None and lon2 != None and lat3 != None and lon3 != None and lat4 != None and lon4 != None):
|
||||
pl = geos.Polygon(((lon1, lat1), (lon2, lat2), (lon3, lat3), (lon4, lat4), (lon1, lat1)), srid=4326)
|
||||
if(cat):
|
||||
if is_rog:
|
||||
if grp:
|
||||
locs = Location.objects.filter(~Q(cp=0), geom__within=pl, category=cat, event_name__isnull=True, group__contains=grp)
|
||||
else:
|
||||
locs = Location.objects.filter(~Q(cp=0), geom__within=pl, category=cat, event_name__isnull=True)
|
||||
locs = locs.exclude(cp=0)
|
||||
|
||||
if grp:
|
||||
locs = locs.filter(group__contains=grp)
|
||||
|
||||
if not is_rog:
|
||||
locs = locs.filter(location_name__contains='観光')
|
||||
|
||||
page = self.paginate_queryset(locs)
|
||||
if page is not None:
|
||||
serializer = LocationSerializer(page, many=True)
|
||||
return self.get_paginated_response(serializer.data)
|
||||
else:
|
||||
if grp:
|
||||
locs = Location.objects.filter(geom__within=pl, category=cat, event_name__isnull=True, group__contains=grp, location_name__contains='観光')
|
||||
else:
|
||||
locs = Location.objects.filter(geom__within=pl, category=cat, event_name__isnull=True, location_name__contains='観光')
|
||||
serializer = LocationSerializer(locs, many=True)
|
||||
return Response(serializer.data)
|
||||
|
||||
else:
|
||||
if is_rog:
|
||||
if grp:
|
||||
locs = Location.objects.filter(~Q(cp=0), geom__within=pl, event_name__isnull=True, group__contains=grp)
|
||||
else:
|
||||
locs = Location.objects.filter(~Q(cp=0), geom__within=pl, event_name__isnull=True)
|
||||
else:
|
||||
if grp:
|
||||
locs = Location.objects.filter(geom__within=pl, event_name__isnull=True, group__contains=grp, location_name__contains='観光')
|
||||
else:
|
||||
locs = Location.objects.filter(geom__within=pl, event_name__isnull=True, location_name__contains='観光')
|
||||
if len(locs) > 120:
|
||||
return JsonResponse({"too_many_points": True}, safe=False, status=500)
|
||||
else:
|
||||
serializer = LocationSerializer(locs, many=True)
|
||||
return JsonResponse(serializer.data, safe=False)
|
||||
else:
|
||||
return JsonResponse({}, safe=False)
|
||||
return Response({}, safe=False)
|
||||
|
||||
def paginate_queryset(self, queryset):
|
||||
if self.paginator is None:
|
||||
return None
|
||||
return self.paginator.paginate_queryset(queryset, self.request, view=self)
|
||||
|
||||
|
||||
|
||||
@ -213,8 +218,8 @@ def ExtentForMainPerf(request):
|
||||
def ExtentForLocations(request):
|
||||
user = request.user
|
||||
ec = user.event_code
|
||||
#print(user.event_code)
|
||||
locs = Location.objects.filter(group__contains=ec).aggregate(Extent('geom'), Union('geom'))
|
||||
# Use case-insensitive matching and select related fields for better performance
|
||||
locs = Location.objects.filter(group__icontains=ec).aggregate(Extent('geom'), Union('geom'))
|
||||
return JsonResponse(locs['geom__extent'], safe=False)
|
||||
|
||||
|
||||
@ -227,39 +232,40 @@ def ExtentForSubPerf(request):
|
||||
|
||||
|
||||
def CatView(request):
|
||||
lat1 = float(request.GET.get('la1'))
|
||||
lon1 = float(request.GET.get('ln1'))
|
||||
lat2 = float(request.GET.get('la2'))
|
||||
lon2 = float(request.GET.get('ln2'))
|
||||
lat3 = float(request.GET.get('la3'))
|
||||
lon3 = float(request.GET.get('ln3'))
|
||||
lat4 = float(request.GET.get('la4'))
|
||||
lon4 = float(request.GET.get('ln4'))
|
||||
try:
|
||||
lat1 = float(request.GET.get('la1'))
|
||||
lon1 = float(request.GET.get('ln1'))
|
||||
lat2 = float(request.GET.get('la2'))
|
||||
lon2 = float(request.GET.get('ln2'))
|
||||
lat3 = float(request.GET.get('la3'))
|
||||
lon3 = float(request.GET.get('ln3'))
|
||||
lat4 = float(request.GET.get('la4'))
|
||||
lon4 = float(request.GET.get('ln4'))
|
||||
except (TypeError, ValueError):
|
||||
# If any of the latitudes or longitudes are not provided or cannot be converted to float,
|
||||
# return a bad request response
|
||||
return JsonResponse({"error": "Invalid latitude or longitude"}, status=400)
|
||||
|
||||
if(lat1 != None and lon1 != None and lat2 != None and lon2 != None and lat3 != None and lon3 != None and lat4 != None and lon4 != None):
|
||||
pl = geos.Polygon(((lon1, lat1), (lon2, lat2), (lon3, lat3), (lon4, lat4), (lon1, lat1)), srid=4326)
|
||||
#locs = Location.objects.filter(geom__within=pl)
|
||||
c = Location.objects.filter(geom__within=pl).values('category').distinct()
|
||||
serializer = LocationCatSerializer(c, many=True)
|
||||
return JsonResponse(serializer.data, safe=False)
|
||||
else:
|
||||
return null
|
||||
|
||||
|
||||
c = Location.objects.filter().values('category').distinct()
|
||||
pl = geos.Polygon(((lon1, lat1), (lon2, lat2), (lon3, lat3), (lon4, lat4), (lon1, lat1)), srid=4326)
|
||||
c = Location.objects.filter(geom__within=pl).values('category').distinct()
|
||||
serializer = LocationCatSerializer(c, many=True)
|
||||
return JsonResponse(serializer.data, safe=False)
|
||||
|
||||
|
||||
|
||||
def CatByCity(request):
|
||||
city = request.GET.get('city')
|
||||
if(city != None):
|
||||
cilt_polygon = JpnSubPerf.objects.filter(adm1_ja=city)
|
||||
cats = Location.objects.filter(geom__within=cilt_polygon[0].geom).values('category').distinct()
|
||||
serializer = LocationCatSerializer(cats, many=True)
|
||||
return JsonResponse(serializer.data, safe=False)
|
||||
else:
|
||||
return None
|
||||
if not city:
|
||||
return JsonResponse({"error": "No city parameter provided"}, status=400)
|
||||
|
||||
try:
|
||||
cilt_polygon = JpnSubPerf.objects.get(adm1_ja=city)
|
||||
except JpnSubPerf.DoesNotExist:
|
||||
return JsonResponse({"error": f"No city found with name: {city}"}, status=404)
|
||||
|
||||
cats = Location.objects.filter(geom__within=cilt_polygon.geom).values('category').distinct()
|
||||
serializer = LocationCatSerializer(cats, many=True)
|
||||
return JsonResponse(serializer.data, safe=False)
|
||||
|
||||
|
||||
|
||||
@ -458,38 +464,26 @@ def DeleteDestination(request):
|
||||
return JsonResponse({"success":0}, safe=False)
|
||||
|
||||
|
||||
def CustomAreaLocations(request):
|
||||
class CustomAreaLocations(APIView):
|
||||
def get(self, request, format=None):
|
||||
cat = request.GET.get('cat')
|
||||
name = request.GET.get('name')
|
||||
is_rog = request.GET.get('rog')
|
||||
grp = request.GET.get('grp')
|
||||
|
||||
cat = request.GET.get('cat')
|
||||
name = request.GET.get('name')
|
||||
is_rog = request.GET.get('rog')
|
||||
grp = request.GET.get('grp')
|
||||
locs = Location.objects.filter(event_name=name, event_name__isnull=False)
|
||||
|
||||
if(cat != None):
|
||||
if cat:
|
||||
locs = locs.filter(category=cat)
|
||||
if is_rog:
|
||||
if grp:
|
||||
locs = Location.objects.filter(~Q(cp=0), event_name__isnull=False, category=cat, event_name=name, group__contains=grp)
|
||||
else:
|
||||
locs = Location.objects.filter(~Q(cp=0), event_name__isnull=False, category=cat, event_name=name)
|
||||
else:
|
||||
if grp:
|
||||
locs = Location.objects.filter(event_name__isnull=False, category=cat, event_name=name, group__contains=grp, location_name__contains='観光')
|
||||
else:
|
||||
locs = Location.objects.filter(event_name__isnull=False, category=cat, event_name=name, location_name__contains='観光')
|
||||
else:
|
||||
if is_rog:
|
||||
if grp:
|
||||
locs = Location.objects.filter(~Q(cp=0), event_name__isnull=False, event_name=name, group__contains=grp)
|
||||
else:
|
||||
locs = Location.objects.filter(~Q(cp=0), event_name__isnull=False, event_name=name)
|
||||
else:
|
||||
if grp:
|
||||
locs = Location.objects.filter(event_name__isnull=False, event_name=name, group__contains=grp, location_name__contains='観光')
|
||||
else:
|
||||
locs = Location.objects.filter(event_name__isnull=False, event_name=name, location_name__contains='観光')
|
||||
locs = locs.exclude(cp=0)
|
||||
if grp:
|
||||
locs = locs.filter(group__contains=grp)
|
||||
if not is_rog:
|
||||
locs = locs.filter(location_name__contains='観光')
|
||||
|
||||
serializer = LocationSerializer(locs, many=True)
|
||||
return JsonResponse(serializer.data, safe=False)
|
||||
serializer = LocationSerializer(locs, many=True)
|
||||
return Response(serializer.data)
|
||||
|
||||
|
||||
def CustomAreaNames(request):
|
||||
|
||||
Reference in New Issue
Block a user