initial commit

This commit is contained in:
2019-01-11 22:16:01 +03:00
commit 24c5f2fcf6
312 changed files with 186972 additions and 0 deletions

0
config/__init__.py Normal file
View File

19
config/celery.py Normal file
View File

@@ -0,0 +1,19 @@
import os
from celery import Celery
config = {
'broker_url': 'redis://127.0.0.1:6379/0',
}
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
app = Celery('telegram_bots')
app.config_from_object(config)
app.autodiscover_tasks()
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))

91
config/settings.py Normal file
View File

@@ -0,0 +1,91 @@
import os
import environ
BASE_DIR = environ.Path(__file__) - 2
env = environ.Env()
env_file = str(BASE_DIR.path('.env'))
if os.path.exists(env_file):
env.read_env(env_file)
SECRET_KEY = '6)mck*tk2eq++!01pr2!7qo7#zf_e(hi_m=-qa4x-ah)lvvt4-'
DEBUG = env.bool('DJANGO_DEBUG', False)
ALLOWED_HOSTS = ['0.0.0.0', '127.0.0.1', 'home.bakatrouble.pw', 'localhost']
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions',
'bootstrap4',
'cabinet',
'feeds',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'config.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [str(BASE_DIR.path('templates'))],
'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',
'config.utils.turbolinks',
],
},
},
]
WSGI_APPLICATION = 'config.wsgi.application'
DATABASES = {
'default': env.db('DATABASE_URL', default='sqlite:///db.sqlite3'),
}
DATABASES['default']['ATOMIC_REQUESTS'] = True
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATICFILES_DIRS = [
str(BASE_DIR.path('static')),
]
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]
PUBLIC_ROOT = BASE_DIR.path('public')
STATIC_URL = '/static/'
STATIC_ROOT = str(PUBLIC_ROOT.path('static'))
MEDIA_URL = '/uploads/'
MEDIA_ROOT = str(PUBLIC_ROOT.path('uploads'))
LOGIN_URL = 'cabinet:login'
LOGIN_REDIRECT_URL = 'cabinet:index'
LOGOUT_REDIRECT_URL = LOGIN_URL

9
config/urls.py Normal file
View File

@@ -0,0 +1,9 @@
from django.contrib import admin
from django.urls import path, include
from django.views.generic import RedirectView
urlpatterns = [
path('', RedirectView.as_view(pattern_name='cabinet:index')),
path('admin/', admin.site.urls),
path('cabinet/', include('cabinet.urls', namespace='cabinet')),
]

44
config/utils.py Normal file
View File

@@ -0,0 +1,44 @@
from urllib.parse import urlparse
from django.http import HttpRequest, HttpResponse, HttpResponseForbidden
def same_origin(current_uri, redirect_uri):
a = urlparse(current_uri)
if not a.scheme:
return True
b = urlparse(redirect_uri)
return (a.scheme, a.hostname, a.port) == (b.scheme, b.hostname, b.port)
def turbolinks(request: HttpRequest):
ctx = {}
if request.META.get('HTTP_TURBOLINKS_REFERRER') is not None:
ctx['is_turbolinks'] = True
return ctx
class TurbolinksMiddleware:
def process_request(self, request: HttpRequest):
referrer = request.META.get('HTTP_TURBOLINKS_REFERRER')
if referrer:
request.META['HTTP_REFERER'] = referrer
return
def process_response(self, request: HttpRequest, response: HttpResponse):
referrer = request.META.get('HTTP_TURBOLINKS_REFERRER')
if referrer is None:
return response
if response.has_header('Location'):
loc = response['Location']
request.session['_turbolinks_redirect_to'] = loc
if referrer and not same_origin(loc, referrer):
return HttpResponseForbidden()
else:
if request.session.get('_turbolinks_redirect_to'):
loc = request.session.pop('_turbolinks_redirect_to')
response['Turbolinks-Location'] = loc
return response

16
config/wsgi.py Normal file
View File

@@ -0,0 +1,16 @@
"""
WSGI config for config 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/2.1/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
application = get_wsgi_application()