2019-05-16 14:51:30 +00:00
|
|
|
# -*- coding:utf-8 -*
|
|
|
|
#
|
|
|
|
# Copyright 2017
|
|
|
|
# - Sli <antoine@bartuccio.fr>
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
2019-06-15 22:04:36 +00:00
|
|
|
from django.views.generic import (
|
|
|
|
CreateView,
|
|
|
|
DeleteView,
|
|
|
|
DetailView,
|
|
|
|
UpdateView,
|
|
|
|
ListView,
|
|
|
|
FormView,
|
|
|
|
View,
|
|
|
|
)
|
2019-06-15 15:01:25 +00:00
|
|
|
from django.core.urlresolvers import reverse_lazy
|
2019-05-16 14:51:30 +00:00
|
|
|
|
2019-06-15 15:01:25 +00:00
|
|
|
from core.views import (
|
|
|
|
DetailFormView,
|
|
|
|
CanCreateMixin,
|
|
|
|
CanEditMixin,
|
|
|
|
CanViewMixin,
|
|
|
|
CanEditPropMixin,
|
|
|
|
)
|
|
|
|
|
2019-06-16 00:19:56 +00:00
|
|
|
from pedagogy.forms import UVForm, UVCommentForm
|
2019-06-15 15:01:25 +00:00
|
|
|
from pedagogy.models import UV
|
2019-05-16 14:51:30 +00:00
|
|
|
|
2019-06-15 22:04:36 +00:00
|
|
|
# Some mixins
|
|
|
|
|
|
|
|
|
|
|
|
class CanCreateUVFunctionMixin(View):
|
|
|
|
"""
|
|
|
|
Add the function can_create_uv(user) into the template
|
|
|
|
"""
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def can_create_uv(user):
|
|
|
|
"""
|
|
|
|
Creates a dummy instance of UV and test is_owner
|
|
|
|
"""
|
|
|
|
return user.is_owner(UV())
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
"""
|
|
|
|
Pass the function to the template
|
|
|
|
"""
|
|
|
|
kwargs = super(CanCreateUVFunctionMixin, self).get_context_data(**kwargs)
|
|
|
|
kwargs["can_create_uv"] = self.can_create_uv
|
|
|
|
return kwargs
|
|
|
|
|
|
|
|
|
|
|
|
# Acutal views
|
|
|
|
|
2019-05-16 14:51:30 +00:00
|
|
|
|
2019-06-16 00:19:56 +00:00
|
|
|
class UVDetailFormView(CanViewMixin, CanCreateUVFunctionMixin, DetailFormView):
|
2019-05-16 14:51:30 +00:00
|
|
|
"""
|
|
|
|
Dispaly every comment of an UV and detailed infos about it
|
|
|
|
Allow to comment the UV
|
|
|
|
"""
|
|
|
|
|
2019-06-16 00:19:56 +00:00
|
|
|
model = UV
|
|
|
|
pk_url_kwarg = "uv_id"
|
|
|
|
template_name = "pedagogy/uv_detail.jinja"
|
|
|
|
form_class = UVCommentForm
|
2019-05-16 14:51:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UVCommentDetailView(DetailView):
|
|
|
|
"""
|
|
|
|
Display a specified UVComment (for easy sharing of the comment)
|
|
|
|
"""
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2019-06-15 22:04:36 +00:00
|
|
|
class UVListView(CanViewMixin, CanCreateUVFunctionMixin, ListView):
|
2019-05-16 14:51:30 +00:00
|
|
|
"""
|
|
|
|
UV guide main page
|
|
|
|
"""
|
|
|
|
|
2019-06-15 21:31:31 +00:00
|
|
|
# This is very basic and is prone to changment
|
|
|
|
|
|
|
|
model = UV
|
|
|
|
ordering = ["code"]
|
|
|
|
template_name = "pedagogy/guide.jinja"
|
2019-05-16 14:51:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UVCommentReportCreateView(CreateView):
|
|
|
|
"""
|
|
|
|
Create a new report for an inapropriate comment
|
|
|
|
"""
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class UVCommentReportListView(ListView):
|
|
|
|
"""
|
|
|
|
List all UV reports for moderation (Privileged)
|
|
|
|
"""
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class UVModerationFormView(FormView):
|
|
|
|
"""
|
|
|
|
List all UVs to moderate and allow to moderate them (Privileged)
|
|
|
|
"""
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2019-06-15 15:01:25 +00:00
|
|
|
class UVCreateView(CanCreateMixin, CreateView):
|
2019-05-16 14:51:30 +00:00
|
|
|
"""
|
|
|
|
Add a new UV (Privileged)
|
|
|
|
"""
|
|
|
|
|
2019-06-15 15:01:25 +00:00
|
|
|
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})
|
2019-05-16 14:51:30 +00:00
|
|
|
|
|
|
|
|
2019-06-15 22:04:36 +00:00
|
|
|
class UVDeleteView(CanEditPropMixin, DeleteView):
|
2019-05-16 14:51:30 +00:00
|
|
|
"""
|
|
|
|
Allow to delete an UV (Privileged)
|
|
|
|
"""
|
|
|
|
|
2019-06-15 22:04:36 +00:00
|
|
|
model = UV
|
|
|
|
pk_url_kwarg = "uv_id"
|
|
|
|
template_name = "core/delete_confirm.jinja"
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return reverse_lazy("pedagogy:guide")
|
|
|
|
|
|
|
|
|
|
|
|
class UVUpdateView(CanEditPropMixin, UpdateView):
|
|
|
|
"""
|
|
|
|
Allow to edit an UV (Privilegied)
|
|
|
|
"""
|
|
|
|
|
|
|
|
model = UV
|
|
|
|
form_class = UVForm
|
|
|
|
pk_url_kwarg = "uv_id"
|
|
|
|
template_name = "core/edit.jinja"
|
|
|
|
|
|
|
|
def get_form_kwargs(self):
|
|
|
|
kwargs = super(UVUpdateView, 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})
|
2019-05-16 14:51:30 +00:00
|
|
|
|
|
|
|
|
2019-05-28 23:30:23 +00:00
|
|
|
class EducationDepartmentCreateView(CreateView):
|
2019-05-16 14:51:30 +00:00
|
|
|
"""
|
2019-05-28 23:30:23 +00:00
|
|
|
Add a new Education Department (Privileged)
|
2019-05-16 14:51:30 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2019-05-28 23:30:23 +00:00
|
|
|
class EducationDepartmentDeleteView(DeleteView):
|
2019-05-16 14:51:30 +00:00
|
|
|
"""
|
2019-05-28 23:30:23 +00:00
|
|
|
Allow to delete an Education Department (Privileged)
|
2019-05-16 14:51:30 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2019-05-28 23:33:50 +00:00
|
|
|
class StudyFieldCreateView(CreateView):
|
2019-05-16 14:51:30 +00:00
|
|
|
"""
|
2019-05-28 23:33:50 +00:00
|
|
|
Add a new Study Field (Privileged)
|
2019-05-16 14:51:30 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2019-05-28 23:33:50 +00:00
|
|
|
class StudyFieldDeleteView(DeleteView):
|
2019-05-16 14:51:30 +00:00
|
|
|
"""
|
2019-05-28 23:33:50 +00:00
|
|
|
Allow to delete an Study Field (Privileged)
|
2019-05-16 14:51:30 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
pass
|