diff --git a/content/migrations/0001_initial.py b/content/migrations/0001_initial.py
index ff3ec93..004b326 100644
--- a/content/migrations/0001_initial.py
+++ b/content/migrations/0001_initial.py
@@ -1,4 +1,4 @@
-# Generated by Django 2.0.1 on 2018-02-28 12:53
+# Generated by Django 2.0.1 on 2018-02-28 18:43
from django.db import migrations, models
import django.db.models.deletion
@@ -9,7 +9,6 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
- ('auth', '0009_alter_user_last_name_max_length'),
]
operations = [
@@ -27,9 +26,8 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255, verbose_name='Nom du contenu')),
- ('content_url', models.URLField(null=True, verbose_name='URL du contenu')),
+ ('file', models.FileField(upload_to='', verbose_name='Fichier')),
('category', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='content.Category', verbose_name='Catégorie')),
- ('group_owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='auth.Group')),
],
),
]
diff --git a/content/migrations/0002_content_school_owner.py b/content/migrations/0002_content_school_owner.py
new file mode 100644
index 0000000..affdd4d
--- /dev/null
+++ b/content/migrations/0002_content_school_owner.py
@@ -0,0 +1,22 @@
+# Generated by Django 2.0.1 on 2018-02-28 18:43
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ initial = True
+
+ dependencies = [
+ ('content', '0001_initial'),
+ ('users', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='content',
+ name='school_owner',
+ field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='users.SchoolProfile'),
+ ),
+ ]
diff --git a/content/models.py b/content/models.py
index 2fefee0..99a61f4 100644
--- a/content/models.py
+++ b/content/models.py
@@ -3,6 +3,7 @@ from django.urls import reverse
from django.contrib.auth.models import Group
from django.conf import settings
+from users.models import SchoolProfile
class Category(models.Model):
"""Une catégorie de contenu."""
@@ -31,20 +32,19 @@ class Content(models.Model):
max_length=255,
verbose_name="Nom du contenu"
)
- group_owner = models.ForeignKey(
- Group,
+ school_owner = models.ForeignKey(
+ SchoolProfile,
on_delete=models.CASCADE,
)
- content_url = models.URLField(
- verbose_name='URL du contenu',
- null=True,
- )
category = models.ForeignKey(
Category,
on_delete=models.SET_NULL,
verbose_name="Catégorie",
null=True
)
+ file = models.FileField(
+ verbose_name="Fichier"
+ )
def __str__(self):
return self.name
diff --git a/content/templates/content/content.html b/content/templates/content/content.html
new file mode 100644
index 0000000..3f86de4
--- /dev/null
+++ b/content/templates/content/content.html
@@ -0,0 +1,18 @@
+
+
+
+
+
{{content.name}}
+
Contenu proposé par {{content.school_owner.group.name}}
+
+
+
+
+
diff --git a/content/templates/content/content_list.html b/content/templates/content/content_list.html
index e74ab0b..d6fb175 100644
--- a/content/templates/content/content_list.html
+++ b/content/templates/content/content_list.html
@@ -27,18 +27,11 @@ $('html, body').animate({scrollTop: $('#category-content').offset().top}, 800);
-
+
{% for content in contents %}
-
-
-
{{content.name}}
-
Contenu proposé par {{content.group_owner.name}}
-
-
-
+ {% include "content/content.html" %}
{% endfor %}
+
diff --git a/content/urls.py b/content/urls.py
index 6ce5612..ab53c2a 100644
--- a/content/urls.py
+++ b/content/urls.py
@@ -5,6 +5,9 @@ from .views import (
CreateCategory,
DeleteCategory,
EditCategory,
+ CreateContent,
+ DeleteContent,
+ EditContent,
)
app_name = 'content'
@@ -28,5 +31,21 @@ urlpatterns = [
'category/edit/',
EditCategory.as_view(),
name='category-edit',
- )
+ ),
+ path(
+ 'new',
+ CreateContent.as_view(),
+ name='content-new',
+ ),
+ path(
+ '/delete',
+ DeleteContent.as_view(),
+ name="content-delete",
+ ),
+ path(
+ '/edit',
+ EditContent.as_view(),
+ name="content-edit",
+ ),
+
]
diff --git a/content/views.py b/content/views.py
index 56ea358..601a2e7 100644
--- a/content/views.py
+++ b/content/views.py
@@ -54,3 +54,53 @@ class EditCategory(generic.UpdateView):
return context
+class CreateContent(generic.CreateView):
+ """Création de contenu."""
+ model = Content
+ fields = [
+ 'name',
+ 'category',
+ 'file'
+ ]
+ template_name = "edit.html"
+ extra_context = {
+ 'title' : 'Envoi de contenu',
+ 'validate' : 'Envoyer'
+ }
+
+ def get_success_url(self):
+ return self.object.school_owner.get_absolute_url()
+
+ def form_valid(self, form):
+ form.instance.school_owner = self.request.user.userprofile.school
+ r = super().form_valid(form)
+ return r
+
+
+class DeleteContent(generic.DeleteView):
+ """Suppression de contenu"""
+ model = Content
+ template_name = "confirm_delete.html"
+
+ def get_success_url(self):
+ return self.object.school_owner.get_absolute_url()
+
+
+class EditContent(generic.UpdateView):
+ """Édition d'un contenu"""
+ model = Content
+ template_name = "edit.html"
+ fields = [
+ 'name',
+ 'category',
+ 'file'
+ ]
+ template_name = "edit.html"
+ extra_context = {
+ 'title' : 'Édition de contenu',
+ 'validate' : 'Envoyer'
+ }
+
+ def get_success_url(self):
+ return self.object.school_owner.get_absolute_url()
+
diff --git a/settings/admin.py b/settings/admin.py
index 0395fe9..49005c3 100644
--- a/settings/admin.py
+++ b/settings/admin.py
@@ -1,6 +1,5 @@
from django.contrib import admin
-from .models import SiteSettings, ContentSettings
+from .models import SiteSettings
admin.site.register(SiteSettings)
-admin.site.register(ContentSettings)
diff --git a/settings/migrations/0001_initial.py b/settings/migrations/0001_initial.py
index d805f92..035ff9e 100644
--- a/settings/migrations/0001_initial.py
+++ b/settings/migrations/0001_initial.py
@@ -1,7 +1,6 @@
-# Generated by Django 2.0.1 on 2018-02-28 12:53
+# Generated by Django 2.0.1 on 2018-02-28 18:43
from django.db import migrations, models
-import settings.aes_field
class Migration(migrations.Migration):
@@ -12,15 +11,6 @@ class Migration(migrations.Migration):
]
operations = [
- migrations.CreateModel(
- name='ContentSettings',
- fields=[
- ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
- ('ftp_url', models.URLField(default='', max_length=255, verbose_name='URL du FTP')),
- ('ftp_id', models.CharField(default='', max_length=255, verbose_name='Identifiant sur le FTP')),
- ('ftp_pass', settings.aes_field.AESEncryptedField(default='', max_length=255, verbose_name='Mot de passe')),
- ],
- ),
migrations.CreateModel(
name='SiteSettings',
fields=[
diff --git a/settings/models.py b/settings/models.py
index 0ab68cf..73ec1cd 100644
--- a/settings/models.py
+++ b/settings/models.py
@@ -3,25 +3,6 @@ from django.db import models
from .aes_field import AESEncryptedField
-class ContentSettings(models.Model):
- PRETTY_NAME = "Réglages des contenus"
- ftp_url = models.URLField(
- max_length=255,
- verbose_name="URL du FTP",
- default="",
- )
- ftp_id = models.CharField(
- max_length=255,
- verbose_name="Identifiant sur le FTP",
- default=""
- )
- ftp_pass = AESEncryptedField(
- max_length=255,
- verbose_name="Mot de passe",
- default=""
- )
-
-
class SiteSettings(models.Model):
PRETTY_NAME = "Réglages du site"
allow_upload = models.BooleanField(
diff --git a/settings/templates/settings/settings.html b/settings/templates/settings/settings.html
index 3bffb27..c42dd06 100644
--- a/settings/templates/settings/settings.html
+++ b/settings/templates/settings/settings.html
@@ -61,7 +61,6 @@
{% endfor %}
Réglages
-Réglages du site
Éditer
@@ -84,22 +83,4 @@
{{site_settings.home_message}} |
-
-Réglage du contenu
-
-
- Éditer
-
-
-
-
-
- URL du FTP |
- {{content_settings.ftp_url}} |
-
-
- Identifiant du FTP |
- {{content_settings.ftp_id}} |
-
-
{% endblock %}
diff --git a/settings/views.py b/settings/views.py
index a841f4a..47b5c1e 100644
--- a/settings/views.py
+++ b/settings/views.py
@@ -2,7 +2,7 @@ from django.views.generic import TemplateView, UpdateView
from django.urls import reverse_lazy
from content.models import Category
from users.models import SchoolProfile
-from .models import ContentSettings, SiteSettings
+from .models import SiteSettings
class SettingsView(TemplateView):
@@ -12,7 +12,6 @@ class SettingsView(TemplateView):
context = super().get_context_data(**kwargs)
context['categories'] = Category.objects.all()
context['site_settings'], _ = SiteSettings.objects.get_or_create()
- context['content_settings'], _ = ContentSettings.objects.get_or_create()
context['schools'] = SchoolProfile.objects.all()
context['settings'] = True
return context
diff --git a/templates/confirm_delete.html b/templates/confirm_delete.html
index 524de5b..6d7994c 100644
--- a/templates/confirm_delete.html
+++ b/templates/confirm_delete.html
@@ -1,5 +1,6 @@
{% extends 'base.html' %}
{% block content %}
+Suppression