Merge branch 'develop' into feature/GM-176_standard_user
This commit is contained in:
commit
d6ffbf5332
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ app = 'main'
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('determine-site/', views.DetermineSiteView.as_view(), name='determine-site'),
|
path('determine-site/', views.DetermineSiteView.as_view(), name='determine-site'),
|
||||||
|
path('determine-location/', views.DetermineLocation.as_view(), name='determine-location'),
|
||||||
path('sites/', views.SiteListView.as_view(), name='site-list'),
|
path('sites/', views.SiteListView.as_view(), name='site-list'),
|
||||||
path('site-settings/<subdomain>/', views.SiteSettingsView.as_view(), name='site-settings'),
|
path('site-settings/<subdomain>/', views.SiteSettingsView.as_view(), name='site-settings'),
|
||||||
path('awards/', views.AwardView.as_view(), name='awards_list'),
|
path('awards/', views.AwardView.as_view(), name='awards_list'),
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ 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
|
from utils.serializers import EmptySerializer
|
||||||
|
from django.http import Http404
|
||||||
|
|
||||||
|
|
||||||
class DetermineSiteView(generics.GenericAPIView):
|
class DetermineSiteView(generics.GenericAPIView):
|
||||||
|
|
@ -18,6 +19,22 @@ class DetermineSiteView(generics.GenericAPIView):
|
||||||
return Response(data={'url': url})
|
return Response(data={'url': url})
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
class SiteSettingsView(generics.RetrieveAPIView):
|
class SiteSettingsView(generics.RetrieveAPIView):
|
||||||
"""Site settings View."""
|
"""Site settings View."""
|
||||||
|
|
||||||
|
|
@ -34,6 +51,8 @@ class SiteListView(generics.ListAPIView):
|
||||||
permission_classes = (permissions.AllowAny,)
|
permission_classes = (permissions.AllowAny,)
|
||||||
queryset = models.SiteSettings.objects.with_country()
|
queryset = models.SiteSettings.objects.with_country()
|
||||||
serializer_class = serializers.SiteSerializer
|
serializer_class = serializers.SiteSerializer
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# class FeatureViewMixin:
|
# class FeatureViewMixin:
|
||||||
# """Feature view mixin."""
|
# """Feature view mixin."""
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ services:
|
||||||
- "5436:5432"
|
- "5436:5432"
|
||||||
volumes:
|
volumes:
|
||||||
- gm-db:/var/lib/postgresql/data/
|
- gm-db:/var/lib/postgresql/data/
|
||||||
|
|
||||||
elasticsearch:
|
elasticsearch:
|
||||||
image: elasticsearch:7.3.1
|
image: elasticsearch:7.3.1
|
||||||
volumes:
|
volumes:
|
||||||
|
|
@ -27,11 +28,18 @@ services:
|
||||||
- discovery.type=single-node
|
- discovery.type=single-node
|
||||||
- xpack.security.enabled=false
|
- xpack.security.enabled=false
|
||||||
|
|
||||||
# RabbitMQ
|
# Redis
|
||||||
rabbitmq:
|
redis:
|
||||||
image: rabbitmq:latest
|
image: redis:2.8.23
|
||||||
ports:
|
ports:
|
||||||
- "5672:5672"
|
- "6379:6379"
|
||||||
|
|
||||||
|
# RabbitMQ
|
||||||
|
#rabbitmq:
|
||||||
|
# image: rabbitmq:latest
|
||||||
|
# ports:
|
||||||
|
# - "5672:5672"
|
||||||
|
|
||||||
# Celery
|
# Celery
|
||||||
worker:
|
worker:
|
||||||
build: .
|
build: .
|
||||||
|
|
@ -47,7 +55,9 @@ services:
|
||||||
- .:/code
|
- .:/code
|
||||||
links:
|
links:
|
||||||
- db
|
- db
|
||||||
- rabbitmq
|
# - rabbitmq
|
||||||
|
- redis
|
||||||
|
|
||||||
worker_beat:
|
worker_beat:
|
||||||
build: .
|
build: .
|
||||||
command: ./run_celery_beat.sh
|
command: ./run_celery_beat.sh
|
||||||
|
|
@ -62,7 +72,8 @@ services:
|
||||||
- .:/code
|
- .:/code
|
||||||
links:
|
links:
|
||||||
- db
|
- db
|
||||||
- rabbitmq
|
# - rabbitmq
|
||||||
|
- redis
|
||||||
# App: G&M
|
# App: G&M
|
||||||
gm_app:
|
gm_app:
|
||||||
build: .
|
build: .
|
||||||
|
|
@ -76,7 +87,8 @@ services:
|
||||||
- DB_PASSWORD=postgres
|
- DB_PASSWORD=postgres
|
||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
- rabbitmq
|
# - rabbitmq
|
||||||
|
- redis
|
||||||
- worker
|
- worker
|
||||||
- worker_beat
|
- worker_beat
|
||||||
- elasticsearch
|
- elasticsearch
|
||||||
|
|
|
||||||
|
|
@ -317,7 +317,10 @@ REDOC_SETTINGS = {
|
||||||
}
|
}
|
||||||
|
|
||||||
# CELERY
|
# CELERY
|
||||||
BROKER_URL = 'amqp://rabbitmq:5672'
|
# RabbitMQ
|
||||||
|
# BROKER_URL = 'amqp://rabbitmq:5672'
|
||||||
|
# Redis
|
||||||
|
BROKER_URL = 'redis://localhost:6379/1'
|
||||||
CELERY_RESULT_BACKEND = BROKER_URL
|
CELERY_RESULT_BACKEND = BROKER_URL
|
||||||
CELERY_BROKER_URL = BROKER_URL
|
CELERY_BROKER_URL = BROKER_URL
|
||||||
CELERY_ACCEPT_CONTENT = ['application/json']
|
CELERY_ACCEPT_CONTENT = ['application/json']
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ ALLOWED_HOSTS = ['*', ]
|
||||||
|
|
||||||
SEND_SMS = False
|
SEND_SMS = False
|
||||||
SMS_CODE_SHOW = True
|
SMS_CODE_SHOW = True
|
||||||
USE_CELERY = False
|
USE_CELERY = True
|
||||||
|
|
||||||
SCHEMA_URI = 'http'
|
SCHEMA_URI = 'http'
|
||||||
DEFAULT_SUBDOMAIN = 'www'
|
DEFAULT_SUBDOMAIN = 'www'
|
||||||
|
|
@ -14,7 +14,10 @@ SITE_DOMAIN_URI = 'testserver.com:8000'
|
||||||
DOMAIN_URI = '0.0.0.0:8000'
|
DOMAIN_URI = '0.0.0.0:8000'
|
||||||
|
|
||||||
# CELERY
|
# CELERY
|
||||||
BROKER_URL = 'amqp://rabbitmq:5672'
|
# RabbitMQ
|
||||||
|
# BROKER_URL = 'amqp://rabbitmq:5672'
|
||||||
|
# Redis
|
||||||
|
BROKER_URL = 'redis://redis:6379/1'
|
||||||
CELERY_RESULT_BACKEND = BROKER_URL
|
CELERY_RESULT_BACKEND = BROKER_URL
|
||||||
CELERY_BROKER_URL = BROKER_URL
|
CELERY_BROKER_URL = BROKER_URL
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,6 @@ djangorestframework==3.9.4
|
||||||
markdown
|
markdown
|
||||||
django-filter==2.1.0
|
django-filter==2.1.0
|
||||||
djangorestframework-xml
|
djangorestframework-xml
|
||||||
celery
|
|
||||||
amqp>=2.4.0
|
|
||||||
geoip2==2.9.0
|
geoip2==2.9.0
|
||||||
django-phonenumber-field[phonenumbers]==2.1.0
|
django-phonenumber-field[phonenumbers]==2.1.0
|
||||||
|
|
||||||
|
|
@ -34,3 +32,8 @@ djangorestframework-simplejwt==4.3.0
|
||||||
django-elasticsearch-dsl>=7.0.0,<8.0.0
|
django-elasticsearch-dsl>=7.0.0,<8.0.0
|
||||||
django-elasticsearch-dsl-drf==0.20.2
|
django-elasticsearch-dsl-drf==0.20.2
|
||||||
sentry-sdk==0.11.2
|
sentry-sdk==0.11.2
|
||||||
|
|
||||||
|
# temp solution
|
||||||
|
redis==3.2.0
|
||||||
|
amqp>=2.4.0
|
||||||
|
celery==4.3.0rc2
|
||||||
Loading…
Reference in New Issue
Block a user