Merge remote-tracking branch 'origin/develop' into review_users
This commit is contained in:
commit
8a34ef6477
|
|
@ -1,19 +1,19 @@
|
|||
import re
|
||||
from mptt.models import MPTTModel, TreeForeignKey
|
||||
|
||||
from django.contrib.contenttypes.fields import ContentType
|
||||
from django.contrib.postgres.fields import JSONField
|
||||
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from mptt.models import MPTTModel, TreeForeignKey
|
||||
from slugify import slugify
|
||||
|
||||
from utils.models import IntermediateGalleryModelMixin
|
||||
from utils.models import (
|
||||
ProjectBaseMixin, TJSONField, TranslatedFieldsMixin,
|
||||
URLImageMixin,
|
||||
)
|
||||
from utils.querysets import RelatedObjectsCountMixin
|
||||
from utils.models import IntermediateGalleryModelMixin, GalleryMixin
|
||||
|
||||
from slugify import slugify
|
||||
|
||||
|
||||
# Mixins
|
||||
|
|
|
|||
20
apps/gallery/migrations/0007_auto_20191110_1329.py
Normal file
20
apps/gallery/migrations/0007_auto_20191110_1329.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 2.2.4 on 2019-11-10 13:29
|
||||
|
||||
from django.db import migrations
|
||||
import sorl.thumbnail.fields
|
||||
import utils.methods
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('gallery', '0006_merge_20191027_1758'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='image',
|
||||
name='image',
|
||||
field=sorl.thumbnail.fields.ImageField(max_length=255, upload_to=utils.methods.image_path, verbose_name='image file'),
|
||||
),
|
||||
]
|
||||
14
apps/gallery/migrations/0008_merge_20191212_0752.py
Normal file
14
apps/gallery/migrations/0008_merge_20191212_0752.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# Generated by Django 2.2.7 on 2019-12-12 07:52
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('gallery', '0007_auto_20191110_1329'),
|
||||
('gallery', '0007_auto_20191211_1528'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
]
|
||||
|
|
@ -21,7 +21,7 @@ class Image(ProjectBaseMixin, SORLImageMixin, PlatformMixin):
|
|||
(VERTICAL, _('Vertical')),
|
||||
)
|
||||
|
||||
image = SORLImageField(upload_to=image_path,
|
||||
image = SORLImageField(max_length=255, upload_to=image_path,
|
||||
verbose_name=_('image file'))
|
||||
orientation = models.PositiveSmallIntegerField(choices=ORIENTATIONS,
|
||||
blank=True, null=True, default=None,
|
||||
|
|
|
|||
122
apps/location/csv/aa_cities.csv
Normal file
122
apps/location/csv/aa_cities.csv
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
old_id,name,zip_code,country,,region,subregion,is_island
|
||||
9854,Sainte Marie,97230,Antilles Guyane West Indies,11,null,null,1
|
||||
9846,La Guyane,,Antilles Guyane West Indies,,null,null,1
|
||||
9845,Macouba,97218,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||
9844,La Martinique,,Antilles Guyane West Indies,,null,null,1
|
||||
9843,Guadeloupe,,Antilles Guyane West Indies,,Guadeloupe,null,1
|
||||
9693,Gustavia,97133,Antilles Guyane West Indies,,St Barthelemy,null,0
|
||||
9663,Saint Martin,97150,Antilles Guyane West Indies,,St Martin,null,0
|
||||
9662,Saint-Barthélemy,97133,Antilles Guyane West Indies,,St Barthelemy,null,0
|
||||
9661,Javouhey,97318,Antilles Guyane West Indies,,Guyane,null,0
|
||||
9660,Kaw,97353,Antilles Guyane West Indies,,Guyane,null,0
|
||||
9659,Apatou,97317,Antilles Guyane West Indies,,Guyane,null,0
|
||||
9658,La comte,97352,Antilles Guyane West Indies,,Guyane,null,0
|
||||
9657,St elie,97312,Antilles Guyane West Indies,,Guyane,null,0
|
||||
9656,Grand santi,97340,Antilles Guyane West Indies,,Guyane,null,0
|
||||
9655,Camopi,97330,Antilles Guyane West Indies,,Guyane,null,0
|
||||
9654,Maripasoula,97370,Antilles Guyane West Indies,,Guyane,null,0
|
||||
9653,Saul,97314,Antilles Guyane West Indies,,Guyane,null,0
|
||||
9652,Ouanary,97380,Antilles Guyane West Indies,,Guyane,null,0
|
||||
9651,Montsinery tonnegrande,97300,Antilles Guyane West Indies,,Guyane,null,0
|
||||
9650,Sinnamary,97315,Antilles Guyane West Indies,,Guyane,null,0
|
||||
9649,St Laurent du Maroni,97320,Antilles Guyane West Indies,,Guyane,null,0
|
||||
9648,Roura,97311,Antilles Guyane West Indies,,Guyane,null,0
|
||||
9647,Rémiré Montjoly,97354,Antilles Guyane West Indies,,Guyane,null,0
|
||||
9646,St georges,97313,Antilles Guyane West Indies,,Guyane,null,0
|
||||
9645,Matoury,97351,Antilles Guyane West Indies,,Guyane,null,0
|
||||
9644,Mana,97360,Antilles Guyane West Indies,,Guyane,null,0
|
||||
9643,Macouria,97355,Antilles Guyane West Indies,,Guyane,null,0
|
||||
9642,Kourou,97310,Antilles Guyane West Indies,,Guyane,null,0
|
||||
9641,Iracoubo,97350,Antilles Guyane West Indies,,Guyane,null,0
|
||||
9640,Cayenne,97300,Antilles Guyane West Indies,,Guyane,null,0
|
||||
9639,Regina,97390,Antilles Guyane West Indies,,Guyane,null,0
|
||||
9638,Vert Pré,97231,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||
9637,Vauclin,97280,Antilles Guyane West Indies,,Martinique,Sud,0
|
||||
9636,Trois Ilets,97229,Antilles Guyane West Indies,,Martinique,Sud,0
|
||||
9635,La Trinité,97220,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||
9634,Schoelcher,97233,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||
9633,Saint-Pierre,97250,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||
9632,Sainte Marie,97230,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||
9631,Sainte-Luce,97228,Antilles Guyane West Indies,,Martinique,Sud,0
|
||||
9630,Saint Joseph,97212,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||
9629,Saint Esprit,97270,Antilles Guyane West Indies,,Martinique,Sud,0
|
||||
9628,Sainte-Anne,97227,Antilles Guyane West Indies,,Martinique,Sud,0
|
||||
9627,Le Robert,97231,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||
9626,Rivière Salée,97215,Antilles Guyane West Indies,,Martinique,Sud,0
|
||||
9625,Rivière Pilote,97211,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||
9624,Prêcheur,97250,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||
9623,Morne Vert,97226,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||
9622,Morne Rouge,97260,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||
9621,Le Marin,97290,Antilles Guyane West Indies,,Martinique,Sud,0
|
||||
9620,Marigot,97225,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||
9619,Lorrain,97214,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||
9618,Lamentin,97232,Antilles Guyane West Indies,,Martinique,Sud,0
|
||||
9617,Gros Morne,97213,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||
9616,Grand Rivière,97218,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||
9615,Le François,97240,Antilles Guyane West Indies,,Martinique,Sud,0
|
||||
9614,Fort de France,97200,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||
9613,Fonds Saint Denis,97250,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||
9612,Ducos,97224,Antilles Guyane West Indies,,Martinique,Sud,0
|
||||
9611,Le Diamant,97223,Antilles Guyane West Indies,,Martinique,Sud,0
|
||||
9610,Case Pilote,97222,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||
9609,Le Carbet,97221,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||
9608,Bellefontaine,97222,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||
9607,Basse Pointe,97218,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||
9606,Anses d'Arlet,97217,Antilles Guyane West Indies,,Martinique,Sud,0
|
||||
9605,Ajoupa Bouillon,97216,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||
9604,Les mangles,97131,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||
9603,Douville,97180,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||
9602,Sainte-Marie,97230,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||
9601,Pigeon,97132,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||
9600,Bananier,97130,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||
9599,Vieux-Habitants,97119,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||
9598,Vieux fort,97141,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||
9597,Trois rivieres,97114,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||
9596,Terre de Haut,97137,Antilles Guyane West Indies,,Guadeloupe,Autres les Îles de Guadeloupe,0
|
||||
9595,Terre de bas,97136,Antilles Guyane West Indies,,Guadeloupe,Autres les Îles de Guadeloupe,0
|
||||
9594,Sainte-Rose,97115,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||
9593,Sainte-Anne,97180,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||
9592,St louis,97134,Antilles Guyane West Indies,,Guadeloupe,Autres les Îles de Guadeloupe,0
|
||||
9591,Saint-François,97118,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||
9590,St claude,97120,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||
9589,Port louis,97117,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||
9588,Pointe noire,97116,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||
9587,Pointe-A-Pitre,97110,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||
9586,Petit canal,97131,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||
9585,Petit bourg,97170,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||
9584,Le moule,97160,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||
9583,Morne a l eau,97111,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||
9582,Lamentin,97129,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||
9581,Goyave,97128,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||
9580,Le Gosier,97190,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||
9579,Grand-Bourg,97112,Antilles Guyane West Indies,,Guadeloupe,Autres les Îles de Guadeloupe,0
|
||||
9578,Deshaies,97126,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||
9577,La desirade,97127,Antilles Guyane West Indies,,Guadeloupe,Autres les Îles de Guadeloupe,0
|
||||
9576,Gourbeyre,97113,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||
9575,Capesterre de Marie-Galante,97140,Antilles Guyane West Indies,,Guadeloupe,Autres les Îles de Guadeloupe,0
|
||||
9574,Capesterre belle eau,97130,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||
9573,Bouillante,97125,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||
9572,Basse terre,97100,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||
9571,Baillif,97123,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||
9570,Baie-Mahault,97122,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||
9569,Anse-Bertrand,97121,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||
9568,Les abymes,97139,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||
11371,Cul-de-Sac,97150,Antilles Guyane West Indies,,St Martin,null,0
|
||||
11370,Ilet Pinel,97150,Antilles Guyane West Indies,,St Martin,null,0
|
||||
11369,Simpson Bay,97150,Antilles Guyane West Indies,,St Martin,null,0
|
||||
11368,Anse Marcel,97150,Antilles Guyane West Indies,,St Martin,null,0
|
||||
11367,Orient Bay,97150,Antilles Guyane West Indies,,St Martin,null,0
|
||||
11366,Marigot,97150,Antilles Guyane West Indies,,St Martin,null,0
|
||||
11365,Baie Longue,97150,Antilles Guyane West Indies,,St Martin,null,0
|
||||
11364,Baie Nettle,97150,Antilles Guyane West Indies,,St Martin,null,0
|
||||
11363,Baie Orientale,97150,Antilles Guyane West Indies,,St Martin,null,0
|
||||
11362,Oyster Pond,97150,Antilles Guyane West Indies,,St Martin,null,0
|
||||
11349,Rodney Bay,LC01 401,Antilles Guyane West Indies,,Sainte-Lucie,null,0
|
||||
11348,Good Lands,null,Antilles Guyane West Indies,,Sainte-Lucie,null,0
|
||||
11347,Soufriere,null,Antilles Guyane West Indies,,Sainte-Lucie,null,0
|
||||
11343,Gros Islet,LC0001,Antilles Guyane West Indies,,Sainte-Lucie,null,0
|
||||
11342,CAP ESTATE,null,Antilles Guyane West Indies,,Sainte-Lucie,null,0
|
||||
11341,Castries,null,Antilles Guyane West Indies,,Sainte-Lucie,null,0
|
||||
11303,Saint- Louis,97134,Antilles Guyane West Indies,,Guadeloupe,Autres les Îles de Guadeloupe,0
|
||||
11302,Grand Cul de Sac,97133,Antilles Guyane West Indies,,St Barthelemy,null,0
|
||||
11301,Grand Case,97150,Antilles Guyane West Indies,,St Martin,null,0
|
||||
|
98
apps/location/migrations/0031_auto_20191121_1236.py
Normal file
98
apps/location/migrations/0031_auto_20191121_1236.py
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
# Generated by Django 2.2.7 on 2019-11-21 12:36
|
||||
|
||||
import django.contrib.postgres.fields
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import utils.models
|
||||
|
||||
|
||||
def copy_country_code(apps, schema_editor):
|
||||
Country = apps.get_model('location', 'Country')
|
||||
to_update = []
|
||||
for country in Country.objects.all():
|
||||
if country.code:
|
||||
country.code_2 = country.code
|
||||
to_update.append(country)
|
||||
Country.objects.bulk_update(to_update, ['code_2', ])
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('location', '0030_auto_20191120_1010'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='city',
|
||||
name='map1',
|
||||
field=models.CharField(blank=True, max_length=255, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='city',
|
||||
name='map2',
|
||||
field=models.CharField(blank=True, max_length=255, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='city',
|
||||
name='map_ref',
|
||||
field=models.CharField(blank=True, max_length=255, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='city',
|
||||
name='mysql_id',
|
||||
field=models.IntegerField(blank=True, default=None, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='city',
|
||||
name='name_translated',
|
||||
field=utils.models.TJSONField(blank=True, default=None, help_text='{"en-GB":"some text"}', null=True, verbose_name='Translated name'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='city',
|
||||
name='situation',
|
||||
field=models.CharField(blank=True, max_length=255, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='country',
|
||||
name='mysql_ids',
|
||||
field=django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(), blank=True, null=True, size=None),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='region',
|
||||
name='mysql_ids',
|
||||
field=django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(), blank=True, null=True, size=None),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='city',
|
||||
name='gallery',
|
||||
field=models.ManyToManyField(blank=True, through='location.CityGallery', to='gallery.Image'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='city',
|
||||
name='region',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='location.Region', verbose_name='parent region'),
|
||||
),
|
||||
# -- fix incorrect removal of uniqueness constraint code field
|
||||
migrations.AddField(
|
||||
model_name='country',
|
||||
name='code_2',
|
||||
field=models.CharField(max_length=255, null=True)
|
||||
),
|
||||
migrations.RunPython(copy_country_code, migrations.RunPython.noop),
|
||||
migrations.RemoveField(
|
||||
model_name='country',
|
||||
name='code',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='country',
|
||||
old_name='code_2',
|
||||
new_name='code',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='country',
|
||||
name='code',
|
||||
field=models.CharField(max_length=255, verbose_name='Code'),
|
||||
),
|
||||
# fix incorrect removal of uniqueness constraint code field --
|
||||
]
|
||||
14
apps/location/migrations/0032_merge_20191209_0832.py
Normal file
14
apps/location/migrations/0032_merge_20191209_0832.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# Generated by Django 2.2.7 on 2019-12-09 08:32
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('location', '0031_establishmentwineoriginaddress_wineoriginaddress'),
|
||||
('location', '0031_auto_20191121_1236'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
]
|
||||
14
apps/location/migrations/0033_merge_20191224_0920.py
Normal file
14
apps/location/migrations/0033_merge_20191224_0920.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# Generated by Django 2.2.7 on 2019-12-24 09:20
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('location', '0032_merge_20191209_0832'),
|
||||
('location', '0032_auto_20191220_1019'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
]
|
||||
|
|
@ -9,6 +9,8 @@ from functools import reduce
|
|||
from typing import List
|
||||
|
||||
|
||||
from django.contrib.postgres.fields import ArrayField
|
||||
|
||||
from translation.models import Language
|
||||
from utils.models import (ProjectBaseMixin, SVGImageMixin, TJSONField,
|
||||
TranslatedFieldsMixin, get_current_locale,
|
||||
|
|
@ -22,7 +24,8 @@ class CountryQuerySet(models.QuerySet):
|
|||
return self.filter(is_active=switcher)
|
||||
|
||||
|
||||
class Country(TranslatedFieldsMixin, SVGImageMixin, ProjectBaseMixin):
|
||||
class Country(TranslatedFieldsMixin,
|
||||
SVGImageMixin, ProjectBaseMixin):
|
||||
"""Country model."""
|
||||
|
||||
STR_FIELD_NAME = 'name'
|
||||
|
|
@ -36,25 +39,17 @@ class Country(TranslatedFieldsMixin, SVGImageMixin, ProjectBaseMixin):
|
|||
|
||||
name = TJSONField(null=True, blank=True, default=None,
|
||||
verbose_name=_('Name'), help_text='{"en-GB":"some text"}')
|
||||
code = models.CharField(max_length=255, unique=True, verbose_name=_('Code'))
|
||||
code = models.CharField(max_length=255, verbose_name=_('Code'))
|
||||
low_price = models.IntegerField(default=25, verbose_name=_('Low price'))
|
||||
high_price = models.IntegerField(default=50, verbose_name=_('High price'))
|
||||
languages = models.ManyToManyField(Language, verbose_name=_('Languages'))
|
||||
is_active = models.BooleanField(_('is active'), default=True)
|
||||
old_id = models.IntegerField(null=True, blank=True, default=None)
|
||||
|
||||
mysql_ids = ArrayField(models.IntegerField(), blank=True, null=True)
|
||||
|
||||
objects = CountryQuerySet.as_manager()
|
||||
|
||||
@property
|
||||
def time_format(self):
|
||||
if self.code.lower() not in self.TWELVE_HOURS_FORMAT_COUNTRIES:
|
||||
return 'HH:mm'
|
||||
return 'hh:mmA'
|
||||
|
||||
@property
|
||||
def country_id(self):
|
||||
return self.id
|
||||
|
||||
class Meta:
|
||||
"""Meta class."""
|
||||
|
||||
|
|
@ -69,6 +64,17 @@ class Country(TranslatedFieldsMixin, SVGImageMixin, ProjectBaseMixin):
|
|||
str_name = translated_name
|
||||
return str_name
|
||||
|
||||
@property
|
||||
def time_format(self):
|
||||
if self.code.lower() not in self.TWELVE_HOURS_FORMAT_COUNTRIES:
|
||||
return 'HH:mm'
|
||||
return 'hh:mmA'
|
||||
|
||||
@property
|
||||
def country_id(self):
|
||||
return self.id
|
||||
|
||||
|
||||
|
||||
class RegionQuerySet(models.QuerySet):
|
||||
"""QuerySet for model Region."""
|
||||
|
|
@ -101,6 +107,7 @@ class Region(models.Model):
|
|||
country = models.ForeignKey(
|
||||
Country, verbose_name=_('country'), on_delete=models.CASCADE)
|
||||
old_id = models.IntegerField(null=True, blank=True, default=None)
|
||||
mysql_ids = ArrayField(models.IntegerField(), blank=True, null=True)
|
||||
|
||||
objects = RegionQuerySet.as_manager()
|
||||
|
||||
|
|
@ -137,9 +144,13 @@ class CityQuerySet(models.QuerySet):
|
|||
class City(GalleryMixin, models.Model):
|
||||
"""Region model."""
|
||||
name = models.CharField(_('name'), max_length=250)
|
||||
name_translated = TJSONField(blank=True, null=True, default=None,
|
||||
verbose_name=_('Translated name'),
|
||||
help_text='{"en-GB":"some text"}')
|
||||
code = models.CharField(_('code'), max_length=250)
|
||||
region = models.ForeignKey(
|
||||
Region, verbose_name=_('parent region'), on_delete=models.CASCADE)
|
||||
region = models.ForeignKey(Region, on_delete=models.CASCADE,
|
||||
blank=True, null=True,
|
||||
verbose_name=_('parent region'))
|
||||
country = models.ForeignKey(
|
||||
Country, verbose_name=_('country'), on_delete=models.CASCADE)
|
||||
|
||||
|
|
@ -148,7 +159,15 @@ class City(GalleryMixin, models.Model):
|
|||
|
||||
is_island = models.BooleanField(_('is island'), default=False)
|
||||
old_id = models.IntegerField(null=True, blank=True, default=None)
|
||||
gallery = models.ManyToManyField('gallery.Image', through='CityGallery')
|
||||
|
||||
map1 = models.CharField(max_length=255, blank=True, null=True)
|
||||
map2 = models.CharField(max_length=255, blank=True, null=True)
|
||||
map_ref = models.CharField(max_length=255, blank=True, null=True)
|
||||
situation = models.CharField(max_length=255, blank=True, null=True)
|
||||
|
||||
gallery = models.ManyToManyField('gallery.Image', through='location.CityGallery', blank=True)
|
||||
|
||||
mysql_id = models.IntegerField(blank=True, null=True, default=None)
|
||||
|
||||
objects = CityQuerySet.as_manager()
|
||||
|
||||
|
|
|
|||
1
apps/location/ruby_data.py
Normal file
1
apps/location/ruby_data.py
Normal file
File diff suppressed because one or more lines are too long
1
apps/location/ruby_unused_data.py
Normal file
1
apps/location/ruby_unused_data.py
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -1,9 +1,23 @@
|
|||
from transfer.serializers import location as location_serializers
|
||||
from transfer import models as transfer_models
|
||||
from location.models import Country, CityGallery, City
|
||||
from gallery.models import Image
|
||||
import csv
|
||||
import json
|
||||
from pprint import pprint
|
||||
|
||||
from django.conf import settings
|
||||
from django.db.transaction import atomic
|
||||
from requests import get
|
||||
from tqdm import tqdm
|
||||
|
||||
from account.models import Role
|
||||
from collection.models import Collection
|
||||
from gallery.models import Image
|
||||
from location.models import Country, Region, City, Address, CityGallery
|
||||
from main.models import AwardType
|
||||
from news.models import News
|
||||
from review.models import Review
|
||||
from tag.models import TagCategory, ChosenTagSettings
|
||||
from transfer import models as transfer_models
|
||||
from transfer.serializers import location as location_serializers
|
||||
from transfer.utils import clean_old_records, clean_old_country_records, clean_old_region_records
|
||||
|
||||
|
||||
def transfer_countries():
|
||||
|
|
@ -111,19 +125,12 @@ def transfer_cities():
|
|||
pprint(f"City serializer errors: {serialized_data.errors}")
|
||||
|
||||
|
||||
@atomic
|
||||
def transfer_addresses():
|
||||
queryset = transfer_models.Locations.objects.raw("""SELECT locations.id, locations.zip_code, locations.longitude,
|
||||
locations.latitude, locations.address, locations.city_id
|
||||
FROM locations WHERE
|
||||
locations.address != "" AND
|
||||
locations.address IS NOT NULL AND
|
||||
locations.city_id IS NOT NULL AND
|
||||
locations.city_id IN (SELECT cities.id
|
||||
FROM cities WHERE
|
||||
region_code IS NOT NULL AND
|
||||
region_code != "" AND
|
||||
country_code_2 IS NOT NULL AND
|
||||
country_code_2 != "")""")
|
||||
locations.city_id IS NOT NULL""")
|
||||
|
||||
queryset = [vars(query) for query in queryset]
|
||||
|
||||
|
|
@ -136,18 +143,18 @@ def transfer_addresses():
|
|||
|
||||
def transfer_wine_region():
|
||||
queryset = transfer_models.WineLocations.objects.filter(type='WineRegion')
|
||||
serialized_data = location_serializers.WineRegion(
|
||||
serialized_data = location_serializers.WineRegionSerializer(
|
||||
data=list(queryset.values()),
|
||||
many=True)
|
||||
if serialized_data.is_valid():
|
||||
serialized_data.save()
|
||||
else:
|
||||
pprint(f"WineStandardClassificationSerializer errors: {serialized_data.errors}")
|
||||
pprint(f"WineRegionSerializer errors: {serialized_data.errors}")
|
||||
|
||||
|
||||
def transfer_wine_sub_region():
|
||||
queryset = transfer_models.WineLocations.objects.filter(type='WineSubRegion')
|
||||
serialized_data = location_serializers.WineSubRegion(
|
||||
serialized_data = location_serializers.WineSubRegionSerializer(
|
||||
data=list(queryset.values()),
|
||||
many=True)
|
||||
if serialized_data.is_valid():
|
||||
|
|
@ -158,7 +165,7 @@ def transfer_wine_sub_region():
|
|||
|
||||
def transfer_wine_village():
|
||||
queryset = transfer_models.WineLocations.objects.filter(type='Village')
|
||||
serialized_data = location_serializers.WineVillage(
|
||||
serialized_data = location_serializers.WineVillageSerializer(
|
||||
data=list(queryset.values()),
|
||||
many=True)
|
||||
if serialized_data.is_valid():
|
||||
|
|
@ -179,6 +186,374 @@ def update_flags():
|
|||
query.save()
|
||||
|
||||
|
||||
def update_fake_country_flag():
|
||||
link_to_request = "https://s3.eu-central-1.amazonaws.com/gm-test.com/media/svg/country/10-31-2019/aa.svg"
|
||||
resp = get(link_to_request)
|
||||
if resp.status_code == 200:
|
||||
country = Country.objects.get(code="aa")
|
||||
country.svg_image = "/svg/country/10-31-2019/aa.svg"
|
||||
country.save()
|
||||
|
||||
|
||||
def migrate_city_map_situation(get_exists_cities=False):
|
||||
if get_exists_cities:
|
||||
ids = City.objects.values_list('mysql_id', flat=True)
|
||||
queryset = transfer_models.Cities.objects.filter(id__in=list(ids))
|
||||
queryset = list(queryset.values())
|
||||
else:
|
||||
queryset = transfer_models.Cities.objects.raw("""SELECT cities.id, cities.map1, cities.map2, cities.map_ref, cities.situation
|
||||
FROM cities WHERE
|
||||
region_code IS NOT NULL AND
|
||||
region_code != "" AND
|
||||
country_code_2 IS NOT NULL AND
|
||||
country_code_2 != ""
|
||||
""")
|
||||
|
||||
queryset = [vars(query) for query in queryset]
|
||||
|
||||
serialized_data = location_serializers.CityMapCorrectSerializer(data=queryset, many=True)
|
||||
if serialized_data.is_valid():
|
||||
serialized_data.save()
|
||||
else:
|
||||
pprint(f"City info serializer errors: {serialized_data.errors}")
|
||||
|
||||
|
||||
def migrate_city_photos():
|
||||
queryset = transfer_models.CityPhotos.objects.raw("""SELECT city_photos.id, city_photos.city_id, city_photos.attachment_file_name
|
||||
FROM city_photos WHERE
|
||||
city_photos.attachment_file_name IS NOT NULL AND
|
||||
city_id IN(
|
||||
SELECT cities.id
|
||||
FROM cities WHERE
|
||||
region_code IS NOT NULL AND
|
||||
region_code != "" AND
|
||||
country_code_2 IS NOT NULL AND
|
||||
country_code_2 != ""
|
||||
)
|
||||
""")
|
||||
|
||||
queryset = [vars(query) for query in queryset]
|
||||
|
||||
serialized_data = location_serializers.CityGallerySerializer(data=queryset, many=True)
|
||||
if serialized_data.is_valid():
|
||||
serialized_data.save()
|
||||
else:
|
||||
pprint(f"Address serializer errors: {serialized_data.errors}")
|
||||
|
||||
|
||||
# Update location models with ruby library
|
||||
# Utils functions defined before transfer functions
|
||||
def get_ruby_socket(params):
|
||||
url = 'http://172.21.0.1:5678' # docker host
|
||||
response = get(url, params=params)
|
||||
try:
|
||||
data = json.loads(response.text)
|
||||
except Exception as e:
|
||||
print(f"{response.text} error: {e}")
|
||||
return None
|
||||
return data
|
||||
|
||||
|
||||
# Get data from ruby and save it to file
|
||||
# Save errors from ruby to another file
|
||||
def get_ruby_data():
|
||||
cities = transfer_models.Cities.objects.all()
|
||||
ruby_data = {}
|
||||
error_file = open(f"{settings.PROJECT_ROOT}/ruby_error.txt", "w")
|
||||
|
||||
for mysql_city in cities:
|
||||
# try:
|
||||
# mysql_city = transfer_models.Cities.objects.get(id=city.old_id)
|
||||
# except transfer_models.Cities.DoesNotExist:
|
||||
# print(f"City with id {city.old_id} not found")
|
||||
# continue
|
||||
|
||||
ruby_params = {}
|
||||
|
||||
if mysql_city.country_code is not None:
|
||||
ruby_params['country_code'] = mysql_city.country_code
|
||||
|
||||
if mysql_city.country_code_2 is not None:
|
||||
ruby_params['country_code_2'] = mysql_city.country_code_2
|
||||
|
||||
if mysql_city.region_code is not None:
|
||||
ruby_params['region_code'] = mysql_city.region_code
|
||||
|
||||
if mysql_city.subregion_code is not None:
|
||||
ruby_params['subregion_code'] = mysql_city.subregion_code
|
||||
|
||||
ruby_response = get_ruby_socket(ruby_params)
|
||||
|
||||
if ruby_response is None:
|
||||
continue
|
||||
|
||||
if "country" not in ruby_response.keys():
|
||||
error_file.write(f"{json.dumps(ruby_params)}: {json.dumps(ruby_response)}\n")
|
||||
continue
|
||||
|
||||
if mysql_city.country_code_2 is None and mysql_city.country_code is None:
|
||||
error_file.write(f"{json.dumps(ruby_params)}: {json.dumps(ruby_response)}\n")
|
||||
continue
|
||||
|
||||
city_name = mysql_city.name.strip()
|
||||
ruby_data[mysql_city.id] = {
|
||||
"mysql_id": mysql_city.id,
|
||||
"name": city_name.strip(),
|
||||
"name_translated": {'en-GB': city_name.strip()},
|
||||
|
||||
"map1": mysql_city.map1,
|
||||
"map2": mysql_city.map2,
|
||||
"map_ref": mysql_city.map_ref,
|
||||
"situation": mysql_city.situation,
|
||||
|
||||
"is_island": True if mysql_city.is_island is not None and mysql_city.is_island > 0 else False,
|
||||
|
||||
"postal_code": mysql_city.zip_code.strip() if mysql_city.zip_code is not None else '',
|
||||
"code": ruby_response['country']['code'].lower().strip()
|
||||
|
||||
}
|
||||
|
||||
for ruby_data_key in ruby_response.keys():
|
||||
if "error" in ruby_response[ruby_data_key]:
|
||||
error_file.write(json.dumps(ruby_response) + '\n')
|
||||
else:
|
||||
ruby_data[mysql_city.id][ruby_data_key] = ruby_response[ruby_data_key]
|
||||
|
||||
error_file.close()
|
||||
|
||||
with open(f"{settings.PROJECT_ROOT}/apps/location/ruby_data.py", "w") as ruby_data_file:
|
||||
ruby_data_file.write(json.dumps(ruby_data))
|
||||
|
||||
return ruby_data
|
||||
|
||||
|
||||
def get_unused_data():
|
||||
ruby_data = {}
|
||||
error_file = open(f"{settings.PROJECT_ROOT}/ruby_unused_error.txt", "w")
|
||||
|
||||
countries = Country.objects.all()
|
||||
|
||||
for country in countries:
|
||||
|
||||
ruby_params = {}
|
||||
|
||||
ruby_response = get_ruby_socket({"country_regions": country.code})
|
||||
|
||||
if ruby_response is None:
|
||||
continue
|
||||
|
||||
if "error" in ruby_response.keys():
|
||||
error_file.write(f"{json.dumps(ruby_params)}: {json.dumps(ruby_response)}\n")
|
||||
continue
|
||||
|
||||
ruby_data[country.code] = ruby_response
|
||||
error_file.close()
|
||||
|
||||
with open(f"{settings.PROJECT_ROOT}/apps/location/ruby_unused_data.py", "w") as ruby_data_file:
|
||||
ruby_data_file.write(json.dumps(ruby_data))
|
||||
|
||||
|
||||
# Add correct objects of Country, Region and City with mysql_ids array (Country, Region) and mysql_id (City)
|
||||
def add_correct_location_models(ruby_data):
|
||||
for mysql_id, city_object in tqdm(ruby_data.items()):
|
||||
country_data = city_object["country"]
|
||||
try:
|
||||
country = Country.objects.get(code=country_data['code'], mysql_ids__isnull=False)
|
||||
country.mysql_ids.append(mysql_id)
|
||||
country.save()
|
||||
except Country.DoesNotExist:
|
||||
country_data['mysql_ids'] = [mysql_id]
|
||||
country = Country.objects.create(**country_data)
|
||||
|
||||
city_object['country'] = country
|
||||
|
||||
if "region" in city_object:
|
||||
region_data = city_object['region']
|
||||
region_data['country'] = country
|
||||
try:
|
||||
region = Region.objects.get(code=region_data['code'], mysql_ids__isnull=False)
|
||||
region.mysql_ids.append(mysql_id)
|
||||
region.save()
|
||||
except Region.DoesNotExist:
|
||||
region_data['mysql_ids'] = [mysql_id]
|
||||
region = Region.objects.create(**region_data)
|
||||
|
||||
if "subregion" in city_object:
|
||||
subregion_data = city_object.pop('subregion')
|
||||
subregion_data['country'] = country
|
||||
try:
|
||||
subregion = Region.objects.get(code=subregion_data['code'],
|
||||
mysql_ids__isnull=False)
|
||||
subregion.mysql_ids.append(mysql_id)
|
||||
subregion.save()
|
||||
except Region.DoesNotExist:
|
||||
subregion_data['parent_region'] = region
|
||||
subregion_data['mysql_ids'] = [mysql_id]
|
||||
subregion = Region.objects.create(**subregion_data)
|
||||
|
||||
city_object['region'] = subregion
|
||||
else:
|
||||
city_object['region'] = region
|
||||
|
||||
if "subregion" in city_object:
|
||||
del(city_object['subregion'])
|
||||
|
||||
try:
|
||||
City.objects.create(**city_object)
|
||||
except Exception as e:
|
||||
print(city_object)
|
||||
print(e)
|
||||
break
|
||||
|
||||
|
||||
def fix_location_address():
|
||||
addresses = Address.objects.filter(old_id__isnull=False)
|
||||
for address in addresses:
|
||||
mysql_location = transfer_models.Locations.objects.get(id=address.old_id)
|
||||
try:
|
||||
correct_city = City.objects.get(mysql_id=mysql_location.city_id)
|
||||
except City.DoesNotExist:
|
||||
continue
|
||||
|
||||
address.city = correct_city
|
||||
address.save()
|
||||
|
||||
|
||||
def fix_location_collection():
|
||||
collections = Collection.objects.filter(old_id__isnull=False)
|
||||
for collection in collections:
|
||||
try:
|
||||
mysql_collection = transfer_models.Collections.objects.\
|
||||
raw(f"""select
|
||||
s.country_code_2,
|
||||
c.id
|
||||
from collections as c
|
||||
join sites s on s.id = c.site_id where c.id={collection.old_id}""")[0]
|
||||
except:
|
||||
continue
|
||||
|
||||
try:
|
||||
correct_country = Country.objects.get(code=mysql_collection.country_code_2, mysql_ids__isnull=False)
|
||||
except Country.DoesNotExist:
|
||||
continue
|
||||
|
||||
collection.country = correct_country
|
||||
collection.save()
|
||||
|
||||
|
||||
def fix_award_type():
|
||||
award_types = AwardType.objects.filter(old_id__isnull=False)
|
||||
for award_type in award_types:
|
||||
mysql_award_type = transfer_models.AwardTypes.objects.\
|
||||
raw(f"""SELECT at.id, s.country_code_2 AS country_code
|
||||
FROM award_types as at
|
||||
JOIN sites s on s.id = at.site_id
|
||||
WHERE at.id={award_type.old_id}""")[0]
|
||||
|
||||
try:
|
||||
correct_country = Country.objects.get(code=mysql_award_type.country_code, mysql_ids__isnull=False)
|
||||
except Country.DoesNotExist:
|
||||
continue
|
||||
|
||||
award_type.country = correct_country
|
||||
award_type.save()
|
||||
|
||||
|
||||
def fix_role():
|
||||
roles_list = Role.objects.filter(country__isnull=False)
|
||||
for role in roles_list:
|
||||
try:
|
||||
correct_country = Country.objects.get(code=role.country.code, mysql_ids__isnull=False)
|
||||
except Country.DoesNotExist:
|
||||
continue
|
||||
|
||||
role.country = correct_country
|
||||
role.save()
|
||||
|
||||
|
||||
def fix_news():
|
||||
news = News.objects.filter(country__isnull=False)
|
||||
for news_item in news:
|
||||
try:
|
||||
correct_country = Country.objects.get(code=news_item.country.code, mysql_ids__isnull=False)
|
||||
except Country.DoesNotExist:
|
||||
continue
|
||||
|
||||
news.country = correct_country
|
||||
news_item.save()
|
||||
|
||||
|
||||
def fix_reviews():
|
||||
reviews = Review.objects.filter(country__isnull=False)
|
||||
for review in reviews:
|
||||
try:
|
||||
correct_country = Country.objects.get(code=review.country.code, mysql_ids__isnull=False)
|
||||
except Country.DoesNotExist:
|
||||
continue
|
||||
|
||||
review.country = correct_country
|
||||
review.save()
|
||||
|
||||
|
||||
def fix_tag_category():
|
||||
tags_categories = TagCategory.objects.filter(country__isnull=False)
|
||||
for tag_category in tags_categories:
|
||||
try:
|
||||
correct_country = Country.objects.get(code=tag_category.country.code, mysql_ids__isnull=False)
|
||||
except Country.DoesNotExist:
|
||||
continue
|
||||
|
||||
tag_category.country = correct_country
|
||||
tag_category.save()
|
||||
|
||||
|
||||
def fix_chosen_tag():
|
||||
chosen_tags = ChosenTagSettings.objects.filter(country__isnull=False)
|
||||
for chosen_tag in chosen_tags:
|
||||
try:
|
||||
correct_country = Country.objects.get(code=chosen_tag.country.code, mysql_ids__isnull=False)
|
||||
except Country.DoesNotExist:
|
||||
continue
|
||||
|
||||
chosen_tag.country = correct_country
|
||||
chosen_tag.save()
|
||||
|
||||
|
||||
def fix_location_models():
|
||||
|
||||
try:
|
||||
ruby_data_file = open(f"{settings.PROJECT_ROOT}/apps/location/ruby_data.py", "r")
|
||||
ruby_data = json.loads(ruby_data_file.read())
|
||||
except FileNotFoundError:
|
||||
print('create ruby data')
|
||||
ruby_data = get_ruby_data()
|
||||
|
||||
print('add_correct_location_models')
|
||||
add_correct_location_models(ruby_data)
|
||||
# print('fix_location_address')
|
||||
# fix_location_address()
|
||||
# print('fix_location_collection')
|
||||
# fix_location_collection()
|
||||
# print('fix_award_type')
|
||||
# fix_award_type()
|
||||
# print('fix_role')
|
||||
# fix_role()
|
||||
# print('fix_news')
|
||||
# fix_news()
|
||||
# print('fix_reviews')
|
||||
# fix_reviews()
|
||||
# print('fix_tag_category')
|
||||
# fix_tag_category()
|
||||
# print('fix_chosen_tag')
|
||||
# fix_chosen_tag()
|
||||
|
||||
|
||||
def remove_old_records():
|
||||
clean_old_records(City, {"mysql_id__isnull": True})
|
||||
clean_old_country_records(Country, {"mysql_ids__isnull": True})
|
||||
clean_old_region_records(Region, {"mysql_ids__isnull": True})
|
||||
|
||||
|
||||
def transfer_city_gallery():
|
||||
created_counter = 0
|
||||
cities_not_exists = {}
|
||||
|
|
@ -215,11 +590,218 @@ def transfer_city_gallery():
|
|||
f'Already added: {gallery_obj_exists_counter}')
|
||||
|
||||
|
||||
@atomic
|
||||
def add_fake_country():
|
||||
# add country
|
||||
country_data = {
|
||||
"name": '{"en-GB": "Antilles Guyane West Indies"}',
|
||||
"code": "aa",
|
||||
"svg_image": "svg/country/11-02-2019/658714.svg",
|
||||
"mysql_ids": []
|
||||
}
|
||||
|
||||
country, _ = Country.objects.get_or_create(**country_data)
|
||||
|
||||
# add regions and subregions
|
||||
regions_data = [
|
||||
{
|
||||
"name": "Guadeloupe",
|
||||
"code": "gp",
|
||||
"subregions": [
|
||||
{
|
||||
"name": "Basse Terre",
|
||||
"code": "bat",
|
||||
},
|
||||
{
|
||||
"name": "Grande Terre",
|
||||
"code": "grt",
|
||||
},
|
||||
{
|
||||
"name": "Autres les Îles de Guadeloupe",
|
||||
"code": "aug",
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Martinique",
|
||||
"code": "mq",
|
||||
"subregions": [
|
||||
{
|
||||
"name": "Nord",
|
||||
"code": "nor",
|
||||
},
|
||||
{
|
||||
"name": "Sud",
|
||||
"code": "sud",
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Guyane",
|
||||
"code": "gy",
|
||||
},
|
||||
{
|
||||
"name": "St Barthelemy",
|
||||
"code": "bl",
|
||||
},
|
||||
{
|
||||
"name": "St Martin",
|
||||
"code": "mf",
|
||||
},
|
||||
{
|
||||
"name": "Sainte-Lucie",
|
||||
"code": "lc",
|
||||
},
|
||||
]
|
||||
regions = {}
|
||||
|
||||
for region_data in regions_data:
|
||||
if "subregions" in region_data:
|
||||
subregions = region_data['subregions']
|
||||
del(region_data['subregions'])
|
||||
else:
|
||||
subregions = False
|
||||
|
||||
region_name = region_data['name']
|
||||
region_data['name'] = '{"en-GB": "' + region_name + '"}'
|
||||
region_data['country'] = country
|
||||
|
||||
region_data['mysql_ids'] = []
|
||||
|
||||
regions[region_name] = Region.objects.create(**region_data)
|
||||
|
||||
if subregions:
|
||||
for subregion_data in subregions:
|
||||
subregion_name = subregion_data['name']
|
||||
subregion_data['name'] = '{"en-GB": "' + subregion_name + '"}'
|
||||
subregion_data['country'] = country
|
||||
subregion_data['parent_region'] = regions[region_name]
|
||||
subregion_data['mysql_ids'] = []
|
||||
|
||||
regions[subregion_name] = Region.objects.create(**subregion_data)
|
||||
|
||||
# add cities
|
||||
file = open(f"{settings.PROJECT_ROOT}/apps/location/csv/aa_cities.csv")
|
||||
reader = csv.DictReader(file, delimiter=',')
|
||||
for city_data in reader:
|
||||
del(city_data[''])
|
||||
|
||||
city_data['mysql_id'] = city_data['old_id']
|
||||
del(city_data['old_id'])
|
||||
|
||||
city_data['postal_code'] = city_data['zip_code']
|
||||
del(city_data['zip_code'])
|
||||
|
||||
if city_data['postal_code'] == 'null' or city_data['postal_code'] == '':
|
||||
del(city_data['postal_code'])
|
||||
|
||||
city_data["country"] = country
|
||||
|
||||
if city_data['subregion'] != 'null':
|
||||
region = regions[city_data['subregion']]
|
||||
elif city_data['region'] != 'null':
|
||||
region = regions[city_data['region']]
|
||||
else:
|
||||
del(city_data['region'])
|
||||
region = None
|
||||
|
||||
del(city_data['subregion'])
|
||||
|
||||
city_data['region'] = region
|
||||
|
||||
city_data['name_translated'] = '{"en-GB": "' + city_data['name'] + '"}'
|
||||
|
||||
city_data['is_island'] = True if int(city_data['is_island']) > 0 else False
|
||||
|
||||
if region is not None:
|
||||
region.mysql_ids.append(city_data['mysql_id'])
|
||||
|
||||
country.mysql_ids.append(city_data['mysql_id'])
|
||||
|
||||
try:
|
||||
mysql_data = transfer_models.Cities.objects.\
|
||||
only("map1", "map2", "map_ref", "situation").get(id=city_data['mysql_id'])
|
||||
city_data['map1'] = mysql_data.map1
|
||||
city_data['map2'] = mysql_data.map2
|
||||
city_data['map_ref'] = mysql_data.map_ref
|
||||
city_data['situation'] = mysql_data.situation
|
||||
|
||||
except transfer_models.Cities.DoesNotExist:
|
||||
pass
|
||||
|
||||
City.objects.create(**city_data)
|
||||
|
||||
country.save()
|
||||
|
||||
for region_name, region in regions.items():
|
||||
if len(region.mysql_ids) > 0:
|
||||
region.save()
|
||||
|
||||
|
||||
@atomic
|
||||
def setup_clean_db():
|
||||
try:
|
||||
ruby_data_file = open(f"{settings.PROJECT_ROOT}/apps/location/ruby_data.py", "r")
|
||||
ruby_data = json.loads(ruby_data_file.read())
|
||||
except FileNotFoundError:
|
||||
ruby_data = get_ruby_data()
|
||||
|
||||
print('add_correct_location_models')
|
||||
add_correct_location_models(ruby_data)
|
||||
|
||||
print('add_fake_country')
|
||||
add_fake_country()
|
||||
|
||||
print('migrate_city_map_situation')
|
||||
migrate_city_map_situation(True)
|
||||
|
||||
print('update_flags')
|
||||
update_flags()
|
||||
|
||||
print('transfer_city_gallery')
|
||||
transfer_city_gallery()
|
||||
|
||||
|
||||
def set_unused_regions():
|
||||
ruby_data_file = open(f"{settings.PROJECT_ROOT}/apps/location/ruby_unused_data.py", "r")
|
||||
ruby_data = json.loads(ruby_data_file.read())
|
||||
|
||||
for country_code, regions in ruby_data.items():
|
||||
try:
|
||||
country = Country.objects.get(code=country_code)
|
||||
except Country.DoesNotExist:
|
||||
print(f"Country with code {country_code} does not exists")
|
||||
continue
|
||||
|
||||
for region_code, region_obj in regions.items():
|
||||
try:
|
||||
region = Region.objects.get(code=region_code, country=country)
|
||||
except Region.DoesNotExist:
|
||||
region = Region.objects.create(
|
||||
name=region_obj['name'],
|
||||
code=region_code,
|
||||
country=country
|
||||
)
|
||||
|
||||
if "subregions" in region_obj:
|
||||
for subregion_code, subregion in region_obj['subregions'].items():
|
||||
try:
|
||||
subregion = Region.objects.get(code=subregion, country=country)
|
||||
except Region.DoesNotExist:
|
||||
subregion = Region.objects.create(
|
||||
name=subregion,
|
||||
code=subregion_code,
|
||||
country=country,
|
||||
parent_region=region
|
||||
)
|
||||
|
||||
|
||||
|
||||
data_types = {
|
||||
"dictionaries": [
|
||||
transfer_countries,
|
||||
transfer_regions,
|
||||
transfer_cities,
|
||||
# transfer_countries,
|
||||
# transfer_regions,
|
||||
# transfer_cities,
|
||||
transfer_addresses,
|
||||
transfer_wine_region,
|
||||
transfer_wine_sub_region,
|
||||
|
|
@ -228,5 +810,27 @@ data_types = {
|
|||
"update_country_flag": [
|
||||
update_flags
|
||||
],
|
||||
"fill_city_gallery": [transfer_city_gallery]
|
||||
"update_city_info": [
|
||||
migrate_city_map_situation
|
||||
],
|
||||
"migrate_city_gallery": [
|
||||
migrate_city_photos
|
||||
],
|
||||
"fix_location": [
|
||||
add_fake_country,
|
||||
fix_location_models,
|
||||
],
|
||||
"remove_old_locations": [
|
||||
remove_old_records
|
||||
],
|
||||
"fill_city_gallery": [
|
||||
transfer_city_gallery
|
||||
],
|
||||
"add_fake_country": [
|
||||
add_fake_country,
|
||||
],
|
||||
|
||||
"setup_clean_db": [setup_clean_db],
|
||||
"set_unused_regions": [set_unused_regions],
|
||||
"update_fake_country_flag": [update_fake_country_flag]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,9 +55,9 @@ def update_product(sender, **kwargs):
|
|||
('product', 'productstandard'): 'standards',
|
||||
('product', 'producttype'): 'product_type',
|
||||
('tag', 'tag'): 'tags',
|
||||
('location', 'wineregion'): 'wine_region',
|
||||
('location', 'winesubregion'): 'wine_sub_region',
|
||||
('location', 'winevillage'): 'wine_village',
|
||||
# ('location', 'wineregion'): 'wine_region',
|
||||
# ('location', 'winesubregion'): 'wine_sub_region',
|
||||
# ('location', 'winevillage'): 'wine_village',
|
||||
('establishment', 'establishment'): 'establishment',
|
||||
}
|
||||
filter_name = app_label_model_name_to_filter.get((app_label, model_name))
|
||||
|
|
|
|||
0
apps/transfer/clear.error.txt
Normal file
0
apps/transfer/clear.error.txt
Normal file
|
|
@ -50,7 +50,15 @@ class Command(BaseCommand):
|
|||
'guide_element_advertorials',
|
||||
'guide_element_label_photo',
|
||||
'guide_complete',
|
||||
'update_city_info',
|
||||
'migrate_city_gallery',
|
||||
'fix_location',
|
||||
'remove_old_locations',
|
||||
'add_fake_country',
|
||||
'setup_clean_db',
|
||||
'languages', # №4 - перенос языков
|
||||
'set_unused_regions',
|
||||
'update_fake_country_flag'
|
||||
]
|
||||
|
||||
def handle(self, *args, **options):
|
||||
|
|
|
|||
|
|
@ -6,9 +6,12 @@ from location import models
|
|||
from transfer.mixins import TransferSerializerMixin
|
||||
from utils.methods import get_point_from_coordinates
|
||||
from transfer.models import Cepages
|
||||
from tag.models import TagCategory
|
||||
from django.utils.text import slugify
|
||||
|
||||
from django.contrib.gis.geos import Point
|
||||
from django.core.exceptions import MultipleObjectsReturned
|
||||
from gallery.models import Image
|
||||
|
||||
|
||||
class CountrySerializer(serializers.ModelSerializer):
|
||||
country_code_2 = serializers.CharField()
|
||||
|
|
@ -73,7 +76,6 @@ class RegionSerializer(serializers.ModelSerializer):
|
|||
return region
|
||||
|
||||
def set_code(self, data):
|
||||
print(data)
|
||||
if "subregion_code" in data and data["subregion_code"] is not None and data["subregion_code"].strip() != "":
|
||||
try:
|
||||
parent_region = models.Region.objects.filter(code=str(data['region_code'])).first()
|
||||
|
|
@ -187,7 +189,7 @@ class AddressSerializer(serializers.ModelSerializer):
|
|||
zip_code = serializers.CharField(allow_null=True, allow_blank=True)
|
||||
latitude = serializers.DecimalField(max_digits=10, decimal_places=6, allow_null=True)
|
||||
longitude = serializers.DecimalField(max_digits=10, decimal_places=6, allow_null=True)
|
||||
address = serializers.CharField()
|
||||
address = serializers.CharField(allow_null=True, allow_blank=True)
|
||||
|
||||
class Meta:
|
||||
model = models.Address
|
||||
|
|
@ -223,7 +225,7 @@ class AddressSerializer(serializers.ModelSerializer):
|
|||
|
||||
def set_city(self, data):
|
||||
try:
|
||||
city = models.City.objects.filter(old_id=data['city_id']).first()
|
||||
city = models.City.objects.filter(mysql_id=data['city_id']).first()
|
||||
except models.City.DoesNotExist as e:
|
||||
raise ValueError(f"City not found with {data}: {e}")
|
||||
|
||||
|
|
@ -232,25 +234,29 @@ class AddressSerializer(serializers.ModelSerializer):
|
|||
return data
|
||||
|
||||
def set_address(self, data):
|
||||
address_list = data.pop('address').split(' ')
|
||||
is_first_street = False
|
||||
data['street_name_1'] = []
|
||||
data['street_name_2'] = []
|
||||
while len(address_list) > 0:
|
||||
address_part = address_list.pop()
|
||||
try:
|
||||
address_part = int(address_part)
|
||||
data['number'] = address_part
|
||||
is_first_street = True
|
||||
except:
|
||||
if is_first_street:
|
||||
data['street_name_1'].append(address_part)
|
||||
else:
|
||||
data['street_name_2'].append(address_part)
|
||||
if "address" in data and data['address'] is not None and data['address'] != "":
|
||||
address_list = data.pop('address').split(' ')
|
||||
is_first_street = False
|
||||
data['street_name_1'] = []
|
||||
data['street_name_2'] = []
|
||||
while len(address_list) > 0:
|
||||
address_part = address_list.pop()
|
||||
try:
|
||||
address_part = int(address_part)
|
||||
data['number'] = address_part
|
||||
is_first_street = True
|
||||
except:
|
||||
if is_first_street:
|
||||
data['street_name_1'].append(address_part)
|
||||
else:
|
||||
data['street_name_2'].append(address_part)
|
||||
|
||||
data['street_name_1'] = " ".join(data['street_name_1'])
|
||||
data['street_name_2'] = " ".join(data['street_name_2'])
|
||||
if "number" not in data:
|
||||
data['street_name_1'] = " ".join(data['street_name_1'])
|
||||
data['street_name_2'] = " ".join(data['street_name_2'])
|
||||
if "number" not in data:
|
||||
data['number'] = 0
|
||||
else:
|
||||
del(data['address'])
|
||||
data['number'] = 0
|
||||
|
||||
return data
|
||||
|
|
@ -273,7 +279,7 @@ class AddressSerializer(serializers.ModelSerializer):
|
|||
return data
|
||||
|
||||
|
||||
class WineRegion(TransferSerializerMixin):
|
||||
class WineRegionSerializer(TransferSerializerMixin):
|
||||
|
||||
id = serializers.IntegerField()
|
||||
name = serializers.CharField()
|
||||
|
|
@ -301,7 +307,8 @@ class WineRegion(TransferSerializerMixin):
|
|||
return attrs
|
||||
|
||||
|
||||
class WineSubRegion(WineRegion):
|
||||
|
||||
class WineSubRegionSerializer(WineRegionSerializer):
|
||||
|
||||
id = serializers.IntegerField()
|
||||
name = serializers.CharField()
|
||||
|
|
@ -328,7 +335,7 @@ class WineSubRegion(WineRegion):
|
|||
return qs.first()
|
||||
|
||||
|
||||
class WineVillage(TransferSerializerMixin):
|
||||
class WineVillageSerializer(TransferSerializerMixin):
|
||||
|
||||
id = serializers.IntegerField()
|
||||
name = serializers.CharField()
|
||||
|
|
@ -349,6 +356,125 @@ class WineVillage(TransferSerializerMixin):
|
|||
return attrs
|
||||
|
||||
|
||||
class CityMapSerializer(serializers.ModelSerializer):
|
||||
id = serializers.IntegerField()
|
||||
map1 = serializers.CharField(allow_blank=True, allow_null=True)
|
||||
map2 = serializers.CharField(allow_blank=True, allow_null=True)
|
||||
map_ref = serializers.CharField(allow_blank=True, allow_null=True)
|
||||
situation = serializers.CharField(allow_blank=True, allow_null=True)
|
||||
|
||||
class Meta:
|
||||
model = models.City
|
||||
fields = (
|
||||
"id",
|
||||
"map1",
|
||||
"map2",
|
||||
"map_ref",
|
||||
"situation",
|
||||
)
|
||||
|
||||
def validate(self, data):
|
||||
data = self.set_old_id(data)
|
||||
data = self.set_city(data)
|
||||
data = self.set_null_fields(data)
|
||||
return data
|
||||
|
||||
def create(self, validated_data):
|
||||
city = validated_data.pop('city')
|
||||
city.update(
|
||||
map1=validated_data['map1'],
|
||||
map2=validated_data['map2'],
|
||||
map_ref=validated_data['map_ref'],
|
||||
situation=validated_data['situation']
|
||||
)
|
||||
|
||||
def set_old_id(self, data):
|
||||
data['old_id'] = data.pop("id")
|
||||
return data
|
||||
|
||||
def set_city(self, data):
|
||||
try:
|
||||
city = models.City.objects.get(old_id=data['old_id'])
|
||||
except models.City.DoesNotExist as e:
|
||||
raise ValueError(f"Cannot find city with id = {data['old_id']}: {e}")
|
||||
except MultipleObjectsReturned as e:
|
||||
raise ValueError(f"Find multiple cities with id = {data['old_id']}: {e}")
|
||||
|
||||
data['city'] = city
|
||||
return data
|
||||
|
||||
def set_null_fields(self, data):
|
||||
for field in ["map1", "map2", "map_ref", "situation"]:
|
||||
if field not in data or data[field] is None:
|
||||
data[field] = ""
|
||||
return data
|
||||
|
||||
|
||||
class CityMapCorrectSerializer(CityMapSerializer):
|
||||
def set_city(self, data):
|
||||
try:
|
||||
city = models.City.objects.get(mysql_id=data['old_id'])
|
||||
except models.City.DoesNotExist as e:
|
||||
raise ValueError(f"Cannot find city with id = {data['old_id']}: {e}")
|
||||
except MultipleObjectsReturned as e:
|
||||
raise ValueError(f"Find multiple cities with id = {data['old_id']}: {e}")
|
||||
|
||||
data['city'] = city
|
||||
return data
|
||||
|
||||
def create(self, validated_data):
|
||||
city = validated_data.pop('city')
|
||||
city.map1=validated_data['map1'],
|
||||
city.map2=validated_data['map2'],
|
||||
city.map_ref=validated_data['map_ref'],
|
||||
city.situation=validated_data['situation']
|
||||
city.save()
|
||||
|
||||
|
||||
class CityGallerySerializer(serializers.ModelSerializer):
|
||||
id = serializers.IntegerField()
|
||||
city_id = serializers.IntegerField()
|
||||
attachment_file_name = serializers.CharField()
|
||||
|
||||
class Meta:
|
||||
model = models.CityGallery
|
||||
fields = ("id", "city_id", "attachment_file_name")
|
||||
|
||||
def validate(self, data):
|
||||
data = self.set_old_id(data)
|
||||
data = self.set_gallery(data)
|
||||
data = self.set_city(data)
|
||||
return data
|
||||
|
||||
def create(self, validated_data):
|
||||
return models.CityGallery.objects.create(**validated_data)
|
||||
|
||||
def set_old_id(self, data):
|
||||
data['old_id'] = data.pop('id')
|
||||
return data
|
||||
|
||||
def set_gallery(self, data):
|
||||
link_prefix = "city_photos/00baf486523f62cdf131fa1b19c5df2bf21fc9f8/"
|
||||
try:
|
||||
data['image'] = Image.objects.create(
|
||||
image=f"{link_prefix}{data['attachment_file_name']}"
|
||||
)
|
||||
except Exception as e:
|
||||
raise ValueError(f"Cannot create image with {data}: {e}")
|
||||
del(data['attachment_file_name'])
|
||||
return data
|
||||
|
||||
def set_city(self, data):
|
||||
try:
|
||||
data['city'] = models.City.objects.get(old_id=data.pop('city_id'))
|
||||
except models.City.DoesNotExist as e:
|
||||
raise ValueError(f"Cannot get city with {data}: {e}")
|
||||
except MultipleObjectsReturned as e:
|
||||
raise ValueError(f"Multiple cities find with {data}: {e}")
|
||||
|
||||
return data
|
||||
|
||||
|
||||
class CepageWineRegionSerializer(TransferSerializerMixin):
|
||||
|
||||
CATEGORY_LABEL = 'Cepage'
|
||||
|
|
@ -358,7 +484,7 @@ class CepageWineRegionSerializer(TransferSerializerMixin):
|
|||
queryset=Cepages.objects.all())
|
||||
wine_region_id = serializers.IntegerField()
|
||||
|
||||
class Meta(WineRegion.Meta):
|
||||
class Meta(WineRegionSerializer.Meta):
|
||||
fields = [
|
||||
'cepage_id',
|
||||
'wine_region_id',
|
||||
|
|
|
|||
|
|
@ -1,10 +1,17 @@
|
|||
from os.path import exists
|
||||
from os import makedirs
|
||||
from importlib.machinery import SourceFileLoader
|
||||
from django.apps import apps
|
||||
from django.conf import settings
|
||||
from django.db.models import Count, Q
|
||||
from tqdm import tqdm
|
||||
import sys
|
||||
|
||||
import timeit
|
||||
|
||||
|
||||
def transfer_objects(data_type):
|
||||
|
||||
start_t = timeit.default_timer()
|
||||
for app in apps.get_app_configs():
|
||||
if exists(f"{app.path}/transfer_data.py"):
|
||||
card_module = SourceFileLoader("transfer", f"{app.path}/transfer_data.py").load_module()
|
||||
|
|
@ -17,4 +24,164 @@ def transfer_objects(data_type):
|
|||
if data_type == module_data_type:
|
||||
for transfer_func in transfer_funcs:
|
||||
print(f"========================== FUNCTION {transfer_func.__name__} ================================")
|
||||
transfer_func = file_log(transfer_func)
|
||||
transfer_func()
|
||||
end_t = timeit.default_timer()
|
||||
print(f"Transfer time: {end_t - start_t}")
|
||||
|
||||
|
||||
def clean_old_records(model, conditions):
|
||||
error_file = open(f"{settings.PROJECT_ROOT}/apps/transfer/clear.error.txt", "w")
|
||||
non_existed_correct_city_ids = []
|
||||
to_delete = []
|
||||
|
||||
try:
|
||||
old_records = model.objects.filter(**conditions)
|
||||
except Exception as e:
|
||||
error_file.write(f"Cannot find model objects: {e}")
|
||||
return
|
||||
|
||||
for old_record in tqdm(old_records):
|
||||
correct_record_qs = model.objects.exclude(id=old_record.id) \
|
||||
.exclude(**conditions) \
|
||||
.filter(name=old_record.name,
|
||||
mysql_id=old_record.old_id)
|
||||
if correct_record_qs.exists():
|
||||
correct_record = correct_record_qs.first()
|
||||
# check object dependencies
|
||||
for rel_instance in old_record._related_instances:
|
||||
field_name = [related_field.name
|
||||
for related_field in rel_instance._meta.fields
|
||||
if related_field.related_model == correct_record._meta.model][0]
|
||||
# rebinding correct dependency instances
|
||||
if getattr(rel_instance, field_name) != correct_record:
|
||||
setattr(rel_instance, field_name, correct_record)
|
||||
rel_instance.save()
|
||||
to_delete.append(old_record.id)
|
||||
else:
|
||||
non_existed_correct_city_ids.append(old_record.id)
|
||||
|
||||
if non_existed_correct_city_ids:
|
||||
print(f"Non existed correct city ids: {non_existed_correct_city_ids}")
|
||||
|
||||
# delete old records
|
||||
counter = len(to_delete)
|
||||
old_records.filter(id__in=to_delete).delete()
|
||||
print(f'Deleted {counter} objects.')
|
||||
|
||||
|
||||
def clean_old_country_records(model, conditions):
|
||||
error_file = open(f"{settings.PROJECT_ROOT}/apps/transfer/clear.error.txt", "w")
|
||||
non_existed_correct_country_ids = []
|
||||
to_delete = []
|
||||
|
||||
try:
|
||||
unique_codes = model.objects.values_list('code', flat=True) \
|
||||
.annotate(counter=Count('code')) \
|
||||
.filter(counter=1) \
|
||||
.values_list('code', flat=True)
|
||||
old_records = model.objects.exclude(code__in=unique_codes) \
|
||||
.filter(**conditions)
|
||||
except Exception as e:
|
||||
error_file.write(f"Cannot find model objects: {e}")
|
||||
return
|
||||
|
||||
for old_record in tqdm(old_records):
|
||||
correct_record_qs = model.objects.exclude(id=old_record.id) \
|
||||
.exclude(**conditions) \
|
||||
.filter(Q(code=old_record.code) |
|
||||
Q(mysql_ids__contains=[old_record.old_id, ]))
|
||||
if correct_record_qs.exists():
|
||||
correct_record = correct_record_qs.first()
|
||||
# check object dependencies
|
||||
for rel_instance in old_record._related_instances:
|
||||
if not hasattr(rel_instance, '_meta'):
|
||||
for related in rel_instance.all():
|
||||
field_name = [related_field.name
|
||||
for related_field in related._meta.fields
|
||||
if related_field.related_model == correct_record._meta.model][0]
|
||||
# rebinding correct dependency instances
|
||||
if getattr(rel_instance, field_name) != correct_record:
|
||||
setattr(rel_instance, field_name, correct_record)
|
||||
rel_instance.save()
|
||||
else:
|
||||
field_name = [related_field.name
|
||||
for related_field in rel_instance._meta.fields
|
||||
if related_field.related_model == correct_record._meta.model][0]
|
||||
# rebinding correct dependency instances
|
||||
if getattr(rel_instance, field_name) != correct_record:
|
||||
setattr(rel_instance, field_name, correct_record)
|
||||
rel_instance.save()
|
||||
to_delete.append(old_record.id)
|
||||
else:
|
||||
non_existed_correct_country_ids.append(old_record.id)
|
||||
|
||||
if non_existed_correct_country_ids:
|
||||
print(f"Non existed correct country ids: {non_existed_correct_country_ids}")
|
||||
|
||||
# delete old records
|
||||
counter = len(to_delete)
|
||||
old_records.filter(id__in=to_delete).delete()
|
||||
print(f'Deleted {counter} objects.')
|
||||
|
||||
|
||||
def clean_old_region_records(model, conditions):
|
||||
error_file = open(f"{settings.PROJECT_ROOT}/apps/transfer/clear.error.txt", "w")
|
||||
non_existed_correct_country_ids = []
|
||||
to_delete = []
|
||||
|
||||
try:
|
||||
old_records = model.objects.filter(**conditions)
|
||||
except Exception as e:
|
||||
error_file.write(f"Cannot find model objects: {e}")
|
||||
return
|
||||
|
||||
for old_record in tqdm(old_records):
|
||||
correct_record_qs = model.objects.exclude(id=old_record.id) \
|
||||
.exclude(**conditions) \
|
||||
.filter(code__iexact=old_record.code,
|
||||
mysql_ids__contains=[old_record.old_id, ])
|
||||
if correct_record_qs.exists():
|
||||
correct_record = correct_record_qs.first()
|
||||
# check object dependencies
|
||||
for rel_instance in old_record._related_instances:
|
||||
if not hasattr(rel_instance, '_meta'):
|
||||
for related in rel_instance.all():
|
||||
field_name = [related_field.name
|
||||
for related_field in related._meta.fields
|
||||
if related_field.related_model == correct_record._meta.model][0]
|
||||
# rebinding correct dependency instances
|
||||
if getattr(rel_instance, field_name) != correct_record:
|
||||
setattr(rel_instance, field_name, correct_record)
|
||||
rel_instance.save()
|
||||
else:
|
||||
field_name = [related_field.name
|
||||
for related_field in rel_instance._meta.fields
|
||||
if related_field.related_model == correct_record._meta.model][0]
|
||||
# rebinding correct dependency instances
|
||||
if getattr(rel_instance, field_name) != correct_record:
|
||||
setattr(rel_instance, field_name, correct_record)
|
||||
rel_instance.save()
|
||||
to_delete.append(old_record.id)
|
||||
else:
|
||||
non_existed_correct_country_ids.append(old_record.id)
|
||||
|
||||
if non_existed_correct_country_ids:
|
||||
print(f"Non existed correct region ids: {non_existed_correct_country_ids}")
|
||||
|
||||
# delete old records
|
||||
counter = len(to_delete)
|
||||
old_records.filter(id__in=to_delete).delete()
|
||||
print(f'Deleted {counter} objects.')
|
||||
|
||||
|
||||
def file_log(f):
|
||||
directory = f"{settings.PROJECT_ROOT}/apps/transfer/log"
|
||||
if not exists(directory):
|
||||
makedirs(directory)
|
||||
sys.stdout = open(f"{directory}/{f.__name__}.log","w+")
|
||||
|
||||
def res_func(*args, **kwargs):
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return res_func
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ def translate_field(self, field_name, toggle_field_name=None):
|
|||
return None
|
||||
return translate
|
||||
|
||||
|
||||
# todo: refactor this
|
||||
class IndexJSON:
|
||||
|
||||
|
|
|
|||
12
apps/utils/signals.py
Normal file
12
apps/utils/signals.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
from functools import wraps
|
||||
|
||||
|
||||
def skip_signal():
|
||||
def _skip_signal(signal_func):
|
||||
@wraps(signal_func)
|
||||
def _decorator(sender, instance, **kwargs):
|
||||
if hasattr(instance, 'skip_signal'):
|
||||
return None
|
||||
return signal_func(sender, instance=instance, **kwargs)
|
||||
return _decorator
|
||||
return _skip_signal
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
./manage.py transfer -a
|
||||
./manage.py transfer --setup_clean_db
|
||||
./manage.py transfer -d
|
||||
./manage.py transfer -e
|
||||
./manage.py transfer -n
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user