From 0b1c16b24f04a55c92b3def07b1f3833a07bba1d Mon Sep 17 00:00:00 2001 From: Llloooggg Date: Sat, 10 Sep 2022 03:55:45 +0300 Subject: [PATCH] init --- .gitignore | 183 ++++++++++++++++++ backend/wheretogo/facilities/__init__.py | 0 backend/wheretogo/facilities/admin.py | 13 ++ backend/wheretogo/facilities/apps.py | 8 + .../facilities/migrations/0001_initial.py | 41 ++++ .../facilities/migrations/__init__.py | 0 backend/wheretogo/facilities/models.py | 20 ++ backend/wheretogo/facilities/serializers.py | 10 + backend/wheretogo/facilities/tests.py | 3 + backend/wheretogo/facilities/urls.py | 11 ++ backend/wheretogo/facilities/views.py | 3 + backend/wheretogo/facilities/viewsets.py | 13 ++ .../wheretogo/locale/ru/LC_MESSAGES/django.po | 32 +++ backend/wheretogo/manage.py | 22 +++ backend/wheretogo/wheretogo/__init__.py | 0 backend/wheretogo/wheretogo/asgi.py | 16 ++ backend/wheretogo/wheretogo/settings.py | 125 ++++++++++++ .../wheretogo/settings_var.py_template | 13 ++ backend/wheretogo/wheretogo/urls.py | 23 +++ backend/wheretogo/wheretogo/wsgi.py | 16 ++ 20 files changed, 552 insertions(+) create mode 100644 .gitignore create mode 100644 backend/wheretogo/facilities/__init__.py create mode 100644 backend/wheretogo/facilities/admin.py create mode 100644 backend/wheretogo/facilities/apps.py create mode 100644 backend/wheretogo/facilities/migrations/0001_initial.py create mode 100644 backend/wheretogo/facilities/migrations/__init__.py create mode 100644 backend/wheretogo/facilities/models.py create mode 100644 backend/wheretogo/facilities/serializers.py create mode 100644 backend/wheretogo/facilities/tests.py create mode 100644 backend/wheretogo/facilities/urls.py create mode 100644 backend/wheretogo/facilities/views.py create mode 100644 backend/wheretogo/facilities/viewsets.py create mode 100644 backend/wheretogo/locale/ru/LC_MESSAGES/django.po create mode 100755 backend/wheretogo/manage.py create mode 100644 backend/wheretogo/wheretogo/__init__.py create mode 100644 backend/wheretogo/wheretogo/asgi.py create mode 100644 backend/wheretogo/wheretogo/settings.py create mode 100644 backend/wheretogo/wheretogo/settings_var.py_template create mode 100644 backend/wheretogo/wheretogo/urls.py create mode 100644 backend/wheretogo/wheretogo/wsgi.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e002f53 --- /dev/null +++ b/.gitignore @@ -0,0 +1,183 @@ +# Created by https://www.toptal.com/developers/gitignore/api/django,vuejs +# Edit at https://www.toptal.com/developers/gitignore?templates=django,vuejs + +### Django ### +*.log +*.pot +*.pyc +__pycache__/ +local_settings.py +db.sqlite3 +db.sqlite3-journal +media + +# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/ +# in your Git repository. Update and uncomment the following line accordingly. +# /staticfiles/ + +### Django.Python Stack ### +# Byte-compiled / optimized / DLL files +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo + +# Django stuff: + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +### Vuejs ### +# Recommended template: Node.gitignore + +node_modules/ +npm-debug.log +yarn-error.log + +# End of https://www.toptal.com/developers/gitignore/api/django,vuejs + +settings_var.py \ No newline at end of file diff --git a/backend/wheretogo/facilities/__init__.py b/backend/wheretogo/facilities/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/wheretogo/facilities/admin.py b/backend/wheretogo/facilities/admin.py new file mode 100644 index 0000000..0c7bfce --- /dev/null +++ b/backend/wheretogo/facilities/admin.py @@ -0,0 +1,13 @@ +from django.contrib.gis.db import models +from django.forms.widgets import Textarea +from django.contrib import admin + + +from facilities.models import Facility + + +class FacilityAdmin(admin.ModelAdmin): + formfield_overrides = {models.PointField: {"widget": Textarea}} + + +admin.site.register(Facility, FacilityAdmin) diff --git a/backend/wheretogo/facilities/apps.py b/backend/wheretogo/facilities/apps.py new file mode 100644 index 0000000..44be46b --- /dev/null +++ b/backend/wheretogo/facilities/apps.py @@ -0,0 +1,8 @@ +from django.apps import AppConfig +from django.utils.translation import gettext_lazy as _ + + +class FacilitiesConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "facilities" + verbose_name = _("Facilities") diff --git a/backend/wheretogo/facilities/migrations/0001_initial.py b/backend/wheretogo/facilities/migrations/0001_initial.py new file mode 100644 index 0000000..2fdd841 --- /dev/null +++ b/backend/wheretogo/facilities/migrations/0001_initial.py @@ -0,0 +1,41 @@ +# Generated by Django 4.1.1 on 2022-09-09 23:29 + +import django.contrib.gis.db.models.fields +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [] + + operations = [ + migrations.CreateModel( + name="Facility", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("name", models.CharField(max_length=200)), + ("address", models.CharField(max_length=100)), + ("city", models.CharField(max_length=50)), + ( + "location", + django.contrib.gis.db.models.fields.PointField( + blank=True, null=True, srid=4326 + ), + ), + ], + options={ + "verbose_name": "facility", + "verbose_name_plural": "facilities", + }, + ), + ] diff --git a/backend/wheretogo/facilities/migrations/__init__.py b/backend/wheretogo/facilities/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/wheretogo/facilities/models.py b/backend/wheretogo/facilities/models.py new file mode 100644 index 0000000..8eaf4bf --- /dev/null +++ b/backend/wheretogo/facilities/models.py @@ -0,0 +1,20 @@ +from django.contrib.gis.db import models as gis_models +from django.utils.translation import gettext_lazy as _ +from django.db import models + + +class Facility(models.Model): + name = models.CharField(max_length=200) + address = models.CharField(max_length=100) + city = models.CharField(max_length=50) + location = gis_models.PointField( + null=True, + blank=True, + ) + + class Meta: + verbose_name = _("facility") + verbose_name_plural = _("facilities") + + def __str__(self): + return f"{self.name}: {self.city}, {self.address}" diff --git a/backend/wheretogo/facilities/serializers.py b/backend/wheretogo/facilities/serializers.py new file mode 100644 index 0000000..7cb04c8 --- /dev/null +++ b/backend/wheretogo/facilities/serializers.py @@ -0,0 +1,10 @@ +from rest_framework_gis import serializers + +from facilities.models import Facility + + +class FacilitySerializer(serializers.GeoFeatureModelSerializer): + class Meta: + model = Facility + fields = ("id", "name", "address", "city") + geo_field = "location" diff --git a/backend/wheretogo/facilities/tests.py b/backend/wheretogo/facilities/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/backend/wheretogo/facilities/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/backend/wheretogo/facilities/urls.py b/backend/wheretogo/facilities/urls.py new file mode 100644 index 0000000..35fb718 --- /dev/null +++ b/backend/wheretogo/facilities/urls.py @@ -0,0 +1,11 @@ +from rest_framework import routers + +from facilities.viewsets import FacilityViewSet + +app_name = "facilities" + + +router = routers.DefaultRouter() +router.register("facilities", FacilityViewSet, "facilities") + +urlpatterns = router.urls diff --git a/backend/wheretogo/facilities/views.py b/backend/wheretogo/facilities/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/backend/wheretogo/facilities/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/backend/wheretogo/facilities/viewsets.py b/backend/wheretogo/facilities/viewsets.py new file mode 100644 index 0000000..4e8ec16 --- /dev/null +++ b/backend/wheretogo/facilities/viewsets.py @@ -0,0 +1,13 @@ +from rest_framework import viewsets +from rest_framework_gis import filters + +from facilities.models import Facility +from facilities.serializers import FacilitySerializer + + +class FacilityViewSet(viewsets.ReadOnlyModelViewSet): + + bbox_filter_field = "location" + filter_backends = (filters.InBBoxFilter,) + queryset = Facility.objects.all() + serializer_class = FacilitySerializer diff --git a/backend/wheretogo/locale/ru/LC_MESSAGES/django.po b/backend/wheretogo/locale/ru/LC_MESSAGES/django.po new file mode 100644 index 0000000..402a694 --- /dev/null +++ b/backend/wheretogo/locale/ru/LC_MESSAGES/django.po @@ -0,0 +1,32 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-09-10 03:41+0300\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n" +"%100>=11 && n%100<=14)? 2 : 3);\n" +#: facilities/apps.py:8 +msgid "Facilities" +msgstr "Заведения" + +#: facilities/models.py:16 +msgid "facility" +msgstr "заведение" + +#: facilities/models.py:17 +msgid "facilities" +msgstr "заведения" diff --git a/backend/wheretogo/manage.py b/backend/wheretogo/manage.py new file mode 100755 index 0000000..c6ae4ed --- /dev/null +++ b/backend/wheretogo/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "wheretogo.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == "__main__": + main() diff --git a/backend/wheretogo/wheretogo/__init__.py b/backend/wheretogo/wheretogo/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/wheretogo/wheretogo/asgi.py b/backend/wheretogo/wheretogo/asgi.py new file mode 100644 index 0000000..ee4ae82 --- /dev/null +++ b/backend/wheretogo/wheretogo/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for wheretogo 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.1/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "wheretogo.settings") + +application = get_asgi_application() diff --git a/backend/wheretogo/wheretogo/settings.py b/backend/wheretogo/wheretogo/settings.py new file mode 100644 index 0000000..4350335 --- /dev/null +++ b/backend/wheretogo/wheretogo/settings.py @@ -0,0 +1,125 @@ +""" +Django settings for wheretogo project. + +Generated by 'django-admin startproject' using Django 4.1.1. + +For more information on this file, see +https://docs.djangoproject.com/en/4.1/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.1/ref/settings/ +""" + +from pathlib import Path + +from wheretogo.settings_var import * # noqa:F401,F403 + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = ( + "django-insecure-^3_1&z7lsvy2co*yh7vlro+lz66y+ij+b57sg^#xz)ya4s3m%+" +) + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + "rest_framework", + "rest_framework_gis", + "corsheaders", + "facilities", +] + +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", + "corsheaders.middleware.CorsMiddleware", +] + +CORS_ALLOW_ALL_ORIGINS = True + +ROOT_URLCONF = "wheretogo.urls" + +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 = "wheretogo.wsgi.application" + + +# Password validation +# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators + +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", + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/4.1/topics/i18n/ + +LANGUAGE_CODE = "ru-ru" + +LOCALE_PATHS = ("locale",) + +TIME_ZONE = "UTC" + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.1/howto/static-files/ + +STATIC_URL = "static/" + +# Default primary key field type +# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" diff --git a/backend/wheretogo/wheretogo/settings_var.py_template b/backend/wheretogo/wheretogo/settings_var.py_template new file mode 100644 index 0000000..efc62a0 --- /dev/null +++ b/backend/wheretogo/wheretogo/settings_var.py_template @@ -0,0 +1,13 @@ +# Database +# https://docs.djangoproject.com/en/4.0/ref/settings/#databases + +DATABASES = { + "default": { + "ENGINE": "django.contrib.gis.db.backends.postgis", + "NAME": "wheretogo", + "USER": "wheretogo", + "PASSWORD": "", + "HOST": "127.0.0.1", + "PORT": "5432", + } +} diff --git a/backend/wheretogo/wheretogo/urls.py b/backend/wheretogo/wheretogo/urls.py new file mode 100644 index 0000000..d8549c6 --- /dev/null +++ b/backend/wheretogo/wheretogo/urls.py @@ -0,0 +1,23 @@ +"""wheretogo URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.1/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path +from django.urls import include + +urlpatterns = [ + path("admin/", admin.site.urls), + path("api/", include("facilities.urls")), +] diff --git a/backend/wheretogo/wheretogo/wsgi.py b/backend/wheretogo/wheretogo/wsgi.py new file mode 100644 index 0000000..977b877 --- /dev/null +++ b/backend/wheretogo/wheretogo/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for wheretogo 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.1/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "wheretogo.settings") + +application = get_wsgi_application()