Merge branch 'develop' into feature/elasticsearch-establishment-tags

This commit is contained in:
evgeniy-st 2019-09-18 11:47:55 +03:00
commit 51d0ae0d60
20 changed files with 156 additions and 32 deletions

View File

@ -1,6 +1,5 @@
"""Serializers for account web"""
from django.contrib.auth import password_validation as password_validators
from django.utils.translation import gettext_lazy as _
from rest_framework import serializers
from account import models
@ -25,7 +24,7 @@ class PasswordResetSerializer(serializers.Serializer):
if not user.is_authenticated:
if not username_or_email:
raise serializers.ValidationError(_('username or email not in request body.'))
raise utils_exceptions.UserNotFoundError()
filters = {}
if username_validator(username_or_email):

View File

@ -116,7 +116,7 @@ class OAuth2SignUpView(OAuth2ViewMixin, JWTGenericViewMixin):
source = serializer.validated_data.get('source')
request_data.update({
'grant_type': settings.OAUTH2_SOCIAL_AUTH_GRANT_TYPE,
'backend': settings.OAUTH2_SOCIAL_AUTH_BACKEND_NAME
'backend': settings.OAUTH2_SOCIAL_AUTH_BACKEND_NAME,
})
# Use the rest framework `.data` to fake the post body of the django request.

View File

@ -0,0 +1,2 @@
from location.serializers.common import *
from location.serializers.back import *

View File

@ -0,0 +1,22 @@
from django.contrib.gis.geos import Point
from rest_framework import serializers
from location import models
from location.serializers import common
class AddressCreateSerializer(common.AddressSerializer):
"""Address create serializer."""
class CountryBackSerializer(common.CountrySerializer):
"""Country back-office serializer."""
class Meta:
model = models.Country
fields = [
'id',
'code',
'svg_image',
'name',
]

View File

