refacto [api]: black formatting
This commit is contained in:
parent
2d996b322f
commit
a396b5be5b
14 changed files with 113 additions and 95 deletions
|
@ -6,7 +6,7 @@ import sys
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Run administrative tasks."""
|
"""Run administrative tasks."""
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ulm_cine_club_api.settings')
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ulm_cine_club_api.settings")
|
||||||
try:
|
try:
|
||||||
from django.core.management import execute_from_command_line
|
from django.core.management import execute_from_command_line
|
||||||
except ImportError as exc:
|
except ImportError as exc:
|
||||||
|
@ -18,5 +18,5 @@ def main():
|
||||||
execute_from_command_line(sys.argv)
|
execute_from_command_line(sys.argv)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -2,5 +2,5 @@ from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
class MyapiConfig(AppConfig):
|
class MyapiConfig(AppConfig):
|
||||||
default_auto_field = 'django.db.models.BigAutoField'
|
default_auto_field = "django.db.models.BigAutoField"
|
||||||
name = 'myapi'
|
name = "myapi"
|
||||||
|
|
|
@ -7,29 +7,52 @@ class Migration(migrations.Migration):
|
||||||
|
|
||||||
initial = True
|
initial = True
|
||||||
|
|
||||||
dependencies = [
|
dependencies = []
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Film',
|
name="Film",
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
(
|
||||||
('projection_date', models.DateTimeField()),
|
"id",
|
||||||
('title', models.CharField(max_length=60)),
|
models.BigAutoField(
|
||||||
('actors', models.JSONField(default='[]')),
|
auto_created=True,
|
||||||
('director', models.CharField(max_length=60)),
|
primary_key=True,
|
||||||
('duration', models.DurationField()),
|
serialize=False,
|
||||||
('synopsis', models.TextField()),
|
verbose_name="ID",
|
||||||
('origin_country', models.CharField(max_length=60)),
|
),
|
||||||
('release_year', models.SmallIntegerField()),
|
),
|
||||||
('trailer_link', models.URLField()),
|
("projection_date", models.DateTimeField()),
|
||||||
('is_in_color', models.BooleanField()),
|
("title", models.CharField(max_length=60)),
|
||||||
('movie_format', models.CharField(choices=[('35mm', 'Analog 35'), ('DVD', 'Dvd'), ('Blu ray', 'Blu Ray')], max_length=20)),
|
("actors", models.JSONField(default="[]")),
|
||||||
('language_subtitles', models.CharField(choices=[('VOF', 'French'), ('VOSTFR', 'Foreign')], max_length=20)),
|
("director", models.CharField(max_length=60)),
|
||||||
('poster_link', models.URLField()),
|
("duration", models.DurationField()),
|
||||||
('banner_link', models.URLField()),
|
("synopsis", models.TextField()),
|
||||||
('is_confirmed', models.BooleanField(default=False)),
|
("origin_country", models.CharField(max_length=60)),
|
||||||
|
("release_year", models.SmallIntegerField()),
|
||||||
|
("trailer_link", models.URLField()),
|
||||||
|
("is_in_color", models.BooleanField()),
|
||||||
|
(
|
||||||
|
"movie_format",
|
||||||
|
models.CharField(
|
||||||
|
choices=[
|
||||||
|
("35mm", "Analog 35"),
|
||||||
|
("DVD", "Dvd"),
|
||||||
|
("Blu ray", "Blu Ray"),
|
||||||
|
],
|
||||||
|
max_length=20,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"language_subtitles",
|
||||||
|
models.CharField(
|
||||||
|
choices=[("VOF", "French"), ("VOSTFR", "Foreign")],
|
||||||
|
max_length=20,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("poster_link", models.URLField()),
|
||||||
|
("banner_link", models.URLField()),
|
||||||
|
("is_confirmed", models.BooleanField(default=False)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -6,13 +6,13 @@ from django.db import migrations, models
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('myapi', '0001_initial'),
|
("myapi", "0001_initial"),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='film',
|
model_name="film",
|
||||||
name='actors',
|
name="actors",
|
||||||
field=models.JSONField(default=list),
|
field=models.JSONField(default=list),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -8,13 +8,13 @@ TODO implement validators
|
||||||
|
|
||||||
class Film(models.Model):
|
class Film(models.Model):
|
||||||
class MovieFormat(models.TextChoices):
|
class MovieFormat(models.TextChoices):
|
||||||
ANALOG_35 = '35mm'
|
ANALOG_35 = "35mm"
|
||||||
DVD = 'DVD'
|
DVD = "DVD"
|
||||||
BLU_RAY = 'Blu ray'
|
BLU_RAY = "Blu ray"
|
||||||
|
|
||||||
class LanguageSubtitles(models.TextChoices):
|
class LanguageSubtitles(models.TextChoices):
|
||||||
FRENCH = 'VOF'
|
FRENCH = "VOF"
|
||||||
FOREIGN = 'VOSTFR'
|
FOREIGN = "VOSTFR"
|
||||||
|
|
||||||
projection_date = models.DateTimeField()
|
projection_date = models.DateTimeField()
|
||||||
title = models.CharField(max_length=60)
|
title = models.CharField(max_length=60)
|
||||||
|
@ -27,7 +27,9 @@ class Film(models.Model):
|
||||||
trailer_link = models.URLField()
|
trailer_link = models.URLField()
|
||||||
is_in_color = models.BooleanField()
|
is_in_color = models.BooleanField()
|
||||||
movie_format = models.CharField(max_length=20, choices=MovieFormat.choices)
|
movie_format = models.CharField(max_length=20, choices=MovieFormat.choices)
|
||||||
language_subtitles = models.CharField(max_length=20, choices=LanguageSubtitles.choices)
|
language_subtitles = models.CharField(
|
||||||
|
max_length=20, choices=LanguageSubtitles.choices
|
||||||
|
)
|
||||||
poster_link = models.URLField()
|
poster_link = models.URLField()
|
||||||
banner_link = models.URLField()
|
banner_link = models.URLField()
|
||||||
is_confirmed = models.BooleanField(default=False)
|
is_confirmed = models.BooleanField(default=False)
|
||||||
|
|
|
@ -3,13 +3,13 @@ from rest_framework import renderers
|
||||||
|
|
||||||
|
|
||||||
class PlainTextRenderer(renderers.BaseRenderer):
|
class PlainTextRenderer(renderers.BaseRenderer):
|
||||||
media_type = 'text/plain'
|
media_type = "text/plain"
|
||||||
format = 'txt'
|
format = "txt"
|
||||||
|
|
||||||
def render(self, data, media_type=None, renderer_context=None):
|
def render(self, data, media_type=None, renderer_context=None):
|
||||||
return smart_str(data, encoding=self.charset)
|
return smart_str(data, encoding=self.charset)
|
||||||
|
|
||||||
|
|
||||||
class LatexRenderer(PlainTextRenderer):
|
class LatexRenderer(PlainTextRenderer):
|
||||||
media_type = 'text/x-tex'
|
media_type = "text/x-tex"
|
||||||
format = 'tex'
|
format = "tex"
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from .models import Film
|
from .models import Film
|
||||||
|
|
||||||
|
|
||||||
class FilmSerializer(serializers.HyperlinkedModelSerializer):
|
class FilmSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Film
|
model = Film
|
||||||
fields = '__all__' # TODO also send id
|
fields = "__all__" # TODO also send id
|
||||||
|
|
|
@ -2,12 +2,7 @@ from django.template.loader import render_to_string
|
||||||
|
|
||||||
from myapi.models import Film
|
from myapi.models import Film
|
||||||
|
|
||||||
prices = {
|
prices = {"one_cof": 4, "one_exte": 5, "card_cof": 30, "card_exte": 35}
|
||||||
'one_cof': 4,
|
|
||||||
'one_exte': 5,
|
|
||||||
'card_cof': 30,
|
|
||||||
'card_exte': 35
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def render_com(template_name, film: Film) -> str:
|
def render_com(template_name, film: Film) -> str:
|
||||||
|
@ -15,4 +10,4 @@ def render_com(template_name, film: Film) -> str:
|
||||||
|
|
||||||
|
|
||||||
def bocal(film: Film) -> str:
|
def bocal(film: Film) -> str:
|
||||||
return render_com('bocal.tex', film)
|
return render_com("bocal.tex", film)
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
from rest_framework import routers
|
from rest_framework import routers
|
||||||
from .views.std_views import (FilmViewSet)
|
from .views.std_views import FilmViewSet
|
||||||
|
|
||||||
router = routers.DefaultRouter()
|
router = routers.DefaultRouter()
|
||||||
router.register(r'films', FilmViewSet)
|
router.register(r"films", FilmViewSet)
|
||||||
|
|
||||||
# Wire up our API using automatic URL routing.
|
# Wire up our API using automatic URL routing.
|
||||||
# Additionally, we include login URLs for the browsable API.
|
# Additionally, we include login URLs for the browsable API.
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', include(router.urls)),
|
path("", include(router.urls)),
|
||||||
path('api-auth/', include('rest_framework.urls', namespace='rest_framework'))
|
path("api-auth/", include("rest_framework.urls", namespace="rest_framework")),
|
||||||
]
|
]
|
||||||
|
|
|
@ -3,18 +3,18 @@ from rest_framework import viewsets
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
from myapi.renderers import LatexRenderer
|
from myapi.renderers import LatexRenderer, PlainTextRenderer
|
||||||
from myapi.serializers import FilmSerializer
|
from myapi.serializers import FilmSerializer
|
||||||
from myapi.models import Film
|
from myapi.models import Film
|
||||||
import myapi.services.com_service as com
|
import myapi.services.com_service as com
|
||||||
|
|
||||||
|
|
||||||
class FilmViewSet(viewsets.ModelViewSet):
|
class FilmViewSet(viewsets.ModelViewSet):
|
||||||
queryset = Film.objects.all().order_by('projection_date')
|
queryset = Film.objects.all().order_by("projection_date")
|
||||||
serializer_class = FilmSerializer
|
serializer_class = FilmSerializer
|
||||||
|
|
||||||
# TODO confirm that latex renderer is not a problem
|
# TODO confirm that latex renderer is not a problem
|
||||||
@action(detail=True, renderer_classes=[LatexRenderer], methods=['GET'])
|
@action(detail=True, renderer_classes=[LatexRenderer], methods=["GET"])
|
||||||
def bocal(self, request, pk=None):
|
def bocal(self, request, pk=None):
|
||||||
film: Film = self.get_object()
|
film: Film = self.get_object()
|
||||||
bocal_text = com.bocal(film)
|
bocal_text = com.bocal(film)
|
||||||
|
|
|
@ -11,6 +11,6 @@ import os
|
||||||
|
|
||||||
from django.core.asgi import get_asgi_application
|
from django.core.asgi import get_asgi_application
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ulm_cine_club_api.settings')
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ulm_cine_club_api.settings")
|
||||||
|
|
||||||
application = get_asgi_application()
|
application = get_asgi_application()
|
||||||
|
|
|
@ -20,7 +20,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
SECRET_KEY = 'django-insecure-)3^d_7xfyv3#+oz#8rj9tym2=g*n!+-sp#_v!t&h+i0y+gv(8u'
|
SECRET_KEY = "django-insecure-)3^d_7xfyv3#+oz#8rj9tym2=g*n!+-sp#_v!t&h+i0y+gv(8u"
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
@ -31,54 +31,54 @@ ALLOWED_HOSTS = []
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
'django.contrib.admin',
|
"django.contrib.admin",
|
||||||
'django.contrib.auth',
|
"django.contrib.auth",
|
||||||
'django.contrib.contenttypes',
|
"django.contrib.contenttypes",
|
||||||
'django.contrib.sessions',
|
"django.contrib.sessions",
|
||||||
'django.contrib.messages',
|
"django.contrib.messages",
|
||||||
'django.contrib.staticfiles',
|
"django.contrib.staticfiles",
|
||||||
'myapi.apps.MyapiConfig',
|
"myapi.apps.MyapiConfig",
|
||||||
'rest_framework'
|
"rest_framework",
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
'django.middleware.security.SecurityMiddleware',
|
"django.middleware.security.SecurityMiddleware",
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||||
'django.middleware.common.CommonMiddleware',
|
"django.middleware.common.CommonMiddleware",
|
||||||
'django.middleware.csrf.CsrfViewMiddleware',
|
"django.middleware.csrf.CsrfViewMiddleware",
|
||||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
"django.contrib.messages.middleware.MessageMiddleware",
|
||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||||
]
|
]
|
||||||
|
|
||||||
ROOT_URLCONF = 'ulm_cine_club_api.urls'
|
ROOT_URLCONF = "ulm_cine_club_api.urls"
|
||||||
|
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||||
'DIRS': [],
|
"DIRS": [],
|
||||||
'APP_DIRS': True,
|
"APP_DIRS": True,
|
||||||
'OPTIONS': {
|
"OPTIONS": {
|
||||||
'context_processors': [
|
"context_processors": [
|
||||||
'django.template.context_processors.debug',
|
"django.template.context_processors.debug",
|
||||||
'django.template.context_processors.request',
|
"django.template.context_processors.request",
|
||||||
'django.contrib.auth.context_processors.auth',
|
"django.contrib.auth.context_processors.auth",
|
||||||
'django.contrib.messages.context_processors.messages',
|
"django.contrib.messages.context_processors.messages",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
WSGI_APPLICATION = 'ulm_cine_club_api.wsgi.application'
|
WSGI_APPLICATION = "ulm_cine_club_api.wsgi.application"
|
||||||
|
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
|
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
|
||||||
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
"default": {
|
||||||
'ENGINE': 'django.db.backends.sqlite3',
|
"ENGINE": "django.db.backends.sqlite3",
|
||||||
'NAME': BASE_DIR / 'db.sqlite3',
|
"NAME": BASE_DIR / "db.sqlite3",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,16 +88,16 @@ DATABASES = {
|
||||||
|
|
||||||
AUTH_PASSWORD_VALIDATORS = [
|
AUTH_PASSWORD_VALIDATORS = [
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -105,9 +105,9 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/3.2/topics/i18n/
|
# https://docs.djangoproject.com/en/3.2/topics/i18n/
|
||||||
|
|
||||||
LANGUAGE_CODE = 'fr-fr'
|
LANGUAGE_CODE = "fr-fr"
|
||||||
|
|
||||||
TIME_ZONE = 'UTC'
|
TIME_ZONE = "UTC"
|
||||||
|
|
||||||
USE_I18N = True
|
USE_I18N = True
|
||||||
|
|
||||||
|
@ -119,9 +119,9 @@ USE_TZ = True
|
||||||
# Static files (CSS, JavaScript, Images)
|
# Static files (CSS, JavaScript, Images)
|
||||||
# https://docs.djangoproject.com/en/3.2/howto/static-files/
|
# https://docs.djangoproject.com/en/3.2/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = "/static/"
|
||||||
|
|
||||||
# Default primary key field type
|
# Default primary key field type
|
||||||
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
|
# 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"
|
||||||
|
|
|
@ -16,7 +16,4 @@ Including another URLconf
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [path("admin/", admin.site.urls), path("api/", include("myapi.urls"))]
|
||||||
path('admin/', admin.site.urls),
|
|
||||||
path('api/', include('myapi.urls'))
|
|
||||||
]
|
|
||||||
|
|
|
@ -11,6 +11,6 @@ import os
|
||||||
|
|
||||||
from django.core.wsgi import get_wsgi_application
|
from django.core.wsgi import get_wsgi_application
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ulm_cine_club_api.settings')
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ulm_cine_club_api.settings")
|
||||||
|
|
||||||
application = get_wsgi_application()
|
application = get_wsgi_application()
|
||||||
|
|
Loading…
Add table
Reference in a new issue