mirror of
https://github.com/task-17-lct/backend.git
synced 2024-11-27 12:33:44 +03:00
Merge branch 'master' of https://github.com/Alexander-D-Karpov/passfinder
This commit is contained in:
commit
2949cd9e6f
|
@ -30,7 +30,7 @@
|
||||||
res = {
|
res = {
|
||||||
"title": info["name"],
|
"title": info["name"],
|
||||||
"parser_source": "mkrf.ru",
|
"parser_source": "mkrf.ru",
|
||||||
"region": Region.objects.get(title=r_name),
|
# "region": Region.objects.get(title=r_name),
|
||||||
"lat": info["address"]["mapPosition"]["coordinates"][0],
|
"lat": info["address"]["mapPosition"]["coordinates"][0],
|
||||||
"lon": info["address"]["mapPosition"]["coordinates"][1],
|
"lon": info["address"]["mapPosition"]["coordinates"][1],
|
||||||
"address": info["address"]["fullAddress"],
|
"address": info["address"]["fullAddress"],
|
||||||
|
@ -39,6 +39,7 @@
|
||||||
}
|
}
|
||||||
if "typologies" in info:
|
if "typologies" in info:
|
||||||
res["extra_kwargs"]["typologies"] = [x["value"] for x in info["typologies"]]
|
res["extra_kwargs"]["typologies"] = [x["value"] for x in info["typologies"]]
|
||||||
|
|
||||||
if "securityInfo" in info or "borderInfo" in info:
|
if "securityInfo" in info or "borderInfo" in info:
|
||||||
for ev in Event.objects.filter(
|
for ev in Event.objects.filter(
|
||||||
title=info["name"],
|
title=info["name"],
|
||||||
|
@ -46,12 +47,7 @@
|
||||||
lat=res["lat"],
|
lat=res["lat"],
|
||||||
lon=res["lon"],
|
lon=res["lon"],
|
||||||
):
|
):
|
||||||
ddd = [
|
ev.extra_kwargs = res["extra_kwargs"]
|
||||||
info["securityInfo"] if "securityInfo" in info else "",
|
|
||||||
info["borderInfo"] if "borderInfo" in info else "",
|
|
||||||
]
|
|
||||||
ddd = [x for x in ddd if x]
|
|
||||||
ev.description = " ".join(ddd)
|
|
||||||
ev.save()
|
ev.save()
|
||||||
|
|
||||||
ret.append(res)
|
ret.append(res)
|
||||||
|
|
|
@ -3,3 +3,6 @@
|
||||||
|
|
||||||
class EventsConfig(AppConfig):
|
class EventsConfig(AppConfig):
|
||||||
name = "passfinder.events"
|
name = "passfinder.events"
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
import passfinder.events.signals # noqa
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
# Generated by Django 4.2.1 on 2023-05-24 09:40
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("events", "0018_userroute_baseuserroutepoint_userroutetransaction_and_more"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="Category",
|
||||||
|
fields=[
|
||||||
|
(
|
||||||
|
"oid",
|
||||||
|
models.CharField(
|
||||||
|
max_length=24, primary_key=True, serialize=False, unique=True
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("name", models.CharField(max_length=500, unique=True)),
|
||||||
|
("description", models.TextField()),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
"abstract": False,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="PointCategory",
|
||||||
|
fields=[
|
||||||
|
(
|
||||||
|
"id",
|
||||||
|
models.BigAutoField(
|
||||||
|
auto_created=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"category",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
related_name="points",
|
||||||
|
to="events.category",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"point",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
related_name="categories",
|
||||||
|
to="events.basepoint",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
"unique_together": {("point", "category")},
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.DeleteModel(
|
||||||
|
name="Tag",
|
||||||
|
),
|
||||||
|
]
|
|
@ -73,13 +73,26 @@ def location(self):
|
||||||
return [self.lat, self.lon]
|
return [self.lat, self.lon]
|
||||||
|
|
||||||
|
|
||||||
class Tag(OIDModel):
|
class Category(OIDModel):
|
||||||
name = models.CharField(max_length=250)
|
name = models.CharField(max_length=500, unique=True)
|
||||||
|
description = models.TextField()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
|
class PointCategory(models.Model):
|
||||||
|
point = models.ForeignKey(
|
||||||
|
"BasePoint", related_name="categories", on_delete=models.CASCADE
|
||||||
|
)
|
||||||
|
category = models.ForeignKey(
|
||||||
|
"Category", related_name="points", on_delete=models.CASCADE
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
unique_together = ("point", "category")
|
||||||
|
|
||||||
|
|
||||||
class BasePoint(OIDModel, PolymorphicModel):
|
class BasePoint(OIDModel, PolymorphicModel):
|
||||||
title = models.CharField(max_length=500)
|
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)
|
||||||
|
|
15
passfinder/events/signals.py
Normal file
15
passfinder/events/signals.py
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
from django.db.models.signals import pre_save
|
||||||
|
from django.dispatch import receiver
|
||||||
|
|
||||||
|
from passfinder.events.models import Category
|
||||||
|
from passfinder.utils.generators import generate_charset
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(pre_save, sender=Category)
|
||||||
|
def create_model_link(sender, instance, created, **kwargs):
|
||||||
|
if instance.id is None:
|
||||||
|
oid = generate_charset(24)
|
||||||
|
while Category.objects.filter(oid=oid).exists():
|
||||||
|
oid = generate_charset(24)
|
||||||
|
|
||||||
|
instance.oid = oid
|
Loading…
Reference in New Issue
Block a user