Merge branch 'develop' into feature/gm-148
# Conflicts: # requirements/base.txt
This commit is contained in:
commit
26ff9963d8
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``
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -311,7 +311,10 @@ REDOC_SETTINGS = {
|
||||||
|
|
||||||
|
|
||||||
# CELERY
|
# CELERY
|
||||||
BROKER_URL = 'amqp://rabbitmq:5672'
|
# RabbitMQ
|
||||||
|
# BROKER_URL = 'amqp://rabbitmq:5672'
|
||||||
|
# Redis
|
||||||
|
BROKER_URL = 'redis://base: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']
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,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'
|
||||||
|
|
@ -18,7 +18,10 @@ 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
|
||||||
|
|
||||||
|
|
@ -40,3 +38,8 @@ boto3==1.9.238
|
||||||
django-storages==1.7.2
|
django-storages==1.7.2
|
||||||
|
|
||||||
sorl-thumbnail==12.5.0
|
sorl-thumbnail==12.5.0
|
||||||
|
|
||||||
|
# temp solution
|
||||||
|
redis==3.2.0
|
||||||
|
amqp>=2.4.0
|
||||||
|
celery==4.3.0rc2
|
||||||
Loading…
Reference in New Issue
Block a user