@ -23,7 +23,12 @@ class CountrySerializer(serializers.ModelSerializer):
class RegionSerializer(serializers.ModelSerializer):
"""Region serializer"""
country = CountrySerializer()
country = CountrySerializer(read_only=True)
country_id = serializers.PrimaryKeyRelatedField(
source='country',
queryset=models.Country.objects.all(),
write_only=True
)
class Meta:
model = models.Region
@ -32,13 +37,24 @@ class RegionSerializer(serializers.ModelSerializer):
'name',
'code',
'parent_region',
'country'
'country',
'country_id'
]
class CitySerializer(serializers.ModelSerializer):
"""City serializer."""
region = RegionSerializer()
region = RegionSerializer(read_only=True)
region_id = serializers.PrimaryKeyRelatedField(
source='region',
queryset=models.Region.objects.all(),
write_only=True
)
country_id = serializers.PrimaryKeyRelatedField(
source='country',
queryset=models.Country.objects.all(),
write_only=True
)
class Meta:
model = models.City
@ -47,6 +63,8 @@ class CitySerializer(serializers.ModelSerializer):
'name',
'code',
'region',
'region_id',
'country_id',
'postal_code',
'is_island',
]
@ -54,13 +72,18 @@ class CitySerializer(serializers.ModelSerializer):
class AddressSerializer(serializers.ModelSerializer):
"""Address serializer."""
city = CitySerializer()
city_id = serializers.PrimaryKeyRelatedField(
source='city',
queryset=models.City.objects.all())
city = CitySerializer(read_only=True)
geo_lon = serializers.FloatField(allow_null=True)
geo_lat = serializers.FloatField(allow_null=True)
class Meta:
model = models.Address
fields = [
'id',
'city_id',
'city',
'street_name_1',
'street_name_2',
@ -74,9 +97,10 @@ class AddressSerializer(serializers.ModelSerializer):
# if geo_lat and geo_lon was sent
geo_lat = attrs.pop('geo_lat') if 'geo_lat' in attrs else None
geo_lon = attrs.pop('geo_lon') if 'geo_lon' in attrs else None
if geo_lat and geo_lon:
# Point(longitude, latitude)
attrs['location'] = Point(geo_lat, geo_lon)
attrs['coordinates'] = Point(geo_lat, geo_lon)
return attrs
def to_representation(self, instance):

View File

View File

@ -0,0 +1,20 @@
"""Location app back-office urlconf."""
from django.urls import path
from location import views
app_name = 'location'
urlpatterns = [
path('addresses/', views.AddressListCreateView.as_view(), name='address-list-create'),
path('addresses/<int:pk>/', views.AddressRUDView.as_view(), name='address-RUD'),
path('cities/', views.CityListCreateView.as_view(), name='city-list-create'),
path('cities/<int:pk>/', views.CityRUDView.as_view(), name='city-retrieve'),
path('countries/', views.CountryListCreateView.as_view(), name='country-list-create'),
path('countries/<int:pk>/', views.CountryRUDView.as_view(), name='country-retrieve'),
path('regions/', views.RegionListCreateView.as_view(), name='region-list-create'),
path('regions/<int:pk>/', views.RegionRUDView.as_view(), name='region-retrieve'),
]

View File

@ -1,4 +1,4 @@
"""Location app urlconf."""
"""Location app common urlconf."""
from django.urls import path
from location import views

View File

@ -0,0 +1,7 @@
"""Location app mobile urlconf."""
from location.urls.common import urlpatterns as common_urlpatterns
urlpatterns = []
urlpatterns.extend(common_urlpatterns)

View File

@ -0,0 +1,7 @@
"""Location app web urlconf."""
from location.urls.common import urlpatterns as common_urlpatterns
urlpatterns = []
urlpatterns.extend(common_urlpatterns)

View File

@ -0,0 +1,2 @@
from location.views.common import *
from location.views.back import *

View File

@ -0,0 +1,53 @@
"""Location app views."""
from rest_framework import generics
from rest_framework import permissions
from location import models, serializers
from location.views import common
# Address
class AddressListCreateView(common.AddressViewMixin, generics.ListCreateAPIView):
"""Create view for model Address."""
serializer_class = serializers.AddressSerializer
queryset = models.Address.objects.all()
class AddressRUDView(common.AddressViewMixin, generics.RetrieveUpdateDestroyAPIView):
"""RUD view for model Address."""
serializer_class = serializers.AddressSerializer
queryset = models.Address.objects.all()
# City
class CityListCreateView(common.CityViewMixin, generics.ListCreateAPIView):
"""Create view for model City."""
serializer_class = serializers.CitySerializer
class CityRUDView(common.CityViewMixin, generics.RetrieveUpdateDestroyAPIView):
"""RUD view for model City."""
serializer_class = serializers.CitySerializer
# Region
class RegionListCreateView(common.RegionViewMixin, generics.ListCreateAPIView):
"""Create view for model Region"""
serializer_class = serializers.RegionSerializer
class RegionRUDView(common.RegionViewMixin, generics.RetrieveUpdateDestroyAPIView):
"""Retrieve view for model Region"""
serializer_class = serializers.RegionSerializer
# Country
class CountryListCreateView(common.CountryViewMixin, generics.ListCreateAPIView):
"""List/Create view for model Country."""
serializer_class = serializers.CountryBackSerializer
pagination_class = None
class CountryRUDView(common.CountryViewMixin, generics.RetrieveUpdateDestroyAPIView):
"""RUD view for model Country."""
serializer_class = serializers.CountryBackSerializer

View File

@ -3,11 +3,10 @@ from rest_framework import generics
from rest_framework import permissions
from location import models, serializers
from utils.views import JWTGenericViewMixin
# Mixins
class CountryViewMixin(JWTGenericViewMixin, generics.GenericAPIView):
class CountryViewMixin(generics.GenericAPIView):
"""View Mixin for model Country"""
serializer_class = serializers.CountrySerializer
@ -115,13 +114,3 @@ class AddressListView(AddressViewMixin, generics.ListAPIView):
serializer_class = serializers.AddressSerializer
class AddressDestroyView(AddressViewMixin, generics.DestroyAPIView):
"""Destroy view for model Address"""
serializer_class = serializers.AddressSerializer
class AddressUpdateView(AddressViewMixin, generics.UpdateAPIView):
"""Update view for model Address"""
serializer_class = serializers.AddressSerializer

View File

@ -67,7 +67,7 @@ class JWTGenericViewMixin(generics.GenericAPIView):
# todo: remove config for develop
from os import environ
configuration = environ.get('SETTINGS_CONFIGURATION', None)
if configuration == 'development':
if configuration == 'development' or configuration == 'stage':
response.set_cookie(key=cookie.key,
value=cookie.value,
secure=cookie.secure,

View File

@ -256,6 +256,10 @@ OAUTH2_PROVIDER_APPLICATION_MODEL = 'authorization.Application'
# Facebook configuration
SOCIAL_AUTH_FACEBOOK_KEY = '386843648701452'
SOCIAL_AUTH_FACEBOOK_SECRET = 'a71cf0bf3980843a8f1ea74c6d805fd7'
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email', ]
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {
'fields': 'id, name, email',
}
# SMS Settings
SMS_EXPIRATION = 5

View File

@ -3,7 +3,7 @@
{% trans "Please go to the following page for confirmation new email address:" %}
<a href="https://{{ country_code }}.{{ domain_uri }}/registered/{{ uidb64 }}/{{ token }}/">https://{{ country_code }}.{{ domain_uri }}/registered/{{ uidb64 }}/{{ token }}/</a>
https://{{ country_code }}.{{ domain_uri }}/registered/{{ uidb64 }}/{{ token }}/
{% trans "Thanks for using our site!" %}

View File

@ -3,7 +3,7 @@
{% trans "Please go to the following page and choose a new password:" %}
<a href="https://{{ country_code }}.{{ domain_uri }}/recovery/{{ uidb64 }}/{{ token }}/">https://{{ country_code }}.{{ domain_uri }}/recovery/{{ uidb64 }}/{{ token }}/</a>
https://{{ country_code }}.{{ domain_uri }}/recovery/{{ uidb64 }}/{{ token }}/
{% trans "Thanks for using our site!" %}

View File

@ -2,8 +2,7 @@
{% blocktrans %}You're receiving this email because you trying to register new account at {{ site_name }}.{% endblocktrans %}
{% trans "Please confirm your email address to complete the registration:" %}
<a href="https://{{ country_code }}.{{ domain_uri }}/registered/{{ uidb64 }}/{{ token }}/">https://{{ country_code }}.{{ domain_uri }}/registered/{{ uidb64 }}/{{ token }}/</a>
https://{{ country_code }}.{{ domain_uri }}/registered/{{ uidb64 }}/{{ token }}/
{% trans "Thanks for using our site!" %}

View File

@ -5,10 +5,6 @@ app_name = 'back'
urlpatterns = [
path('gallery/', include(('gallery.urls', 'gallery'),
namespace='gallery')),
# path('account/', include('account.urls.web')),
# path('advertisement/', include('advertisement.urls.web')),
# path('collection/', include('collection.urls.web')),
path('establishments/', include('establishment.urls.back')),
# path('news/', include('news.urls.web')),
# path('partner/', include('partner.urls.web')),
path('location/', include('location.urls.back')),
]

View File

@ -25,7 +25,7 @@ urlpatterns = [
path('news/', include('news.urls.web')),
path('notifications/', include('notification.urls.web')),
path('partner/', include('partner.urls.web')),
path('location/', include('location.urls')),
path('location/', include('location.urls.web')),
path('main/', include('main.urls')),
path('translation/', include('translation.urls')),
path('comments/', include('comment.urls.web')),