From d366be57a168b94bee35660cb802fd393d90ded0 Mon Sep 17 00:00:00 2001 From: Mohamed Nouffer Date: Tue, 8 Feb 2022 16:44:09 +0530 Subject: [PATCH] first commit --- .gitignore | 167 +++++++++++++++++++++++ Dockerfile.gdal | 55 ++++++++ Makefile | 33 +++++ config/__init__.py | 0 config/asgi.py | 16 +++ config/settings.py | 167 +++++++++++++++++++++++ config/urls.py | 28 ++++ config/wsgi.py | 16 +++ docker-compose.yaml | 42 ++++++ dockerignore | 55 ++++++++ manage.py | 22 +++ requirements.txt | 64 +++++++++ rog/__init__.py | 0 rog/admin.py | 23 ++++ rog/apps.py | 6 + rog/migrations/0001_initial.py | 33 +++++ rog/migrations/0002_rename_shops_shop.py | 17 +++ rog/migrations/0003_eventroute.py | 24 ++++ rog/migrations/0004_shoproute.py | 24 ++++ rog/migrations/__init__.py | 0 rog/models.py | 37 +++++ rog/serializers.py | 32 +++++ rog/tests.py | 3 + rog/urls.py | 14 ++ rog/views.py | 31 +++++ 25 files changed, 909 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile.gdal create mode 100644 Makefile create mode 100644 config/__init__.py create mode 100644 config/asgi.py create mode 100644 config/settings.py create mode 100644 config/urls.py create mode 100644 config/wsgi.py create mode 100644 docker-compose.yaml create mode 100644 dockerignore create mode 100755 manage.py create mode 100644 requirements.txt create mode 100644 rog/__init__.py create mode 100644 rog/admin.py create mode 100644 rog/apps.py create mode 100644 rog/migrations/0001_initial.py create mode 100644 rog/migrations/0002_rename_shops_shop.py create mode 100644 rog/migrations/0003_eventroute.py create mode 100644 rog/migrations/0004_shoproute.py create mode 100644 rog/migrations/__init__.py create mode 100644 rog/models.py create mode 100644 rog/serializers.py create mode 100644 rog/tests.py create mode 100644 rog/urls.py create mode 100644 rog/views.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a012b54 --- /dev/null +++ b/.gitignore @@ -0,0 +1,167 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/django +# Edit at https://www.toptal.com/developers/gitignore?templates=django + +### 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 + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__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 maintainted 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/ + +# End of https://www.toptal.com/developers/gitignore/api/django diff --git a/Dockerfile.gdal b/Dockerfile.gdal new file mode 100644 index 0000000..b4e236e --- /dev/null +++ b/Dockerfile.gdal @@ -0,0 +1,55 @@ +# FROM python:3.9.9-slim-buster +FROM osgeo/gdal:ubuntu-small-3.4.0 + +WORKDIR /app + +LABEL maintainer="nouffer@gmail.com" +LABEL description="Development image for the Rogaining JP" + +ENV PYTHONDONTWRITEBYTECODE 1 + +ENV PYTHONUNBUFFERED 1 + +ARG TZ Asia/Tokyo \ + DEBIAN_FRONTEND=noninteractive + + +RUN apt-get update -y + +# Install GDAL dependencies +RUN apt-get install -y libgdal-dev g++ --no-install-recommends && \ + apt-get clean -y + + + +# Update C env vars so compiler can find gdal +ENV CPLUS_INCLUDE_PATH=/usr/include/gdal +ENV C_INCLUDE_PATH=/usr/include/gdal + + +RUN apt-get update \ + && apt-get -y install netcat gcc postgresql \ + && apt-get clean + +RUN apt-get update \ + && apt-get install -y binutils libproj-dev gdal-bin python3-gdal + +RUN apt-get install -y libcurl4-openssl-dev libssl-dev + +RUN apt-get install -y libspatialindex-dev + +RUN apt-get install -y python3 + +RUN apt-get update && apt-get install -y \ + python3-pip + +RUN pip install --upgrade pip + +RUN apt-get update + +COPY ./requirements.txt /app/requirements.txt + +RUN pip install -r requirements.txt + +COPY . /app + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..570ffee --- /dev/null +++ b/Makefile @@ -0,0 +1,33 @@ + + +ifneq (,$(wildcard ./.env)) + include .env + export + ENV_FILE_PARAM = --env-file .env +endif + +build: + docker-compose up --build -d --remove-orphans +up: + docker-compose up -d +down: + docker-compose down +logs: + docker-compose logs +migrate: + docker-compose exec api python3 manage.py migrate --noinput +makemigrations: + docker-compose exec api python3 manage.py makemigrations + +superuser: + docker-compose exec api python3 manage.py createsuperuser + +down-v: + docker-compose down -v + +volume: + docker volume inspect rog_src_postgres_data + +shell: + docker-compose exec api python3 manage.py shell + diff --git a/config/__init__.py b/config/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/config/asgi.py b/config/asgi.py new file mode 100644 index 0000000..8dad602 --- /dev/null +++ b/config/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for config 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/3.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') + +application = get_asgi_application() diff --git a/config/settings.py b/config/settings.py new file mode 100644 index 0000000..bd67a04 --- /dev/null +++ b/config/settings.py @@ -0,0 +1,167 @@ +""" +Django settings for config project. + +Generated by 'django-admin startproject' using Django 3.2.9. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.2/ref/settings/ +""" + +from pathlib import Path +import environ +import os + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + +env = environ.Env(DEBUG=(bool, False)) +environ.Env.read_env(env_file=".env") + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +#SECRET_KEY = 'django-insecure-@!z!i#bheb)(o1-e2tss(i^dav-ql=cm4*+$unm^3=4)k_ttda' +SECRET_KEY = env("SECRET_KEY") + +# SECURITY WARNING: don't run with debug turned on in production! +#DEBUG = True +DEBUG = env("DEBUG") + +#ALLOWED_HOSTS = [] +ALLOWED_HOSTS = env("ALLOWED_HOSTS").split(" ") + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'django.contrib.gis', + 'rest_framework', + 'rest_framework_gis', + 'leaflet', + 'leaflet_admin_list', + 'rog.apps.RogConfig', +] + +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': [BASE_DIR / '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', + ], + }, + }, +] + +WSGI_APPLICATION = 'config.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.contrib.gis.db.backends.postgis', + 'NAME': env("POSTGRES_DBNAME"), + 'USER': env("POSTGRES_USER"), + 'PASSWORD': env("POSTGRES_PASS"), + 'HOST': env("PG_HOST"), + 'PORT': env("PG_PORT") + } +} + + +# Password validation +# https://docs.djangoproject.com/en/3.2/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/3.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'Asia/Tokyo' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.2/howto/static-files/ + +STATIC_URL = '/static/' + +#STATIC_URL = '/static2/' +STATIC_ROOT = BASE_DIR / "static" + +MEDIA_URL = '/media/' +MEDIA_ROOT = BASE_DIR / "media/" + +#STATICFILES_DIRS = (os.path.join(BASE_DIR, "static2"),os.path.join(BASE_DIR, "media")) + + + +# Default primary key field type +# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +LEAFLET_CONFIG = { + 'DEFAULT_CENTER': (35.41864442627996, 138.14094040951784), + 'DEFAULT_ZOOM': 6, + 'MIN_ZOOM': 3, + 'MAX_ZOOM': 19, + 'DEFAULT_PRECISION': 6, + 'SCALE':"both", + 'ATTRIBUTION_PREFIX':"ROGAINING API", + 'TILES': [('Satellite', 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {'attribution': '© ESRI', 'maxZoom': 19}), + ('Streets', 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {'attribution': '© Contributors'})] +} diff --git a/config/urls.py b/config/urls.py new file mode 100644 index 0000000..33576f7 --- /dev/null +++ b/config/urls.py @@ -0,0 +1,28 @@ +"""config URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.2/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, include +from django.conf import settings +from django.conf.urls.static import static + +urlpatterns = [ + path('admin/', admin.site.urls), + path('api/', include("rog.urls")), +]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + +admin.site.site_header = "ROGANING" +admin.site.site_title = "Roganing Admin Portal" +admin.site.index_title = "Welcome to Roganing Portal" diff --git a/config/wsgi.py b/config/wsgi.py new file mode 100644 index 0000000..8915671 --- /dev/null +++ b/config/wsgi.py @@ -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/3.2/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() diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..7dffd97 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,42 @@ +version: "3.9" + +services: + api: + build: + context: . + dockerfile: Dockerfile.gdal + command: python3 manage.py runserver 0.0.0.0:8100 + volumes: + - .:/app + ports: + - 8100:8100 + env_file: + - .env + restart: "on-failure" + depends_on: + - postgres-db + networks: + - rog-api + + postgres-db: + image: kartoza/postgis:12.0 + ports: + - 5432:5432 + volumes: + - postgres_data:/var/lib/postgresql + environment: + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASS=${POSTGRES_PASS} + - POSTGRES_DBNAME=${POSTGRES_DBNAME} + restart: "on-failure" + networks: + - rog-api + + +networks: + rog-api: + driver: bridge + +volumes: + postgres_data: + geoserver-data: \ No newline at end of file diff --git a/dockerignore b/dockerignore new file mode 100644 index 0000000..7aa35c9 --- /dev/null +++ b/dockerignore @@ -0,0 +1,55 @@ +# Docker/Podman image doesn't need any files that git doesn't track. +#Therefore the .dockerignore largely follows the structure of .gitignore. +# C extensions +*.so +# Packages +*.egg* +*.egg-info +dist +build +eggs +parts +bin +var +sdist +develop-eggs +.installed.cfg +lib +lib64 +# Installer logs +pip-log.txt +# Unit test / coverage reports +cover/ +.coverage* +!.coveragerc +.tox +nosetests.xml +.testrepository +.venv +.stestr/* +# Translations +*.mo +# Mr Developer +.mr.developer.cfg +.project +.pydevproject +# Complexity +output/*.html +output/*/index.html +# Sphinx +doc/build +doc/source/reference/api/ +# pbr generates these +AUTHORS +ChangeLog +# Editors +*~ +.*.swp +.*sw? +# Files created by releasenotes build +releasenotes/build +# Ansible specific +hosts +*.retry +#Vagrantfiles, since we are using docker +Vagrantfile.* \ No newline at end of file diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..8e7ac79 --- /dev/null +++ b/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', 'config.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/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e754cfb --- /dev/null +++ b/requirements.txt @@ -0,0 +1,64 @@ +affine==2.3.0 +asgiref==3.4.1 +attrs==21.2.0 +black==21.11b0 +certifi==2021.10.8 +charset-normalizer==2.0.8 +click==8.0.3 +click-plugins==1.1.1 +cligj==0.7.2 +cycler==0.11.0 +Django==3.2.9 +django-adminlte-3==0.1.6 +django-environ==0.8.1 +django-filter==21.1 +django-leaflet==0.28.2 +django-leaflet-admin-list==0.0.4 +django-suit==2.0a1 +djangorestframework==3.12.4 +djangorestframework-gis==0.17 +Fiona==1.8.20 +flake8==4.0.1 +fonttools==4.28.2 +# GDAL==3.3.0 +GeoAlchemy2==0.9.4 +geopandas==0.10.2 +geoserver-rest==2.1.4 +greenlet==1.1.2 +idna==3.3 +kiwisolver==1.3.2 +matplotlib==3.5.0 +mccabe==0.6.1 +munch==2.5.0 +mypy-extensions==0.4.3 +numpy==1.21.4 +packaging==21.3 +pandas==1.3.4 +pathspec==0.9.0 +Pillow==8.4.0 +platformdirs==2.4.0 +psycopg2-binary==2.9.2 +pycodestyle==2.8.0 +pycurl==7.44.1 +pyflakes==2.4.0 +Pygments==2.10.0 +pyparsing==3.0.6 +pyproj==3.3.0 +python-dateutil==2.8.2 +pytz==2021.3 +rasterio==1.2.10 +regex==2021.11.10 +requests==2.26.0 +Rtree==0.9.7 +scipy==1.7.3 +seaborn==0.11.2 +setuptools-scm==6.3.2 +Shapely==1.8.0 +six==1.16.0 +snuggs==1.4.7 +SQLAlchemy==1.4.27 +sqlparse==0.4.2 +tomli==1.2.2 +typing_extensions==4.0.0 +urllib3==1.26.7 +django-extra-fields==3.0.2 diff --git a/rog/__init__.py b/rog/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rog/admin.py b/rog/admin.py new file mode 100644 index 0000000..6f319a0 --- /dev/null +++ b/rog/admin.py @@ -0,0 +1,23 @@ +from django.contrib import admin +from leaflet.admin import LeafletGeoAdmin +from leaflet.admin import LeafletGeoAdminMixin +from leaflet_admin_list.admin import LeafletAdminListMixin +from .models import RogEvent, Shop, EventRoute, ShopRoute + + +class RogAdmin(LeafletAdminListMixin, LeafletGeoAdminMixin, admin.ModelAdmin): + list_display=['title', 'venue', 'at_date',] + +class ShopAdmin(LeafletAdminListMixin, LeafletGeoAdminMixin, admin.ModelAdmin): + list_display=['name',] + +class EventRouteAdmin(LeafletAdminListMixin, LeafletGeoAdminMixin, admin.ModelAdmin): + list_display=['name',] + +class ShopRouteAdmin(LeafletAdminListMixin, LeafletGeoAdminMixin, admin.ModelAdmin): + list_display=['name',] + +admin.site.register(RogEvent, RogAdmin) +admin.site.register(Shop, ShopAdmin) +admin.site.register(EventRoute, EventRouteAdmin) +admin.site.register(ShopRoute, ShopRouteAdmin) \ No newline at end of file diff --git a/rog/apps.py b/rog/apps.py new file mode 100644 index 0000000..85c3443 --- /dev/null +++ b/rog/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class RogConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'rog' diff --git a/rog/migrations/0001_initial.py b/rog/migrations/0001_initial.py new file mode 100644 index 0000000..45566d4 --- /dev/null +++ b/rog/migrations/0001_initial.py @@ -0,0 +1,33 @@ +# Generated by Django 3.2.9 on 2022-02-04 06:00 + +import django.contrib.gis.db.models.fields +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='RogEvent', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=255, verbose_name='Title')), + ('venue', models.CharField(max_length=255, verbose_name='Venue')), + ('at_date', models.DateTimeField(auto_now_add=True, verbose_name='At Date')), + ('geom', django.contrib.gis.db.models.fields.MultiPointField(srid=4326)), + ], + ), + migrations.CreateModel( + name='Shops', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255, verbose_name='Shop name')), + ('geom', django.contrib.gis.db.models.fields.MultiPointField(srid=4326)), + ], + ), + ] diff --git a/rog/migrations/0002_rename_shops_shop.py b/rog/migrations/0002_rename_shops_shop.py new file mode 100644 index 0000000..ca59452 --- /dev/null +++ b/rog/migrations/0002_rename_shops_shop.py @@ -0,0 +1,17 @@ +# Generated by Django 3.2.9 on 2022-02-04 11:39 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('rog', '0001_initial'), + ] + + operations = [ + migrations.RenameModel( + old_name='Shops', + new_name='Shop', + ), + ] diff --git a/rog/migrations/0003_eventroute.py b/rog/migrations/0003_eventroute.py new file mode 100644 index 0000000..c207be5 --- /dev/null +++ b/rog/migrations/0003_eventroute.py @@ -0,0 +1,24 @@ +# Generated by Django 3.2.9 on 2022-02-04 17:17 + +import django.contrib.gis.db.models.fields +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('rog', '0002_rename_shops_shop'), + ] + + operations = [ + migrations.CreateModel( + name='EventRoute', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255, verbose_name='Name')), + ('geom', django.contrib.gis.db.models.fields.MultiLineStringField(srid=4326)), + ('event', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='rog.rogevent')), + ], + ), + ] diff --git a/rog/migrations/0004_shoproute.py b/rog/migrations/0004_shoproute.py new file mode 100644 index 0000000..5171d1c --- /dev/null +++ b/rog/migrations/0004_shoproute.py @@ -0,0 +1,24 @@ +# Generated by Django 3.2.9 on 2022-02-04 17:23 + +import django.contrib.gis.db.models.fields +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('rog', '0003_eventroute'), + ] + + operations = [ + migrations.CreateModel( + name='ShopRoute', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255, verbose_name='Name')), + ('geom', django.contrib.gis.db.models.fields.MultiLineStringField(srid=4326)), + ('shop', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='rog.shop')), + ], + ), + ] diff --git a/rog/migrations/__init__.py b/rog/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rog/models.py b/rog/models.py new file mode 100644 index 0000000..8fa19c5 --- /dev/null +++ b/rog/models.py @@ -0,0 +1,37 @@ +from django.contrib.gis.db import models +from django.utils.translation import gettext_lazy as _ + + +class RogEvent(models.Model): + title=models.CharField(_('Title'), max_length=255) + venue=models.CharField(_('Venue'), max_length=255) + at_date=models.DateTimeField(_('At Date'), auto_now_add=True) + geom=models.MultiPointField(srid=4326) + + def __str__(self): + return self.title + +class EventRoute(models.Model): + name = models.CharField(_("Name"), max_length=255) + event = models.OneToOneField(RogEvent, on_delete=models.CASCADE) + geom = models.MultiLineStringField(srid=4326) + + def __str__(self): + return self.name + + +class Shop(models.Model): + name=models.CharField(_('Shop name'), max_length=255) + geom=models.MultiPointField(srid=4326) + + def __str__(self): + return self.name + + +class ShopRoute(models.Model): + name = models.CharField(_("Name"), max_length=255) + shop = models.OneToOneField(Shop, on_delete=models.CASCADE) + geom = models.MultiLineStringField(srid=4326) + + def __str__(self): + return self.name \ No newline at end of file diff --git a/rog/serializers.py b/rog/serializers.py new file mode 100644 index 0000000..b53aaa2 --- /dev/null +++ b/rog/serializers.py @@ -0,0 +1,32 @@ +from rest_framework_gis.serializers import GeoFeatureModelSerializer +from sqlalchemy.sql.functions import mode +from .models import RogEvent, Shop, EventRoute, ShopRoute +from drf_extra_fields.fields import Base64ImageField + + +class RogEventSerializer(GeoFeatureModelSerializer): + class Meta: + model=RogEvent + geo_field="geom" + fields="__all__" + + +class ShopSerializer(GeoFeatureModelSerializer): + class Meta: + model=Shop + geo_field="geom" + fields="__all__" + + +class EventRouteSerializer(GeoFeatureModelSerializer): + class Meta: + model=EventRoute + geo_field="geom" + fields="__all__" + + +class ShopRouteSerializer(GeoFeatureModelSerializer): + class Meta: + model=ShopRoute + geo_field="geom" + fields="__all__" \ No newline at end of file diff --git a/rog/tests.py b/rog/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/rog/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/rog/urls.py b/rog/urls.py new file mode 100644 index 0000000..7df2325 --- /dev/null +++ b/rog/urls.py @@ -0,0 +1,14 @@ +from rest_framework import urlpatterns +from rest_framework.routers import DefaultRouter +from .views import RogEventViewSet, EventRouteViewSet, ShopViewSet, ShopRouteViewSet +from django.urls import path, include + + +router = DefaultRouter() + +router.register(prefix='v1/rog', viewset=RogEventViewSet, basename='rog') +router.register(prefix='v1/eventroute', viewset=EventRouteViewSet, basename='eventroute') +router.register(prefix='v1/shop', viewset=ShopViewSet, basename='shop') +router.register(prefix='v1/shoproute', viewset=ShopRouteViewSet, basename='shoproute') + +urlpatterns = router.urls diff --git a/rog/views.py b/rog/views.py new file mode 100644 index 0000000..d55587c --- /dev/null +++ b/rog/views.py @@ -0,0 +1,31 @@ +from django.core.serializers import serialize +from .models import RogEvent, ShopRoute, EventRoute, Shop +from rest_framework import viewsets +from .serializers import RogEventSerializer, EventRouteSerializer, ShopSerializer, ShopRouteSerializer +from rest_framework.decorators import action +from rest_framework.response import Response +from rest_framework.parsers import JSONParser, MultiPartParser + + + + + +class RogEventViewSet(viewsets.ModelViewSet): + queryset=RogEvent.objects.all() + serializer_class=RogEventSerializer + + +class EventRouteViewSet(viewsets.ModelViewSet): + queryset=EventRoute.objects.all() + serializer_class=EventRouteSerializer + + +class ShopViewSet(viewsets.ModelViewSet): + queryset=Shop.objects.all() + serializer_class=ShopSerializer + + +class ShopRouteViewSet(viewsets.ModelViewSet): + queryset=ShopRoute.objects.all() + serializer_class=ShopRouteSerializer +