Merge branch 'develop' into feature/establishment_by_slug_by_country_fix
This commit is contained in:
commit
6f2a2e537d
28
README.md
28
README.md
|
|
@ -1,2 +1,30 @@
|
||||||
# gm-backend
|
# gm-backend
|
||||||
|
|
||||||
|
## Build
|
||||||
|
|
||||||
|
1. ``git clone ssh://git@gl.id-east.ru:222/gm/gm-backend.git``
|
||||||
|
1. ``cd ./gm-backend``
|
||||||
|
1. ``git checkout develop``
|
||||||
|
1. ``docker-compose build``
|
||||||
|
1. First start database: ``docker-compose up db``
|
||||||
|
1. ``docker-compose up -d``
|
||||||
|
### Migrate data
|
||||||
|
|
||||||
|
1.Connect to container with django ``docker exec -it gm-backend_gm_app_1 bash``
|
||||||
|
|
||||||
|
#### In docker container(django)
|
||||||
|
|
||||||
|
1. Migrate ``python manage.py migrate``
|
||||||
|
1. Create super-user ``python manage.py createsuperuser``
|
||||||
|
|
||||||
|
Backend is available at localhost:8000 or 0.0.0.0:8000
|
||||||
|
|
||||||
|
URL for admin http://0.0.0.0:8000/admin
|
||||||
|
URL for swagger http://0.0.0.0:8000/docs/
|
||||||
|
URL for redocs http://0.0.0.0:8000/redocs/
|
||||||
|
|
||||||
|
## Start and stop backend containers
|
||||||
|
|
||||||
|
Demonize start ``docker-compose up -d``
|
||||||
|
Stop ``docker-compose down``
|
||||||
|
Stop and remove volumes ``docker-compose down -v``
|
||||||
|
|
@ -12,7 +12,7 @@ class RoleAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
@admin.register(models.UserRole)
|
@admin.register(models.UserRole)
|
||||||
class UserRoleAdmin(admin.ModelAdmin):
|
class UserRoleAdmin(admin.ModelAdmin):
|
||||||
list_display = ['user', 'role']
|
list_display = ['user', 'role', 'establishment']
|
||||||
|
|
||||||
|
|
||||||
@admin.register(models.User)
|
@admin.register(models.User)
|
||||||
|
|
|
||||||
14
apps/account/migrations/0011_merge_20191014_0839.py
Normal file
14
apps/account/migrations/0011_merge_20191014_0839.py
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-14 08:39
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('account', '0009_auto_20191011_1123'),
|
||||||
|
('account', '0010_user_password_confirmed'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
]
|
||||||
14
apps/account/migrations/0012_merge_20191015_0708.py
Normal file
14
apps/account/migrations/0012_merge_20191015_0708.py
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-15 07:08
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('account', '0011_merge_20191014_0839'),
|
||||||
|
('account', '0011_merge_20191014_1258'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
]
|
||||||
30
apps/account/migrations/0013_auto_20191016_0810.py
Normal file
30
apps/account/migrations/0013_auto_20191016_0810.py
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-16 08:10
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('establishment', '0033_auto_20191003_0943_squashed_0034_auto_20191003_1036'),
|
||||||
|
('account', '0012_merge_20191015_0708'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='userrole',
|
||||||
|
name='establishment',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='establishment.Establishment', verbose_name='Establishment'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='role',
|
||||||
|
name='country',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='location.Country', verbose_name='Country'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='role',
|
||||||
|
name='role',
|
||||||
|
field=models.PositiveIntegerField(choices=[(1, 'Standard user'), (2, 'Comments moderator'), (3, 'Country admin'), (4, 'Content page manager'), (5, 'Establishment manager')], verbose_name='Role'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -13,6 +13,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||||
from rest_framework.authtoken.models import Token
|
from rest_framework.authtoken.models import Token
|
||||||
|
|
||||||
from authorization.models import Application
|
from authorization.models import Application
|
||||||
|
from establishment.models import Establishment
|
||||||
from location.models import Country
|
from location.models import Country
|
||||||
from utils.models import GMTokenGenerator
|
from utils.models import GMTokenGenerator
|
||||||
from utils.models import ImageMixin, ProjectBaseMixin, PlatformMixin
|
from utils.models import ImageMixin, ProjectBaseMixin, PlatformMixin
|
||||||
|
|
@ -23,14 +24,25 @@ class Role(ProjectBaseMixin):
|
||||||
"""Base Role model."""
|
"""Base Role model."""
|
||||||
STANDARD_USER = 1
|
STANDARD_USER = 1
|
||||||
COMMENTS_MODERATOR = 2
|
COMMENTS_MODERATOR = 2
|
||||||
|
COUNTRY_ADMIN = 3
|
||||||
|
CONTENT_PAGE_MANAGER = 4
|
||||||
|
ESTABLISHMENT_MANAGER = 5
|
||||||
|
REVIEWER_MANGER = 6
|
||||||
|
RESTAURANT_REVIEWER = 7
|
||||||
|
|
||||||
ROLE_CHOICES =(
|
ROLE_CHOICES = (
|
||||||
(STANDARD_USER, 'Standard user'),
|
(STANDARD_USER, 'Standard user'),
|
||||||
(COMMENTS_MODERATOR, 'Comments moderator'),
|
(COMMENTS_MODERATOR, 'Comments moderator'),
|
||||||
|
(COUNTRY_ADMIN, 'Country admin'),
|
||||||
|
(CONTENT_PAGE_MANAGER, 'Content page manager'),
|
||||||
|
(ESTABLISHMENT_MANAGER, 'Establishment manager'),
|
||||||
|
(REVIEWER_MANGER, 'Reviewer manager'),
|
||||||
|
(RESTAURANT_REVIEWER, 'Restaurant reviewer')
|
||||||
)
|
)
|
||||||
role = models.PositiveIntegerField(verbose_name=_('Role'), choices=ROLE_CHOICES,
|
role = models.PositiveIntegerField(verbose_name=_('Role'), choices=ROLE_CHOICES,
|
||||||
null=False, blank=False)
|
null=False, blank=False)
|
||||||
country = models.ForeignKey(Country, verbose_name=_('Country'), on_delete=models.CASCADE)
|
country = models.ForeignKey(Country, verbose_name=_('Country'),
|
||||||
|
null=True, blank=True, on_delete=models.SET_NULL)
|
||||||
# is_list = models.BooleanField(verbose_name=_('list'), default=True, null=False)
|
# is_list = models.BooleanField(verbose_name=_('list'), default=True, null=False)
|
||||||
# is_create = models.BooleanField(verbose_name=_('create'), default=False, null=False)
|
# is_create = models.BooleanField(verbose_name=_('create'), default=False, null=False)
|
||||||
# is_update = models.BooleanField(verbose_name=_('update'), default=False, null=False)
|
# is_update = models.BooleanField(verbose_name=_('update'), default=False, null=False)
|
||||||
|
|
@ -225,3 +237,5 @@ class UserRole(ProjectBaseMixin):
|
||||||
"""UserRole model."""
|
"""UserRole model."""
|
||||||
user = models.ForeignKey(User, verbose_name=_('User'), on_delete=models.CASCADE)
|
user = models.ForeignKey(User, verbose_name=_('User'), on_delete=models.CASCADE)
|
||||||
role = models.ForeignKey(Role, verbose_name=_('Role'), on_delete=models.SET_NULL, null=True)
|
role = models.ForeignKey(Role, verbose_name=_('Role'), on_delete=models.SET_NULL, null=True)
|
||||||
|
establishment = models.ForeignKey(Establishment, verbose_name=_('Establishment'),
|
||||||
|
on_delete=models.SET_NULL, null=True, blank=True)
|
||||||
|
|
@ -40,8 +40,7 @@ class PasswordResetConfirmView(JWTGenericViewMixin):
|
||||||
queryset = models.User.objects.active()
|
queryset = models.User.objects.active()
|
||||||
|
|
||||||
def get_object(self):
|
def get_object(self):
|
||||||
"""Override get_object method
|
"""Override get_object method"""
|
||||||
"""
|
|
||||||
queryset = self.filter_queryset(self.get_queryset())
|
queryset = self.filter_queryset(self.get_queryset())
|
||||||
uidb64 = self.kwargs.get('uidb64')
|
uidb64 = self.kwargs.get('uidb64')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
"""Authorization app celery tasks."""
|
"""Authorization app celery tasks."""
|
||||||
import logging
|
import logging
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
from celery import shared_task
|
from celery import shared_task
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from account import models as account_models
|
from account import models as account_models
|
||||||
from smtplib import SMTPException
|
|
||||||
|
|
||||||
logging.basicConfig(format='[%(levelname)s] %(message)s', level=logging.INFO)
|
logging.basicConfig(format='[%(levelname)s] %(message)s', level=logging.INFO)
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
|
||||||
23
apps/collection/migrations/0014_auto_20191022_1242.py
Normal file
23
apps/collection/migrations/0014_auto_20191022_1242.py
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-22 12:42
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('collection', '0013_collection_slug'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='collection',
|
||||||
|
name='end',
|
||||||
|
field=models.DateTimeField(blank=True, default=None, null=True, verbose_name='end'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='guide',
|
||||||
|
name='end',
|
||||||
|
field=models.DateTimeField(blank=True, default=None, null=True, verbose_name='end'),
|
||||||
|
),
|
||||||
|
]
|
||||||
44
apps/collection/migrations/0015_auto_20191023_0715.py
Normal file
44
apps/collection/migrations/0015_auto_20191023_0715.py
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-23 07:15
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
import utils.models
|
||||||
|
|
||||||
|
|
||||||
|
def fill_title_json_from_title(apps, schema_editor):
|
||||||
|
# We can't import the Person model directly as it may be a newer
|
||||||
|
# version than this migration expects. We use the historical version.
|
||||||
|
Collection = apps.get_model('collection', 'Collection')
|
||||||
|
for collection in Collection.objects.all():
|
||||||
|
collection.name_json = {'en-GB': collection.name}
|
||||||
|
collection.save()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('collection', '0014_auto_20191022_1242'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='collection',
|
||||||
|
name='name_json',
|
||||||
|
field=utils.models.TJSONField(blank=True, default=None, help_text='{"en-GB":"some text"}', null=True, verbose_name='name'),
|
||||||
|
),
|
||||||
|
migrations.RunPython(fill_title_json_from_title, migrations.RunPython.noop),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='collection',
|
||||||
|
name='name',
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='collection',
|
||||||
|
old_name='name_json',
|
||||||
|
new_name='name',
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='collection',
|
||||||
|
name='name',
|
||||||
|
field=utils.models.TJSONField(help_text='{"en-GB":"some text"}', verbose_name='name'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -1,13 +1,11 @@
|
||||||
from django.contrib.postgres.fields import JSONField
|
|
||||||
from django.contrib.contenttypes.fields import ContentType
|
from django.contrib.contenttypes.fields import ContentType
|
||||||
|
from django.contrib.postgres.fields import JSONField
|
||||||
from utils.models import TJSONField
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from utils.models import ProjectBaseMixin, URLImageMixin
|
from utils.models import ProjectBaseMixin, URLImageMixin
|
||||||
|
from utils.models import TJSONField
|
||||||
from utils.models import TranslatedFieldsMixin
|
from utils.models import TranslatedFieldsMixin
|
||||||
|
|
||||||
from utils.querysets import RelatedObjectsCountMixin
|
from utils.querysets import RelatedObjectsCountMixin
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -24,7 +22,8 @@ class CollectionNameMixin(models.Model):
|
||||||
class CollectionDateMixin(models.Model):
|
class CollectionDateMixin(models.Model):
|
||||||
"""CollectionDate mixin"""
|
"""CollectionDate mixin"""
|
||||||
start = models.DateTimeField(_('start'))
|
start = models.DateTimeField(_('start'))
|
||||||
end = models.DateTimeField(_('end'))
|
end = models.DateTimeField(blank=True, null=True, default=None,
|
||||||
|
verbose_name=_('end'))
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""Meta class"""
|
"""Meta class"""
|
||||||
|
|
@ -44,9 +43,11 @@ class CollectionQuerySet(RelatedObjectsCountMixin):
|
||||||
return self.filter(is_publish=True)
|
return self.filter(is_publish=True)
|
||||||
|
|
||||||
|
|
||||||
class Collection(ProjectBaseMixin, CollectionNameMixin, CollectionDateMixin,
|
class Collection(ProjectBaseMixin, CollectionDateMixin,
|
||||||
TranslatedFieldsMixin, URLImageMixin):
|
TranslatedFieldsMixin, URLImageMixin):
|
||||||
"""Collection model."""
|
"""Collection model."""
|
||||||
|
STR_FIELD_NAME = 'name'
|
||||||
|
|
||||||
ORDINARY = 0 # Ordinary collection
|
ORDINARY = 0 # Ordinary collection
|
||||||
POP = 1 # POP collection
|
POP = 1 # POP collection
|
||||||
|
|
||||||
|
|
@ -55,6 +56,8 @@ class Collection(ProjectBaseMixin, CollectionNameMixin, CollectionDateMixin,
|
||||||
(POP, _('Pop')),
|
(POP, _('Pop')),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
name = TJSONField(verbose_name=_('name'),
|
||||||
|
help_text='{"en-GB":"some text"}')
|
||||||
collection_type = models.PositiveSmallIntegerField(choices=COLLECTION_TYPES,
|
collection_type = models.PositiveSmallIntegerField(choices=COLLECTION_TYPES,
|
||||||
default=ORDINARY,
|
default=ORDINARY,
|
||||||
verbose_name=_('Collection type'))
|
verbose_name=_('Collection type'))
|
||||||
|
|
@ -80,10 +83,6 @@ class Collection(ProjectBaseMixin, CollectionNameMixin, CollectionDateMixin,
|
||||||
verbose_name = _('collection')
|
verbose_name = _('collection')
|
||||||
verbose_name_plural = _('collections')
|
verbose_name_plural = _('collections')
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
"""String method."""
|
|
||||||
return f'{self.name}'
|
|
||||||
|
|
||||||
|
|
||||||
class GuideQuerySet(models.QuerySet):
|
class GuideQuerySet(models.QuerySet):
|
||||||
"""QuerySet for Guide."""
|
"""QuerySet for Guide."""
|
||||||
|
|
|
||||||
|
|
@ -2,18 +2,19 @@ from rest_framework import serializers
|
||||||
|
|
||||||
from collection import models
|
from collection import models
|
||||||
from location import models as location_models
|
from location import models as location_models
|
||||||
|
from utils.serializers import TranslatedField
|
||||||
|
|
||||||
|
|
||||||
class CollectionBaseSerializer(serializers.ModelSerializer):
|
class CollectionBaseSerializer(serializers.ModelSerializer):
|
||||||
"""Collection base serializer"""
|
"""Collection base serializer"""
|
||||||
# RESPONSE
|
name_translated = TranslatedField()
|
||||||
description_translated = serializers.CharField(read_only=True, allow_null=True)
|
description_translated = TranslatedField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Collection
|
model = models.Collection
|
||||||
fields = [
|
fields = [
|
||||||
'id',
|
'id',
|
||||||
'name',
|
'name_translated',
|
||||||
'description_translated',
|
'description_translated',
|
||||||
'image_url',
|
'image_url',
|
||||||
'slug',
|
'slug',
|
||||||
|
|
@ -35,8 +36,7 @@ class CollectionSerializer(CollectionBaseSerializer):
|
||||||
queryset=location_models.Country.objects.all(),
|
queryset=location_models.Country.objects.all(),
|
||||||
write_only=True)
|
write_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta(CollectionBaseSerializer.Meta):
|
||||||
model = models.Collection
|
|
||||||
fields = CollectionBaseSerializer.Meta.fields + [
|
fields = CollectionBaseSerializer.Meta.fields + [
|
||||||
'start',
|
'start',
|
||||||
'end',
|
'end',
|
||||||
|
|
|
||||||
|
|
@ -40,12 +40,13 @@ class CollectionDetailTests(BaseTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
country = Country.objects.first()
|
# country = Country.objects.first()
|
||||||
if not country:
|
# if not country:
|
||||||
country = Country.objects.create(
|
country = Country.objects.create(
|
||||||
name=json.dumps({"en-GB": "Test country"}),
|
name=json.dumps({"en-GB": "Test country"}),
|
||||||
code="en"
|
code="en"
|
||||||
)
|
)
|
||||||
|
country.save()
|
||||||
|
|
||||||
self.collection = Collection.objects.create(
|
self.collection = Collection.objects.create(
|
||||||
name='Test collection',
|
name='Test collection',
|
||||||
|
|
@ -56,6 +57,8 @@ class CollectionDetailTests(BaseTestCase):
|
||||||
slug='test-collection-slug',
|
slug='test-collection-slug',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.collection.save()
|
||||||
|
|
||||||
def test_collection_detail_Read(self):
|
def test_collection_detail_Read(self):
|
||||||
response = self.client.get(f'/api/web/collections/{self.collection.slug}/establishments/?country_code=en',
|
response = self.client.get(f'/api/web/collections/{self.collection.slug}/establishments/?country_code=en',
|
||||||
format='json')
|
format='json')
|
||||||
|
|
@ -66,7 +69,7 @@ class CollectionGuideTests(CollectionDetailTests):
|
||||||
|
|
||||||
def test_guide_list_Read(self):
|
def test_guide_list_Read(self):
|
||||||
response = self.client.get('/api/web/collections/guides/', format='json')
|
response = self.client.get('/api/web/collections/guides/', format='json')
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
||||||
|
|
||||||
|
|
||||||
class CollectionGuideDetailTests(CollectionDetailTests):
|
class CollectionGuideDetailTests(CollectionDetailTests):
|
||||||
|
|
@ -78,6 +81,7 @@ class CollectionGuideDetailTests(CollectionDetailTests):
|
||||||
start=datetime.now(pytz.utc),
|
start=datetime.now(pytz.utc),
|
||||||
end=datetime.now(pytz.utc)
|
end=datetime.now(pytz.utc)
|
||||||
)
|
)
|
||||||
|
self.guide.save()
|
||||||
|
|
||||||
def test_guide_detail_Read(self):
|
def test_guide_detail_Read(self):
|
||||||
response = self.client.get(f'/api/web/collections/guides/{self.guide.id}/', format='json')
|
response = self.client.get(f'/api/web/collections/guides/{self.guide.id}/', format='json')
|
||||||
|
|
|
||||||
24
apps/comment/migrations/0003_auto_20191015_0704.py
Normal file
24
apps/comment/migrations/0003_auto_20191015_0704.py
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-15 07:04
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('location', '0012_data_migrate'),
|
||||||
|
('comment', '0002_comment_language'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='comment',
|
||||||
|
name='language',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='comment',
|
||||||
|
name='country',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='location.Country', verbose_name='Country'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -7,6 +7,8 @@ from account.models import User
|
||||||
from utils.models import ProjectBaseMixin
|
from utils.models import ProjectBaseMixin
|
||||||
from utils.querysets import ContentTypeQuerySetMixin
|
from utils.querysets import ContentTypeQuerySetMixin
|
||||||
from translation.models import Language
|
from translation.models import Language
|
||||||
|
from location.models import Country
|
||||||
|
|
||||||
|
|
||||||
class CommentQuerySet(ContentTypeQuerySetMixin):
|
class CommentQuerySet(ContentTypeQuerySetMixin):
|
||||||
"""QuerySets for Comment model."""
|
"""QuerySets for Comment model."""
|
||||||
|
|
@ -41,7 +43,8 @@ class Comment(ProjectBaseMixin):
|
||||||
content_object = generic.GenericForeignKey('content_type', 'object_id')
|
content_object = generic.GenericForeignKey('content_type', 'object_id')
|
||||||
|
|
||||||
objects = CommentQuerySet.as_manager()
|
objects = CommentQuerySet.as_manager()
|
||||||
language = models.ForeignKey(Language, verbose_name=_('Locale'), on_delete=models.SET_NULL, null=True)
|
country = models.ForeignKey(Country, verbose_name=_('Country'),
|
||||||
|
on_delete=models.SET_NULL, null=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""Meta class"""
|
"""Meta class"""
|
||||||
|
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
from rest_framework import permissions
|
|
||||||
from account.models import UserRole, Role, User
|
|
||||||
|
|
||||||
|
|
||||||
class IsCommentModerator(permissions.IsAuthenticatedOrReadOnly):
|
|
||||||
"""
|
|
||||||
Object-level permission to only allow owners of an object to edit it.
|
|
||||||
Assumes the model instance has an `owner` attribute.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def has_object_permission(self, request, view, obj):
|
|
||||||
# Read permissions are allowed to any request,
|
|
||||||
# so we'll always allow GET, HEAD or OPTIONS requests.
|
|
||||||
if request.method in permissions.SAFE_METHODS or \
|
|
||||||
obj.user == request.user or request.user.is_superuser:
|
|
||||||
return True
|
|
||||||
|
|
||||||
# Must have role
|
|
||||||
role = Role.objects.filter(role=Role.COMMENTS_MODERATOR,
|
|
||||||
country__languages__id=obj.language_id)\
|
|
||||||
.first() # 'Comments moderator'
|
|
||||||
|
|
||||||
is_access = UserRole.objects.filter(user=request.user, role=role).exists()
|
|
||||||
if obj.user != request.user and is_access:
|
|
||||||
return True
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
@ -1,32 +1,16 @@
|
||||||
from rest_framework.test import APITestCase
|
from utils.tests.tests_permissions import BasePermissionTests
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from authorization.tests.tests_authorization import get_tokens_for_user
|
from authorization.tests.tests_authorization import get_tokens_for_user
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from http.cookies import SimpleCookie
|
from http.cookies import SimpleCookie
|
||||||
from location.models import Country
|
|
||||||
from account.models import Role, User, UserRole
|
from account.models import Role, User, UserRole
|
||||||
from comment.models import Comment
|
from comment.models import Comment
|
||||||
from translation.models import Language
|
|
||||||
|
|
||||||
|
|
||||||
class CommentModeratorPermissionTests(APITestCase):
|
class CommentModeratorPermissionTests(BasePermissionTests):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
self.lang = Language.objects.create(
|
|
||||||
title='Russia',
|
|
||||||
locale='ru-RU'
|
|
||||||
)
|
|
||||||
self.lang.save()
|
|
||||||
|
|
||||||
self.country_ru = Country.objects.create(
|
|
||||||
name='{"ru-RU":"Russia"}',
|
|
||||||
code='23',
|
|
||||||
low_price=15,
|
|
||||||
high_price=150000,
|
|
||||||
)
|
|
||||||
self.country_ru.languages.add(self.lang)
|
|
||||||
self.country_ru.save()
|
|
||||||
|
|
||||||
self.role = Role.objects.create(
|
self.role = Role.objects.create(
|
||||||
role=2,
|
role=2,
|
||||||
|
|
@ -51,14 +35,11 @@ class CommentModeratorPermissionTests(APITestCase):
|
||||||
user=self.user_test["user"],
|
user=self.user_test["user"],
|
||||||
object_id= self.country_ru.pk,
|
object_id= self.country_ru.pk,
|
||||||
content_type_id=content_type.id,
|
content_type_id=content_type.id,
|
||||||
language=self.lang
|
country=self.country_ru
|
||||||
)
|
)
|
||||||
self.comment.save()
|
self.comment.save()
|
||||||
self.url = reverse('back:comment:comment-crud', kwargs={"id": self.comment.id})
|
self.url = reverse('back:comment:comment-crud', kwargs={"id": self.comment.id})
|
||||||
|
|
||||||
def test_get(self):
|
|
||||||
response = self.client.get(self.url, format='json')
|
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
||||||
|
|
||||||
def test_put_moderator(self):
|
def test_put_moderator(self):
|
||||||
tokens = User.create_jwt_tokens(self.moderator)
|
tokens = User.create_jwt_tokens(self.moderator)
|
||||||
|
|
@ -76,6 +57,10 @@ class CommentModeratorPermissionTests(APITestCase):
|
||||||
response = self.client.put(self.url, data=data, format='json')
|
response = self.client.put(self.url, data=data, format='json')
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
def test_get(self):
|
||||||
|
response = self.client.get(self.url, format='json')
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
|
||||||
|
|
||||||
def test_put_other_user(self):
|
def test_put_other_user(self):
|
||||||
other_user = User.objects.create_user(username='test',
|
other_user = User.objects.create_user(username='test',
|
||||||
email='test@mail.com',
|
email='test@mail.com',
|
||||||
|
|
@ -120,4 +105,3 @@ class CommentModeratorPermissionTests(APITestCase):
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
from rest_framework import generics, permissions
|
from rest_framework import generics, permissions
|
||||||
from comment.serializers import back as serializers
|
from comment.serializers import back as serializers
|
||||||
from comment import models
|
from comment import models
|
||||||
from comment.permissions import IsCommentModerator
|
from utils.permissions import IsCommentModerator, IsCountryAdmin
|
||||||
|
|
||||||
|
|
||||||
class CommentLstView(generics.ListCreateAPIView):
|
class CommentLstView(generics.ListCreateAPIView):
|
||||||
|
|
@ -15,5 +15,5 @@ class CommentRUDView(generics.RetrieveUpdateDestroyAPIView):
|
||||||
"""Comment RUD view."""
|
"""Comment RUD view."""
|
||||||
serializer_class = serializers.CommentBaseSerializer
|
serializer_class = serializers.CommentBaseSerializer
|
||||||
queryset = models.Comment.objects.all()
|
queryset = models.Comment.objects.all()
|
||||||
permission_classes = [IsCommentModerator]
|
permission_classes = [IsCountryAdmin|IsCommentModerator]
|
||||||
lookup_field = 'id'
|
lookup_field = 'id'
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from comment.models import Comment
|
from comment.models import Comment
|
||||||
from establishment import models
|
from establishment import models
|
||||||
from main.models import Award, MetaDataContent
|
from main.models import Award
|
||||||
from review import models as review_models
|
from review import models as review_models
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -24,11 +24,6 @@ class AwardInline(GenericTabularInline):
|
||||||
extra = 0
|
extra = 0
|
||||||
|
|
||||||
|
|
||||||
class MetaDataContentInline(GenericTabularInline):
|
|
||||||
model = MetaDataContent
|
|
||||||
extra = 0
|
|
||||||
|
|
||||||
|
|
||||||
class ContactPhoneInline(admin.TabularInline):
|
class ContactPhoneInline(admin.TabularInline):
|
||||||
"""Contact phone inline admin."""
|
"""Contact phone inline admin."""
|
||||||
model = models.ContactPhone
|
model = models.ContactPhone
|
||||||
|
|
@ -56,8 +51,7 @@ class EstablishmentAdmin(admin.ModelAdmin):
|
||||||
"""Establishment admin."""
|
"""Establishment admin."""
|
||||||
list_display = ['id', '__str__', 'image_tag', ]
|
list_display = ['id', '__str__', 'image_tag', ]
|
||||||
inlines = [
|
inlines = [
|
||||||
AwardInline, MetaDataContentInline,
|
AwardInline, ContactPhoneInline, ContactEmailInline,
|
||||||
ContactPhoneInline, ContactEmailInline,
|
|
||||||
ReviewInline, CommentInline]
|
ReviewInline, CommentInline]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
"""Establishment app filters."""
|
"""Establishment app filters."""
|
||||||
from django.core.validators import EMPTY_VALUES
|
from django.core.validators import EMPTY_VALUES
|
||||||
from django_filters import rest_framework as filters
|
from django_filters import rest_framework as filters
|
||||||
|
|
||||||
from establishment import models
|
from establishment import models
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -10,6 +11,10 @@ class EstablishmentFilter(filters.FilterSet):
|
||||||
tag_id = filters.NumberFilter(field_name='tags__metadata__id',)
|
tag_id = filters.NumberFilter(field_name='tags__metadata__id',)
|
||||||
award_id = filters.NumberFilter(field_name='awards__id',)
|
award_id = filters.NumberFilter(field_name='awards__id',)
|
||||||
search = filters.CharFilter(method='search_text')
|
search = filters.CharFilter(method='search_text')
|
||||||
|
type = filters.ChoiceFilter(choices=models.EstablishmentType.INDEX_NAME_TYPES,
|
||||||
|
method='by_type')
|
||||||
|
subtype = filters.ChoiceFilter(choices=models.EstablishmentSubType.INDEX_NAME_TYPES,
|
||||||
|
method='by_subtype')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""Meta class."""
|
"""Meta class."""
|
||||||
|
|
@ -19,6 +24,8 @@ class EstablishmentFilter(filters.FilterSet):
|
||||||
'tag_id',
|
'tag_id',
|
||||||
'award_id',
|
'award_id',
|
||||||
'search',
|
'search',
|
||||||
|
'type',
|
||||||
|
'subtype',
|
||||||
)
|
)
|
||||||
|
|
||||||
def search_text(self, queryset, name, value):
|
def search_text(self, queryset, name, value):
|
||||||
|
|
@ -26,3 +33,27 @@ class EstablishmentFilter(filters.FilterSet):
|
||||||
if value not in EMPTY_VALUES:
|
if value not in EMPTY_VALUES:
|
||||||
return queryset.search(value, locale=self.request.locale)
|
return queryset.search(value, locale=self.request.locale)
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
def by_type(self, queryset, name, value):
|
||||||
|
if value not in EMPTY_VALUES:
|
||||||
|
return queryset.by_type(value)
|
||||||
|
return queryset
|
||||||
|
|
||||||
|
def by_subtype(self, queryset, name, value):
|
||||||
|
if value not in EMPTY_VALUES:
|
||||||
|
return queryset.by_subtype(value)
|
||||||
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
|
class EstablishmentTypeTagFilter(filters.FilterSet):
|
||||||
|
"""Establishment tag filter set."""
|
||||||
|
|
||||||
|
type_id = filters.NumberFilter(field_name='id')
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
"""Meta class."""
|
||||||
|
|
||||||
|
model = models.EstablishmentType
|
||||||
|
fields = (
|
||||||
|
'type_id',
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-09 07:15
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('establishment', '0031_establishment_slug'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='EstablishmentTag',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'establishment tag',
|
||||||
|
'verbose_name_plural': 'establishment tags',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='EstablishmentTypeTagCategory',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('establishment_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tag_categories', to='establishment.EstablishmentType', verbose_name='establishment type')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'establishment type tag categories',
|
||||||
|
'verbose_name_plural': 'establishment type tag categories',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
30
apps/establishment/migrations/0033_auto_20191009_0715.py
Normal file
30
apps/establishment/migrations/0033_auto_20191009_0715.py
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-09 07:15
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('tag', '0001_initial'),
|
||||||
|
('establishment', '0032_establishmenttag_establishmenttypetagcategory'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='establishmenttypetagcategory',
|
||||||
|
name='tag_category',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='est_type_tag_categories', to='tag.TagCategory', verbose_name='tag category'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='establishmenttag',
|
||||||
|
name='establishment',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tags', to='establishment.Establishment', verbose_name='establishment'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='establishmenttag',
|
||||||
|
name='tag',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tags', to='tag.Tag', verbose_name='tag'),
|
||||||
|
),
|
||||||
|
]
|
||||||
14
apps/establishment/migrations/0034_merge_20191009_1457.py
Normal file
14
apps/establishment/migrations/0034_merge_20191009_1457.py
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-09 14:57
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('establishment', '0033_auto_20191009_0715'),
|
||||||
|
('establishment', '0033_auto_20191003_0943_squashed_0034_auto_20191003_1036'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
]
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-11 10:47
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('tag', '0002_auto_20191009_1408'),
|
||||||
|
('establishment', '0034_merge_20191009_1457'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='EstablishmentSubTypeTagCategory',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('establishment_subtype', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tag_categories', to='establishment.EstablishmentSubType', verbose_name='establishment subtype')),
|
||||||
|
('tag_category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='est_subtype_tag_categories', to='tag.TagCategory', verbose_name='tag category')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'establishment subtype tag categories',
|
||||||
|
'verbose_name_plural': 'establishment subtype tag categories',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
18
apps/establishment/migrations/0036_auto_20191011_1356.py
Normal file
18
apps/establishment/migrations/0036_auto_20191011_1356.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-11 13:56
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('establishment', '0035_establishmentsubtypetagcategory'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='establishment',
|
||||||
|
name='establishment_subtypes',
|
||||||
|
field=models.ManyToManyField(blank=True, related_name='subtype_establishment', to='establishment.EstablishmentSubType', verbose_name='subtype'),
|
||||||
|
),
|
||||||
|
]
|
||||||
54
apps/establishment/migrations/0037_auto_20191015_1404.py
Normal file
54
apps/establishment/migrations/0037_auto_20191015_1404.py
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-15 14:04
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('tag', '0002_auto_20191009_1408'),
|
||||||
|
('establishment', '0036_auto_20191011_1356'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='establishmenttag',
|
||||||
|
name='establishment',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='establishmenttag',
|
||||||
|
name='tag',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='establishmenttypetagcategory',
|
||||||
|
name='establishment_type',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='establishmenttypetagcategory',
|
||||||
|
name='tag_category',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='establishment',
|
||||||
|
name='tags',
|
||||||
|
field=models.ManyToManyField(related_name='establishments', to='tag.Tag', verbose_name='Tag'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='establishmentsubtype',
|
||||||
|
name='tag_categories',
|
||||||
|
field=models.ManyToManyField(related_name='establishment_subtypes', to='tag.TagCategory', verbose_name='Tag'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='establishmenttype',
|
||||||
|
name='tag_categories',
|
||||||
|
field=models.ManyToManyField(related_name='establishment_types', to='tag.TagCategory', verbose_name='Tag'),
|
||||||
|
),
|
||||||
|
migrations.DeleteModel(
|
||||||
|
name='EstablishmentSubTypeTagCategory',
|
||||||
|
),
|
||||||
|
migrations.DeleteModel(
|
||||||
|
name='EstablishmentTag',
|
||||||
|
),
|
||||||
|
migrations.DeleteModel(
|
||||||
|
name='EstablishmentTypeTagCategory',
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-16 11:33
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
def fill_establishment_type(apps, schema_editor):
|
||||||
|
# We can't import the Person model directly as it may be a newer
|
||||||
|
# version than this migration expects. We use the historical version.
|
||||||
|
EstablishmentType = apps.get_model('establishment', 'EstablishmentType')
|
||||||
|
for n, et in enumerate(EstablishmentType.objects.all()):
|
||||||
|
et.index_name = f'Type {n}'
|
||||||
|
et.save()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('establishment', '0037_auto_20191015_1404'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='establishmenttype',
|
||||||
|
name='index_name',
|
||||||
|
field=models.CharField(blank=True, db_index=True, max_length=50, null=True, unique=True, default=None, verbose_name='Index name'),
|
||||||
|
),
|
||||||
|
migrations.RunPython(fill_establishment_type, migrations.RunPython.noop),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='establishmenttype',
|
||||||
|
name='index_name',
|
||||||
|
field=models.CharField(choices=[('restaurant', 'Restaurant'), ('artisan', 'Artisan'),
|
||||||
|
('producer', 'Producer')], db_index=True, max_length=50,
|
||||||
|
unique=True, verbose_name='Index name'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-18 13:47
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
def fill_establishment_subtype(apps, schema_editor):
|
||||||
|
# We can't import the Person model directly as it may be a newer
|
||||||
|
# version than this migration expects. We use the historical version.
|
||||||
|
EstablishmentSubType = apps.get_model('establishment', 'EstablishmentSubType')
|
||||||
|
for n, et in enumerate(EstablishmentSubType.objects.all()):
|
||||||
|
et.index_name = f'Type {n}'
|
||||||
|
et.save()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('establishment', '0038_establishmenttype_index_name'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='establishmentsubtype',
|
||||||
|
name='index_name',
|
||||||
|
field=models.CharField(blank=True, db_index=True, max_length=50, null=True, unique=True, default=None, verbose_name='Index name'),
|
||||||
|
),
|
||||||
|
migrations.RunPython(fill_establishment_subtype, migrations.RunPython.noop),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='establishmentsubtype',
|
||||||
|
name='index_name',
|
||||||
|
field=models.CharField(choices=[('winery', 'Winery'), ], db_index=True, max_length=50,
|
||||||
|
unique=True, verbose_name='Index name'),
|
||||||
|
),
|
||||||
|
|
||||||
|
]
|
||||||
19
apps/establishment/migrations/0040_employee_tags.py
Normal file
19
apps/establishment/migrations/0040_employee_tags.py
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-22 13:59
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('tag', '0004_tag_priority'),
|
||||||
|
('establishment', '0039_establishmentsubtype_index_name'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='employee',
|
||||||
|
name='tags',
|
||||||
|
field=models.ManyToManyField(related_name='employees', to='tag.Tag', verbose_name='Tags'),
|
||||||
|
),
|
||||||
|
]
|
||||||
18
apps/establishment/migrations/0041_auto_20191023_0920.py
Normal file
18
apps/establishment/migrations/0041_auto_20191023_0920.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-23 09:20
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('establishment', '0040_employee_tags'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='establishment',
|
||||||
|
name='slug',
|
||||||
|
field=models.SlugField(max_length=255, null=True, unique=True, verbose_name='Establishment slug'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -15,7 +15,7 @@ from phonenumber_field.modelfields import PhoneNumberField
|
||||||
|
|
||||||
from collection.models import Collection
|
from collection.models import Collection
|
||||||
from location.models import Address
|
from location.models import Address
|
||||||
from main.models import Award, MetaDataContent
|
from main.models import Award
|
||||||
from review.models import Review
|
from review.models import Review
|
||||||
from utils.models import (ProjectBaseMixin, TJSONField, URLImageMixin,
|
from utils.models import (ProjectBaseMixin, TJSONField, URLImageMixin,
|
||||||
TranslatedFieldsMixin, BaseAttributes)
|
TranslatedFieldsMixin, BaseAttributes)
|
||||||
|
|
@ -27,9 +27,26 @@ class EstablishmentType(TranslatedFieldsMixin, ProjectBaseMixin):
|
||||||
|
|
||||||
STR_FIELD_NAME = 'name'
|
STR_FIELD_NAME = 'name'
|
||||||
|
|
||||||
|
# INDEX NAME CHOICES
|
||||||
|
RESTAURANT = 'restaurant'
|
||||||
|
ARTISAN = 'artisan'
|
||||||
|
PRODUCER = 'producer'
|
||||||
|
|
||||||
|
INDEX_NAME_TYPES = (
|
||||||
|
(RESTAURANT, _('Restaurant')),
|
||||||
|
(ARTISAN, _('Artisan')),
|
||||||
|
(PRODUCER, _('Producer')),
|
||||||
|
)
|
||||||
|
|
||||||
name = TJSONField(blank=True, null=True, default=None, verbose_name=_('Description'),
|
name = TJSONField(blank=True, null=True, default=None, verbose_name=_('Description'),
|
||||||
help_text='{"en-GB":"some text"}')
|
help_text='{"en-GB":"some text"}')
|
||||||
|
index_name = models.CharField(max_length=50, choices=INDEX_NAME_TYPES,
|
||||||
|
unique=True, db_index=True,
|
||||||
|
verbose_name=_('Index name'))
|
||||||
use_subtypes = models.BooleanField(_('Use subtypes'), default=True)
|
use_subtypes = models.BooleanField(_('Use subtypes'), default=True)
|
||||||
|
tag_categories = models.ManyToManyField('tag.TagCategory',
|
||||||
|
related_name='establishment_types',
|
||||||
|
verbose_name=_('Tag'))
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""Meta class."""
|
"""Meta class."""
|
||||||
|
|
@ -51,11 +68,24 @@ class EstablishmentSubTypeManager(models.Manager):
|
||||||
class EstablishmentSubType(ProjectBaseMixin, TranslatedFieldsMixin):
|
class EstablishmentSubType(ProjectBaseMixin, TranslatedFieldsMixin):
|
||||||
"""Establishment type model."""
|
"""Establishment type model."""
|
||||||
|
|
||||||
|
# INDEX NAME CHOICES
|
||||||
|
WINERY = 'winery'
|
||||||
|
|
||||||
|
INDEX_NAME_TYPES = (
|
||||||
|
(WINERY, _('Winery')),
|
||||||
|
)
|
||||||
|
|
||||||
name = TJSONField(blank=True, null=True, default=None, verbose_name=_('Description'),
|
name = TJSONField(blank=True, null=True, default=None, verbose_name=_('Description'),
|
||||||
help_text='{"en-GB":"some text"}')
|
help_text='{"en-GB":"some text"}')
|
||||||
|
index_name = models.CharField(max_length=50, choices=INDEX_NAME_TYPES,
|
||||||
|
unique=True, db_index=True,
|
||||||
|
verbose_name=_('Index name'))
|
||||||
establishment_type = models.ForeignKey(EstablishmentType,
|
establishment_type = models.ForeignKey(EstablishmentType,
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
verbose_name=_('Type'))
|
verbose_name=_('Type'))
|
||||||
|
tag_categories = models.ManyToManyField('tag.TagCategory',
|
||||||
|
related_name='establishment_subtypes',
|
||||||
|
verbose_name=_('Tag'))
|
||||||
|
|
||||||
objects = EstablishmentSubTypeManager()
|
objects = EstablishmentSubTypeManager()
|
||||||
|
|
||||||
|
|
@ -75,11 +105,8 @@ class EstablishmentQuerySet(models.QuerySet):
|
||||||
|
|
||||||
def with_base_related(self):
|
def with_base_related(self):
|
||||||
"""Return qs with related objects."""
|
"""Return qs with related objects."""
|
||||||
return self.select_related('address').prefetch_related(
|
return self.select_related('address', 'establishment_type').\
|
||||||
models.Prefetch('tags',
|
prefetch_related('tags')
|
||||||
MetaDataContent.objects.select_related(
|
|
||||||
'metadata__category'))
|
|
||||||
)
|
|
||||||
|
|
||||||
def with_extended_related(self):
|
def with_extended_related(self):
|
||||||
return self.select_related('establishment_type').\
|
return self.select_related('establishment_type').\
|
||||||
|
|
@ -87,6 +114,9 @@ class EstablishmentQuerySet(models.QuerySet):
|
||||||
'phones').\
|
'phones').\
|
||||||
prefetch_actual_employees()
|
prefetch_actual_employees()
|
||||||
|
|
||||||
|
def with_type_related(self):
|
||||||
|
return self.prefetch_related('establishment_subtypes')
|
||||||
|
|
||||||
def search(self, value, locale=None):
|
def search(self, value, locale=None):
|
||||||
"""Search text in JSON fields."""
|
"""Search text in JSON fields."""
|
||||||
if locale is not None:
|
if locale is not None:
|
||||||
|
|
@ -234,6 +264,31 @@ class EstablishmentQuerySet(models.QuerySet):
|
||||||
kwargs = {unit: radius}
|
kwargs = {unit: radius}
|
||||||
return self.filter(address__coordinates__distance_lte=(center, DistanceMeasure(**kwargs)))
|
return self.filter(address__coordinates__distance_lte=(center, DistanceMeasure(**kwargs)))
|
||||||
|
|
||||||
|
def artisans(self):
|
||||||
|
"""Return artisans."""
|
||||||
|
return self.filter(establishment_type__index_name=EstablishmentType.ARTISAN)
|
||||||
|
|
||||||
|
def producers(self):
|
||||||
|
"""Return producers."""
|
||||||
|
return self.filter(establishment_type__index_name=EstablishmentType.PRODUCER)
|
||||||
|
|
||||||
|
def restaurants(self):
|
||||||
|
"""Return restaurants."""
|
||||||
|
return self.filter(establishment_type__index_name=EstablishmentType.RESTAURANT)
|
||||||
|
|
||||||
|
def wineries(self):
|
||||||
|
"""Return wineries."""
|
||||||
|
return self.producers().filter(
|
||||||
|
establishment_subtypes__index_name=EstablishmentSubType.WINERY)
|
||||||
|
|
||||||
|
def by_type(self, value):
|
||||||
|
"""Return QuerySet with type by value."""
|
||||||
|
return self.filter(establishment_type__index_name=value)
|
||||||
|
|
||||||
|
def by_subtype(self, value):
|
||||||
|
"""Return QuerySet with subtype by value."""
|
||||||
|
return self.filter(establishment_subtypes__index_name=value)
|
||||||
|
|
||||||
|
|
||||||
class Establishment(ProjectBaseMixin, URLImageMixin, TranslatedFieldsMixin):
|
class Establishment(ProjectBaseMixin, URLImageMixin, TranslatedFieldsMixin):
|
||||||
"""Establishment model."""
|
"""Establishment model."""
|
||||||
|
|
@ -255,6 +310,7 @@ class Establishment(ProjectBaseMixin, URLImageMixin, TranslatedFieldsMixin):
|
||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
verbose_name=_('type'))
|
verbose_name=_('type'))
|
||||||
establishment_subtypes = models.ManyToManyField(EstablishmentSubType,
|
establishment_subtypes = models.ManyToManyField(EstablishmentSubType,
|
||||||
|
blank=True,
|
||||||
related_name='subtype_establishment',
|
related_name='subtype_establishment',
|
||||||
verbose_name=_('subtype'))
|
verbose_name=_('subtype'))
|
||||||
address = models.ForeignKey(Address, blank=True, null=True, default=None,
|
address = models.ForeignKey(Address, blank=True, null=True, default=None,
|
||||||
|
|
@ -293,11 +349,12 @@ class Establishment(ProjectBaseMixin, URLImageMixin, TranslatedFieldsMixin):
|
||||||
verbose_name=_('Collections'))
|
verbose_name=_('Collections'))
|
||||||
preview_image_url = models.URLField(verbose_name=_('Preview image URL path'),
|
preview_image_url = models.URLField(verbose_name=_('Preview image URL path'),
|
||||||
blank=True, null=True, default=None)
|
blank=True, null=True, default=None)
|
||||||
slug = models.SlugField(unique=True, max_length=50, null=True,
|
slug = models.SlugField(unique=True, max_length=255, null=True,
|
||||||
verbose_name=_('Establishment slug'), editable=True)
|
verbose_name=_('Establishment slug'))
|
||||||
|
|
||||||
awards = generic.GenericRelation(to='main.Award', related_query_name='establishment')
|
awards = generic.GenericRelation(to='main.Award', related_query_name='establishment')
|
||||||
tags = generic.GenericRelation(to='main.MetaDataContent')
|
tags = models.ManyToManyField('tag.Tag', related_name='establishments',
|
||||||
|
verbose_name=_('Tag'))
|
||||||
reviews = generic.GenericRelation(to='review.Review')
|
reviews = generic.GenericRelation(to='review.Review')
|
||||||
comments = generic.GenericRelation(to='comment.Comment')
|
comments = generic.GenericRelation(to='comment.Comment')
|
||||||
favorites = generic.GenericRelation(to='favorites.Favorites')
|
favorites = generic.GenericRelation(to='favorites.Favorites')
|
||||||
|
|
@ -359,11 +416,6 @@ class Establishment(ProjectBaseMixin, URLImageMixin, TranslatedFieldsMixin):
|
||||||
def best_price_carte(self):
|
def best_price_carte(self):
|
||||||
return 200
|
return 200
|
||||||
|
|
||||||
@property
|
|
||||||
def tags_indexing(self):
|
|
||||||
return [{'id': tag.metadata.id,
|
|
||||||
'label': tag.metadata.label} for tag in self.tags.all()]
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def last_published_review(self):
|
def last_published_review(self):
|
||||||
"""Return last published review"""
|
"""Return last published review"""
|
||||||
|
|
@ -382,6 +434,20 @@ class Establishment(ProjectBaseMixin, URLImageMixin, TranslatedFieldsMixin):
|
||||||
return Award.objects.filter(Q(establishment=self) | Q(employees__establishments=self)).latest(
|
return Award.objects.filter(Q(establishment=self) | Q(employees__establishments=self)).latest(
|
||||||
field_name='vintage_year')
|
field_name='vintage_year')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def country_id(self):
|
||||||
|
"""
|
||||||
|
Return Country id of establishment location
|
||||||
|
"""
|
||||||
|
return self.address.country_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def establishment_id(self):
|
||||||
|
"""
|
||||||
|
Return establishment id of establishment location
|
||||||
|
"""
|
||||||
|
return self.id
|
||||||
|
|
||||||
|
|
||||||
class Position(BaseAttributes, TranslatedFieldsMixin):
|
class Position(BaseAttributes, TranslatedFieldsMixin):
|
||||||
"""Position model."""
|
"""Position model."""
|
||||||
|
|
@ -437,7 +503,8 @@ class Employee(BaseAttributes):
|
||||||
establishments = models.ManyToManyField(Establishment, related_name='employees',
|
establishments = models.ManyToManyField(Establishment, related_name='employees',
|
||||||
through=EstablishmentEmployee,)
|
through=EstablishmentEmployee,)
|
||||||
awards = generic.GenericRelation(to='main.Award', related_query_name='employees')
|
awards = generic.GenericRelation(to='main.Award', related_query_name='employees')
|
||||||
tags = generic.GenericRelation(to='main.MetaDataContent')
|
tags = models.ManyToManyField('tag.Tag', related_name='employees',
|
||||||
|
verbose_name=_('Tags'))
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""Meta class."""
|
"""Meta class."""
|
||||||
|
|
@ -477,6 +544,7 @@ class ContactEmail(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'{self.email}'
|
return f'{self.email}'
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# class Wine(TranslatedFieldsMixin, models.Model):
|
# class Wine(TranslatedFieldsMixin, models.Model):
|
||||||
# """Wine model."""
|
# """Wine model."""
|
||||||
|
|
@ -515,6 +583,10 @@ class Plate(TranslatedFieldsMixin, models.Model):
|
||||||
menu = models.ForeignKey(
|
menu = models.ForeignKey(
|
||||||
'establishment.Menu', verbose_name=_('menu'), on_delete=models.CASCADE)
|
'establishment.Menu', verbose_name=_('menu'), on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def establishment_id(self):
|
||||||
|
return self.menu.establishment.id
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _('plate')
|
verbose_name = _('plate')
|
||||||
verbose_name_plural = _('plates')
|
verbose_name_plural = _('plates')
|
||||||
|
|
@ -550,3 +622,4 @@ class SocialNetwork(models.Model):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from establishment import models
|
from establishment import models
|
||||||
from establishment.serializers import (
|
from establishment.serializers import (
|
||||||
EstablishmentBaseSerializer, PlateSerializer, ContactEmailsSerializer,
|
EstablishmentBaseSerializer, PlateSerializer, ContactEmailsSerializer,
|
||||||
ContactPhonesSerializer, SocialNetworkRelatedSerializers,
|
ContactPhonesSerializer, SocialNetworkRelatedSerializers,
|
||||||
EstablishmentTypeSerializer)
|
EstablishmentTypeBaseSerializer)
|
||||||
|
|
||||||
from utils.decorators import with_base_attributes
|
|
||||||
|
|
||||||
from main.models import Currency
|
from main.models import Currency
|
||||||
|
from utils.decorators import with_base_attributes
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentListCreateSerializer(EstablishmentBaseSerializer):
|
class EstablishmentListCreateSerializer(EstablishmentBaseSerializer):
|
||||||
|
|
@ -21,7 +20,7 @@ class EstablishmentListCreateSerializer(EstablishmentBaseSerializer):
|
||||||
emails = ContactEmailsSerializer(read_only=True, many=True, )
|
emails = ContactEmailsSerializer(read_only=True, many=True, )
|
||||||
socials = SocialNetworkRelatedSerializers(read_only=True, many=True, )
|
socials = SocialNetworkRelatedSerializers(read_only=True, many=True, )
|
||||||
slug = serializers.SlugField(required=True, allow_blank=False, max_length=50)
|
slug = serializers.SlugField(required=True, allow_blank=False, max_length=50)
|
||||||
type = EstablishmentTypeSerializer(source='establishment_type', read_only=True)
|
type = EstablishmentTypeBaseSerializer(source='establishment_type', read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Establishment
|
model = models.Establishment
|
||||||
|
|
@ -55,7 +54,7 @@ class EstablishmentRUDSerializer(EstablishmentBaseSerializer):
|
||||||
phones = ContactPhonesSerializer(read_only=False, many=True, )
|
phones = ContactPhonesSerializer(read_only=False, many=True, )
|
||||||
emails = ContactEmailsSerializer(read_only=False, many=True, )
|
emails = ContactEmailsSerializer(read_only=False, many=True, )
|
||||||
socials = SocialNetworkRelatedSerializers(read_only=False, many=True, )
|
socials = SocialNetworkRelatedSerializers(read_only=False, many=True, )
|
||||||
type = EstablishmentTypeSerializer(source='establishment_type')
|
type = EstablishmentTypeBaseSerializer(source='establishment_type')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Establishment
|
model = models.Establishment
|
||||||
|
|
@ -141,4 +140,3 @@ class EmployeeBackSerializers(serializers.ModelSerializer):
|
||||||
'user',
|
'user',
|
||||||
'name'
|
'name'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,19 @@
|
||||||
"""Establishment serializers."""
|
"""Establishment serializers."""
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from comment import models as comment_models
|
from comment import models as comment_models
|
||||||
from comment.serializers import common as comment_serializers
|
from comment.serializers import common as comment_serializers
|
||||||
from establishment import models
|
from establishment import models
|
||||||
from favorites.models import Favorites
|
from favorites.models import Favorites
|
||||||
from location.serializers import AddressBaseSerializer
|
from location.serializers import AddressBaseSerializer
|
||||||
from main.models import MetaDataContent
|
from main.serializers import AwardSerializer, CurrencySerializer
|
||||||
from main.serializers import MetaDataContentSerializer, AwardSerializer, CurrencySerializer
|
|
||||||
from review import models as review_models
|
from review import models as review_models
|
||||||
|
from tag.serializers import TagBaseSerializer
|
||||||
from timetable.serialziers import ScheduleRUDSerializer
|
from timetable.serialziers import ScheduleRUDSerializer
|
||||||
from utils import exceptions as utils_exceptions
|
from utils import exceptions as utils_exceptions
|
||||||
from utils.serializers import TranslatedField, ProjectModelSerializer
|
from utils.serializers import ProjectModelSerializer
|
||||||
|
from utils.serializers import TranslatedField
|
||||||
|
|
||||||
|
|
||||||
class ContactPhonesSerializer(serializers.ModelSerializer):
|
class ContactPhonesSerializer(serializers.ModelSerializer):
|
||||||
|
|
@ -86,30 +88,6 @@ class MenuRUDSerializers(ProjectModelSerializer):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentTypeSerializer(serializers.ModelSerializer):
|
|
||||||
"""Serializer for EstablishmentType model."""
|
|
||||||
|
|
||||||
name_translated = serializers.CharField(allow_null=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
"""Meta class."""
|
|
||||||
|
|
||||||
model = models.EstablishmentType
|
|
||||||
fields = ('id', 'name_translated')
|
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentSubTypeSerializer(serializers.ModelSerializer):
|
|
||||||
"""Serializer for EstablishmentSubType models."""
|
|
||||||
|
|
||||||
name_translated = serializers.CharField(allow_null=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
"""Meta class."""
|
|
||||||
|
|
||||||
model = models.EstablishmentSubType
|
|
||||||
fields = ('id', 'name_translated')
|
|
||||||
|
|
||||||
|
|
||||||
class ReviewSerializer(serializers.ModelSerializer):
|
class ReviewSerializer(serializers.ModelSerializer):
|
||||||
"""Serializer for model Review."""
|
"""Serializer for model Review."""
|
||||||
text_translated = serializers.CharField(read_only=True)
|
text_translated = serializers.CharField(read_only=True)
|
||||||
|
|
@ -122,6 +100,45 @@ class ReviewSerializer(serializers.ModelSerializer):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class EstablishmentTypeBaseSerializer(serializers.ModelSerializer):
|
||||||
|
"""Serializer for EstablishmentType model."""
|
||||||
|
name_translated = TranslatedField()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
"""Meta class."""
|
||||||
|
model = models.EstablishmentType
|
||||||
|
fields = [
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
'name_translated',
|
||||||
|
'use_subtypes'
|
||||||
|
]
|
||||||
|
extra_kwargs = {
|
||||||
|
'name': {'write_only': True},
|
||||||
|
'use_subtypes': {'write_only': True},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class EstablishmentSubTypeBaseSerializer(serializers.ModelSerializer):
|
||||||
|
"""Serializer for EstablishmentSubType models."""
|
||||||
|
|
||||||
|
name_translated = TranslatedField()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
"""Meta class."""
|
||||||
|
model = models.EstablishmentSubType
|
||||||
|
fields = [
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
'name_translated',
|
||||||
|
'establishment_type'
|
||||||
|
]
|
||||||
|
extra_kwargs = {
|
||||||
|
'name': {'write_only': True},
|
||||||
|
'establishment_type': {'write_only': True}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentEmployeeSerializer(serializers.ModelSerializer):
|
class EstablishmentEmployeeSerializer(serializers.ModelSerializer):
|
||||||
"""Serializer for actual employees."""
|
"""Serializer for actual employees."""
|
||||||
|
|
||||||
|
|
@ -144,8 +161,8 @@ class EstablishmentBaseSerializer(ProjectModelSerializer):
|
||||||
preview_image = serializers.URLField(source='preview_image_url')
|
preview_image = serializers.URLField(source='preview_image_url')
|
||||||
slug = serializers.SlugField(allow_blank=False, required=True, max_length=50)
|
slug = serializers.SlugField(allow_blank=False, required=True, max_length=50)
|
||||||
address = AddressBaseSerializer()
|
address = AddressBaseSerializer()
|
||||||
tags = MetaDataContentSerializer(many=True)
|
|
||||||
in_favorites = serializers.BooleanField(allow_null=True)
|
in_favorites = serializers.BooleanField(allow_null=True)
|
||||||
|
tags = TagBaseSerializer(read_only=True, many=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""Meta class."""
|
"""Meta class."""
|
||||||
|
|
@ -171,8 +188,8 @@ class EstablishmentDetailSerializer(EstablishmentBaseSerializer):
|
||||||
|
|
||||||
description_translated = TranslatedField()
|
description_translated = TranslatedField()
|
||||||
image = serializers.URLField(source='image_url')
|
image = serializers.URLField(source='image_url')
|
||||||
type = EstablishmentTypeSerializer(source='establishment_type', read_only=True)
|
type = EstablishmentTypeBaseSerializer(source='establishment_type', read_only=True)
|
||||||
subtypes = EstablishmentSubTypeSerializer(many=True, source='establishment_subtypes')
|
subtypes = EstablishmentSubTypeBaseSerializer(many=True, source='establishment_subtypes')
|
||||||
awards = AwardSerializer(many=True)
|
awards = AwardSerializer(many=True)
|
||||||
schedule = ScheduleRUDSerializer(many=True, allow_null=True)
|
schedule = ScheduleRUDSerializer(many=True, allow_null=True)
|
||||||
phones = ContactPhonesSerializer(read_only=True, many=True)
|
phones = ContactPhonesSerializer(read_only=True, many=True)
|
||||||
|
|
@ -306,17 +323,3 @@ class EstablishmentFavoritesCreateSerializer(serializers.ModelSerializer):
|
||||||
})
|
})
|
||||||
return super().create(validated_data)
|
return super().create(validated_data)
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentTagListSerializer(serializers.ModelSerializer):
|
|
||||||
"""List establishment tag serializer."""
|
|
||||||
id = serializers.IntegerField(source='metadata.id')
|
|
||||||
label_translated = serializers.CharField(
|
|
||||||
source='metadata.label_translated', read_only=True, allow_null=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
"""Meta class."""
|
|
||||||
model = MetaDataContent
|
|
||||||
fields = [
|
|
||||||
'id',
|
|
||||||
'label_translated',
|
|
||||||
]
|
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,11 @@ from main.models import Currency
|
||||||
from establishment.models import Establishment, EstablishmentType, Menu
|
from establishment.models import Establishment, EstablishmentType, Menu
|
||||||
# Create your tests here.
|
# Create your tests here.
|
||||||
from translation.models import Language
|
from translation.models import Language
|
||||||
|
from account.models import Role, UserRole
|
||||||
|
from location.models import Country, Address, City, Region
|
||||||
|
|
||||||
|
|
||||||
class BaseTestCase(APITestCase):
|
class BaseTestCase(APITestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.username = 'sedragurda'
|
self.username = 'sedragurda'
|
||||||
self.password = 'sedragurdaredips19'
|
self.password = 'sedragurdaredips19'
|
||||||
|
|
@ -27,11 +28,44 @@ class BaseTestCase(APITestCase):
|
||||||
self.establishment_type = EstablishmentType.objects.create(name="Test establishment type")
|
self.establishment_type = EstablishmentType.objects.create(name="Test establishment type")
|
||||||
|
|
||||||
# Create lang object
|
# Create lang object
|
||||||
Language.objects.create(
|
self.lang = Language.objects.get(
|
||||||
title='English',
|
title='Russia',
|
||||||
locale='en-GB'
|
locale='ru-RU'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.country_ru = Country.objects.get(
|
||||||
|
name={"en-GB": "Russian"}
|
||||||
|
)
|
||||||
|
|
||||||
|
self.region = Region.objects.create(name='Moscow area', code='01',
|
||||||
|
country=self.country_ru)
|
||||||
|
self.region.save()
|
||||||
|
|
||||||
|
self.city = City.objects.create(name='Mosocow', code='01',
|
||||||
|
region=self.region, country=self.country_ru)
|
||||||
|
self.city.save()
|
||||||
|
|
||||||
|
self.address = Address.objects.create(city=self.city, street_name_1='Krasnaya',
|
||||||
|
number=2, postal_code='010100')
|
||||||
|
self.address.save()
|
||||||
|
|
||||||
|
self.role = Role.objects.create(role=Role.ESTABLISHMENT_MANAGER)
|
||||||
|
self.role.save()
|
||||||
|
|
||||||
|
self.establishment = Establishment.objects.create(
|
||||||
|
name="Test establishment",
|
||||||
|
establishment_type_id=self.establishment_type.id,
|
||||||
|
is_publish=True,
|
||||||
|
slug="test",
|
||||||
|
address=self.address
|
||||||
|
)
|
||||||
|
|
||||||
|
self.establishment.save()
|
||||||
|
|
||||||
|
self.user_role = UserRole.objects.create(user=self.user, role=self.role,
|
||||||
|
establishment=self.establishment)
|
||||||
|
self.user_role.save()
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentBTests(BaseTestCase):
|
class EstablishmentBTests(BaseTestCase):
|
||||||
def test_establishment_CRUD(self):
|
def test_establishment_CRUD(self):
|
||||||
|
|
@ -43,25 +77,25 @@ class EstablishmentBTests(BaseTestCase):
|
||||||
'name': 'Test establishment',
|
'name': 'Test establishment',
|
||||||
'type_id': self.establishment_type.id,
|
'type_id': self.establishment_type.id,
|
||||||
'is_publish': True,
|
'is_publish': True,
|
||||||
'slug': 'test-establishment-slug',
|
'slug': 'test-establishment-slug'
|
||||||
}
|
}
|
||||||
|
|
||||||
response = self.client.post('/api/back/establishments/', data=data, format='json')
|
response = self.client.post('/api/back/establishments/', data=data, format='json')
|
||||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||||
|
|
||||||
establishment = response.json()
|
response = self.client.get(f'/api/back/establishments/{self.establishment.id}/', format='json')
|
||||||
|
|
||||||
response = self.client.get(f'/api/back/establishments/{establishment["id"]}/', format='json')
|
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
update_data = {
|
update_data = {
|
||||||
'name': 'Test new establishment'
|
'name': 'Test new establishment'
|
||||||
}
|
}
|
||||||
|
|
||||||
response = self.client.patch(f'/api/back/establishments/{establishment["id"]}/', data=update_data)
|
response = self.client.patch(f'/api/back/establishments/{self.establishment.id}/',
|
||||||
|
data=update_data)
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
response = self.client.delete(f'/api/back/establishments/{establishment["id"]}/', format='json')
|
response = self.client.delete(f'/api/back/establishments/{self.establishment.id}/',
|
||||||
|
format='json')
|
||||||
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
|
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -96,39 +130,45 @@ class EmployeeTests(BaseTestCase):
|
||||||
class ChildTestCase(BaseTestCase):
|
class ChildTestCase(BaseTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.establishment = Establishment.objects.create(
|
|
||||||
name="Test establishment",
|
|
||||||
establishment_type_id=self.establishment_type.id,
|
|
||||||
is_publish=True,
|
|
||||||
slug="test"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# Test childs
|
# Test childs
|
||||||
class EmailTests(ChildTestCase):
|
class EmailTests(ChildTestCase):
|
||||||
def test_email_CRUD(self):
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
|
||||||
|
def test_get(self):
|
||||||
response = self.client.get('/api/back/establishments/emails/', format='json')
|
response = self.client.get('/api/back/establishments/emails/', format='json')
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
def test_post(self):
|
||||||
data = {
|
data = {
|
||||||
'email': "test@test.com",
|
'email': "test@test.com",
|
||||||
'establishment': self.establishment.id
|
'establishment': self.establishment.id
|
||||||
}
|
}
|
||||||
|
|
||||||
response = self.client.post('/api/back/establishments/emails/', data=data)
|
response = self.client.post('/api/back/establishments/emails/', data=data)
|
||||||
|
self.id_email = response.json()['id']
|
||||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||||
|
|
||||||
response = self.client.get('/api/back/establishments/emails/1/', format='json')
|
def test_get_by_pk(self):
|
||||||
|
self.test_post()
|
||||||
|
response = self.client.get(f'/api/back/establishments/emails/{self.id_email}/', format='json')
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
def test_patch(self):
|
||||||
|
self.test_post()
|
||||||
|
|
||||||
update_data = {
|
update_data = {
|
||||||
'email': 'testnew@test.com'
|
'email': 'testnew@test.com'
|
||||||
}
|
}
|
||||||
|
|
||||||
response = self.client.patch('/api/back/establishments/emails/1/', data=update_data)
|
response = self.client.patch(f'/api/back/establishments/emails/{self.id_email}/',
|
||||||
|
data=update_data)
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
response = self.client.delete('/api/back/establishments/emails/1/')
|
def test_email_CRUD(self):
|
||||||
|
self.test_post()
|
||||||
|
response = self.client.delete(f'/api/back/establishments/emails/{self.id_email}/')
|
||||||
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
|
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -285,7 +325,7 @@ class EstablishmentWebTagTests(BaseTestCase):
|
||||||
|
|
||||||
def test_tag_Read(self):
|
def test_tag_Read(self):
|
||||||
response = self.client.get('/api/web/establishments/tags/', format='json')
|
response = self.client.get('/api/web/establishments/tags/', format='json')
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentWebSlugTests(ChildTestCase):
|
class EstablishmentWebSlugTests(ChildTestCase):
|
||||||
|
|
|
||||||
|
|
@ -26,4 +26,8 @@ urlpatterns = [
|
||||||
path('emails/<int:pk>/', views.EmailRUDView.as_view(), name='emails-rud'),
|
path('emails/<int:pk>/', views.EmailRUDView.as_view(), name='emails-rud'),
|
||||||
path('employees/', views.EmployeeListCreateView.as_view(), name='employees'),
|
path('employees/', views.EmployeeListCreateView.as_view(), name='employees'),
|
||||||
path('employees/<int:pk>/', views.EmployeeRUDView.as_view(), name='employees-rud'),
|
path('employees/<int:pk>/', views.EmployeeRUDView.as_view(), name='employees-rud'),
|
||||||
|
path('types/', views.EstablishmentTypeListCreateView.as_view(), name='type-list'),
|
||||||
|
path('types/<int:pk>/', views.EstablishmentTypeRUDView.as_view(), name='type-rud'),
|
||||||
|
path('subtypes/', views.EstablishmentSubtypeListCreateView.as_view(), name='subtype-list'),
|
||||||
|
path('subtypes/<int:pk>/', views.EstablishmentSubtypeRUDView.as_view(), name='subtype-rud'),
|
||||||
]
|
]
|
||||||
|
|
@ -7,9 +7,9 @@ app_name = 'establishment'
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.EstablishmentListView.as_view(), name='list'),
|
path('', views.EstablishmentListView.as_view(), name='list'),
|
||||||
path('tags/', views.EstablishmentTagListView.as_view(), name='tags'),
|
|
||||||
path('recent-reviews/', views.EstablishmentRecentReviewListView.as_view(),
|
path('recent-reviews/', views.EstablishmentRecentReviewListView.as_view(),
|
||||||
name='recent-reviews'),
|
name='recent-reviews'),
|
||||||
|
# path('wineries/', views.WineriesListView.as_view(), name='wineries-list'),
|
||||||
path('slug/<slug:slug>/', views.EstablishmentRetrieveView.as_view(), name='detail'),
|
path('slug/<slug:slug>/', views.EstablishmentRetrieveView.as_view(), name='detail'),
|
||||||
path('slug/<slug:slug>/similar/', views.EstablishmentSimilarListView.as_view(), name='similar'),
|
path('slug/<slug:slug>/similar/', views.EstablishmentSimilarListView.as_view(), name='similar'),
|
||||||
path('slug/<slug:slug>/comments/', views.EstablishmentCommentListView.as_view(), name='list-comments'),
|
path('slug/<slug:slug>/comments/', views.EstablishmentCommentListView.as_view(), name='list-comments'),
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
"""Establishment app views."""
|
"""Establishment app views."""
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
from rest_framework import generics
|
from rest_framework import generics
|
||||||
|
|
||||||
from establishment import models
|
from utils.permissions import IsCountryAdmin, IsEstablishmentManager
|
||||||
from establishment import serializers
|
from establishment import models, serializers
|
||||||
|
from timetable.serialziers import ScheduleRUDSerializer, ScheduleCreateSerializer
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentMixinViews:
|
class EstablishmentMixinViews:
|
||||||
|
|
@ -18,23 +19,55 @@ class EstablishmentListCreateView(EstablishmentMixinViews, generics.ListCreateAP
|
||||||
"""Establishment list/create view."""
|
"""Establishment list/create view."""
|
||||||
queryset = models.Establishment.objects.all()
|
queryset = models.Establishment.objects.all()
|
||||||
serializer_class = serializers.EstablishmentListCreateSerializer
|
serializer_class = serializers.EstablishmentListCreateSerializer
|
||||||
|
permission_classes = [IsCountryAdmin|IsEstablishmentManager]
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentRUDView(generics.RetrieveUpdateDestroyAPIView):
|
class EstablishmentRUDView(generics.RetrieveUpdateDestroyAPIView):
|
||||||
queryset = models.Establishment.objects.all()
|
queryset = models.Establishment.objects.all()
|
||||||
serializer_class = serializers.EstablishmentRUDSerializer
|
serializer_class = serializers.EstablishmentRUDSerializer
|
||||||
|
permission_classes = [IsCountryAdmin|IsEstablishmentManager]
|
||||||
|
|
||||||
|
|
||||||
|
class EstablishmentScheduleRUDView(generics.RetrieveUpdateDestroyAPIView):
|
||||||
|
"""Establishment schedule RUD view"""
|
||||||
|
serializer_class = ScheduleRUDSerializer
|
||||||
|
|
||||||
|
def get_object(self):
|
||||||
|
"""
|
||||||
|
Returns the object the view is displaying.
|
||||||
|
"""
|
||||||
|
establishment_pk = self.kwargs['pk']
|
||||||
|
schedule_id = self.kwargs['schedule_id']
|
||||||
|
|
||||||
|
establishment = get_object_or_404(klass=models.Establishment.objects.all(),
|
||||||
|
pk=establishment_pk)
|
||||||
|
schedule = get_object_or_404(klass=establishment.schedule,
|
||||||
|
id=schedule_id)
|
||||||
|
|
||||||
|
# May raise a permission denied
|
||||||
|
self.check_object_permissions(self.request, establishment)
|
||||||
|
self.check_object_permissions(self.request, schedule)
|
||||||
|
|
||||||
|
return schedule
|
||||||
|
|
||||||
|
|
||||||
|
class EstablishmentScheduleCreateView(generics.CreateAPIView):
|
||||||
|
"""Establishment schedule Create view"""
|
||||||
|
serializer_class = ScheduleCreateSerializer
|
||||||
|
|
||||||
|
|
||||||
class MenuListCreateView(generics.ListCreateAPIView):
|
class MenuListCreateView(generics.ListCreateAPIView):
|
||||||
"""Menu list create view."""
|
"""Menu list create view."""
|
||||||
serializer_class = serializers.MenuSerializers
|
serializer_class = serializers.MenuSerializers
|
||||||
queryset = models.Menu.objects.all()
|
queryset = models.Menu.objects.all()
|
||||||
|
permission_classes = [IsEstablishmentManager]
|
||||||
|
|
||||||
|
|
||||||
class MenuRUDView(generics.RetrieveUpdateDestroyAPIView):
|
class MenuRUDView(generics.RetrieveUpdateDestroyAPIView):
|
||||||
"""Menu RUD view."""
|
"""Menu RUD view."""
|
||||||
serializer_class = serializers.MenuRUDSerializers
|
serializer_class = serializers.MenuRUDSerializers
|
||||||
queryset = models.Menu.objects.all()
|
queryset = models.Menu.objects.all()
|
||||||
|
permission_classes = [IsEstablishmentManager]
|
||||||
|
|
||||||
|
|
||||||
class SocialListCreateView(generics.ListCreateAPIView):
|
class SocialListCreateView(generics.ListCreateAPIView):
|
||||||
|
|
@ -42,12 +75,14 @@ class SocialListCreateView(generics.ListCreateAPIView):
|
||||||
serializer_class = serializers.SocialNetworkSerializers
|
serializer_class = serializers.SocialNetworkSerializers
|
||||||
queryset = models.SocialNetwork.objects.all()
|
queryset = models.SocialNetwork.objects.all()
|
||||||
pagination_class = None
|
pagination_class = None
|
||||||
|
permission_classes = [IsEstablishmentManager]
|
||||||
|
|
||||||
|
|
||||||
class SocialRUDView(generics.RetrieveUpdateDestroyAPIView):
|
class SocialRUDView(generics.RetrieveUpdateDestroyAPIView):
|
||||||
"""Social RUD view."""
|
"""Social RUD view."""
|
||||||
serializer_class = serializers.SocialNetworkSerializers
|
serializer_class = serializers.SocialNetworkSerializers
|
||||||
queryset = models.SocialNetwork.objects.all()
|
queryset = models.SocialNetwork.objects.all()
|
||||||
|
permission_classes = [IsEstablishmentManager]
|
||||||
|
|
||||||
|
|
||||||
class PlateListCreateView(generics.ListCreateAPIView):
|
class PlateListCreateView(generics.ListCreateAPIView):
|
||||||
|
|
@ -55,12 +90,14 @@ class PlateListCreateView(generics.ListCreateAPIView):
|
||||||
serializer_class = serializers.PlatesSerializers
|
serializer_class = serializers.PlatesSerializers
|
||||||
queryset = models.Plate.objects.all()
|
queryset = models.Plate.objects.all()
|
||||||
pagination_class = None
|
pagination_class = None
|
||||||
|
permission_classes = [IsEstablishmentManager]
|
||||||
|
|
||||||
|
|
||||||
class PlateRUDView(generics.RetrieveUpdateDestroyAPIView):
|
class PlateRUDView(generics.RetrieveUpdateDestroyAPIView):
|
||||||
"""Social RUD view."""
|
"""Social RUD view."""
|
||||||
serializer_class = serializers.PlatesSerializers
|
serializer_class = serializers.PlatesSerializers
|
||||||
queryset = models.Plate.objects.all()
|
queryset = models.Plate.objects.all()
|
||||||
|
permission_classes = [IsEstablishmentManager]
|
||||||
|
|
||||||
|
|
||||||
class PhonesListCreateView(generics.ListCreateAPIView):
|
class PhonesListCreateView(generics.ListCreateAPIView):
|
||||||
|
|
@ -68,12 +105,14 @@ class PhonesListCreateView(generics.ListCreateAPIView):
|
||||||
serializer_class = serializers.ContactPhoneBackSerializers
|
serializer_class = serializers.ContactPhoneBackSerializers
|
||||||
queryset = models.ContactPhone.objects.all()
|
queryset = models.ContactPhone.objects.all()
|
||||||
pagination_class = None
|
pagination_class = None
|
||||||
|
permission_classes = [IsEstablishmentManager]
|
||||||
|
|
||||||
|
|
||||||
class PhonesRUDView(generics.RetrieveUpdateDestroyAPIView):
|
class PhonesRUDView(generics.RetrieveUpdateDestroyAPIView):
|
||||||
"""Social RUD view."""
|
"""Social RUD view."""
|
||||||
serializer_class = serializers.ContactPhoneBackSerializers
|
serializer_class = serializers.ContactPhoneBackSerializers
|
||||||
queryset = models.ContactPhone.objects.all()
|
queryset = models.ContactPhone.objects.all()
|
||||||
|
permission_classes = [IsEstablishmentManager]
|
||||||
|
|
||||||
|
|
||||||
class EmailListCreateView(generics.ListCreateAPIView):
|
class EmailListCreateView(generics.ListCreateAPIView):
|
||||||
|
|
@ -81,12 +120,14 @@ class EmailListCreateView(generics.ListCreateAPIView):
|
||||||
serializer_class = serializers.ContactEmailBackSerializers
|
serializer_class = serializers.ContactEmailBackSerializers
|
||||||
queryset = models.ContactEmail.objects.all()
|
queryset = models.ContactEmail.objects.all()
|
||||||
pagination_class = None
|
pagination_class = None
|
||||||
|
permission_classes = [IsEstablishmentManager]
|
||||||
|
|
||||||
|
|
||||||
class EmailRUDView(generics.RetrieveUpdateDestroyAPIView):
|
class EmailRUDView(generics.RetrieveUpdateDestroyAPIView):
|
||||||
"""Social RUD view."""
|
"""Social RUD view."""
|
||||||
serializer_class = serializers.ContactEmailBackSerializers
|
serializer_class = serializers.ContactEmailBackSerializers
|
||||||
queryset = models.ContactEmail.objects.all()
|
queryset = models.ContactEmail.objects.all()
|
||||||
|
permission_classes = [IsEstablishmentManager]
|
||||||
|
|
||||||
|
|
||||||
class EmployeeListCreateView(generics.ListCreateAPIView):
|
class EmployeeListCreateView(generics.ListCreateAPIView):
|
||||||
|
|
@ -100,3 +141,29 @@ class EmployeeRUDView(generics.RetrieveUpdateDestroyAPIView):
|
||||||
"""Social RUD view."""
|
"""Social RUD view."""
|
||||||
serializer_class = serializers.EmployeeBackSerializers
|
serializer_class = serializers.EmployeeBackSerializers
|
||||||
queryset = models.Employee.objects.all()
|
queryset = models.Employee.objects.all()
|
||||||
|
|
||||||
|
|
||||||
|
class EstablishmentTypeListCreateView(generics.ListCreateAPIView):
|
||||||
|
"""Establishment type list/create view."""
|
||||||
|
serializer_class = serializers.EstablishmentTypeBaseSerializer
|
||||||
|
queryset = models.EstablishmentType.objects.all()
|
||||||
|
pagination_class = None
|
||||||
|
|
||||||
|
|
||||||
|
class EstablishmentTypeRUDView(generics.RetrieveUpdateDestroyAPIView):
|
||||||
|
"""Establishment type retrieve/update/destroy view."""
|
||||||
|
serializer_class = serializers.EstablishmentTypeBaseSerializer
|
||||||
|
queryset = models.EstablishmentType.objects.all()
|
||||||
|
|
||||||
|
|
||||||
|
class EstablishmentSubtypeListCreateView(generics.ListCreateAPIView):
|
||||||
|
"""Establishment subtype list/create view."""
|
||||||
|
serializer_class = serializers.EstablishmentSubTypeBaseSerializer
|
||||||
|
queryset = models.EstablishmentSubType.objects.all()
|
||||||
|
pagination_class = None
|
||||||
|
|
||||||
|
|
||||||
|
class EstablishmentSubtypeRUDView(generics.RetrieveUpdateDestroyAPIView):
|
||||||
|
"""Establishment subtype retrieve/update/destroy view."""
|
||||||
|
serializer_class = serializers.EstablishmentSubTypeBaseSerializer
|
||||||
|
queryset = models.EstablishmentSubType.objects.all()
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,8 @@ from comment import models as comment_models
|
||||||
from establishment import filters
|
from establishment import filters
|
||||||
from establishment import models, serializers
|
from establishment import models, serializers
|
||||||
from main import methods
|
from main import methods
|
||||||
from main.models import MetaDataContent
|
|
||||||
from timetable.serialziers import ScheduleRUDSerializer, ScheduleCreateSerializer
|
|
||||||
from utils.pagination import EstablishmentPortionPagination
|
from utils.pagination import EstablishmentPortionPagination
|
||||||
|
from utils.permissions import IsCountryAdmin
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentMixinView:
|
class EstablishmentMixinView:
|
||||||
|
|
@ -19,9 +18,10 @@ class EstablishmentMixinView:
|
||||||
permission_classes = (permissions.AllowAny,)
|
permission_classes = (permissions.AllowAny,)
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
"""Overrided method 'get_queryset'."""
|
"""Overridden method 'get_queryset'."""
|
||||||
return models.Establishment.objects.published().with_base_related().\
|
return models.Establishment.objects.published() \
|
||||||
annotate_in_favorites(self.request.user)
|
.with_base_related() \
|
||||||
|
.annotate_in_favorites(self.request.user)
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentListView(EstablishmentMixinView, generics.ListAPIView):
|
class EstablishmentListView(EstablishmentMixinView, generics.ListAPIView):
|
||||||
|
|
@ -86,7 +86,7 @@ class EstablishmentTypeListView(generics.ListAPIView):
|
||||||
"""Resource for getting a list of establishment types."""
|
"""Resource for getting a list of establishment types."""
|
||||||
|
|
||||||
permission_classes = (permissions.AllowAny,)
|
permission_classes = (permissions.AllowAny,)
|
||||||
serializer_class = serializers.EstablishmentTypeSerializer
|
serializer_class = serializers.EstablishmentTypeBaseSerializer
|
||||||
queryset = models.EstablishmentType.objects.all()
|
queryset = models.EstablishmentType.objects.all()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -178,42 +178,12 @@ class EstablishmentNearestRetrieveView(EstablishmentListView, generics.ListAPIVi
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentTagListView(generics.ListAPIView):
|
# Wineries
|
||||||
"""List view for establishment tags."""
|
# todo: find out about difference between subtypes data
|
||||||
serializer_class = serializers.EstablishmentTagListSerializer
|
# class WineriesListView(EstablishmentListView):
|
||||||
permission_classes = (permissions.AllowAny,)
|
# """Return list establishments with type Wineries"""
|
||||||
pagination_class = None
|
#
|
||||||
|
# def get_queryset(self):
|
||||||
def get_queryset(self):
|
# """Overridden get_queryset method."""
|
||||||
"""Override get_queryset method"""
|
# qs = super(WineriesListView, self).get_queryset()
|
||||||
return MetaDataContent.objects.by_content_type(app_label='establishment',
|
# return qs.with_type_related().wineries()
|
||||||
model='establishment')\
|
|
||||||
.distinct('metadata__label')
|
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentScheduleRUDView(generics.RetrieveUpdateDestroyAPIView):
|
|
||||||
"""Establishment schedule RUD view"""
|
|
||||||
serializer_class = ScheduleRUDSerializer
|
|
||||||
|
|
||||||
def get_object(self):
|
|
||||||
"""
|
|
||||||
Returns the object the view is displaying.
|
|
||||||
"""
|
|
||||||
establishment_pk = self.kwargs['pk']
|
|
||||||
schedule_id = self.kwargs['schedule_id']
|
|
||||||
|
|
||||||
establishment = get_object_or_404(klass=models.Establishment.objects.all(),
|
|
||||||
pk=establishment_pk)
|
|
||||||
schedule = get_object_or_404(klass=establishment.schedule,
|
|
||||||
id=schedule_id)
|
|
||||||
|
|
||||||
# May raise a permission denied
|
|
||||||
self.check_object_permissions(self.request, establishment)
|
|
||||||
self.check_object_permissions(self.request, schedule)
|
|
||||||
|
|
||||||
return schedule
|
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentScheduleCreateView(generics.CreateAPIView):
|
|
||||||
"""Establishment schedule Create view"""
|
|
||||||
serializer_class = ScheduleCreateSerializer
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import os
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
# Check migration
|
||||||
def load_data_from_sql(apps, schema_editor):
|
def load_data_from_sql(apps, schema_editor):
|
||||||
file_path = os.path.join(os.path.dirname(__file__), 'migrate_lang.sql')
|
file_path = os.path.join(os.path.dirname(__file__), 'migrate_lang.sql')
|
||||||
sql_statement = open(file_path).read()
|
sql_statement = open(file_path).read()
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,6 @@ INSERT INTO codelang (code,country) VALUES
|
||||||
,('es-CR','Spanish (Costa Rica)')
|
,('es-CR','Spanish (Costa Rica)')
|
||||||
,('es-DO','Spanish (Dominican Republic)')
|
,('es-DO','Spanish (Dominican Republic)')
|
||||||
,('es-EC','Spanish (Ecuador)')
|
,('es-EC','Spanish (Ecuador)')
|
||||||
,('es-ES','Spanish (Castilian)')
|
|
||||||
,('es-ES','Spanish (Spain)')
|
,('es-ES','Spanish (Spain)')
|
||||||
;
|
;
|
||||||
INSERT INTO codelang (code,country) VALUES
|
INSERT INTO codelang (code,country) VALUES
|
||||||
|
|
@ -326,7 +325,7 @@ commit;
|
||||||
|
|
||||||
INSERT INTO location_country
|
INSERT INTO location_country
|
||||||
(code, "name", low_price, high_price, created, modified)
|
(code, "name", low_price, high_price, created, modified)
|
||||||
select
|
select distinct
|
||||||
lpad((row_number() over (order by t.country asc))::text, 3, '0') as code,
|
lpad((row_number() over (order by t.country asc))::text, 3, '0') as code,
|
||||||
jsonb_build_object('en-GB', t.country),
|
jsonb_build_object('en-GB', t.country),
|
||||||
0 as low_price,
|
0 as low_price,
|
||||||
|
|
@ -348,6 +347,7 @@ commit;
|
||||||
INSERT INTO translation_language
|
INSERT INTO translation_language
|
||||||
(title, locale)
|
(title, locale)
|
||||||
select
|
select
|
||||||
|
distinct
|
||||||
t.country as title,
|
t.country as title,
|
||||||
t.code as locale
|
t.code as locale
|
||||||
from
|
from
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,10 @@ class Country(TranslatedFieldsMixin, SVGImageMixin, ProjectBaseMixin):
|
||||||
high_price = models.IntegerField(default=50, verbose_name=_('High price'))
|
high_price = models.IntegerField(default=50, verbose_name=_('High price'))
|
||||||
languages = models.ManyToManyField(Language, verbose_name=_('Languages'))
|
languages = models.ManyToManyField(Language, verbose_name=_('Languages'))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def country_id(self):
|
||||||
|
return self.id
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""Meta class."""
|
"""Meta class."""
|
||||||
|
|
||||||
|
|
@ -49,6 +53,14 @@ class Region(models.Model):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
|
class CityQuerySet(models.QuerySet):
|
||||||
|
"""Extended queryset for City model."""
|
||||||
|
|
||||||
|
def by_country_code(self, code):
|
||||||
|
"""Return establishments by country code"""
|
||||||
|
return self.filter(country__code=code)
|
||||||
|
|
||||||
|
|
||||||
class City(models.Model):
|
class City(models.Model):
|
||||||
"""Region model."""
|
"""Region model."""
|
||||||
|
|
||||||
|
|
@ -64,6 +76,8 @@ class City(models.Model):
|
||||||
|
|
||||||
is_island = models.BooleanField(_('is island'), default=False)
|
is_island = models.BooleanField(_('is island'), default=False)
|
||||||
|
|
||||||
|
objects = CityQuerySet.as_manager()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name_plural = _('cities')
|
verbose_name_plural = _('cities')
|
||||||
verbose_name = _('city')
|
verbose_name = _('city')
|
||||||
|
|
@ -73,7 +87,6 @@ class City(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class Address(models.Model):
|
class Address(models.Model):
|
||||||
|
|
||||||
"""Address model."""
|
"""Address model."""
|
||||||
city = models.ForeignKey(City, verbose_name=_('city'), on_delete=models.CASCADE)
|
city = models.ForeignKey(City, verbose_name=_('city'), on_delete=models.CASCADE)
|
||||||
street_name_1 = models.CharField(
|
street_name_1 = models.CharField(
|
||||||
|
|
@ -112,6 +125,10 @@ class Address(models.Model):
|
||||||
return {'lat': self.latitude,
|
return {'lat': self.latitude,
|
||||||
'lon': self.longitude}
|
'lon': self.longitude}
|
||||||
|
|
||||||
|
@property
|
||||||
|
def country_id(self):
|
||||||
|
return self.city.country_id
|
||||||
|
|
||||||
|
|
||||||
# todo: Make recalculate price levels
|
# todo: Make recalculate price levels
|
||||||
@receiver(post_save, sender=Country)
|
@receiver(post_save, sender=Country)
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,12 @@ from account.models import User
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from http.cookies import SimpleCookie
|
from http.cookies import SimpleCookie
|
||||||
|
|
||||||
from location.models import City, Region, Country
|
from location.models import City, Region, Country, Language
|
||||||
|
from django.contrib.gis.geos import Point
|
||||||
|
from account.models import Role, UserRole
|
||||||
|
|
||||||
|
|
||||||
class BaseTestCase(APITestCase):
|
class BaseTestCase(APITestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.username = 'sedragurda'
|
self.username = 'sedragurda'
|
||||||
self.password = 'sedragurdaredips19'
|
self.password = 'sedragurdaredips19'
|
||||||
|
|
@ -20,27 +21,57 @@ class BaseTestCase(APITestCase):
|
||||||
|
|
||||||
# get tokens
|
# get tokens
|
||||||
|
|
||||||
|
# self.user.is_superuser = True
|
||||||
|
# self.user.save()
|
||||||
|
|
||||||
tokkens = User.create_jwt_tokens(self.user)
|
tokkens = User.create_jwt_tokens(self.user)
|
||||||
self.client.cookies = SimpleCookie(
|
self.client.cookies = SimpleCookie(
|
||||||
{'access_token': tokkens.get('access_token'),
|
{'access_token': tokkens.get('access_token'),
|
||||||
'refresh_token': tokkens.get('refresh_token')})
|
'refresh_token': tokkens.get('refresh_token')})
|
||||||
|
|
||||||
|
self.lang = Language.objects.get(
|
||||||
|
title='Russia',
|
||||||
|
locale='ru-RU'
|
||||||
|
)
|
||||||
|
|
||||||
|
self.country_ru = Country.objects.get(
|
||||||
|
name={"en-GB": "Russian"}
|
||||||
|
)
|
||||||
|
|
||||||
|
self.role = Role.objects.create(role=Role.COUNTRY_ADMIN,
|
||||||
|
country=self.country_ru)
|
||||||
|
self.role.save()
|
||||||
|
|
||||||
|
self.user_role = UserRole.objects.create(user=self.user, role=self.role)
|
||||||
|
|
||||||
|
self.user_role.save()
|
||||||
|
|
||||||
|
|
||||||
class CountryTests(BaseTestCase):
|
class CountryTests(BaseTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
|
||||||
def test_country_CRUD(self):
|
def test_country_CRUD(self):
|
||||||
response = self.client.get('/api/back/location/countries/', format='json')
|
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'name': 'Test country',
|
'name': {"ru-RU": "NewCountry"},
|
||||||
'code': 'test'
|
'code': 'test1'
|
||||||
}
|
}
|
||||||
|
|
||||||
response = self.client.post('/api/back/location/countries/', data=data, format='json')
|
response = self.client.post('/api/back/location/countries/', data=data, format='json')
|
||||||
response_data = response.json()
|
response_data = response.json()
|
||||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||||
|
|
||||||
|
country = Country.objects.get(pk=response_data["id"])
|
||||||
|
role = Role.objects.create(role=Role.COUNTRY_ADMIN, country=country)
|
||||||
|
role.save()
|
||||||
|
|
||||||
|
user_role = UserRole.objects.create(user=self.user, role=role)
|
||||||
|
|
||||||
|
user_role.save()
|
||||||
|
|
||||||
|
response = self.client.get('/api/back/location/countries/', format='json')
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
response = self.client.get(f'/api/back/location/countries/{response_data["id"]}/', format='json')
|
response = self.client.get(f'/api/back/location/countries/{response_data["id"]}/', format='json')
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
@ -64,6 +95,14 @@ class RegionTests(BaseTestCase):
|
||||||
code="test"
|
code="test"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
role = Role.objects.create(role=Role.COUNTRY_ADMIN, country=self.country)
|
||||||
|
role.save()
|
||||||
|
|
||||||
|
user_role = UserRole.objects.create(user=self.user, role=role)
|
||||||
|
|
||||||
|
user_role.save()
|
||||||
|
|
||||||
|
|
||||||
def test_region_CRUD(self):
|
def test_region_CRUD(self):
|
||||||
response = self.client.get('/api/back/location/regions/', format='json')
|
response = self.client.get('/api/back/location/regions/', format='json')
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
@ -108,6 +147,13 @@ class CityTests(BaseTestCase):
|
||||||
country=self.country
|
country=self.country
|
||||||
)
|
)
|
||||||
|
|
||||||
|
role = Role.objects.create(role=Role.COUNTRY_ADMIN, country=self.country)
|
||||||
|
role.save()
|
||||||
|
|
||||||
|
user_role = UserRole.objects.create(user=self.user, role=role)
|
||||||
|
|
||||||
|
user_role.save()
|
||||||
|
|
||||||
def test_city_CRUD(self):
|
def test_city_CRUD(self):
|
||||||
response = self.client.get('/api/back/location/cities/', format='json')
|
response = self.client.get('/api/back/location/cities/', format='json')
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
@ -142,6 +188,7 @@ class AddressTests(BaseTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
|
|
||||||
self.country = Country.objects.create(
|
self.country = Country.objects.create(
|
||||||
name=json.dumps({"en-GB": "Test country"}),
|
name=json.dumps({"en-GB": "Test country"}),
|
||||||
code="test"
|
code="test"
|
||||||
|
|
@ -160,6 +207,13 @@ class AddressTests(BaseTestCase):
|
||||||
country=self.country
|
country=self.country
|
||||||
)
|
)
|
||||||
|
|
||||||
|
role = Role.objects.create(role=Role.COUNTRY_ADMIN, country=self.country)
|
||||||
|
role.save()
|
||||||
|
|
||||||
|
user_role = UserRole.objects.create(user=self.user, role=role)
|
||||||
|
|
||||||
|
user_role.save()
|
||||||
|
|
||||||
def test_address_CRUD(self):
|
def test_address_CRUD(self):
|
||||||
response = self.client.get('/api/back/location/addresses/', format='json')
|
response = self.client.get('/api/back/location/addresses/', format='json')
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
@ -167,10 +221,8 @@ class AddressTests(BaseTestCase):
|
||||||
data = {
|
data = {
|
||||||
'city_id': self.city.id,
|
'city_id': self.city.id,
|
||||||
'number': '+79999999',
|
'number': '+79999999',
|
||||||
"coordinates": {
|
"latitude": 37.0625,
|
||||||
"latitude": 37.0625,
|
"longitude": -95.677068,
|
||||||
"longitude": -95.677068
|
|
||||||
},
|
|
||||||
"geo_lon": -95.677068,
|
"geo_lon": -95.677068,
|
||||||
"geo_lat": 37.0625
|
"geo_lat": 37.0625
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
"""Location app mobile urlconf."""
|
"""Location app mobile urlconf."""
|
||||||
from location.urls.common import urlpatterns as common_urlpatterns
|
from location.urls.common import urlpatterns as common_urlpatterns
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = []
|
urlpatterns = []
|
||||||
|
|
||||||
urlpatterns.extend(common_urlpatterns)
|
urlpatterns.extend(common_urlpatterns)
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
"""Location app web urlconf."""
|
"""Location app web urlconf."""
|
||||||
from location.urls.common import urlpatterns as common_urlpatterns
|
from location.urls.common import urlpatterns as common_urlpatterns
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = []
|
urlpatterns = []
|
||||||
|
|
||||||
urlpatterns.extend(common_urlpatterns)
|
urlpatterns.extend(common_urlpatterns)
|
||||||
|
|
@ -3,50 +3,57 @@ from rest_framework import generics
|
||||||
|
|
||||||
from location import models, serializers
|
from location import models, serializers
|
||||||
from location.views import common
|
from location.views import common
|
||||||
|
from utils.permissions import IsCountryAdmin
|
||||||
|
|
||||||
# Address
|
# Address
|
||||||
class AddressListCreateView(common.AddressViewMixin, generics.ListCreateAPIView):
|
class AddressListCreateView(common.AddressViewMixin, generics.ListCreateAPIView):
|
||||||
"""Create view for model Address."""
|
"""Create view for model Address."""
|
||||||
serializer_class = serializers.AddressDetailSerializer
|
serializer_class = serializers.AddressDetailSerializer
|
||||||
queryset = models.Address.objects.all()
|
queryset = models.Address.objects.all()
|
||||||
|
permission_classes = [IsCountryAdmin]
|
||||||
|
|
||||||
|
|
||||||
class AddressRUDView(common.AddressViewMixin, generics.RetrieveUpdateDestroyAPIView):
|
class AddressRUDView(common.AddressViewMixin, generics.RetrieveUpdateDestroyAPIView):
|
||||||
"""RUD view for model Address."""
|
"""RUD view for model Address."""
|
||||||
serializer_class = serializers.AddressDetailSerializer
|
serializer_class = serializers.AddressDetailSerializer
|
||||||
queryset = models.Address.objects.all()
|
queryset = models.Address.objects.all()
|
||||||
|
permission_classes = [IsCountryAdmin]
|
||||||
|
|
||||||
|
|
||||||
# City
|
# City
|
||||||
class CityListCreateView(common.CityViewMixin, generics.ListCreateAPIView):
|
class CityListCreateView(common.CityViewMixin, generics.ListCreateAPIView):
|
||||||
"""Create view for model City."""
|
"""Create view for model City."""
|
||||||
serializer_class = serializers.CitySerializer
|
serializer_class = serializers.CitySerializer
|
||||||
|
permission_classes = [IsCountryAdmin]
|
||||||
|
|
||||||
class CityRUDView(common.CityViewMixin, generics.RetrieveUpdateDestroyAPIView):
|
class CityRUDView(common.CityViewMixin, generics.RetrieveUpdateDestroyAPIView):
|
||||||
"""RUD view for model City."""
|
"""RUD view for model City."""
|
||||||
serializer_class = serializers.CitySerializer
|
serializer_class = serializers.CitySerializer
|
||||||
|
permission_classes = [IsCountryAdmin]
|
||||||
|
|
||||||
|
|
||||||
# Region
|
# Region
|
||||||
class RegionListCreateView(common.RegionViewMixin, generics.ListCreateAPIView):
|
class RegionListCreateView(common.RegionViewMixin, generics.ListCreateAPIView):
|
||||||
"""Create view for model Region"""
|
"""Create view for model Region"""
|
||||||
serializer_class = serializers.RegionSerializer
|
serializer_class = serializers.RegionSerializer
|
||||||
|
permission_classes = [IsCountryAdmin]
|
||||||
|
|
||||||
class RegionRUDView(common.RegionViewMixin, generics.RetrieveUpdateDestroyAPIView):
|
class RegionRUDView(common.RegionViewMixin, generics.RetrieveUpdateDestroyAPIView):
|
||||||
"""Retrieve view for model Region"""
|
"""Retrieve view for model Region"""
|
||||||
serializer_class = serializers.RegionSerializer
|
serializer_class = serializers.RegionSerializer
|
||||||
|
permission_classes = [IsCountryAdmin]
|
||||||
|
|
||||||
|
|
||||||
# Country
|
# Country
|
||||||
class CountryListCreateView(common.CountryViewMixin, generics.ListCreateAPIView):
|
class CountryListCreateView(generics.ListCreateAPIView):
|
||||||
"""List/Create view for model Country."""
|
"""List/Create view for model Country."""
|
||||||
|
queryset = models.Country.objects.all()
|
||||||
serializer_class = serializers.CountryBackSerializer
|
serializer_class = serializers.CountryBackSerializer
|
||||||
pagination_class = None
|
pagination_class = None
|
||||||
|
permission_classes = [IsCountryAdmin]
|
||||||
|
|
||||||
|
class CountryRUDView(generics.RetrieveUpdateDestroyAPIView):
|
||||||
class CountryRUDView(common.CountryViewMixin, generics.RetrieveUpdateDestroyAPIView):
|
|
||||||
"""RUD view for model Country."""
|
"""RUD view for model Country."""
|
||||||
serializer_class = serializers.CountryBackSerializer
|
serializer_class = serializers.CountryBackSerializer
|
||||||
|
permission_classes = [IsCountryAdmin]
|
||||||
|
queryset = models.Country.objects.all()
|
||||||
|
|
@ -10,7 +10,7 @@ class CountryViewMixin(generics.GenericAPIView):
|
||||||
"""View Mixin for model Country"""
|
"""View Mixin for model Country"""
|
||||||
|
|
||||||
serializer_class = serializers.CountrySerializer
|
serializer_class = serializers.CountrySerializer
|
||||||
permission_classes = (permissions.AllowAny, )
|
permission_classes = (permissions.AllowAny,)
|
||||||
queryset = models.Country.objects.all()
|
queryset = models.Country.objects.all()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -56,7 +56,7 @@ class RegionRetrieveView(RegionViewMixin, generics.RetrieveAPIView):
|
||||||
|
|
||||||
class RegionListView(RegionViewMixin, generics.ListAPIView):
|
class RegionListView(RegionViewMixin, generics.ListAPIView):
|
||||||
"""List view for model Country"""
|
"""List view for model Country"""
|
||||||
permission_classes = (permissions.AllowAny, )
|
permission_classes = (permissions.AllowAny,)
|
||||||
serializer_class = serializers.CountrySerializer
|
serializer_class = serializers.CountrySerializer
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -83,9 +83,15 @@ class CityRetrieveView(CityViewMixin, generics.RetrieveAPIView):
|
||||||
|
|
||||||
class CityListView(CityViewMixin, generics.ListAPIView):
|
class CityListView(CityViewMixin, generics.ListAPIView):
|
||||||
"""List view for model City"""
|
"""List view for model City"""
|
||||||
permission_classes = (permissions.AllowAny, )
|
permission_classes = (permissions.AllowAny,)
|
||||||
serializer_class = serializers.CitySerializer
|
serializer_class = serializers.CitySerializer
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
qs = super().get_queryset()
|
||||||
|
if self.request.country_code:
|
||||||
|
qs = qs.by_country_code(self.request.country_code)
|
||||||
|
return qs
|
||||||
|
|
||||||
|
|
||||||
class CityDestroyView(CityViewMixin, generics.DestroyAPIView):
|
class CityDestroyView(CityViewMixin, generics.DestroyAPIView):
|
||||||
"""Destroy view for model City"""
|
"""Destroy view for model City"""
|
||||||
|
|
@ -110,7 +116,5 @@ class AddressRetrieveView(AddressViewMixin, generics.RetrieveAPIView):
|
||||||
|
|
||||||
class AddressListView(AddressViewMixin, generics.ListAPIView):
|
class AddressListView(AddressViewMixin, generics.ListAPIView):
|
||||||
"""List view for model Address"""
|
"""List view for model Address"""
|
||||||
permission_classes = (permissions.AllowAny, )
|
permission_classes = (permissions.AllowAny,)
|
||||||
serializer_class = serializers.AddressDetailSerializer
|
serializer_class = serializers.AddressDetailSerializer
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,22 +25,6 @@ class AwardAdmin(admin.ModelAdmin):
|
||||||
# list_display_links = ['id', '__str__']
|
# list_display_links = ['id', '__str__']
|
||||||
|
|
||||||
|
|
||||||
@admin.register(models.MetaData)
|
|
||||||
class MetaDataAdmin(admin.ModelAdmin):
|
|
||||||
"""MetaData admin."""
|
|
||||||
|
|
||||||
|
|
||||||
@admin.register(models.MetaDataCategory)
|
|
||||||
class MetaDataCategoryAdmin(admin.ModelAdmin):
|
|
||||||
"""MetaData admin."""
|
|
||||||
list_display = ['id', 'country', 'content_type']
|
|
||||||
|
|
||||||
|
|
||||||
@admin.register(models.MetaDataContent)
|
|
||||||
class MetaDataContentAdmin(admin.ModelAdmin):
|
|
||||||
"""MetaDataContent admin"""
|
|
||||||
|
|
||||||
|
|
||||||
@admin.register(models.Currency)
|
@admin.register(models.Currency)
|
||||||
class CurrencContentAdmin(admin.ModelAdmin):
|
class CurrencContentAdmin(admin.ModelAdmin):
|
||||||
"""CurrencContent admin"""
|
"""CurrencContent admin"""
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
"""Main app methods."""
|
"""Main app methods."""
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Tuple, Optional
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.gis.geoip2 import GeoIP2, GeoIP2Exception
|
from django.contrib.gis.geoip2 import GeoIP2, GeoIP2Exception
|
||||||
|
from geoip2.models import City
|
||||||
|
|
||||||
from main import models
|
from main import models
|
||||||
|
|
||||||
|
|
@ -39,17 +41,16 @@ def determine_country_code(ip_addr):
|
||||||
return country_code
|
return country_code
|
||||||
|
|
||||||
|
|
||||||
def determine_coordinates(ip_addr):
|
def determine_coordinates(ip_addr: str) -> Tuple[Optional[float], Optional[float]]:
|
||||||
longitude, latitude = None, None
|
|
||||||
if ip_addr:
|
if ip_addr:
|
||||||
try:
|
try:
|
||||||
geoip = GeoIP2()
|
geoip = GeoIP2()
|
||||||
longitude, latitude = geoip.coords(ip_addr)
|
return geoip.coords(ip_addr)
|
||||||
except GeoIP2Exception as ex:
|
except GeoIP2Exception as ex:
|
||||||
logger.info(f'GEOIP Exception: {ex}. ip: {ip_addr}')
|
logger.warning(f'GEOIP Exception: {ex}. ip: {ip_addr}')
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.error(f'GEOIP Base exception: {ex}')
|
logger.warning(f'GEOIP Base exception: {ex}')
|
||||||
return longitude, latitude
|
return None, None
|
||||||
|
|
||||||
|
|
||||||
def determine_user_site_url(country_code):
|
def determine_user_site_url(country_code):
|
||||||
|
|
@ -73,3 +74,12 @@ def determine_user_site_url(country_code):
|
||||||
return site.site_url
|
return site.site_url
|
||||||
|
|
||||||
|
|
||||||
|
def determine_user_city(ip_addr: str) -> Optional[City]:
|
||||||
|
try:
|
||||||
|
geoip = GeoIP2()
|
||||||
|
return geoip.city(ip_addr)
|
||||||
|
except GeoIP2Exception as ex:
|
||||||
|
logger.warning(f'GEOIP Exception: {ex}. ip: {ip_addr}')
|
||||||
|
except Exception as ex:
|
||||||
|
logger.warning(f'GEOIP Base exception: {ex}')
|
||||||
|
return None
|
||||||
|
|
|
||||||
19
apps/main/migrations/0017_feature_route.py
Normal file
19
apps/main/migrations/0017_feature_route.py
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-07 14:39
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0016_merge_20190919_0954'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='feature',
|
||||||
|
name='route',
|
||||||
|
field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, to='main.Page'),
|
||||||
|
),
|
||||||
|
]
|
||||||
18
apps/main/migrations/0018_feature_source.py
Normal file
18
apps/main/migrations/0018_feature_source.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-07 14:51
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0017_feature_route'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='feature',
|
||||||
|
name='source',
|
||||||
|
field=models.PositiveSmallIntegerField(choices=[(0, 'Mobile'), (1, 'Web'), (2, 'All')], default=0, verbose_name='Source'),
|
||||||
|
),
|
||||||
|
]
|
||||||
38
apps/main/migrations/0019_auto_20191022_1359.py
Normal file
38
apps/main/migrations/0019_auto_20191022_1359.py
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-22 13:59
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0018_feature_source'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='metadatacategory',
|
||||||
|
name='content_type',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='metadatacategory',
|
||||||
|
name='country',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='metadatacontent',
|
||||||
|
name='content_type',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='metadatacontent',
|
||||||
|
name='metadata',
|
||||||
|
),
|
||||||
|
migrations.DeleteModel(
|
||||||
|
name='MetaData',
|
||||||
|
),
|
||||||
|
migrations.DeleteModel(
|
||||||
|
name='MetaDataCategory',
|
||||||
|
),
|
||||||
|
migrations.DeleteModel(
|
||||||
|
name='MetaDataContent',
|
||||||
|
),
|
||||||
|
]
|
||||||
18
apps/main/migrations/0019_award_image_url.py
Normal file
18
apps/main/migrations/0019_award_image_url.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-22 14:56
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0018_feature_source'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='award',
|
||||||
|
name='image_url',
|
||||||
|
field=models.URLField(blank=True, default=None, null=True, verbose_name='Image URL path'),
|
||||||
|
),
|
||||||
|
]
|
||||||
14
apps/main/migrations/0020_merge_20191023_0750.py
Normal file
14
apps/main/migrations/0020_merge_20191023_0750.py
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-23 07:50
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0019_award_image_url'),
|
||||||
|
('main', '0019_auto_20191022_1359'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
]
|
||||||
18
apps/main/migrations/0021_auto_20191023_0924.py
Normal file
18
apps/main/migrations/0021_auto_20191023_0924.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-23 09:24
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0020_merge_20191023_0750'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='feature',
|
||||||
|
name='slug',
|
||||||
|
field=models.SlugField(max_length=255, unique=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -1,19 +1,24 @@
|
||||||
"""Main app models."""
|
"""Main app models."""
|
||||||
|
from typing import Iterable
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.contenttypes import fields as generic
|
from django.contrib.contenttypes import fields as generic
|
||||||
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.contrib.postgres.fields import JSONField
|
from django.contrib.postgres.fields import JSONField
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.db.models import Q
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.contrib.contenttypes.models import ContentType
|
|
||||||
|
|
||||||
from advertisement.models import Advertisement
|
from advertisement.models import Advertisement
|
||||||
|
from configuration.models import TranslationSettings
|
||||||
from location.models import Country
|
from location.models import Country
|
||||||
from main import methods
|
from main import methods
|
||||||
from review.models import Review
|
from review.models import Review
|
||||||
from utils.models import (ProjectBaseMixin, TJSONField,
|
from utils.models import (ProjectBaseMixin, TJSONField,
|
||||||
TranslatedFieldsMixin, ImageMixin)
|
TranslatedFieldsMixin, ImageMixin,
|
||||||
|
PlatformMixin, URLImageMixin)
|
||||||
from utils.querysets import ContentTypeQuerySetMixin
|
from utils.querysets import ContentTypeQuerySetMixin
|
||||||
from configuration.models import TranslationSettings
|
|
||||||
|
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
@ -109,7 +114,6 @@ class SiteSettingsQuerySet(models.QuerySet):
|
||||||
|
|
||||||
|
|
||||||
class SiteSettings(ProjectBaseMixin):
|
class SiteSettings(ProjectBaseMixin):
|
||||||
|
|
||||||
subdomain = models.CharField(max_length=255, db_index=True, unique=True,
|
subdomain = models.CharField(max_length=255, db_index=True, unique=True,
|
||||||
verbose_name=_('Subdomain'))
|
verbose_name=_('Subdomain'))
|
||||||
country = models.OneToOneField(Country, on_delete=models.PROTECT,
|
country = models.OneToOneField(Country, on_delete=models.PROTECT,
|
||||||
|
|
@ -150,7 +154,8 @@ class SiteSettings(ProjectBaseMixin):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def published_sitefeatures(self):
|
def published_sitefeatures(self):
|
||||||
return self.sitefeature_set.filter(published=True)
|
return self.sitefeature_set\
|
||||||
|
.filter(Q(published=True) and Q(feature__source__in=[PlatformMixin.WEB, PlatformMixin.ALL]))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def site_url(self):
|
def site_url(self):
|
||||||
|
|
@ -159,11 +164,27 @@ class SiteSettings(ProjectBaseMixin):
|
||||||
domain=settings.SITE_DOMAIN_URI)
|
domain=settings.SITE_DOMAIN_URI)
|
||||||
|
|
||||||
|
|
||||||
class Feature(ProjectBaseMixin):
|
class Page(models.Model):
|
||||||
|
"""Page model."""
|
||||||
|
|
||||||
|
page_name = models.CharField(max_length=255, unique=True)
|
||||||
|
advertisements = models.ManyToManyField(Advertisement)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
"""Meta class."""
|
||||||
|
verbose_name = _('Page')
|
||||||
|
verbose_name_plural = _('Pages')
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f'{self.page_name}'
|
||||||
|
|
||||||
|
|
||||||
|
class Feature(ProjectBaseMixin, PlatformMixin):
|
||||||
"""Feature model."""
|
"""Feature model."""
|
||||||
|
|
||||||
slug = models.CharField(max_length=255, unique=True)
|
slug = models.SlugField(max_length=255, unique=True)
|
||||||
priority = models.IntegerField(unique=True, null=True, default=None)
|
priority = models.IntegerField(unique=True, null=True, default=None)
|
||||||
|
route = models.ForeignKey(Page, on_delete=models.PROTECT, null=True, default=None)
|
||||||
site_settings = models.ManyToManyField(SiteSettings, through='SiteFeature')
|
site_settings = models.ManyToManyField(SiteSettings, through='SiteFeature')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
@ -181,6 +202,12 @@ class SiteFeatureQuerySet(models.QuerySet):
|
||||||
def published(self, switcher=True):
|
def published(self, switcher=True):
|
||||||
return self.filter(published=switcher)
|
return self.filter(published=switcher)
|
||||||
|
|
||||||
|
def by_country_code(self, country_code: str):
|
||||||
|
return self.filter(site_settings__country__code=country_code)
|
||||||
|
|
||||||
|
def by_sources(self, sources: Iterable[int]):
|
||||||
|
return self.filter(feature__source__in=sources)
|
||||||
|
|
||||||
|
|
||||||
class SiteFeature(ProjectBaseMixin):
|
class SiteFeature(ProjectBaseMixin):
|
||||||
"""SiteFeature model."""
|
"""SiteFeature model."""
|
||||||
|
|
@ -200,7 +227,7 @@ class SiteFeature(ProjectBaseMixin):
|
||||||
unique_together = ('site_settings', 'feature')
|
unique_together = ('site_settings', 'feature')
|
||||||
|
|
||||||
|
|
||||||
class Award(TranslatedFieldsMixin, models.Model):
|
class Award(TranslatedFieldsMixin, URLImageMixin, models.Model):
|
||||||
"""Award model."""
|
"""Award model."""
|
||||||
award_type = models.ForeignKey('main.AwardType', on_delete=models.CASCADE)
|
award_type = models.ForeignKey('main.AwardType', on_delete=models.CASCADE)
|
||||||
title = TJSONField(
|
title = TJSONField(
|
||||||
|
|
@ -230,49 +257,6 @@ class AwardType(models.Model):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class MetaDataCategory(models.Model):
|
|
||||||
"""MetaData category model."""
|
|
||||||
|
|
||||||
country = models.ForeignKey(
|
|
||||||
'location.Country', null=True, default=None, on_delete=models.CASCADE)
|
|
||||||
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
|
|
||||||
public = models.BooleanField()
|
|
||||||
|
|
||||||
|
|
||||||
class MetaData(TranslatedFieldsMixin, models.Model):
|
|
||||||
"""MetaData model."""
|
|
||||||
label = TJSONField(
|
|
||||||
_('label'), null=True, blank=True,
|
|
||||||
default=None, help_text='{"en-GB":"some text"}')
|
|
||||||
category = models.ForeignKey(
|
|
||||||
MetaDataCategory, verbose_name=_('category'), on_delete=models.CASCADE)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
verbose_name = _('metadata')
|
|
||||||
verbose_name_plural = _('metadata')
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
label = 'None'
|
|
||||||
lang = TranslationSettings.get_solo().default_language
|
|
||||||
if self.label and lang in self.label:
|
|
||||||
label = self.label[lang]
|
|
||||||
return f'id:{self.id}-{label}'
|
|
||||||
|
|
||||||
|
|
||||||
class MetaDataContentQuerySet(ContentTypeQuerySetMixin):
|
|
||||||
"""QuerySets for MetaDataContent model."""
|
|
||||||
|
|
||||||
|
|
||||||
class MetaDataContent(models.Model):
|
|
||||||
"""MetaDataContent model."""
|
|
||||||
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
|
|
||||||
object_id = models.PositiveIntegerField()
|
|
||||||
content_object = generic.GenericForeignKey('content_type', 'object_id')
|
|
||||||
metadata = models.ForeignKey(MetaData, on_delete=models.CASCADE)
|
|
||||||
|
|
||||||
objects = MetaDataContentQuerySet.as_manager()
|
|
||||||
|
|
||||||
|
|
||||||
class Currency(models.Model):
|
class Currency(models.Model):
|
||||||
"""Currency model."""
|
"""Currency model."""
|
||||||
name = models.CharField(_('name'), max_length=50)
|
name = models.CharField(_('name'), max_length=50)
|
||||||
|
|
@ -351,19 +335,3 @@ class Carousel(models.Model):
|
||||||
def model_name(self):
|
def model_name(self):
|
||||||
if hasattr(self.content_object, 'establishment_type'):
|
if hasattr(self.content_object, 'establishment_type'):
|
||||||
return self.content_object.establishment_type.name_translated
|
return self.content_object.establishment_type.name_translated
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Page(models.Model):
|
|
||||||
"""Page model."""
|
|
||||||
|
|
||||||
page_name = models.CharField(max_length=255, unique=True)
|
|
||||||
advertisements = models.ManyToManyField(Advertisement)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
"""Meta class."""
|
|
||||||
verbose_name = _('Page')
|
|
||||||
verbose_name_plural = _('Pages')
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f'{self.page_name}'
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
"""Main app serializers."""
|
"""Main app serializers."""
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from advertisement.serializers.web import AdvertisementSerializer
|
from advertisement.serializers.web import AdvertisementSerializer
|
||||||
from location.serializers import CountrySerializer
|
from location.serializers import CountrySerializer
|
||||||
from main import models
|
from main import models
|
||||||
from establishment.models import Establishment
|
|
||||||
from utils.serializers import TranslatedField
|
from utils.serializers import TranslatedField
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -25,6 +25,8 @@ class SiteFeatureSerializer(serializers.ModelSerializer):
|
||||||
id = serializers.IntegerField(source='feature.id')
|
id = serializers.IntegerField(source='feature.id')
|
||||||
slug = serializers.CharField(source='feature.slug')
|
slug = serializers.CharField(source='feature.slug')
|
||||||
priority = serializers.IntegerField(source='feature.priority')
|
priority = serializers.IntegerField(source='feature.priority')
|
||||||
|
route = serializers.CharField(source='feature.route.page_name')
|
||||||
|
source = serializers.IntegerField(source='feature.source')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""Meta class."""
|
"""Meta class."""
|
||||||
|
|
@ -32,7 +34,9 @@ class SiteFeatureSerializer(serializers.ModelSerializer):
|
||||||
fields = ('main',
|
fields = ('main',
|
||||||
'id',
|
'id',
|
||||||
'slug',
|
'slug',
|
||||||
'priority'
|
'priority',
|
||||||
|
'route',
|
||||||
|
'source'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -98,6 +102,7 @@ class AwardBaseSerializer(serializers.ModelSerializer):
|
||||||
'id',
|
'id',
|
||||||
'title_translated',
|
'title_translated',
|
||||||
'vintage_year',
|
'vintage_year',
|
||||||
|
'image_url',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -109,19 +114,6 @@ class AwardSerializer(AwardBaseSerializer):
|
||||||
fields = AwardBaseSerializer.Meta.fields + ['award_type', ]
|
fields = AwardBaseSerializer.Meta.fields + ['award_type', ]
|
||||||
|
|
||||||
|
|
||||||
class MetaDataContentSerializer(serializers.ModelSerializer):
|
|
||||||
"""MetaData content serializer."""
|
|
||||||
|
|
||||||
id = serializers.IntegerField(source='metadata.id', read_only=True)
|
|
||||||
label_translated = TranslatedField(source='metadata.label_translated')
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
"""Meta class."""
|
|
||||||
|
|
||||||
model = models.MetaDataContent
|
|
||||||
fields = ('id', 'label_translated')
|
|
||||||
|
|
||||||
|
|
||||||
class CurrencySerializer(serializers.ModelSerializer):
|
class CurrencySerializer(serializers.ModelSerializer):
|
||||||
"""Currency serializer"""
|
"""Currency serializer"""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
"""Main app urls."""
|
|
||||||
from django.urls import path
|
|
||||||
from main import views
|
|
||||||
|
|
||||||
app = 'main'
|
|
||||||
|
|
||||||
urlpatterns = [
|
|
||||||
path('determine-site/', views.DetermineSiteView.as_view(), name='determine-site'),
|
|
||||||
path('sites/', views.SiteListView.as_view(), name='site-list'),
|
|
||||||
path('site-settings/<subdomain>/', views.SiteSettingsView.as_view(), name='site-settings'),
|
|
||||||
path('awards/', views.AwardView.as_view(), name='awards_list'),
|
|
||||||
path('awards/<int:pk>/', views.AwardRetrieveView.as_view(), name='awards_retrieve'),
|
|
||||||
path('carousel/', views.CarouselListView.as_view(), name='carousel-list'),
|
|
||||||
]
|
|
||||||
12
apps/main/urls/common.py
Normal file
12
apps/main/urls/common.py
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
"""Main app urls."""
|
||||||
|
from django.urls import path
|
||||||
|
from main.views.common import *
|
||||||
|
|
||||||
|
app = 'main'
|
||||||
|
|
||||||
|
common_urlpatterns = [
|
||||||
|
path('awards/', AwardView.as_view(), name='awards_list'),
|
||||||
|
path('awards/<int:pk>/', AwardRetrieveView.as_view(), name='awards_retrieve'),
|
||||||
|
path('carousel/', CarouselListView.as_view(), name='carousel-list'),
|
||||||
|
path('determine-location/', DetermineLocation.as_view(), name='determine-location')
|
||||||
|
]
|
||||||
11
apps/main/urls/mobile.py
Normal file
11
apps/main/urls/mobile.py
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
from main.urls.common import common_urlpatterns
|
||||||
|
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
from main.views.mobile import FeaturesView
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('features/', FeaturesView.as_view(), name='features'),
|
||||||
|
]
|
||||||
|
|
||||||
|
urlpatterns.extend(common_urlpatterns)
|
||||||
11
apps/main/urls/web.py
Normal file
11
apps/main/urls/web.py
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
from main.urls.common import common_urlpatterns
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
from main.views.web import DetermineSiteView, SiteListView, SiteSettingsView
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('determine-site/', DetermineSiteView.as_view(), name='determine-site'),
|
||||||
|
path('sites/', SiteListView.as_view(), name='site-list'),
|
||||||
|
path('site-settings/<subdomain>/', SiteSettingsView.as_view(), name='site-settings'), ]
|
||||||
|
|
||||||
|
urlpatterns.extend(common_urlpatterns)
|
||||||
|
|
@ -1,39 +1,11 @@
|
||||||
"""Main app views."""
|
"""Main app views."""
|
||||||
|
from django.http import Http404
|
||||||
from rest_framework import generics, permissions
|
from rest_framework import generics, permissions
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
from main import methods, models, serializers
|
from main import methods, models, serializers
|
||||||
from utils.serializers import EmptySerializer
|
|
||||||
|
|
||||||
|
|
||||||
class DetermineSiteView(generics.GenericAPIView):
|
|
||||||
"""Determine user's site."""
|
|
||||||
|
|
||||||
permission_classes = (permissions.AllowAny,)
|
|
||||||
serializer_class = EmptySerializer
|
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
|
||||||
user_ip = methods.get_user_ip(request)
|
|
||||||
country_code = methods.determine_country_code(user_ip)
|
|
||||||
url = methods.determine_user_site_url(country_code)
|
|
||||||
return Response(data={'url': url})
|
|
||||||
|
|
||||||
|
|
||||||
class SiteSettingsView(generics.RetrieveAPIView):
|
|
||||||
"""Site settings View."""
|
|
||||||
|
|
||||||
lookup_field = 'subdomain'
|
|
||||||
permission_classes = (permissions.AllowAny,)
|
|
||||||
queryset = models.SiteSettings.objects.all()
|
|
||||||
serializer_class = serializers.SiteSettingsSerializer
|
|
||||||
|
|
||||||
|
|
||||||
class SiteListView(generics.ListAPIView):
|
|
||||||
"""Site settings View."""
|
|
||||||
|
|
||||||
pagination_class = None
|
|
||||||
permission_classes = (permissions.AllowAny,)
|
|
||||||
queryset = models.SiteSettings.objects.with_country()
|
|
||||||
serializer_class = serializers.SiteSerializer
|
|
||||||
#
|
#
|
||||||
# class FeatureViewMixin:
|
# class FeatureViewMixin:
|
||||||
# """Feature view mixin."""
|
# """Feature view mixin."""
|
||||||
|
|
@ -70,13 +42,14 @@ class SiteListView(generics.ListAPIView):
|
||||||
# class SiteFeaturesRUDView(SiteFeaturesViewMixin,
|
# class SiteFeaturesRUDView(SiteFeaturesViewMixin,
|
||||||
# generics.RetrieveUpdateDestroyAPIView):
|
# generics.RetrieveUpdateDestroyAPIView):
|
||||||
# """Site features RUD."""
|
# """Site features RUD."""
|
||||||
|
from utils.serializers import EmptySerializer
|
||||||
|
|
||||||
|
|
||||||
class AwardView(generics.ListAPIView):
|
class AwardView(generics.ListAPIView):
|
||||||
"""Awards list view."""
|
"""Awards list view."""
|
||||||
serializer_class = serializers.AwardSerializer
|
serializer_class = serializers.AwardSerializer
|
||||||
queryset = models.Award.objects.all()
|
queryset = models.Award.objects.all()
|
||||||
permission_classes = (permissions.AllowAny, )
|
permission_classes = (permissions.AllowAny,)
|
||||||
|
|
||||||
|
|
||||||
class AwardRetrieveView(generics.RetrieveAPIView):
|
class AwardRetrieveView(generics.RetrieveAPIView):
|
||||||
|
|
@ -90,5 +63,22 @@ class CarouselListView(generics.ListAPIView):
|
||||||
"""Return list of carousel items."""
|
"""Return list of carousel items."""
|
||||||
queryset = models.Carousel.objects.all()
|
queryset = models.Carousel.objects.all()
|
||||||
serializer_class = serializers.CarouselListSerializer
|
serializer_class = serializers.CarouselListSerializer
|
||||||
permission_classes = (permissions.AllowAny, )
|
permission_classes = (permissions.AllowAny,)
|
||||||
pagination_class = None
|
pagination_class = None
|
||||||
|
|
||||||
|
|
||||||
|
class DetermineLocation(generics.GenericAPIView):
|
||||||
|
"""Determine user's location."""
|
||||||
|
|
||||||
|
permission_classes = (permissions.AllowAny,)
|
||||||
|
serializer_class = EmptySerializer
|
||||||
|
|
||||||
|
def get(self, request, *args, **kwargs):
|
||||||
|
user_ip = methods.get_user_ip(request)
|
||||||
|
longitude, latitude = methods.determine_coordinates(user_ip)
|
||||||
|
city = methods.determine_user_city(user_ip)
|
||||||
|
if longitude and latitude and city:
|
||||||
|
return Response(data={'latitude': latitude, 'longitude': longitude, 'city': city})
|
||||||
|
else:
|
||||||
|
raise Http404
|
||||||
|
|
||||||
16
apps/main/views/mobile.py
Normal file
16
apps/main/views/mobile.py
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
from rest_framework import generics, permissions
|
||||||
|
|
||||||
|
from main import models, serializers
|
||||||
|
from utils.models import PlatformMixin
|
||||||
|
|
||||||
|
|
||||||
|
class FeaturesView(generics.ListAPIView):
|
||||||
|
pagination_class = None
|
||||||
|
permission_classes = (permissions.AllowAny,)
|
||||||
|
serializer_class = serializers.SiteFeatureSerializer
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
return models.SiteFeature.objects\
|
||||||
|
.prefetch_related('feature', 'feature__route') \
|
||||||
|
.by_country_code(self.request.country_code) \
|
||||||
|
.by_sources([PlatformMixin.ALL, PlatformMixin.MOBILE])
|
||||||
38
apps/main/views/web.py
Normal file
38
apps/main/views/web.py
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
from typing import Iterable
|
||||||
|
|
||||||
|
from rest_framework import generics, permissions
|
||||||
|
|
||||||
|
from utils.serializers import EmptySerializer
|
||||||
|
from rest_framework.response import Response
|
||||||
|
from main import methods, models, serializers
|
||||||
|
|
||||||
|
|
||||||
|
class DetermineSiteView(generics.GenericAPIView):
|
||||||
|
"""Determine user's site."""
|
||||||
|
|
||||||
|
permission_classes = (permissions.AllowAny,)
|
||||||
|
serializer_class = EmptySerializer
|
||||||
|
|
||||||
|
def get(self, request, *args, **kwargs):
|
||||||
|
user_ip = methods.get_user_ip(request)
|
||||||
|
country_code = methods.determine_country_code(user_ip)
|
||||||
|
url = methods.determine_user_site_url(country_code)
|
||||||
|
return Response(data={'url': url})
|
||||||
|
|
||||||
|
|
||||||
|
class SiteSettingsView(generics.RetrieveAPIView):
|
||||||
|
"""Site settings View."""
|
||||||
|
|
||||||
|
lookup_field = 'subdomain'
|
||||||
|
permission_classes = (permissions.AllowAny,)
|
||||||
|
queryset = models.SiteSettings.objects.all()
|
||||||
|
serializer_class = serializers.SiteSettingsSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class SiteListView(generics.ListAPIView):
|
||||||
|
"""Site settings View."""
|
||||||
|
|
||||||
|
pagination_class = None
|
||||||
|
permission_classes = (permissions.AllowAny,)
|
||||||
|
queryset = models.SiteSettings.objects.with_country()
|
||||||
|
serializer_class = serializers.SiteSerializer
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from news import models
|
from news import models
|
||||||
from .tasks import send_email_with_news
|
from .tasks import send_email_with_news
|
||||||
|
|
||||||
|
|
||||||
@admin.register(models.NewsType)
|
@admin.register(models.NewsType)
|
||||||
class NewsTypeAdmin(admin.ModelAdmin):
|
class NewsTypeAdmin(admin.ModelAdmin):
|
||||||
"""News type admin."""
|
"""News type admin."""
|
||||||
|
|
|
||||||
24
apps/news/migrations/0021_auto_20191009_1408.py
Normal file
24
apps/news/migrations/0021_auto_20191009_1408.py
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-09 14:08
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('tag', '0002_auto_20191009_1408'),
|
||||||
|
('news', '0020_remove_news_author'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='news',
|
||||||
|
name='tags',
|
||||||
|
field=models.ManyToManyField(related_name='news', to='tag.Tag', verbose_name='Tags'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='newstype',
|
||||||
|
name='tag_categories',
|
||||||
|
field=models.ManyToManyField(related_name='news_types', to='tag.TagCategory'),
|
||||||
|
),
|
||||||
|
]
|
||||||
57
apps/news/migrations/0022_auto_20191021_1306.py
Normal file
57
apps/news/migrations/0022_auto_20191021_1306.py
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-21 13:06
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
import django.utils.timezone
|
||||||
|
import utils.models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('location', '0012_data_migrate'),
|
||||||
|
('news', '0021_auto_20191009_1408'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='NewsBanner',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('created', models.DateTimeField(default=django.utils.timezone.now, editable=False, verbose_name='Date created')),
|
||||||
|
('modified', models.DateTimeField(auto_now=True, verbose_name='Date updated')),
|
||||||
|
('title', utils.models.TJSONField(blank=True, default=None, help_text='{"en-GB":"some text"}', null=True, verbose_name='title')),
|
||||||
|
('image_url', models.URLField(blank=True, default=None, null=True, verbose_name='Image URL path')),
|
||||||
|
('content_url', models.URLField(blank=True, default=None, null=True, verbose_name='Content URL path')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'abstract': False,
|
||||||
|
},
|
||||||
|
bases=(models.Model, utils.models.TranslatedFieldsMixin),
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Agenda',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('created', models.DateTimeField(default=django.utils.timezone.now, editable=False, verbose_name='Date created')),
|
||||||
|
('modified', models.DateTimeField(auto_now=True, verbose_name='Date updated')),
|
||||||
|
('event_datetime', models.DateTimeField(default=django.utils.timezone.now, editable=False, verbose_name='Event datetime')),
|
||||||
|
('content', utils.models.TJSONField(blank=True, default=None, help_text='{"en-GB":"some text"}', null=True, verbose_name='content')),
|
||||||
|
('address', models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.SET_NULL, to='location.Address', verbose_name='address')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'abstract': False,
|
||||||
|
},
|
||||||
|
bases=(models.Model, utils.models.TranslatedFieldsMixin),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='news',
|
||||||
|
name='agenda',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='news.Agenda', verbose_name='agenda'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='news',
|
||||||
|
name='banner',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='news.NewsBanner', verbose_name='banner'),
|
||||||
|
),
|
||||||
|
]
|
||||||
18
apps/news/migrations/0023_auto_20191023_0903.py
Normal file
18
apps/news/migrations/0023_auto_20191023_0903.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-23 09:03
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('news', '0022_auto_20191021_1306'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='news',
|
||||||
|
name='slug',
|
||||||
|
field=models.SlugField(max_length=255, unique=True, verbose_name='News slug'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -4,7 +4,7 @@ from django.contrib.contenttypes import fields as generic
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from rest_framework.reverse import reverse
|
from rest_framework.reverse import reverse
|
||||||
from utils.models import BaseAttributes, TJSONField, TranslatedFieldsMixin
|
from utils.models import BaseAttributes, TJSONField, TranslatedFieldsMixin, ProjectBaseMixin
|
||||||
from rating.models import Rating
|
from rating.models import Rating
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -12,6 +12,8 @@ class NewsType(models.Model):
|
||||||
"""NewsType model."""
|
"""NewsType model."""
|
||||||
|
|
||||||
name = models.CharField(_('name'), max_length=250)
|
name = models.CharField(_('name'), max_length=250)
|
||||||
|
tag_categories = models.ManyToManyField('tag.TagCategory',
|
||||||
|
related_name='news_types')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""Meta class."""
|
"""Meta class."""
|
||||||
|
|
@ -36,7 +38,7 @@ class NewsQuerySet(models.QuerySet):
|
||||||
|
|
||||||
def with_extended_related(self):
|
def with_extended_related(self):
|
||||||
"""Return qs with related objects."""
|
"""Return qs with related objects."""
|
||||||
return self.select_related('created_by')
|
return self.select_related('created_by', 'agenda', 'banner')
|
||||||
|
|
||||||
def by_type(self, news_type):
|
def by_type(self, news_type):
|
||||||
"""Filter News by type"""
|
"""Filter News by type"""
|
||||||
|
|
@ -59,15 +61,39 @@ class NewsQuerySet(models.QuerySet):
|
||||||
# todo: filter by best score
|
# todo: filter by best score
|
||||||
# todo: filter by country?
|
# todo: filter by country?
|
||||||
def should_read(self, news):
|
def should_read(self, news):
|
||||||
return self.model.objects.exclude(pk=news.pk).published().\
|
return self.model.objects.exclude(pk=news.pk).published(). \
|
||||||
with_base_related().by_type(news.news_type).distinct().order_by('?')
|
with_base_related().by_type(news.news_type).distinct().order_by('?')
|
||||||
|
|
||||||
def same_theme(self, news):
|
def same_theme(self, news):
|
||||||
return self.model.objects.exclude(pk=news.pk).published().\
|
return self.model.objects.exclude(pk=news.pk).published(). \
|
||||||
with_base_related().by_type(news.news_type).\
|
with_base_related().by_type(news.news_type). \
|
||||||
by_tags(news.tags.all()).distinct().order_by('-start')
|
by_tags(news.tags.all()).distinct().order_by('-start')
|
||||||
|
|
||||||
|
|
||||||
|
class Agenda(ProjectBaseMixin, TranslatedFieldsMixin):
|
||||||
|
"""News agenda model"""
|
||||||
|
|
||||||
|
event_datetime = models.DateTimeField(default=timezone.now, editable=False,
|
||||||
|
verbose_name=_('Event datetime'))
|
||||||
|
address = models.ForeignKey('location.Address', blank=True, null=True,
|
||||||
|
default=None, verbose_name=_('address'),
|
||||||
|
on_delete=models.SET_NULL)
|
||||||
|
content = TJSONField(blank=True, null=True, default=None,
|
||||||
|
verbose_name=_('content'),
|
||||||
|
help_text='{"en-GB":"some text"}')
|
||||||
|
|
||||||
|
|
||||||
|
class NewsBanner(ProjectBaseMixin, TranslatedFieldsMixin):
|
||||||
|
"""News banner model"""
|
||||||
|
title = TJSONField(blank=True, null=True, default=None,
|
||||||
|
verbose_name=_('title'),
|
||||||
|
help_text='{"en-GB":"some text"}')
|
||||||
|
image_url = models.URLField(verbose_name=_('Image URL path'),
|
||||||
|
blank=True, null=True, default=None)
|
||||||
|
content_url = models.URLField(verbose_name=_('Content URL path'),
|
||||||
|
blank=True, null=True, default=None)
|
||||||
|
|
||||||
|
|
||||||
class News(BaseAttributes, TranslatedFieldsMixin):
|
class News(BaseAttributes, TranslatedFieldsMixin):
|
||||||
"""News model."""
|
"""News model."""
|
||||||
|
|
||||||
|
|
@ -113,15 +139,13 @@ class News(BaseAttributes, TranslatedFieldsMixin):
|
||||||
start = models.DateTimeField(verbose_name=_('Start'))
|
start = models.DateTimeField(verbose_name=_('Start'))
|
||||||
end = models.DateTimeField(blank=True, null=True, default=None,
|
end = models.DateTimeField(blank=True, null=True, default=None,
|
||||||
verbose_name=_('End'))
|
verbose_name=_('End'))
|
||||||
slug = models.SlugField(unique=True, max_length=50,
|
slug = models.SlugField(unique=True, max_length=255,
|
||||||
verbose_name=_('News slug'))
|
verbose_name=_('News slug'))
|
||||||
playlist = models.IntegerField(_('playlist'))
|
playlist = models.IntegerField(_('playlist'))
|
||||||
state = models.PositiveSmallIntegerField(default=WAITING, choices=STATE_CHOICES,
|
state = models.PositiveSmallIntegerField(default=WAITING, choices=STATE_CHOICES,
|
||||||
verbose_name=_('State'))
|
verbose_name=_('State'))
|
||||||
is_highlighted = models.BooleanField(default=False,
|
is_highlighted = models.BooleanField(default=False,
|
||||||
verbose_name=_('Is highlighted'))
|
verbose_name=_('Is highlighted'))
|
||||||
# TODO: metadata_keys - описание ключей для динамического построения полей метаданных
|
|
||||||
# TODO: metadata_values - Описание значений для динамических полей из MetadataKeys
|
|
||||||
image_url = models.URLField(blank=True, null=True, default=None,
|
image_url = models.URLField(blank=True, null=True, default=None,
|
||||||
verbose_name=_('Image URL path'))
|
verbose_name=_('Image URL path'))
|
||||||
preview_image_url = models.URLField(blank=True, null=True, default=None,
|
preview_image_url = models.URLField(blank=True, null=True, default=None,
|
||||||
|
|
@ -133,10 +157,18 @@ class News(BaseAttributes, TranslatedFieldsMixin):
|
||||||
country = models.ForeignKey('location.Country', blank=True, null=True,
|
country = models.ForeignKey('location.Country', blank=True, null=True,
|
||||||
on_delete=models.SET_NULL,
|
on_delete=models.SET_NULL,
|
||||||
verbose_name=_('country'))
|
verbose_name=_('country'))
|
||||||
tags = generic.GenericRelation(to='main.MetaDataContent')
|
tags = models.ManyToManyField('tag.Tag', related_name='news',
|
||||||
|
verbose_name=_('Tags'))
|
||||||
ratings = generic.GenericRelation(Rating)
|
ratings = generic.GenericRelation(Rating)
|
||||||
|
|
||||||
|
agenda = models.ForeignKey('news.Agenda', blank=True, null=True,
|
||||||
|
on_delete=models.SET_NULL,
|
||||||
|
verbose_name=_('agenda'))
|
||||||
|
|
||||||
|
banner = models.ForeignKey('news.NewsBanner', blank=True, null=True,
|
||||||
|
on_delete=models.SET_NULL,
|
||||||
|
verbose_name=_('banner'))
|
||||||
|
|
||||||
objects = NewsQuerySet.as_manager()
|
objects = NewsQuerySet.as_manager()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
@ -163,4 +195,3 @@ class News(BaseAttributes, TranslatedFieldsMixin):
|
||||||
@property
|
@property
|
||||||
def same_theme(self):
|
def same_theme(self):
|
||||||
return self.__class__.objects.same_theme(self)[:3]
|
return self.__class__.objects.same_theme(self)[:3]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,46 @@
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from account.serializers.common import UserBaseSerializer
|
from account.serializers.common import UserBaseSerializer
|
||||||
from location import models as location_models
|
from location import models as location_models
|
||||||
from location.serializers import CountrySimpleSerializer
|
from location.serializers import CountrySimpleSerializer, AddressBaseSerializer
|
||||||
from main.serializers import MetaDataContentSerializer
|
|
||||||
from news import models
|
from news import models
|
||||||
|
from tag.serializers import TagBaseSerializer
|
||||||
from utils.serializers import TranslatedField, ProjectModelSerializer
|
from utils.serializers import TranslatedField, ProjectModelSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class AgendaSerializer(ProjectModelSerializer):
|
||||||
|
event_datetime = serializers.DateTimeField()
|
||||||
|
address = AddressBaseSerializer()
|
||||||
|
content_translated = TranslatedField()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
"""Meta class."""
|
||||||
|
|
||||||
|
model = models.Agenda
|
||||||
|
fields = (
|
||||||
|
'id',
|
||||||
|
'event_datetime',
|
||||||
|
'address',
|
||||||
|
'content_translated'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class NewsBannerSerializer(ProjectModelSerializer):
|
||||||
|
title_translated = TranslatedField()
|
||||||
|
image_url = serializers.URLField()
|
||||||
|
content_url = serializers.URLField()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
"""Meta class."""
|
||||||
|
|
||||||
|
model = models.NewsBanner
|
||||||
|
fields = (
|
||||||
|
'id',
|
||||||
|
'title_translated',
|
||||||
|
'image_url',
|
||||||
|
'content_url'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class NewsTypeSerializer(serializers.ModelSerializer):
|
class NewsTypeSerializer(serializers.ModelSerializer):
|
||||||
"""News type serializer."""
|
"""News type serializer."""
|
||||||
|
|
||||||
|
|
@ -22,12 +56,12 @@ class NewsBaseSerializer(ProjectModelSerializer):
|
||||||
"""Base serializer for News model."""
|
"""Base serializer for News model."""
|
||||||
|
|
||||||
# read only fields
|
# read only fields
|
||||||
title_translated = TranslatedField()
|
title_translated = TranslatedField(source='title')
|
||||||
subtitle_translated = TranslatedField()
|
subtitle_translated = TranslatedField()
|
||||||
|
|
||||||
# related fields
|
# related fields
|
||||||
news_type = NewsTypeSerializer(read_only=True)
|
news_type = NewsTypeSerializer(read_only=True)
|
||||||
tags = MetaDataContentSerializer(read_only=True, many=True)
|
tags = TagBaseSerializer(read_only=True, many=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""Meta class."""
|
"""Meta class."""
|
||||||
|
|
@ -76,6 +110,8 @@ class NewsDetailWebSerializer(NewsDetailSerializer):
|
||||||
|
|
||||||
same_theme = NewsBaseSerializer(many=True, read_only=True)
|
same_theme = NewsBaseSerializer(many=True, read_only=True)
|
||||||
should_read = NewsBaseSerializer(many=True, read_only=True)
|
should_read = NewsBaseSerializer(many=True, read_only=True)
|
||||||
|
agenda = AgendaSerializer()
|
||||||
|
banner = NewsBannerSerializer()
|
||||||
|
|
||||||
class Meta(NewsDetailSerializer.Meta):
|
class Meta(NewsDetailSerializer.Meta):
|
||||||
"""Meta class."""
|
"""Meta class."""
|
||||||
|
|
@ -83,6 +119,8 @@ class NewsDetailWebSerializer(NewsDetailSerializer):
|
||||||
fields = NewsDetailSerializer.Meta.fields + (
|
fields = NewsDetailSerializer.Meta.fields + (
|
||||||
'same_theme',
|
'same_theme',
|
||||||
'should_read',
|
'should_read',
|
||||||
|
'agenda',
|
||||||
|
'banner'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -116,10 +154,9 @@ class NewsBackOfficeDetailSerializer(NewsBackOfficeBaseSerializer,
|
||||||
|
|
||||||
fields = NewsBackOfficeBaseSerializer.Meta.fields + \
|
fields = NewsBackOfficeBaseSerializer.Meta.fields + \
|
||||||
NewsDetailSerializer.Meta.fields + (
|
NewsDetailSerializer.Meta.fields + (
|
||||||
'description',
|
'description',
|
||||||
'news_type_id',
|
'news_type_id',
|
||||||
'country_id',
|
'country_id',
|
||||||
'template',
|
'template',
|
||||||
'template_display',
|
'template_display',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
from django.urls import reverse
|
||||||
from http.cookies import SimpleCookie
|
from http.cookies import SimpleCookie
|
||||||
|
|
||||||
from rest_framework.test import APITestCase
|
from rest_framework.test import APITestCase
|
||||||
|
|
@ -5,8 +6,9 @@ from rest_framework import status
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from news.models import NewsType, News
|
from news.models import NewsType, News
|
||||||
from account.models import User
|
from account.models import User, Role, UserRole
|
||||||
|
from translation.models import Language
|
||||||
|
from location.models import Country
|
||||||
# Create your tests here.
|
# Create your tests here.
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -22,23 +24,51 @@ class BaseTestCase(APITestCase):
|
||||||
self.client.cookies = SimpleCookie({'access_token': tokkens.get('access_token'),
|
self.client.cookies = SimpleCookie({'access_token': tokkens.get('access_token'),
|
||||||
'refresh_token': tokkens.get('refresh_token')})
|
'refresh_token': tokkens.get('refresh_token')})
|
||||||
self.test_news_type = NewsType.objects.create(name="Test news type")
|
self.test_news_type = NewsType.objects.create(name="Test news type")
|
||||||
self.test_news = News.objects.create(created_by=self.user, modified_by=self.user, title={"en-GB": "Test news"},
|
|
||||||
news_type=self.test_news_type, description={"en-GB": "Description test news"},
|
self.lang = Language.objects.get(
|
||||||
|
title='Russia',
|
||||||
|
locale='ru-RU'
|
||||||
|
)
|
||||||
|
|
||||||
|
self.country_ru = Country.objects.get(
|
||||||
|
name={"en-GB": "Russian"}
|
||||||
|
)
|
||||||
|
|
||||||
|
role = Role.objects.create(
|
||||||
|
role=Role.CONTENT_PAGE_MANAGER,
|
||||||
|
country=self.country_ru
|
||||||
|
)
|
||||||
|
role.save()
|
||||||
|
|
||||||
|
user_role = UserRole.objects.create(
|
||||||
|
user=self.user,
|
||||||
|
role=role
|
||||||
|
)
|
||||||
|
user_role.save()
|
||||||
|
|
||||||
|
self.test_news = News.objects.create(created_by=self.user, modified_by=self.user,
|
||||||
|
title={"en-GB": "Test news"},
|
||||||
|
news_type=self.test_news_type,
|
||||||
|
description={"en-GB": "Description test news"},
|
||||||
playlist=1, start=datetime.now() + timedelta(hours=-2),
|
playlist=1, start=datetime.now() + timedelta(hours=-2),
|
||||||
end=datetime.now() + timedelta(hours=2),
|
end=datetime.now() + timedelta(hours=2),
|
||||||
state=News.PUBLISHED, slug='test-news-slug',)
|
state=News.PUBLISHED, slug='test-news-slug',
|
||||||
|
country=self.country_ru)
|
||||||
|
|
||||||
class NewsTestCase(BaseTestCase):
|
class NewsTestCase(BaseTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
|
||||||
def test_news_list(self):
|
def test_web_news(self):
|
||||||
response = self.client.get("/api/web/news/")
|
response = self.client.get("/api/web/news/")
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
def test_news_web_detail(self):
|
|
||||||
response = self.client.get(f"/api/web/news/slug/{self.test_news.slug}/")
|
response = self.client.get(f"/api/web/news/slug/{self.test_news.slug}/")
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
response = self.client.get("/api/web/news/types/")
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
def test_news_back_detail(self):
|
def test_news_back_detail(self):
|
||||||
response = self.client.get(f"/api/back/news/{self.test_news.id}/")
|
response = self.client.get(f"/api/back/news/{self.test_news.id}/")
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
@ -47,6 +77,18 @@ class NewsTestCase(BaseTestCase):
|
||||||
response = self.client.get("/api/back/news/")
|
response = self.client.get("/api/back/news/")
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
def test_news_type_list(self):
|
def test_news_back_detail_put(self):
|
||||||
response = self.client.get("/api/web/news/types/")
|
# retrieve-update-destroy
|
||||||
|
url = reverse('back:news:retrieve-update-destroy', kwargs={'pk': self.test_news.id})
|
||||||
|
data = {
|
||||||
|
'id': self.test_news.id,
|
||||||
|
'description': {"en-GB": "Description test news!"},
|
||||||
|
'slug': self.test_news.slug,
|
||||||
|
'start': self.test_news.start,
|
||||||
|
'playlist': self.test_news.playlist,
|
||||||
|
'news_type_id':self.test_news.news_type_id,
|
||||||
|
'country_id': self.country_ru.id
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self.client.put(url, data=data, format='json')
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
"""News app views."""
|
"""News app views."""
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
from rest_framework import generics, permissions
|
from rest_framework import generics, permissions
|
||||||
from news import filters, models, serializers
|
from news import filters, models, serializers
|
||||||
from rating.tasks import add_rating
|
from rating.tasks import add_rating
|
||||||
|
from utils.permissions import IsCountryAdmin, IsContentPageManager
|
||||||
|
|
||||||
|
|
||||||
class NewsMixinView:
|
class NewsMixinView:
|
||||||
"""News mixin."""
|
"""News mixin."""
|
||||||
|
|
@ -34,6 +37,7 @@ class NewsDetailView(NewsMixinView, generics.RetrieveAPIView):
|
||||||
"""Override get_queryset method."""
|
"""Override get_queryset method."""
|
||||||
return super().get_queryset().with_extended_related()
|
return super().get_queryset().with_extended_related()
|
||||||
|
|
||||||
|
|
||||||
class NewsTypeListView(generics.ListAPIView):
|
class NewsTypeListView(generics.ListAPIView):
|
||||||
"""NewsType list view."""
|
"""NewsType list view."""
|
||||||
|
|
||||||
|
|
@ -57,6 +61,7 @@ class NewsBackOfficeLCView(NewsBackOfficeMixinView,
|
||||||
|
|
||||||
serializer_class = serializers.NewsBackOfficeBaseSerializer
|
serializer_class = serializers.NewsBackOfficeBaseSerializer
|
||||||
create_serializers_class = serializers.NewsBackOfficeDetailSerializer
|
create_serializers_class = serializers.NewsBackOfficeDetailSerializer
|
||||||
|
permission_classes = [IsCountryAdmin|IsContentPageManager]
|
||||||
|
|
||||||
def get_serializer_class(self):
|
def get_serializer_class(self):
|
||||||
"""Override serializer class."""
|
"""Override serializer class."""
|
||||||
|
|
@ -74,6 +79,7 @@ class NewsBackOfficeRUDView(NewsBackOfficeMixinView,
|
||||||
"""Resource for detailed information about news for back-office users."""
|
"""Resource for detailed information about news for back-office users."""
|
||||||
|
|
||||||
serializer_class = serializers.NewsBackOfficeDetailSerializer
|
serializer_class = serializers.NewsBackOfficeDetailSerializer
|
||||||
|
permission_classes = [IsCountryAdmin|IsContentPageManager]
|
||||||
|
|
||||||
def get(self, request, pk, *args, **kwargs):
|
def get(self, request, pk, *args, **kwargs):
|
||||||
add_rating(remote_addr=request.META.get('REMOTE_ADDR'),
|
add_rating(remote_addr=request.META.get('REMOTE_ADDR'),
|
||||||
|
|
|
||||||
7
apps/product/apps.py
Normal file
7
apps/product/apps.py
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
|
class ProductConfig(AppConfig):
|
||||||
|
name = 'product'
|
||||||
|
verbose_name = _('Product')
|
||||||
110
apps/product/models.py
Normal file
110
apps/product/models.py
Normal file
|
|
@ -0,0 +1,110 @@
|
||||||
|
"""Product app models."""
|
||||||
|
from django.db import models
|
||||||
|
from django.contrib.postgres.fields import JSONField
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from utils.models import (BaseAttributes, ProjectBaseMixin,
|
||||||
|
TranslatedFieldsMixin, TJSONField)
|
||||||
|
|
||||||
|
|
||||||
|
class ProductType(TranslatedFieldsMixin, ProjectBaseMixin):
|
||||||
|
"""ProductType model."""
|
||||||
|
|
||||||
|
name = TJSONField(blank=True, null=True, default=None,
|
||||||
|
verbose_name=_('Name'), help_text='{"en-GB":"some text"}')
|
||||||
|
index_name = models.CharField(max_length=50, unique=True, db_index=True,
|
||||||
|
verbose_name=_('Index name'))
|
||||||
|
use_subtypes = models.BooleanField(_('Use subtypes'), default=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
"""Meta class."""
|
||||||
|
|
||||||
|
verbose_name = _('Product type')
|
||||||
|
verbose_name_plural = _('Product types')
|
||||||
|
|
||||||
|
|
||||||
|
class ProductSubType(TranslatedFieldsMixin, ProjectBaseMixin):
|
||||||
|
"""ProductSubtype model."""
|
||||||
|
|
||||||
|
product_type = models.ForeignKey(ProductType, on_delete=models.CASCADE,
|
||||||
|
related_name='subtypes',
|
||||||
|
verbose_name=_('Product type'))
|
||||||
|
name = TJSONField(blank=True, null=True, default=None,
|
||||||
|
verbose_name=_('Name'), help_text='{"en-GB":"some text"}')
|
||||||
|
index_name = models.CharField(max_length=50, unique=True, db_index=True,
|
||||||
|
verbose_name=_('Index name'))
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
"""Meta class."""
|
||||||
|
|
||||||
|
verbose_name = _('Product type')
|
||||||
|
verbose_name_plural = _('Product types')
|
||||||
|
|
||||||
|
|
||||||
|
class ProductManager(models.Manager):
|
||||||
|
"""Extended manager for Product model."""
|
||||||
|
|
||||||
|
|
||||||
|
class ProductQuerySet(models.QuerySet):
|
||||||
|
"""Product queryset."""
|
||||||
|
|
||||||
|
def common(self):
|
||||||
|
return self.filter(category=self.model.COMMON)
|
||||||
|
|
||||||
|
def online(self):
|
||||||
|
return self.filter(category=self.model.ONLINE)
|
||||||
|
|
||||||
|
|
||||||
|
class Product(TranslatedFieldsMixin, BaseAttributes):
|
||||||
|
"""Product models."""
|
||||||
|
|
||||||
|
COMMON = 0
|
||||||
|
ONLINE = 1
|
||||||
|
|
||||||
|
CATEGORY_CHOICES = (
|
||||||
|
(COMMON, _('Common')),
|
||||||
|
(ONLINE, _('Online')),
|
||||||
|
)
|
||||||
|
|
||||||
|
category = models.PositiveIntegerField(choices=CATEGORY_CHOICES,
|
||||||
|
default=COMMON)
|
||||||
|
name = TJSONField(_('Name'), null=True, blank=True, default=None,
|
||||||
|
help_text='{"en-GB":"some text"}')
|
||||||
|
description = TJSONField(_('Description'), null=True, blank=True,
|
||||||
|
default=None, help_text='{"en-GB":"some text"}')
|
||||||
|
characteristics = JSONField(_('Characteristics'))
|
||||||
|
country = models.ForeignKey('location.Country', on_delete=models.PROTECT,
|
||||||
|
verbose_name=_('Country'))
|
||||||
|
available = models.BooleanField(_('Available'), default=True)
|
||||||
|
type = models.ForeignKey(ProductType, on_delete=models.PROTECT,
|
||||||
|
related_name='products', verbose_name=_('Type'))
|
||||||
|
subtypes = models.ManyToManyField(ProductSubType, related_name='products',
|
||||||
|
verbose_name=_('Subtypes'))
|
||||||
|
|
||||||
|
objects = ProductManager.from_queryset(ProductQuerySet)()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
"""Meta class."""
|
||||||
|
|
||||||
|
verbose_name = _('Product')
|
||||||
|
verbose_name_plural = _('Products')
|
||||||
|
|
||||||
|
|
||||||
|
class OnlineProductManager(ProductManager):
|
||||||
|
"""Extended manger for OnlineProduct model."""
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
"""Overrided get_queryset method."""
|
||||||
|
return super().get_queryset().online()
|
||||||
|
|
||||||
|
|
||||||
|
class OnlineProduct(Product):
|
||||||
|
"""Online product."""
|
||||||
|
|
||||||
|
objects = OnlineProductManager.from_queryset(ProductQuerySet)()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
"""Meta class."""
|
||||||
|
|
||||||
|
proxy = True
|
||||||
|
verbose_name = _('Online product')
|
||||||
|
verbose_name_plural = _('Online products')
|
||||||
0
apps/product/views/common.py
Normal file
0
apps/product/views/common.py
Normal file
0
apps/product/views/mobile.py
Normal file
0
apps/product/views/mobile.py
Normal file
0
apps/product/views/web.py
Normal file
0
apps/product/views/web.py
Normal file
|
|
@ -1,3 +0,0 @@
|
||||||
from django.contrib import admin
|
|
||||||
|
|
||||||
# Register your models here.
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
from django.apps import AppConfig
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class ProductsConfig(AppConfig):
|
|
||||||
"""Products model."""
|
|
||||||
name = 'products'
|
|
||||||
verbose_name = _('products')
|
|
||||||
|
|
@ -1,63 +0,0 @@
|
||||||
# from django.contrib.postgres.fields import JSONField
|
|
||||||
# from django.db import models
|
|
||||||
# from django.utils.translation import gettext_lazy as _
|
|
||||||
#
|
|
||||||
# from utils.models import BaseAttributes
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# class ProductManager(models.Manager):
|
|
||||||
# """Product manager."""
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# class ProductQuerySet(models.QuerySet):
|
|
||||||
# """Product queryset."""
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# class Product(BaseAttributes):
|
|
||||||
# """Product models."""
|
|
||||||
# name = models.CharField(_('name'), max_length=255)
|
|
||||||
# country = models.ForeignKey('location.Country', on_delete=models.CASCADE)
|
|
||||||
# region = models.ForeignKey('location.Region', on_delete=models.CASCADE)
|
|
||||||
# # ASK: What is the "subregion"
|
|
||||||
#
|
|
||||||
# description = JSONField(_('description'))
|
|
||||||
# characteristics = JSONField(_('characteristics'))
|
|
||||||
# metadata_values = JSONField(_('metadata_values'))
|
|
||||||
# # common_relations_id
|
|
||||||
# # product_region_id
|
|
||||||
# code = models.CharField(_('code'), max_length=255)
|
|
||||||
# available = models.BooleanField(_('available'))
|
|
||||||
#
|
|
||||||
# # dealer_type
|
|
||||||
# # target_scope
|
|
||||||
# # target_type
|
|
||||||
# # rank
|
|
||||||
# # excluding_tax_unit_price
|
|
||||||
# # column_21
|
|
||||||
# # currencies_id
|
|
||||||
# # vintage
|
|
||||||
# # producer_price
|
|
||||||
# # producer_description
|
|
||||||
# # annual_produced_quantity
|
|
||||||
# # production_method_description
|
|
||||||
# # unit_name
|
|
||||||
# # unit
|
|
||||||
# # unit_values
|
|
||||||
# # organic_source
|
|
||||||
# # certificates
|
|
||||||
# # establishments_id
|
|
||||||
# # restrictions
|
|
||||||
# #
|
|
||||||
# objects = ProductManager.from_queryset(ProductQuerySet)()
|
|
||||||
#
|
|
||||||
# class Meta:
|
|
||||||
# verbose_name = _('product')
|
|
||||||
# verbose_name_plural = _('products')
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# class ProductType(models.Model):
|
|
||||||
# """ProductType model."""
|
|
||||||
#
|
|
||||||
# class Meta:
|
|
||||||
# verbose_name_plural = _('product types')
|
|
||||||
# verbose_name = _('product type')
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
# Create your views here.
|
|
||||||
20
apps/review/migrations/0004_review_country.py
Normal file
20
apps/review/migrations/0004_review_country.py
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-17 12:17
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('location', '0012_data_migrate'),
|
||||||
|
('review', '0003_review_text'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='review',
|
||||||
|
name='country',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='country', to='location.Country', verbose_name='Country'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -65,6 +65,9 @@ class Review(BaseAttributes, TranslatedFieldsMixin):
|
||||||
validators=[MinValueValidator(1900),
|
validators=[MinValueValidator(1900),
|
||||||
MaxValueValidator(2100)])
|
MaxValueValidator(2100)])
|
||||||
|
|
||||||
|
country = models.ForeignKey('location.Country', on_delete=models.CASCADE,
|
||||||
|
related_name='country', verbose_name=_('Country'),
|
||||||
|
null=True)
|
||||||
objects = ReviewQuerySet.as_manager()
|
objects = ReviewQuerySet.as_manager()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
||||||
18
apps/review/serializers/back.py
Normal file
18
apps/review/serializers/back.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
"""Review app common serializers."""
|
||||||
|
from review import models
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
|
||||||
|
class ReviewBaseSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = models.Review
|
||||||
|
fields = ('id',
|
||||||
|
'reviewer',
|
||||||
|
'text',
|
||||||
|
'language',
|
||||||
|
'status',
|
||||||
|
'child',
|
||||||
|
'published_at',
|
||||||
|
'vintage',
|
||||||
|
'country'
|
||||||
|
)
|
||||||
11
apps/review/urls/back.py
Normal file
11
apps/review/urls/back.py
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
"""Back review URLs"""
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
from review.views import back as views
|
||||||
|
|
||||||
|
app_name = 'review'
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('', views.ReviewLstView.as_view(), name='review-list-create'),
|
||||||
|
path('<int:id>/', views.ReviewRUDView.as_view(), name='review-crud'),
|
||||||
|
]
|
||||||
19
apps/review/views/back.py
Normal file
19
apps/review/views/back.py
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
from rest_framework import generics, permissions
|
||||||
|
from review.serializers import back as serializers
|
||||||
|
from review import models
|
||||||
|
from utils.permissions import IsReviewerManager, IsRestaurantReviewer
|
||||||
|
|
||||||
|
|
||||||
|
class ReviewLstView(generics.ListCreateAPIView):
|
||||||
|
"""Comment list create view."""
|
||||||
|
serializer_class = serializers.ReviewBaseSerializer
|
||||||
|
queryset = models.Review.objects.all()
|
||||||
|
permission_classes = [permissions.IsAuthenticatedOrReadOnly,]
|
||||||
|
|
||||||
|
|
||||||
|
class ReviewRUDView(generics.RetrieveUpdateDestroyAPIView):
|
||||||
|
"""Comment RUD view."""
|
||||||
|
serializer_class = serializers.ReviewBaseSerializer
|
||||||
|
queryset = models.Review.objects.all()
|
||||||
|
permission_classes = [IsReviewerManager|IsRestaurantReviewer]
|
||||||
|
lookup_field = 'id'
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user