mirror of
https://github.com/ae-utbm/sith.git
synced 2024-12-22 15:51:19 +00:00
pedagogy: complete CRUD for UV model
This commit is contained in:
parent
ec33311715
commit
ab344ba02f
@ -44,8 +44,14 @@ class UV(models.Model):
|
||||
return user.is_in_group(settings.SITH_GROUP_PEDAGOGY_ADMIN_ID)
|
||||
|
||||
def can_be_viewed_by(self, user):
|
||||
"""
|
||||
Only visible by subscribers
|
||||
"""
|
||||
return user.is_subscribed
|
||||
|
||||
def __str__(self):
|
||||
return self.code
|
||||
|
||||
code = models.CharField(
|
||||
_("code"),
|
||||
max_length=10,
|
||||
|
@ -6,7 +6,18 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if can_create_uv(user) %}
|
||||
<p>
|
||||
<a href="{{ url('pedagogy:uv_create') }}">{% trans %}Create UV{% endtrans %}</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
{% for uv in object_list %}
|
||||
{{ uv.code }}
|
||||
<p>
|
||||
{{ uv.code }}
|
||||
{% if user.is_owner(uv) -%}
|
||||
<a href="{{ url('pedagogy:uv_update', uv_id=uv.id) }}">{% trans %}Edit{% endtrans %}</a>
|
||||
<a href="{{ url('pedagogy:uv_delete', uv_id=uv.id) }}">{% trans %}Delete{% endtrans %}</a>
|
||||
{%- endif -%}
|
||||
</p>
|
||||
{% endfor %}
|
||||
{% endblock content %}
|
@ -46,6 +46,7 @@ urlpatterns = [
|
||||
# Administration : Create Update Delete Edit
|
||||
url(r"^uv/create$", UVCreateView.as_view(), name="uv_create"),
|
||||
url(r"^uv/(?P<uv_id>[0-9]+)/delete$", UVDeleteView.as_view(), name="uv_delete"),
|
||||
url(r"^uv/(?P<uv_id>[0-9]+)/edit$", UVUpdateView.as_view(), name="uv_update"),
|
||||
url(
|
||||
r"^department/create$",
|
||||
EducationDepartmentCreateView.as_view(),
|
||||
|
@ -22,7 +22,15 @@
|
||||
#
|
||||
#
|
||||
|
||||
from django.views.generic import CreateView, DeleteView, DetailView, ListView, FormView
|
||||
from django.views.generic import (
|
||||
CreateView,
|
||||
DeleteView,
|
||||
DetailView,
|
||||
UpdateView,
|
||||
ListView,
|
||||
FormView,
|
||||
View,
|
||||
)
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
|
||||
from core.views import (
|
||||
@ -36,6 +44,32 @@ from core.views import (
|
||||
from pedagogy.forms import UVForm
|
||||
from pedagogy.models import UV
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
class UVDetailFormView(DetailFormView):
|
||||
"""
|
||||
@ -54,7 +88,7 @@ class UVCommentDetailView(DetailView):
|
||||
pass
|
||||
|
||||
|
||||
class UVListView(CanViewMixin, ListView):
|
||||
class UVListView(CanViewMixin, CanCreateUVFunctionMixin, ListView):
|
||||
"""
|
||||
UV guide main page
|
||||
"""
|
||||
@ -108,12 +142,36 @@ class UVCreateView(CanCreateMixin, CreateView):
|
||||
return reverse_lazy("pedagogy:uv_detail", kwargs={"uv_id": self.object.id})
|
||||
|
||||
|
||||
class UVDeleteView(DeleteView):
|
||||
class UVDeleteView(CanEditPropMixin, DeleteView):
|
||||
"""
|
||||
Allow to delete an UV (Privileged)
|
||||
"""
|
||||
|
||||
pass
|
||||
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})
|
||||
|
||||
|
||||
class EducationDepartmentCreateView(CreateView):
|
||||
|
Loading…
Reference in New Issue
Block a user