From 6b44e159e5cadd9fafef160ca6729079722832bd Mon Sep 17 00:00:00 2001 From: mist Date: Fri, 23 Apr 2021 08:57:37 +0200 Subject: [PATCH] initial version --- .gitignore | 2 +- Pipfile | 15 +++ Pipfile.lock | 107 +++++++++++++++++ manage.py | 22 ++++ media/placeholder | 0 pak/__init__.py | 0 pak/admin.py | 7 ++ pak/apps.py | 6 + pak/migrations/0001_initial.py | 44 +++++++ pak/migrations/0002_auto_20210423_0824.py | 30 +++++ pak/migrations/__init__.py | 0 pak/models.py | 60 ++++++++++ pak/serializers.py | 25 ++++ pak/tests.py | 3 + pak/views.py | 16 +++ pakajo/__init__.py | 0 pakajo/asgi.py | 16 +++ pakajo/settings.py | 138 ++++++++++++++++++++++ pakajo/urls.py | 31 +++++ pakajo/wsgi.py | 16 +++ 20 files changed, 537 insertions(+), 1 deletion(-) create mode 100644 Pipfile create mode 100644 Pipfile.lock create mode 100755 manage.py create mode 100644 media/placeholder create mode 100644 pak/__init__.py create mode 100644 pak/admin.py create mode 100644 pak/apps.py create mode 100644 pak/migrations/0001_initial.py create mode 100644 pak/migrations/0002_auto_20210423_0824.py create mode 100644 pak/migrations/__init__.py create mode 100644 pak/models.py create mode 100644 pak/serializers.py create mode 100644 pak/tests.py create mode 100644 pak/views.py create mode 100644 pakajo/__init__.py create mode 100644 pakajo/asgi.py create mode 100644 pakajo/settings.py create mode 100644 pakajo/urls.py create mode 100644 pakajo/wsgi.py diff --git a/.gitignore b/.gitignore index 13d1490..092cb6a 100644 --- a/.gitignore +++ b/.gitignore @@ -128,4 +128,4 @@ dmypy.json # Pyre type checker .pyre/ - +media/ diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..9fea633 --- /dev/null +++ b/Pipfile @@ -0,0 +1,15 @@ +[[source]] +name = "pypi" +url = "https://pypi.org/simple" +verify_ssl = true + +[dev-packages] + +[packages] +django = "*" +djangorestframework = "*" +markdown = "*" +pillow = "*" + +[requires] +python_version = "3.8" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000..398b6e7 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,107 @@ +{ + "_meta": { + "hash": { + "sha256": "1cacd6133aec887ab1622c274f09c244ceab1ccfba1de3b5e30b142e5d0d50d4" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.8" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "asgiref": { + "hashes": [ + "sha256:92906c611ce6c967347bbfea733f13d6313901d54dcca88195eaeb52b2a8e8ee", + "sha256:d1216dfbdfb63826470995d31caed36225dcaf34f182e0fa257a4dd9e86f1b78" + ], + "markers": "python_version >= '3.6'", + "version": "==3.3.4" + }, + "django": { + "hashes": [ + "sha256:0604e84c4fb698a5e53e5857b5aea945b2f19a18f25f10b8748dbdf935788927", + "sha256:21f0f9643722675976004eb683c55d33c05486f94506672df3d6a141546f389d" + ], + "index": "pypi", + "version": "==3.2" + }, + "djangorestframework": { + "hashes": [ + "sha256:6d1d59f623a5ad0509fe0d6bfe93cbdfe17b8116ebc8eda86d45f6e16e819aaf", + "sha256:f747949a8ddac876e879190df194b925c177cdeb725a099db1460872f7c0a7f2" + ], + "index": "pypi", + "version": "==3.12.4" + }, + "markdown": { + "hashes": [ + "sha256:31b5b491868dcc87d6c24b7e3d19a0d730d59d3e46f4eea6430a321bed387a49", + "sha256:96c3ba1261de2f7547b46a00ea8463832c921d3f9d6aba3f255a6f71386db20c" + ], + "index": "pypi", + "version": "==3.3.4" + }, + "pillow": { + "hashes": [ + "sha256:01425106e4e8cee195a411f729cff2a7d61813b0b11737c12bd5991f5f14bcd5", + "sha256:031a6c88c77d08aab84fecc05c3cde8414cd6f8406f4d2b16fed1e97634cc8a4", + "sha256:083781abd261bdabf090ad07bb69f8f5599943ddb539d64497ed021b2a67e5a9", + "sha256:0d19d70ee7c2ba97631bae1e7d4725cdb2ecf238178096e8c82ee481e189168a", + "sha256:0e04d61f0064b545b989126197930807c86bcbd4534d39168f4aa5fda39bb8f9", + "sha256:12e5e7471f9b637762453da74e390e56cc43e486a88289995c1f4c1dc0bfe727", + "sha256:22fd0f42ad15dfdde6c581347eaa4adb9a6fc4b865f90b23378aa7914895e120", + "sha256:238c197fc275b475e87c1453b05b467d2d02c2915fdfdd4af126145ff2e4610c", + "sha256:3b570f84a6161cf8865c4e08adf629441f56e32f180f7aa4ccbd2e0a5a02cba2", + "sha256:463822e2f0d81459e113372a168f2ff59723e78528f91f0bd25680ac185cf797", + "sha256:4d98abdd6b1e3bf1a1cbb14c3895226816e666749ac040c4e2554231068c639b", + "sha256:5afe6b237a0b81bd54b53f835a153770802f164c5570bab5e005aad693dab87f", + "sha256:5b70110acb39f3aff6b74cf09bb4169b167e2660dabc304c1e25b6555fa781ef", + "sha256:5cbf3e3b1014dddc45496e8cf38b9f099c95a326275885199f427825c6522232", + "sha256:624b977355cde8b065f6d51b98497d6cd5fbdd4f36405f7a8790e3376125e2bb", + "sha256:63728564c1410d99e6d1ae8e3b810fe012bc440952168af0a2877e8ff5ab96b9", + "sha256:66cc56579fd91f517290ab02c51e3a80f581aba45fd924fcdee01fa06e635812", + "sha256:6c32cc3145928c4305d142ebec682419a6c0a8ce9e33db900027ddca1ec39178", + "sha256:8bb1e155a74e1bfbacd84555ea62fa21c58e0b4e7e6b20e4447b8d07990ac78b", + "sha256:95d5ef984eff897850f3a83883363da64aae1000e79cb3c321915468e8c6add5", + "sha256:a013cbe25d20c2e0c4e85a9daf438f85121a4d0344ddc76e33fd7e3965d9af4b", + "sha256:a787ab10d7bb5494e5f76536ac460741788f1fbce851068d73a87ca7c35fc3e1", + "sha256:a7d5e9fad90eff8f6f6106d3b98b553a88b6f976e51fce287192a5d2d5363713", + "sha256:aac00e4bc94d1b7813fe882c28990c1bc2f9d0e1aa765a5f2b516e8a6a16a9e4", + "sha256:b91c36492a4bbb1ee855b7d16fe51379e5f96b85692dc8210831fbb24c43e484", + "sha256:c03c07ed32c5324939b19e36ae5f75c660c81461e312a41aea30acdd46f93a7c", + "sha256:c5236606e8570542ed424849f7852a0ff0bce2c4c8d0ba05cc202a5a9c97dee9", + "sha256:c6b39294464b03457f9064e98c124e09008b35a62e3189d3513e5148611c9388", + "sha256:cb7a09e173903541fa888ba010c345893cd9fc1b5891aaf060f6ca77b6a3722d", + "sha256:d68cb92c408261f806b15923834203f024110a2e2872ecb0bd2a110f89d3c602", + "sha256:dc38f57d8f20f06dd7c3161c59ca2c86893632623f33a42d592f097b00f720a9", + "sha256:e98eca29a05913e82177b3ba3d198b1728e164869c613d76d0de4bde6768a50e", + "sha256:f217c3954ce5fd88303fc0c317af55d5e0204106d86dea17eb8205700d47dec2" + ], + "index": "pypi", + "version": "==8.2.0" + }, + "pytz": { + "hashes": [ + "sha256:83a4a90894bf38e243cf052c8b58f381bfe9a7a483f6a9cab140bc7f702ac4da", + "sha256:eb10ce3e7736052ed3623d49975ce333bcd712c7bb19a58b9e2089d4057d0798" + ], + "version": "==2021.1" + }, + "sqlparse": { + "hashes": [ + "sha256:017cde379adbd6a1f15a61873f43e8274179378e95ef3fede90b5aa64d304ed0", + "sha256:0f91fd2e829c44362cbcfab3e9ae12e22badaa8a29ad5ff599f9ec109f0454e8" + ], + "markers": "python_version >= '3.5'", + "version": "==0.4.1" + } + }, + "develop": {} +} diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..c1389b8 --- /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', 'pakajo.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/media/placeholder b/media/placeholder new file mode 100644 index 0000000..e69de29 diff --git a/pak/__init__.py b/pak/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pak/admin.py b/pak/admin.py new file mode 100644 index 0000000..bae9416 --- /dev/null +++ b/pak/admin.py @@ -0,0 +1,7 @@ +from django.contrib import admin +from pak.models import Pak, City, OpenDay + + +admin.site.register(Pak) +admin.site.register(City) +admin.site.register(OpenDay) diff --git a/pak/apps.py b/pak/apps.py new file mode 100644 index 0000000..3e9493a --- /dev/null +++ b/pak/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class PakConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'pak' diff --git a/pak/migrations/0001_initial.py b/pak/migrations/0001_initial.py new file mode 100644 index 0000000..2ff0329 --- /dev/null +++ b/pak/migrations/0001_initial.py @@ -0,0 +1,44 @@ +# Generated by Django 3.2 on 2021-04-16 07:00 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='City', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ], + ), + migrations.CreateModel( + name='Pak', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ('address', models.CharField(max_length=255)), + ('pay_by_card', models.BooleanField(default=True)), + ('pay_by_cash', models.BooleanField(default=True)), + ('fee', models.IntegerField()), + ('city', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='pak.city')), + ], + ), + migrations.CreateModel( + name='OpenDay', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('day', models.CharField(choices=[('monday', 'pondělí'), ('thuesday', 'úterý'), ('wednesday', 'středa'), ('thuesday', 'čtvrtek'), ('friday', 'pátek'), ('saturday', 'sobota'), ('sunday', 'neděle')], max_length=64)), + ('open_from', models.IntegerField()), + ('open_till', models.IntegerField()), + ('pak', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='pak.pak')), + ], + ), + ] diff --git a/pak/migrations/0002_auto_20210423_0824.py b/pak/migrations/0002_auto_20210423_0824.py new file mode 100644 index 0000000..c62fb38 --- /dev/null +++ b/pak/migrations/0002_auto_20210423_0824.py @@ -0,0 +1,30 @@ +# Generated by Django 3.2 on 2021-04-23 06:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('pak', '0001_initial'), + ] + + operations = [ + migrations.AlterModelOptions( + name='city', + options={'ordering': ('name',)}, + ), + migrations.AlterModelOptions( + name='openday', + options={'ordering': ('id',)}, + ), + migrations.AlterModelOptions( + name='pak', + options={'ordering': ('name',)}, + ), + migrations.AddField( + model_name='pak', + name='image', + field=models.ImageField(blank=True, null=True, upload_to='paks/'), + ), + ] diff --git a/pak/migrations/__init__.py b/pak/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pak/models.py b/pak/models.py new file mode 100644 index 0000000..c472154 --- /dev/null +++ b/pak/models.py @@ -0,0 +1,60 @@ +from django.db import models + + +class Pak(models.Model): + name = models.CharField(max_length=255) + address = models.CharField(max_length=255) + city = models.ForeignKey('City', on_delete=models.PROTECT) + pay_by_card = models.BooleanField(default=True) + pay_by_cash = models.BooleanField(default=True) + fee = models.IntegerField() + image = models.ImageField(upload_to='paks/', blank=True, null=True) + + def __str__(self): + return self.name + + class Meta: + ordering = ('name', ) + + +class City(models.Model): + name = models.CharField(max_length=255) + + def __str__(self): + return self.name + + class Meta: + ordering = ('name', ) + + +class OpenDay(models.Model): + MONDAY = 'monday' + THUESDAY = 'thuesday' + WEDNESDAY = 'wednesday' + THURSDAY = 'thursday' + FRIDAY = 'friday' + SATURDAY = 'saturday' + SUNDAY = 'sunday' + + DAYS = ( + (MONDAY, 'pondělí'), + (THUESDAY, 'úterý'), + (WEDNESDAY, 'středa'), + (THUESDAY, 'čtvrtek'), + (FRIDAY, 'pátek'), + (SATURDAY, 'sobota'), + (SUNDAY, 'neděle')) + + pak = models.ForeignKey('Pak', on_delete=models.CASCADE) + day = models.CharField(max_length=64, choices=DAYS) + open_from = models.IntegerField() + open_till = models.IntegerField() + + def __str__(self): + return '%s' % (self.get_day_display(), ) + + def day_locale(self): + return str(self) + + class Meta: + ordering = ('id', ) diff --git a/pak/serializers.py b/pak/serializers.py new file mode 100644 index 0000000..81e4d5f --- /dev/null +++ b/pak/serializers.py @@ -0,0 +1,25 @@ +from rest_framework import serializers +from pak.models import Pak, City, OpenDay + + +class OpenDaySerializer(serializers.ModelSerializer): + class Meta: + model = OpenDay + fields = ['day', 'day_locale', 'open_from', 'open_till'] + + +class PakSerializer(serializers.ModelSerializer): + city = serializers.StringRelatedField() + openday_set = OpenDaySerializer(many=True) + + class Meta: + model = Pak + fields = ['id', 'name', 'image', 'address', 'city', 'openday_set'] + + +class CitySerializer(serializers.ModelSerializer): + class Meta: + model = City + fields = ['name'] + + diff --git a/pak/tests.py b/pak/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/pak/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/pak/views.py b/pak/views.py new file mode 100644 index 0000000..b87c8eb --- /dev/null +++ b/pak/views.py @@ -0,0 +1,16 @@ +from rest_framework.authentication import SessionAuthentication, BasicAuthentication, TokenAuthentication +from rest_framework import viewsets +from rest_framework import permissions + +from pak.serializers import PakSerializer, CitySerializer +from pak.models import Pak, City + + +class PakViewSet(viewsets.ReadOnlyModelViewSet): + """ + API endpoint that allows users to be viewed or edited. + """ + queryset = Pak.objects.all() + serializer_class = PakSerializer + permission_classes = [permissions.IsAuthenticated] + authentication_classes = [SessionAuthentication, BasicAuthentication, TokenAuthentication] diff --git a/pakajo/__init__.py b/pakajo/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pakajo/asgi.py b/pakajo/asgi.py new file mode 100644 index 0000000..6b58fca --- /dev/null +++ b/pakajo/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for pakajo 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', 'pakajo.settings') + +application = get_asgi_application() diff --git a/pakajo/settings.py b/pakajo/settings.py new file mode 100644 index 0000000..20d274c --- /dev/null +++ b/pakajo/settings.py @@ -0,0 +1,138 @@ +""" +Django settings for pakajo project. + +Generated by 'django-admin startproject' using Django 3.2. + +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/ +""" + +import os +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent +MEDIA_ROOT = os.path.join(BASE_DIR, 'media') +MEDIA_URL = '/media/' +# 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-+eq5m&i2@de0_gid)#8(8mst%7i9gyvu@5wh&l8l&okee^hdd9' + +# 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.authtoken', + 'pak', +] + +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 = 'pakajo.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 = 'pakajo.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# 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 = 'cs-cz' + +TIME_ZONE = 'Europe/Prague' + +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/' + +# Default primary key field type +# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + + +REST_FRAMEWORK = { + 'DEFAULT_AUTHENTICATION_CLASSES': [ + 'rest_framework.authentication.BasicAuthentication', + 'rest_framework.authentication.SessionAuthentication', + 'rest_framework.authentication.TokenAuthentication', + ] +} diff --git a/pakajo/urls.py b/pakajo/urls.py new file mode 100644 index 0000000..a81d642 --- /dev/null +++ b/pakajo/urls.py @@ -0,0 +1,31 @@ +"""pakajo 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 rest_framework import routers +from pak import views as pak_views + + +router = routers.DefaultRouter() +router.register(r'paks', pak_views.PakViewSet) + + +urlpatterns = [ + path('admin/', admin.site.urls), + path('api-auth/', include('rest_framework.urls', namespace='rest_framework')), + path('', include(router.urls)), +] diff --git a/pakajo/wsgi.py b/pakajo/wsgi.py new file mode 100644 index 0000000..9df9b27 --- /dev/null +++ b/pakajo/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for pakajo 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', 'pakajo.settings') + +application = get_wsgi_application()