Commit 5bf5d027 authored by Sli's avatar Sli

pedagogy: create view and form for UV

WARNING: A new group has been created, to be set by the infra team at deployment !!!
parent 31f6ee9c
Pipeline #1787 passed with stage
in 16 minutes and 4 seconds
......@@ -84,6 +84,7 @@ class Command(BaseCommand):
Group(name="Banned to subscribe").save()
Group(name="SAS admin").save()
Group(name="Forum admin").save()
Group(name="Pedagogy admin").save()
self.reset_index("core", "auth")
root = User(
id=0,
......
# -*- coding:utf-8 -*
#
# Copyright 2016,2017
# - Skia <skia@libskia.so>
#
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
# http://ae.utbm.fr.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License a published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Sofware Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
from django import forms
from core.views.forms import MarkdownInput
from core.models import User
from pedagogy.models import UV
class UVForm(forms.ModelForm):
"""
Form handeling creation and edit of an UV
"""
class Meta:
model = UV
fields = (
"code",
"author",
"credit_type",
"semester",
"language",
"credits",
"hours_CM",
"hours_TD",
"hours_TP",
"hours_THE",
"hours_TE",
"manager",
"title",
"objectives",
"program",
"skills",
"key_concepts",
)
widgets = {
"objectives": MarkdownInput,
"program": MarkdownInput,
"skills": MarkdownInput,
"key_concepts": MarkdownInput,
"author": forms.HiddenInput,
}
def __init__(self, author_id, *args, **kwargs):
super(UVForm, self).__init__(*args, **kwargs)
self.fields["author"].queryset = User.objects.filter(id=author_id).all()
self.fields["author"].initial = author_id
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-06-15 12:13
# Generated by Django 1.11.20 on 2019-06-15 15:00
from __future__ import unicode_literals
from django.conf import settings
......@@ -76,9 +76,11 @@ class Migration(migrations.Migration):
("FREE", "Free"),
("CS", "CS"),
("TM", "TM"),
("OM", "OM"),
("QC", "QC"),
("EC", "EC"),
("CG", "CG"),
("RN", "RN"),
("ST", "ST"),
("EXT", "EXT"),
],
default="FREE",
......@@ -96,7 +98,7 @@ class Migration(migrations.Migration):
("AUTOMN_AND_SPRING", "Autumn and spring"),
],
default="CLOSED",
max_length=10,
max_length=20,
verbose_name="semester",
),
),
......@@ -129,10 +131,11 @@ class Migration(migrations.Migration):
("objectives", models.TextField(verbose_name="objectives")),
("program", models.TextField(verbose_name="program")),
("skills", models.TextField(verbose_name="skills")),
("key_concepts", models.TextField(verbose_name="key_concepts")),
("key_concepts", models.TextField(verbose_name="key concepts")),
(
"hours_CM",
models.IntegerField(
default=0,
validators=[django.core.validators.MinValueValidator(0)],
verbose_name="hours CM",
),
......@@ -140,6 +143,7 @@ class Migration(migrations.Migration):
(
"hours_TD",
models.IntegerField(
default=0,
validators=[django.core.validators.MinValueValidator(0)],
verbose_name="hours TD",
),
......@@ -147,6 +151,7 @@ class Migration(migrations.Migration):
(
"hours_TP",
models.IntegerField(
default=0,
validators=[django.core.validators.MinValueValidator(0)],
verbose_name="hours TP",
),
......@@ -154,6 +159,7 @@ class Migration(migrations.Migration):
(
"hours_THE",
models.IntegerField(
default=0,
validators=[django.core.validators.MinValueValidator(0)],
verbose_name="hours THE",
),
......@@ -161,6 +167,7 @@ class Migration(migrations.Migration):
(
"hours_TE",
models.IntegerField(
default=0,
validators=[django.core.validators.MinValueValidator(0)],
verbose_name="hours TE",
),
......@@ -171,18 +178,7 @@ class Migration(migrations.Migration):
on_delete=django.db.models.deletion.CASCADE,
related_name="created_UVs",
to=settings.AUTH_USER_MODEL,
verbose_name="created UVs",
),
),
(
"moderator",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="moderated_UVs",
to=settings.AUTH_USER_MODEL,
verbose_name="moderated UVs",
verbose_name="author",
),
),
],
......
......@@ -37,6 +37,12 @@ class UV(models.Model):
Contains infos about an UV (course)
"""
def is_owned_by(self, user):
"""
Can be created by superuser, root or pedagogy admin user
"""
return user.is_in_group(settings.SITH_GROUP_PEDAGOGY_ADMIN_ID)
code = models.CharField(
_("code"),
max_length=10,
......@@ -50,17 +56,10 @@ class UV(models.Model):
)
],
)
moderator = models.ForeignKey(
User,
related_name="moderated_UVs",
verbose_name=_("moderated UVs"),
null=True,
blank=True,
)
author = models.ForeignKey(
User,
related_name="created_UVs",
verbose_name=_("created UVs"),
verbose_name=_("author"),
null=False,
blank=False,
)
......@@ -73,7 +72,7 @@ class UV(models.Model):
manager = models.CharField(_("uv manager"), max_length=300)
semester = models.CharField(
_("semester"),
max_length=10,
max_length=20,
choices=settings.SITH_PEDAGOGY_UV_SEMESTER,
default=settings.SITH_PEDAGOGY_UV_SEMESTER[0][0],
)
......@@ -98,7 +97,7 @@ class UV(models.Model):
objectives = models.TextField(_("objectives"))
program = models.TextField(_("program"))
skills = models.TextField(_("skills"))
key_concepts = models.TextField(_("key_concepts"))
key_concepts = models.TextField(_("key concepts"))
# Hours types CM, TD, TP, THE and TE
# Kind of dirty but I have nothing else in mind for now
......@@ -107,30 +106,35 @@ class UV(models.Model):
validators=[validators.MinValueValidator(0)],
blank=False,
null=False,
default=0,
)
hours_TD = models.IntegerField(
_("hours TD"),
validators=[validators.MinValueValidator(0)],
blank=False,
null=False,
default=0,
)
hours_TP = models.IntegerField(
_("hours TP"),
validators=[validators.MinValueValidator(0)],
blank=False,
null=False,
default=0,
)
hours_THE = models.IntegerField(
_("hours THE"),
validators=[validators.MinValueValidator(0)],
blank=False,
null=False,
default=0,
)
hours_TE = models.IntegerField(
_("hours TE"),
validators=[validators.MinValueValidator(0)],
blank=False,
null=False,
default=0,
)
......
......@@ -23,8 +23,18 @@
#
from django.views.generic import CreateView, DeleteView, DetailView, ListView, FormView
from django.core.urlresolvers import reverse_lazy
from core.views import DetailFormView
from core.views import (
DetailFormView,
CanCreateMixin,
CanEditMixin,
CanViewMixin,
CanEditPropMixin,
)
from pedagogy.forms import UVForm
from pedagogy.models import UV
class UVDetailFormView(DetailFormView):
......@@ -76,12 +86,22 @@ class UVModerationFormView(FormView):
pass
class UVCreateView(CreateView):
class UVCreateView(CanCreateMixin, CreateView):
"""
Add a new UV (Privileged)
"""
pass
model = UV
form_class = UVForm
template_name = "core/edit.jinja"
def get_form_kwargs(self):
kwargs = super(UVCreateView, self).get_form_kwargs()
kwargs["author_id"] = self.request.user.id
return kwargs
def get_success_url(self):
return reverse_lazy("pedagogy:uv_detail", kwargs={"uv_id": self.object.id})
class UVDeleteView(DeleteView):
......
......@@ -322,6 +322,7 @@ SITH_GROUP_BANNED_COUNTER_ID = 9
SITH_GROUP_BANNED_SUBSCRIPTION_ID = 10
SITH_GROUP_SAS_ADMIN_ID = 11
SITH_GROUP_FORUM_ADMIN_ID = 12
SITH_GROUP_PEDAGOGY_ADMIN_ID = 13
SITH_CLUB_REFOUND_ID = 89
......@@ -408,9 +409,11 @@ SITH_PEDAGOGY_UV_TYPE = [
("FREE", _("Free")),
("CS", _("CS")),
("TM", _("TM")),
("OM", _("OM")),
("QC", _("QC")),
("EC", _("EC")),
("CG", _("CG")),
("RN", _("RN")),
("ST", _("ST")),
("EXT", _("EXT")),
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment