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
|
||||
|
||||
## 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."""
|
||||
import logging
|
||||
from typing import Tuple, Optional
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.gis.geoip2 import GeoIP2, GeoIP2Exception
|
||||
from geoip2.models import City
|
||||
|
||||
from main import models
|
||||
|
||||
|
|
@ -39,17 +41,16 @@ def determine_country_code(ip_addr):
|
|||
return country_code
|
||||
|
||||
|
||||
def determine_coordinates(ip_addr):
|
||||
longitude, latitude = None, None
|
||||
def determine_coordinates(ip_addr: str) -> Tuple[Optional[float], Optional[float]]:
|
||||
if ip_addr:
|
||||
try:
|
||||
geoip = GeoIP2()
|
||||
longitude, latitude = geoip.coords(ip_addr)
|
||||
return geoip.coords(ip_addr)
|
||||
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:
|
||||
logger.error(f'GEOIP Base exception: {ex}')
|
||||
return longitude, latitude
|
||||
logger.warning(f'GEOIP Base exception: {ex}')
|
||||
return None, None
|
||||
|
||||
|
||||
def determine_user_site_url(country_code):
|
||||
|
|
@ -73,3 +74,12 @@ def determine_user_site_url(country_code):
|
|||
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 = [
|
||||
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('site-settings/<subdomain>/', views.SiteSettingsView.as_view(), name='site-settings'),
|
||||
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 main import methods, models, serializers
|
||||
from utils.serializers import EmptySerializer
|
||||
from django.http import Http404
|
||||
|
||||
|
||||
class DetermineSiteView(generics.GenericAPIView):
|
||||
|
|
@ -18,6 +19,22 @@ class DetermineSiteView(generics.GenericAPIView):
|
|||
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):
|
||||
"""Site settings View."""
|
||||
|
||||
|
|
@ -34,6 +51,8 @@ class SiteListView(generics.ListAPIView):
|
|||
permission_classes = (permissions.AllowAny,)
|
||||
queryset = models.SiteSettings.objects.with_country()
|
||||
serializer_class = serializers.SiteSerializer
|
||||
|
||||
|
||||
#
|
||||
# class FeatureViewMixin:
|
||||
# """Feature view mixin."""
|
||||
|
|
@ -76,7 +95,7 @@ class AwardView(generics.ListAPIView):
|
|||
"""Awards list view."""
|
||||
serializer_class = serializers.AwardSerializer
|
||||
queryset = models.Award.objects.all()
|
||||
permission_classes = (permissions.AllowAny, )
|
||||
permission_classes = (permissions.AllowAny,)
|
||||
|
||||
|
||||
class AwardRetrieveView(generics.RetrieveAPIView):
|
||||
|
|
@ -90,5 +109,5 @@ class CarouselListView(generics.ListAPIView):
|
|||
"""Return list of carousel items."""
|
||||
queryset = models.Carousel.objects.all()
|
||||
serializer_class = serializers.CarouselListSerializer
|
||||
permission_classes = (permissions.AllowAny, )
|
||||
permission_classes = (permissions.AllowAny,)
|
||||
pagination_class = None
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ services:
|
|||
- "5436:5432"
|
||||
volumes:
|
||||
- gm-db:/var/lib/postgresql/data/
|
||||
|
||||
elasticsearch:
|
||||
image: elasticsearch:7.3.1
|
||||
volumes:
|
||||
|
|
@ -27,11 +28,18 @@ services:
|
|||
- discovery.type=single-node
|
||||
- xpack.security.enabled=false
|
||||
|
||||
# RabbitMQ
|
||||
rabbitmq:
|
||||
image: rabbitmq:latest
|
||||
# Redis
|
||||
redis:
|
||||
image: redis:2.8.23
|
||||
ports:
|
||||
- "5672:5672"
|
||||
- "6379:6379"
|
||||
|
||||
# RabbitMQ
|
||||
#rabbitmq:
|
||||
# image: rabbitmq:latest
|
||||
# ports:
|
||||
# - "5672:5672"
|
||||
|
||||
# Celery
|
||||
worker:
|
||||
build: .
|
||||
|
|
@ -47,7 +55,9 @@ services:
|
|||
- .:/code
|
||||
links:
|
||||
- db
|
||||
- rabbitmq
|
||||
# - rabbitmq
|
||||
- redis
|
||||
|
||||
worker_beat:
|
||||
build: .
|
||||
command: ./run_celery_beat.sh
|
||||
|
|
@ -62,7 +72,8 @@ services:
|
|||
- .:/code
|
||||
links:
|
||||
- db
|
||||
- rabbitmq
|
||||
# - rabbitmq
|
||||
- redis
|
||||
# App: G&M
|
||||
gm_app:
|
||||
build: .
|
||||
|
|
@ -76,7 +87,8 @@ services:
|
|||
- DB_PASSWORD=postgres
|
||||
depends_on:
|
||||
- db
|
||||
- rabbitmq
|
||||
# - rabbitmq
|
||||
- redis
|
||||
- worker
|
||||
- worker_beat
|
||||
- elasticsearch
|
||||
|
|
|
|||
|
|
@ -311,7 +311,10 @@ REDOC_SETTINGS = {
|
|||
|
||||
|
||||
# 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_BROKER_URL = BROKER_URL
|
||||
CELERY_ACCEPT_CONTENT = ['application/json']
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ ALLOWED_HOSTS = ['*', ]
|
|||
|
||||
SEND_SMS = False
|
||||
SMS_CODE_SHOW = True
|
||||
USE_CELERY = False
|
||||
USE_CELERY = True
|
||||
|
||||
|
||||
SCHEMA_URI = 'http'
|
||||
|
|
@ -18,7 +18,10 @@ DOMAIN_URI = '0.0.0.0:8000'
|
|||
|
||||
|
||||
# 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_BROKER_URL = BROKER_URL
|
||||
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@ djangorestframework==3.9.4
|
|||
markdown
|
||||
django-filter==2.1.0
|
||||
djangorestframework-xml
|
||||
celery
|
||||
amqp>=2.4.0
|
||||
geoip2==2.9.0
|
||||
django-phonenumber-field[phonenumbers]==2.1.0
|
||||
|
||||
|
|
@ -39,4 +37,9 @@ sentry-sdk==0.11.2
|
|||
boto3==1.9.238
|
||||
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