From 5a96b90025d3f5dfdc100c20124de14b540336fd Mon Sep 17 00:00:00 2001 From: Klafyvel Date: Sat, 20 Jan 2018 23:07:16 +0100 Subject: [PATCH 1/6] Admin --- content/admin.py | 5 ++++- settings/admin.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/content/admin.py b/content/admin.py index 8c38f3f..75f042a 100644 --- a/content/admin.py +++ b/content/admin.py @@ -1,3 +1,6 @@ from django.contrib import admin -# Register your models here. +from .models import Category, Content + +admin.site.register(Category) +admin.site.register(Content) diff --git a/settings/admin.py b/settings/admin.py index 8c38f3f..0395fe9 100644 --- a/settings/admin.py +++ b/settings/admin.py @@ -1,3 +1,6 @@ from django.contrib import admin -# Register your models here. +from .models import SiteSettings, ContentSettings + +admin.site.register(SiteSettings) +admin.site.register(ContentSettings) From afb8d3c0ecd9d08235c5e70fba3bc9c49411f94d Mon Sep 17 00:00:00 2001 From: Klafyvel Date: Sat, 20 Jan 2018 23:08:46 +0100 Subject: [PATCH 2/6] FTP encryption --- settings/models.py | 24 ++++++++++++++++-------- site_tps/settings.py | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/settings/models.py b/settings/models.py index 2575479..b4a4ddd 100644 --- a/settings/models.py +++ b/settings/models.py @@ -1,6 +1,6 @@ from django.db import models import binascii -import site_tps.qaes +from site_tps import qaes from django.conf import settings @@ -17,23 +17,31 @@ class AESEncryptedField(models.CharField): class ContentSettings(models.Model): ftp_url = models.URLField( max_length=255, - name="URL du FTP", + verbose_name="URL du FTP", + default="", ) ftp_id = models.CharField( max_length=255, - name="Identifiant sur le FTP", + verbose_name="Identifiant sur le FTP", + default="" ) ftp_pass = AESEncryptedField( max_length=255, - name="Mot de passe" + verbose_name="Mot de passe", + default="" ) class SiteSettings(models.Model): allow_upload = models.BooleanField( - help_text="Autoriser l'upload de vidéos." + verbose_name="Autoriser l'upload de vidéos.", + default=False, ) - site_name = models.CharField( - max_length=255, - help_text="Nom du site", + home_message = models.TextField( + verbose_name="Message de la page d'accueil", + default="" ) + + @classmethod + def get_settings(cls): + return cls.objects.get_or_create()[0] diff --git a/site_tps/settings.py b/site_tps/settings.py index 3b190e8..ab16df0 100644 --- a/site_tps/settings.py +++ b/site_tps/settings.py @@ -56,7 +56,7 @@ ROOT_URLCONF = 'site_tps.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], + 'DIRS': [os.path.join(BASE_DIR, 'templates')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ From 1b830b87fb45f077d12723c93e605d6d54b9ffb1 Mon Sep 17 00:00:00 2001 From: Klafyvel Date: Sat, 20 Jan 2018 23:09:55 +0100 Subject: [PATCH 3/6] =?UTF-8?q?Chargement=20des=20cat=C3=A9gories=20par=20?= =?UTF-8?q?templatetag.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- content/templatetags/__init__.py | 0 content/templatetags/categories.py | 15 +++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 content/templatetags/__init__.py create mode 100644 content/templatetags/categories.py diff --git a/content/templatetags/__init__.py b/content/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/content/templatetags/categories.py b/content/templatetags/categories.py new file mode 100644 index 0000000..fb31157 --- /dev/null +++ b/content/templatetags/categories.py @@ -0,0 +1,15 @@ +from django import template +from content.models import Category + +register = template.Library() + + +@register.tag('load_categories') +def load_site_settings(parser, token): + return LoadCategoriesNode() + + +class LoadCategoriesNode(template.Node): + def render(self, context): + context['categories'] = Category.objects.all() + return '' From 32a7493bb7e2a3dad273db68082da216ed516c19 Mon Sep 17 00:00:00 2001 From: Klafyvel Date: Sat, 20 Jan 2018 23:11:00 +0100 Subject: [PATCH 4/6] Migrations. --- .../migrations/0002_auto_20180114_1832.py | 31 ++++++++++ .../migrations/0003_auto_20180114_1837.py | 59 +++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 settings/migrations/0002_auto_20180114_1832.py create mode 100644 settings/migrations/0003_auto_20180114_1837.py diff --git a/settings/migrations/0002_auto_20180114_1832.py b/settings/migrations/0002_auto_20180114_1832.py new file mode 100644 index 0000000..abab904 --- /dev/null +++ b/settings/migrations/0002_auto_20180114_1832.py @@ -0,0 +1,31 @@ +# Generated by Django 2.0.1 on 2018-01-14 18:32 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('settings', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='sitesettings', + name='allow_upload', + ), + migrations.RemoveField( + model_name='sitesettings', + name='site_name', + ), + migrations.AddField( + model_name='sitesettings', + name="Autoriser l'upload de vidéos.", + field=models.BooleanField(default=False), + ), + migrations.AddField( + model_name='sitesettings', + name="Message de la page d'accueil", + field=models.TextField(default=''), + ), + ] diff --git a/settings/migrations/0003_auto_20180114_1837.py b/settings/migrations/0003_auto_20180114_1837.py new file mode 100644 index 0000000..27d6385 --- /dev/null +++ b/settings/migrations/0003_auto_20180114_1837.py @@ -0,0 +1,59 @@ +# Generated by Django 2.0.1 on 2018-01-14 18:37 + +from django.db import migrations, models +import settings.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('settings', '0002_auto_20180114_1832'), + ] + + operations = [ + migrations.RemoveField( + model_name='contentsettings', + name='Identifiant sur le FTP', + ), + migrations.RemoveField( + model_name='contentsettings', + name='Mot de passe', + ), + migrations.RemoveField( + model_name='contentsettings', + name='URL du FTP', + ), + migrations.RemoveField( + model_name='sitesettings', + name="Autoriser l'upload de vidéos.", + ), + migrations.RemoveField( + model_name='sitesettings', + name="Message de la page d'accueil", + ), + migrations.AddField( + model_name='contentsettings', + name='ftp_id', + field=models.CharField(default='', max_length=255, verbose_name='Identifiant sur le FTP'), + ), + migrations.AddField( + model_name='contentsettings', + name='ftp_pass', + field=settings.models.AESEncryptedField(default='', max_length=255, verbose_name='Mot de passe'), + ), + migrations.AddField( + model_name='contentsettings', + name='ftp_url', + field=models.URLField(default='', max_length=255, verbose_name='URL du FTP'), + ), + migrations.AddField( + model_name='sitesettings', + name='allow_upload', + field=models.BooleanField(default=False, verbose_name="Autoriser l'upload de vidéos."), + ), + migrations.AddField( + model_name='sitesettings', + name='home_message', + field=models.TextField(default='', verbose_name="Message de la page d'accueil"), + ), + ] From 5dfa004a4fa20a24529faad214f88d7eeed62dcc Mon Sep 17 00:00:00 2001 From: Klafyvel Date: Sat, 20 Jan 2018 23:13:30 +0100 Subject: [PATCH 5/6] Templatetag pour charger les options du site --- settings/templatetags/__init__.py | 0 settings/templatetags/load_settings.py | 15 +++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 settings/templatetags/__init__.py create mode 100644 settings/templatetags/load_settings.py diff --git a/settings/templatetags/__init__.py b/settings/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/settings/templatetags/load_settings.py b/settings/templatetags/load_settings.py new file mode 100644 index 0000000..e45c9b1 --- /dev/null +++ b/settings/templatetags/load_settings.py @@ -0,0 +1,15 @@ +from django import template +from settings.models import SiteSettings + +register = template.Library() + + +@register.tag('load_site_settings') +def load_site_settings(parser, token): + return LoadSiteSettingsNode() + + +class LoadSiteSettingsNode(template.Node): + def render(self, context): + context['site_settings'] = SiteSettings.get_settings() + return '' From e172c3e2e2322ce816f35a0916895cb48cde103d Mon Sep 17 00:00:00 2001 From: Klafyvel Date: Sat, 20 Jan 2018 23:14:11 +0100 Subject: [PATCH 6/6] =?UTF-8?q?D=C3=A9but=20d'affichage.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- site_tps/urls.py | 3 +++ site_tps/views.py | 10 ++++++++++ templates/base.html | 16 ++++++++++++++++ templates/home.html | 7 +++++++ templates/nav_bar.html | 8 ++++++++ 5 files changed, 44 insertions(+) create mode 100644 site_tps/views.py create mode 100644 templates/home.html create mode 100644 templates/nav_bar.html diff --git a/site_tps/urls.py b/site_tps/urls.py index 997c293..dd0d9e5 100644 --- a/site_tps/urls.py +++ b/site_tps/urls.py @@ -16,6 +16,9 @@ Including another URLconf from django.contrib import admin from django.urls import path +from . import views + urlpatterns = [ path('admin/', admin.site.urls), + path('', views.home), ] diff --git a/site_tps/views.py b/site_tps/views.py new file mode 100644 index 0000000..a90820c --- /dev/null +++ b/site_tps/views.py @@ -0,0 +1,10 @@ +from django.shortcuts import render +from settings.models import SiteSettings + + +def home(request): + settings, _created = SiteSettings.objects.get_or_create() + return render(request, "home.html", { + 'upload_allowed': settings.allow_upload, + 'message': settings.home_message, + }) diff --git a/templates/base.html b/templates/base.html index e69de29..7d2ac97 100644 --- a/templates/base.html +++ b/templates/base.html @@ -0,0 +1,16 @@ + + + + + NOM DE SITE + + + + + {% include 'nav_bar.html' %} + {% block content %}{% endblock %} + + + + + diff --git a/templates/home.html b/templates/home.html new file mode 100644 index 0000000..5d33ec9 --- /dev/null +++ b/templates/home.html @@ -0,0 +1,7 @@ +{% extends 'base.html'%} +{% block content %} +

{{message|safe}}

+{% if not upload_allowed %} +

Les envois de contenu ne sont pas autorisés actuellement.

+{% endif %} +{% endblock %} diff --git a/templates/nav_bar.html b/templates/nav_bar.html new file mode 100644 index 0000000..54d5ddd --- /dev/null +++ b/templates/nav_bar.html @@ -0,0 +1,8 @@ +