mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 22:23:23 +00:00
pedagogy: functional but basic uv comment system
This commit is contained in:
parent
b7c2da53fe
commit
5003e57338
@ -77,4 +77,25 @@ class UVCommentForm(forms.ModelForm):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = UVComment
|
model = UVComment
|
||||||
fields = ()
|
fields = (
|
||||||
|
"author",
|
||||||
|
"uv",
|
||||||
|
"grade_global",
|
||||||
|
"grade_utility",
|
||||||
|
"grade_interest",
|
||||||
|
"grade_teaching",
|
||||||
|
"grade_work_load",
|
||||||
|
"comment",
|
||||||
|
)
|
||||||
|
widgets = {
|
||||||
|
"comment": MarkdownInput,
|
||||||
|
"author": forms.HiddenInput,
|
||||||
|
"uv": forms.HiddenInput,
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, author_id, uv_id, *args, **kwargs):
|
||||||
|
super(UVCommentForm, self).__init__(*args, **kwargs)
|
||||||
|
self.fields["author"].queryset = User.objects.filter(id=author_id).all()
|
||||||
|
self.fields["author"].initial = author_id
|
||||||
|
self.fields["uv"].queryset = UV.objects.filter(id=uv_id).all()
|
||||||
|
self.fields["uv"].initial = uv_id
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Generated by Django 1.11.20 on 2019-06-16 13:36
|
# Generated by Django 1.11.20 on 2019-06-16 14:22
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@ -264,6 +264,15 @@ class Migration(migrations.Migration):
|
|||||||
verbose_name="author",
|
verbose_name="author",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"uv",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
related_name="comments",
|
||||||
|
to="pedagogy.UV",
|
||||||
|
verbose_name="uv",
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
|
@ -152,6 +152,12 @@ class UVComment(models.Model):
|
|||||||
A comment about an UV
|
A comment about an UV
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def is_owned_by(self, user):
|
||||||
|
"""
|
||||||
|
Is owned by a pedagogy admin, a superuser or the author himself
|
||||||
|
"""
|
||||||
|
return self.author == user or user.is_owner(self.uv)
|
||||||
|
|
||||||
author = models.ForeignKey(
|
author = models.ForeignKey(
|
||||||
User,
|
User,
|
||||||
related_name="uv_comments",
|
related_name="uv_comments",
|
||||||
@ -159,6 +165,7 @@ class UVComment(models.Model):
|
|||||||
null=False,
|
null=False,
|
||||||
blank=False,
|
blank=False,
|
||||||
)
|
)
|
||||||
|
uv = models.ForeignKey(UV, related_name="comments", verbose_name=_("uv"))
|
||||||
comment = models.TextField(_("comment"))
|
comment = models.TextField(_("comment"))
|
||||||
grade_global = models.IntegerField(
|
grade_global = models.IntegerField(
|
||||||
_("global grade"),
|
_("global grade"),
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% for uv in object_list %}
|
{% for uv in object_list %}
|
||||||
<p>
|
<p>
|
||||||
{{ uv.code }}
|
<a href="{{ url('pedagogy:uv_detail', uv_id=uv.id) }}">{{ uv.code }}</a>
|
||||||
{% if user.is_owner(uv) -%}
|
{% if user.is_owner(uv) -%}
|
||||||
<a href="{{ url('pedagogy:uv_update', uv_id=uv.id) }}">{% trans %}Edit{% endtrans %}</a>
|
<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>
|
<a href="{{ url('pedagogy:uv_delete', uv_id=uv.id) }}">{% trans %}Delete{% endtrans %}</a>
|
||||||
|
@ -10,4 +10,27 @@
|
|||||||
<p>{{ object.program|markdown }}</p>
|
<p>{{ object.program|markdown }}</p>
|
||||||
<p>{{ object.skills|markdown }}</p>
|
<p>{{ object.skills|markdown }}</p>
|
||||||
<p>{{ object.key_concepts|markdown }}</p>
|
<p>{{ object.key_concepts|markdown }}</p>
|
||||||
|
|
||||||
|
{% if object.comments.exists() %}
|
||||||
|
<h2>{% trans %}Comments{% endtrans %}</h2>
|
||||||
|
{% for comment in object.comments.all() %}
|
||||||
|
<p>{{ comment.grade_global }}</p>
|
||||||
|
<p>{{ comment.grade_utility }}</p>
|
||||||
|
<p>{{ comment.grade_interest }}</p>
|
||||||
|
<p>{{ comment.grade_teaching }}</p>
|
||||||
|
<p>{{ comment.grade_work_load }}</p>
|
||||||
|
<p>{{ comment.comment }}</p>
|
||||||
|
{% if user.is_owner(comment) %}
|
||||||
|
<p><a href="{{ url('pedagogy:comment_edit', comment_id=comment.id) }}">{% trans %}Edit{% endtrans %}</a></p>
|
||||||
|
<p><a href="{{ url('pedagogy:comment_delete', comment_id=comment.id) }}">{% trans %}Delete{% endtrans %}</a></p>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<h2>{% trans %}Leave comment{% endtrans %}</h2>
|
||||||
|
<form action="{{ url('pedagogy:uv_detail', uv_id=object.id) }}" method="post" enctype="multipart/form-data">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p() }}
|
||||||
|
<p><input type="submit" value="{% trans %}Comment{% endtrans %}" /></p>
|
||||||
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
@ -31,9 +31,14 @@ urlpatterns = [
|
|||||||
url(r"^$", UVListView.as_view(), name="guide"),
|
url(r"^$", UVListView.as_view(), name="guide"),
|
||||||
url(r"^uv/(?P<uv_id>[0-9]+)$", UVDetailFormView.as_view(), name="uv_detail"),
|
url(r"^uv/(?P<uv_id>[0-9]+)$", UVDetailFormView.as_view(), name="uv_detail"),
|
||||||
url(
|
url(
|
||||||
r"^comment/(?P<comment_id>[0-9]+)$",
|
r"^comment/(?P<comment_id>[0-9]+)/edit$",
|
||||||
UVCommentDetailView.as_view(),
|
UVCommentUpdateView.as_view(),
|
||||||
name="comment_detail",
|
name="comment_edit",
|
||||||
|
),
|
||||||
|
url(
|
||||||
|
r"^comment/(?P<comment_id>[0-9]+)/delete$",
|
||||||
|
UVCommentDeleteView.as_view(),
|
||||||
|
name="comment_delete",
|
||||||
),
|
),
|
||||||
url(
|
url(
|
||||||
r"^comment/(?P<comment_id>[0-9]+)/report$",
|
r"^comment/(?P<comment_id>[0-9]+)/report$",
|
||||||
|
@ -42,7 +42,7 @@ from core.views import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from pedagogy.forms import UVForm, UVCommentForm
|
from pedagogy.forms import UVForm, UVCommentForm
|
||||||
from pedagogy.models import UV
|
from pedagogy.models import UV, UVComment
|
||||||
|
|
||||||
# Some mixins
|
# Some mixins
|
||||||
|
|
||||||
@ -82,13 +82,54 @@ class UVDetailFormView(CanViewMixin, CanCreateUVFunctionMixin, DetailFormView):
|
|||||||
template_name = "pedagogy/uv_detail.jinja"
|
template_name = "pedagogy/uv_detail.jinja"
|
||||||
form_class = UVCommentForm
|
form_class = UVCommentForm
|
||||||
|
|
||||||
|
def get_form_kwargs(self):
|
||||||
|
kwargs = super(UVDetailFormView, self).get_form_kwargs()
|
||||||
|
kwargs["author_id"] = self.request.user.id
|
||||||
|
kwargs["uv_id"] = self.get_object().id
|
||||||
|
return kwargs
|
||||||
|
|
||||||
class UVCommentDetailView(DetailView):
|
def form_valid(self, form):
|
||||||
|
form.save()
|
||||||
|
return super(UVDetailFormView, self).form_valid(form)
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
return reverse_lazy(
|
||||||
|
"pedagogy:uv_detail", kwargs={"uv_id": self.get_object().id}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class UVCommentUpdateView(CanEditPropMixin, UpdateView):
|
||||||
"""
|
"""
|
||||||
Display a specified UVComment (for easy sharing of the comment)
|
Allow edit of a given comment
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pass
|
model = UVComment
|
||||||
|
form_class = UVCommentForm
|
||||||
|
pk_url_kwarg = "comment_id"
|
||||||
|
template_name = "core/edit.jinja"
|
||||||
|
|
||||||
|
def get_form_kwargs(self):
|
||||||
|
kwargs = super(UVCommentUpdateView, self).get_form_kwargs()
|
||||||
|
kwargs["author_id"] = self.request.user.id
|
||||||
|
kwargs["uv_id"] = self.get_object().uv.id
|
||||||
|
|
||||||
|
return kwargs
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
return reverse_lazy("pedagogy:uv_detail", kwargs={"uv_id": self.object.uv.id})
|
||||||
|
|
||||||
|
|
||||||
|
class UVCommentDeleteView(CanEditPropMixin, DeleteView):
|
||||||
|
"""
|
||||||
|
Allow delete of a given comment
|
||||||
|
"""
|
||||||
|
|
||||||
|
model = UVComment
|
||||||
|
pk_url_kwarg = "comment_id"
|
||||||
|
template_name = "core/delete_confirm.jinja"
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
return reverse_lazy("pedagogy:uv_detail", kwargs={"uv_id": self.object.uv.id})
|
||||||
|
|
||||||
|
|
||||||
class UVListView(CanViewMixin, CanCreateUVFunctionMixin, ListView):
|
class UVListView(CanViewMixin, CanCreateUVFunctionMixin, ListView):
|
||||||
|
Loading…
Reference in New Issue
Block a user