mirror of
https://github.com/task-17-lct/backend.git
synced 2024-11-27 14:13:44 +03:00
added attractions
This commit is contained in:
parent
cfdd4487d6
commit
a159f9befa
45
parsers/attractions.py
Normal file
45
parsers/attractions.py
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
import json
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
from passfinder.events.models import Region
|
||||||
|
|
||||||
|
with open("data/pos-attr.json") as f:
|
||||||
|
data = json.load(f)
|
||||||
|
|
||||||
|
reggg = {
|
||||||
|
"г. Санкт-Петербург": "Санкт-Петербург",
|
||||||
|
"г. Москва": "Москва",
|
||||||
|
"г. Севастополь": "Севастополь",
|
||||||
|
"Республика Адыгея (Адыгея)": "Республика Адыгея",
|
||||||
|
"Чувашская Республика - Чувашия": "Чувашская Республика",
|
||||||
|
"Республика Татарстан (Татарстан)": "Республика Татарстан",
|
||||||
|
"Республика Северная Осетия - Алания": "Республика Северная Осетия – Алания",
|
||||||
|
"Ханты-Мансийский автономный округ - Югра": "Ханты-Мансийский автономный округ — Югра",
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = []
|
||||||
|
for infff in data:
|
||||||
|
info = infff["general"]
|
||||||
|
if info["address"] and "mapPosition" in info["address"]:
|
||||||
|
r_name = (
|
||||||
|
reggg[info["region"]["value"]]
|
||||||
|
if info["region"]["value"] in reggg
|
||||||
|
else info["region"]["value"]
|
||||||
|
)
|
||||||
|
res = {
|
||||||
|
"title": info["name"],
|
||||||
|
"parser_source": "mkrf.ru",
|
||||||
|
"region": Region.objects.get(title=r_name),
|
||||||
|
"lat": info["address"]["mapPosition"]["coordinates"][0],
|
||||||
|
"lon": info["address"]["mapPosition"]["coordinates"][1],
|
||||||
|
"address": info["address"]["fullAddress"],
|
||||||
|
"type": "attraction",
|
||||||
|
"extra_kwargs": {"objectType": info["objectType"]["value"]},
|
||||||
|
}
|
||||||
|
if "typologies" in info:
|
||||||
|
res["extra_kwargs"]["typologies"] = [x["value"] for x in info["typologies"]]
|
||||||
|
ret.append(res)
|
||||||
|
|
||||||
|
|
||||||
|
def get_att():
|
||||||
|
return ret
|
|
@ -1,4 +1,5 @@
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
from rest_framework.generics import get_object_or_404
|
||||||
|
|
||||||
from passfinder.events.models import Hotel, HotelPhone, City, Event, BasePoint, Region
|
from passfinder.events.models import Hotel, HotelPhone, City, Event, BasePoint, Region
|
||||||
|
|
||||||
|
@ -49,6 +50,14 @@ class RouteSerializer(serializers.Serializer):
|
||||||
points = serializers.ListSerializer(child=PointSerializer())
|
points = serializers.ListSerializer(child=PointSerializer())
|
||||||
|
|
||||||
|
|
||||||
|
class RouteInputSerializer(serializers.Serializer):
|
||||||
|
date_from = serializers.DateField(required=False, allow_null=True)
|
||||||
|
date_to = serializers.DateField(required=False, allow_null=True)
|
||||||
|
region = serializers.CharField(
|
||||||
|
min_length=24, max_length=24, required=False, allow_blank=True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class RegionSerializer(serializers.ModelSerializer):
|
class RegionSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Region
|
model = Region
|
||||||
|
|
|
@ -1,21 +1,20 @@
|
||||||
from django_filters import DateFilter
|
from rest_framework.generics import GenericAPIView, ListAPIView, get_object_or_404
|
||||||
from django_filters.rest_framework import DjangoFilterBackend
|
|
||||||
from rest_framework.generics import GenericAPIView, ListAPIView
|
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
from drf_spectacular.utils import extend_schema
|
||||||
|
|
||||||
from passfinder.events.api.serializers import (
|
from passfinder.events.api.serializers import (
|
||||||
PointSerializer,
|
PointSerializer,
|
||||||
RouteSerializer,
|
RouteSerializer,
|
||||||
RegionSerializer,
|
RegionSerializer,
|
||||||
|
RouteInputSerializer,
|
||||||
)
|
)
|
||||||
from passfinder.events.models import BasePoint, Region
|
from passfinder.events.models import BasePoint, Region
|
||||||
|
|
||||||
|
|
||||||
class BuildRouteApiView(GenericAPIView):
|
class BuildRouteApiView(GenericAPIView):
|
||||||
filter_backends = (DjangoFilterBackend,)
|
|
||||||
filterset_class = DateFilter
|
|
||||||
serializer_class = RouteSerializer
|
serializer_class = RouteSerializer
|
||||||
|
|
||||||
|
@extend_schema(responses={200: RouteSerializer(many=True)})
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
routes = []
|
routes = []
|
||||||
for _ in range(10):
|
for _ in range(10):
|
||||||
|
@ -30,6 +29,39 @@ def get(self, request):
|
||||||
)
|
)
|
||||||
return Response(data=routes)
|
return Response(data=routes)
|
||||||
|
|
||||||
|
@extend_schema(
|
||||||
|
request=RouteInputSerializer, responses={200: RouteSerializer(many=True)}
|
||||||
|
)
|
||||||
|
def post(self, request):
|
||||||
|
serializer = RouteInputSerializer(data=request.data)
|
||||||
|
serializer.is_valid(raise_exception=True)
|
||||||
|
region = serializer.data["region"]
|
||||||
|
routes = []
|
||||||
|
if region:
|
||||||
|
region = get_object_or_404(Region, oid=region)
|
||||||
|
for _ in range(2):
|
||||||
|
routes.append(
|
||||||
|
{
|
||||||
|
"name": "bebra",
|
||||||
|
"description": "bebra bebra bebra",
|
||||||
|
"points": PointSerializer(many=True).to_representation(
|
||||||
|
region.points.all().order_by("?")[:10]
|
||||||
|
),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
for _ in range(10):
|
||||||
|
routes.append(
|
||||||
|
{
|
||||||
|
"name": "bebra",
|
||||||
|
"description": "bebra bebra bebra",
|
||||||
|
"points": PointSerializer(many=True).to_representation(
|
||||||
|
BasePoint.objects.order_by("?")[:10]
|
||||||
|
),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return Response(data=routes)
|
||||||
|
|
||||||
|
|
||||||
class ListRegionApiView(ListAPIView):
|
class ListRegionApiView(ListAPIView):
|
||||||
serializer_class = RegionSerializer
|
serializer_class = RegionSerializer
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
# Generated by Django 4.2.1 on 2023-05-23 14:57
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("events", "0016_remove_basepoint_location_remove_city_location_and_more"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="event",
|
||||||
|
name="address",
|
||||||
|
field=models.CharField(max_length=250, null=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="event",
|
||||||
|
name="extra_kwargs",
|
||||||
|
field=models.JSONField(null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="basepoint",
|
||||||
|
name="title",
|
||||||
|
field=models.CharField(max_length=500),
|
||||||
|
),
|
||||||
|
]
|
|
@ -81,7 +81,7 @@ def __str__(self):
|
||||||
|
|
||||||
|
|
||||||
class BasePoint(OIDModel, PolymorphicModel):
|
class BasePoint(OIDModel, PolymorphicModel):
|
||||||
title = models.CharField(max_length=250)
|
title = models.CharField(max_length=500)
|
||||||
parser_source = models.CharField(max_length=250, null=True, blank=True)
|
parser_source = models.CharField(max_length=250, null=True, blank=True)
|
||||||
description = models.TextField()
|
description = models.TextField()
|
||||||
city = models.ForeignKey(
|
city = models.ForeignKey(
|
||||||
|
@ -136,6 +136,7 @@ class EventType(models.TextChoices):
|
||||||
concert = "concert", "концерт"
|
concert = "concert", "концерт"
|
||||||
spektatli = "plays", "спектакли"
|
spektatli = "plays", "спектакли"
|
||||||
|
|
||||||
|
address = models.CharField(max_length=250, null=True)
|
||||||
payment_method = models.CharField(max_length=250, null=True, blank=True)
|
payment_method = models.CharField(max_length=250, null=True, blank=True)
|
||||||
type = models.CharField(
|
type = models.CharField(
|
||||||
db_index=True,
|
db_index=True,
|
||||||
|
@ -151,6 +152,8 @@ class EventType(models.TextChoices):
|
||||||
ticket_price = models.IntegerField(blank=True, null=True)
|
ticket_price = models.IntegerField(blank=True, null=True)
|
||||||
schedule = models.JSONField(null=True)
|
schedule = models.JSONField(null=True)
|
||||||
|
|
||||||
|
extra_kwargs = models.JSONField(null=True)
|
||||||
|
|
||||||
|
|
||||||
class Hotel(BasePoint):
|
class Hotel(BasePoint):
|
||||||
address = models.CharField(max_length=250)
|
address = models.CharField(max_length=250)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user