-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c9e86d6
commit 7523409
Showing
70 changed files
with
5,088 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FROM python:3.10-alpine as builder-image | ||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PYTHONUNBUFFERED 1 | ||
RUN apk update && apk add postgresql-dev gcc python3-dev \ | ||
musl-dev libffi-dev libevent-dev libart-lgpl zlib-dev \ | ||
libxslt-dev zlib libc-dev linux-headers freetype-dev pgbouncer | ||
RUN pip install --upgrade pip | ||
WORKDIR /usr/src/app | ||
COPY ./requirements.txt . | ||
RUN pip wheel --no-cache-dir --wheel-dir /usr/src/app/wheels -r requirements.txt | ||
|
||
|
||
FROM python:3.10-alpine | ||
WORKDIR /app | ||
RUN apk update && apk add freetype-dev libpq pgbouncer | ||
COPY --from=builder-image /usr/src/app/wheels /wheels | ||
COPY --from=builder-image /usr/src/app/requirements.txt . | ||
RUN pip install --no-cache /wheels/* | ||
COPY . . | ||
RUN chmod +x ./compile | ||
RUN ls -l | ||
RUN ./compile /app | ||
RUN python manage.py collectstatic --noinput |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
web: daphne bagchat.asgi:application -p $PORT -b 0.0.0.0 --proxy-headers | ||
worker: python manage.py beatserver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# from .celery import app as celery_app | ||
|
||
# __all__ = ['celery_app'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
""" | ||
ASGI config for bagchat project. | ||
It exposes the ASGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/ | ||
""" | ||
|
||
import os | ||
from django.core.asgi import get_asgi_application | ||
django_asgi_app = get_asgi_application() | ||
|
||
from channels.routing import ProtocolTypeRouter, URLRouter, ChannelNameRouter | ||
from channels.security.websocket import AllowedHostsOriginValidator | ||
import chat.routing | ||
from chat.AuthMiddlewareToken import AuthMiddlewareToken | ||
from base.views import EntryPointTasks | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bagchat.settings') | ||
os.environ['ASGI_THREADS']="4" | ||
application = ProtocolTypeRouter({ | ||
"http": django_asgi_app, | ||
"websocket": | ||
AllowedHostsOriginValidator( | ||
AuthMiddlewareToken( | ||
URLRouter( | ||
chat.routing.websocket_urlpatterns | ||
) | ||
) | ||
), | ||
"channel": ChannelNameRouter({ | ||
"channel-tasks": EntryPointTasks.as_asgi(), | ||
}), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from datetime import timedelta | ||
BEAT_SCHEDULE = { | ||
'channel-tasks': [ | ||
{ | ||
'type': 'test.holidays', | ||
'message': None, | ||
'schedule': '0 3 * * *' | ||
# 'schedule': timedelta(seconds=5) | ||
} | ||
# { | ||
# 'type': 'chat_force_test', | ||
# 'message': None, | ||
# # 'schedule': timedelta(seconds=5) | ||
# }, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import os | ||
from celery import Celery | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bagchat.settings') | ||
|
||
app = Celery('bagchat') | ||
app.config_from_object('django.conf:settings', namespace='CELERY') | ||
app.autodiscover_tasks() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
from pathlib import Path | ||
from datetime import timedelta | ||
from dotenv import load_dotenv | ||
import django_heroku | ||
import dj_database_url | ||
import os | ||
import firebase_admin | ||
from firebase_admin import credentials | ||
from django.core.management.utils import get_random_secret_key | ||
|
||
BASE_DIR = Path(__file__).resolve().parent.parent | ||
|
||
# path_env = os.path.join(BASE_DIR, '.env') | ||
# load_dotenv(path_env) | ||
|
||
if not os.path.exists(os.path.join(BASE_DIR, 'antonio-glyzin-storage.json')) \ | ||
and os.environ.get('CERTIFICATE_STORAGE'): | ||
with open(os.path.join(BASE_DIR, 'antonio-glyzin-storage.json'), 'w') as file: | ||
file.write(os.environ.get('CERTIFICATE_STORAGE')) | ||
if os.path.exists(os.path.join(BASE_DIR, 'antonio-glyzin-storage.json')): | ||
FIREBASE_STORAGE = credentials.Certificate(os.path.join(BASE_DIR, 'antonio-glyzin-storage.json')) | ||
firebase_admin.initialize_app(FIREBASE_STORAGE, { | ||
'storageBucket': os.environ.get('BUCKET_STORAGE_NAME') | ||
}) | ||
|
||
if not os.path.exists(BASE_DIR / 'genie.json') \ | ||
and os.environ.get('GOOGLE_APPLICATION_CREDENTIALS'): | ||
with open(BASE_DIR / 'genie.json', 'w') as file: | ||
file.write(os.environ.get('GOOGLE_APPLICATION_CREDENTIALS')) | ||
|
||
if os.path.exists(BASE_DIR / 'genie.json'): | ||
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = os.path.join(BASE_DIR, 'genie.json') | ||
|
||
# os.path.join(BASE_DIR, 'antonio-glyzin-storage.json') | ||
MY_HOST = 'https://puzzle-chats.herokuapp.com' | ||
# MY_HOST = 'http://127.0.0.1:8000' | ||
SITE_ID = 333333333 | ||
SECRET_KEY = os.environ.get('SECRET_KEY', get_random_secret_key()) | ||
TOKEN_BOT_GLYZIN = os.environ.get('TOKEN_BOT_GLYZIN') | ||
# ME_CHAT_ID = int(os.environ.get('ME_CHAT_ID')) | ||
ME_CHAT_ID = 654579717 | ||
DEBUG = False | ||
ALLOWED_HOSTS = ['antonioglyzin.pythonanywhere.com', | ||
'portfolio-puzzle.web.app', | ||
'puzzle-chats.herokuapp.com', | ||
'127.0.0.1'] | ||
CORS_ALLOWED_ORIGINS = [ | ||
"https://antonioglyzin.pythonanywhere.com", | ||
'https://portfolio-puzzle.web.app', | ||
'https://puzzle-chats.herokuapp.com', | ||
'http://127.0.0.1' | ||
] | ||
|
||
CSRF_TRUSTED_ORIGINS = [ | ||
"https://antonioglyzin.pythonanywhere.com", | ||
'https://puzzle-chats.herokuapp.com', | ||
'https://portfolio-puzzle.web.app' | ||
] | ||
INSTALLED_APPS = [ | ||
'django.contrib.admin', | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'django.contrib.messages', | ||
'django.contrib.staticfiles', | ||
'rest_framework', | ||
'django_filters', | ||
'beatserver', | ||
'channels', | ||
'channels_postgres', | ||
'corsheaders', | ||
'captcha', | ||
'rest_framework_simplejwt', | ||
'easy_thumbnails', | ||
'martor', | ||
'chat.apps.ChatConfig', | ||
'portfolio.apps.PortfolioConfig', | ||
'base.apps.AuthConfig', | ||
'genie.apps.GenieConfig' | ||
] | ||
SIMPLE_JWT = { | ||
'ACCESS_TOKEN_LIFETIME': timedelta(days=15), | ||
'REFRESH_TOKEN_LIFETIME': timedelta(days=15) | ||
} | ||
MIDDLEWARE = [ | ||
'django.middleware.security.SecurityMiddleware', | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
"corsheaders.middleware.CorsMiddleware", | ||
'django.middleware.common.CommonMiddleware', | ||
'django.middleware.csrf.CsrfViewMiddleware', | ||
'whitenoise.middleware.WhiteNoiseMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
] | ||
|
||
ROOT_URLCONF = 'bagchat.urls' | ||
ASGI_APPLICATION = "bagchat.asgi.application" | ||
TEMPLATES = [ | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'DIRS': [], | ||
'APP_DIRS': True, | ||
'OPTIONS': { | ||
'context_processors': [ | ||
'django.template.context_processors.debug', | ||
'django.template.context_processors.request', | ||
'django.contrib.auth.context_processors.auth', | ||
'django.contrib.messages.context_processors.messages', | ||
], | ||
}, | ||
}, | ||
] | ||
|
||
# WSGI_APPLICATION = 'bagchat.wsgi.application' | ||
TMP_DATABASE_URL='postgres://postgres:postgres@localhost:5432/app' | ||
CHANNEL_LAYERS = { | ||
'default': { | ||
'BACKEND': 'channels_postgres.core.PostgresChannelLayer', | ||
'CONFIG': dj_database_url.parse(os.environ.get('DATABASE_URL', TMP_DATABASE_URL)) | ||
} | ||
} | ||
DATABASES = { | ||
'default': dj_database_url.parse(os.environ.get('DATABASE_URL', TMP_DATABASE_URL)), | ||
'channels_postgres': dj_database_url.parse(os.environ.get('DATABASE_URL', TMP_DATABASE_URL)) | ||
} | ||
AUTH_PASSWORD_VALIDATORS = [ | ||
{ | ||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', | ||
}, | ||
{ | ||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', | ||
}, | ||
{ | ||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', | ||
}, | ||
{ | ||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', | ||
}, | ||
] | ||
REST_FRAMEWORK = { | ||
'DEFAULT_FILTER_BACKENDS': ( | ||
'django_filters.rest_framework.DjangoFilterBackend', | ||
), | ||
'DEFAULT_AUTHENTICATION_CLASSES': ( | ||
'rest_framework_simplejwt.authentication.JWTAuthentication', | ||
), | ||
'DEFAULT_PARSER_CLASSES': ( | ||
'rest_framework.parsers.FormParser', | ||
'rest_framework.parsers.MultiPartParser' | ||
), | ||
'DEFAULT_RENDERER_CLASSES': ( | ||
'rest_framework.renderers.JSONRenderer', | ||
) | ||
} | ||
STATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage' | ||
LANGUAGE_CODE = 'ru' | ||
TIME_ZONE = 'Europe/Moscow' | ||
USE_I18N = True | ||
USE_TZ = True | ||
|
||
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') | ||
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') | ||
STATIC_URL = "/static/" | ||
|
||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' | ||
django_heroku.settings(locals()) | ||
DATABASES['default']['CONN_MAX_AGE'] = 0 | ||
del DATABASES['default']['OPTIONS']['sslmode'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from django.contrib import admin | ||
from django.urls import path, include | ||
from rest_framework_simplejwt.views import TokenVerifyView | ||
from base.views import EntryPointByPass | ||
|
||
urlpatterns = [ | ||
path('adminus/', admin.site.urls), | ||
path('martor/', include('martor.urls')), | ||
path('api/captcha/', include('captcha.urls')), | ||
path('api/genie/', include('genie.urls')), | ||
path('api/bag/', include('portfolio.urls')), | ||
path('api/token/', EntryPointByPass.as_view(), name='token_obtain_pair'), | ||
path('api/token/verify/', TokenVerifyView.as_view(), name='verify_true'), | ||
path('', include('base.urls')), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
WSGI config for bagchat project. | ||
It exposes the WSGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.wsgi import get_wsgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bagchat.settings') | ||
|
||
application = get_wsgi_application() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from django.contrib import admin | ||
from base.models import Profile, MySkils, ImagesLink | ||
from django.utils.safestring import mark_safe | ||
|
||
@admin.register(MySkils) | ||
class MySkilsAdmin(admin.ModelAdmin): | ||
list_display = ('name', 'slug', ) | ||
list_display_links = ('name', 'slug', ) | ||
ist_filter = ('name', ) | ||
prepopulated_fields = {"slug": ("name",)} | ||
search_fields = ('name', 'slug') | ||
|
||
# Register your models here. | ||
@admin.register(ImagesLink) | ||
class ImagesLinkAdmin(admin.ModelAdmin): | ||
list_display = ('get_html_photo', 'link', ) | ||
list_display_links = ('get_html_photo', 'link', ) | ||
readonly_fields = ('get_html_photo', 'link') | ||
def get_html_photo(self, object): | ||
if object.link: | ||
return mark_safe(f"<img src='{object.link}' width=113>") | ||
def add_view(self,request,extra_content=None): | ||
return super(ImagesLinkAdmin,self).add_view(request) | ||
def change_view(self, request, object_id, extra_context=None): | ||
self.exclude = ('name',) | ||
return super(ImagesLinkAdmin, self).change_view(request, object_id) | ||
get_html_photo.short_description = "Миниатюра" | ||
|
||
@admin.register(Profile) | ||
class ProfileAdmin(admin.ModelAdmin): | ||
list_display = ['user', 'get_name_user', 'get_html_photo', 'get_staff', 'get_active', 'type_app'] | ||
list_filter = ('user__is_staff', 'type_app') | ||
list_editable = ('type_app', ) | ||
readonly_fields = ('photo_user', ) | ||
def get_name_user(self, object): | ||
return object.user.get_full_name() | ||
def get_staff(self, object): | ||
if object.user.is_staff: | ||
return mark_safe('<img src="/static/admin/img/icon-yes.svg" alt="True">') | ||
else: | ||
return mark_safe('<img src="/static/admin/img/icon-no.svg" alt="False">') | ||
def get_active(self, object): | ||
if object.user.is_active: | ||
return mark_safe('<img src="/static/admin/img/icon-yes.svg" alt="True">') | ||
else: | ||
return mark_safe('<img src="/static/admin/img/icon-no.svg" alt="False">') | ||
def get_html_photo(self, object): | ||
if object.photo: | ||
# ava = object.preview['avatar'].url | ||
ava = object.photo | ||
return mark_safe(f"<img src='{ava}' width=70>") | ||
get_html_photo.short_description = "Миниатюра" | ||
get_staff.short_description = "Доступ к админке" | ||
get_active.short_description = "Активен" | ||
get_name_user.short_description = 'Имя и Фамилия' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class AuthConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'base' | ||
verbose_name = 'Аутентификация' |
Oops, something went wrong.