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/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 '' 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) 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"), + ), + ] 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/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 '' 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': [ 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 @@ + + +
+ +{{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 @@ +