mirror of
https://github.com/ae-utbm/sith.git
synced 2026-08-28 08:09:16 +00:00
Use HTMX in UE details
This commit is contained in:
+1
-1
@@ -473,7 +473,7 @@ class UserClubView(UserTabsMixin, CanViewMixin, DetailView):
|
|||||||
class UserVisibilityFormFragment(FragmentMixin, SuccessMessageMixin, UpdateView):
|
class UserVisibilityFormFragment(FragmentMixin, SuccessMessageMixin, UpdateView):
|
||||||
model = User
|
model = User
|
||||||
form_class = UserVisibilityForm
|
form_class = UserVisibilityForm
|
||||||
template_name = "core/fragment/user_visibility.jinja"
|
template_name = "core/fragments/user_visibility.jinja"
|
||||||
pk_url_kwarg = "user_id"
|
pk_url_kwarg = "user_id"
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
def get_form_kwargs(self):
|
||||||
|
|||||||
+5
-1
@@ -126,7 +126,11 @@ class UE(models.Model):
|
|||||||
Returns:
|
Returns:
|
||||||
True if the user has already posted a comment on this UE, else False.
|
True if the user has already posted a comment on this UE, else False.
|
||||||
"""
|
"""
|
||||||
return self.comments.filter(author=user).exists()
|
self._has_user_commented = getattr(self, "_has_user_commented", {})
|
||||||
|
self._has_user_commented[user] = self._has_user_commented.get(
|
||||||
|
user, self.comments.filter(author=user).exists()
|
||||||
|
)
|
||||||
|
return self._has_user_commented[user]
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def grade_global_average(self):
|
def grade_global_average(self):
|
||||||
|
|||||||
@@ -205,14 +205,14 @@ $pedagogy-white-text: #f0f0f0;
|
|||||||
grid-area: hours-the;
|
grid-area: hours-the;
|
||||||
}
|
}
|
||||||
|
|
||||||
#leave_comment_not_allowed {
|
.leave-comment-not-allowed {
|
||||||
p {
|
p {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: red;
|
color: red;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#leave_comment {
|
.leave-comment {
|
||||||
.leave-comment-grid-container {
|
.leave-comment-grid-container {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 270px auto;
|
grid-template-columns: 270px auto;
|
||||||
@@ -246,9 +246,11 @@ $pedagogy-white-text: #f0f0f0;
|
|||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
input[type="submit"] {
|
.right {
|
||||||
float: right;
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.ue-details-container {
|
.ue-details-container {
|
||||||
@@ -410,8 +412,9 @@ $pedagogy-white-text: #f0f0f0;
|
|||||||
padding-left: 10px;
|
padding-left: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.actions {
|
.action {
|
||||||
float: right;
|
float: right;
|
||||||
|
margin-top: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
{% from "pedagogy/macros.jinja" import display_star %}
|
||||||
|
{% from "core/macros.jinja" import user_profile_link %}
|
||||||
|
|
||||||
|
<div id="comment-{{ comment.id }}" class="comment-container">
|
||||||
|
|
||||||
|
<div class="grade-block">
|
||||||
|
<div class="grade-type">
|
||||||
|
<p>{% trans %}Global grade{% endtrans %}</p>
|
||||||
|
<p>{% trans %}Utility{% endtrans %}</p>
|
||||||
|
<p>{% trans %}Interest{% endtrans %}</p>
|
||||||
|
<p>{% trans %}Teaching{% endtrans %}</p>
|
||||||
|
<p>{% trans %}Work load{% endtrans %}</p>
|
||||||
|
</div>
|
||||||
|
<div class="grade-stars">
|
||||||
|
<p>{{ display_star(comment.grade_global) }}</p>
|
||||||
|
<p>{{ display_star(comment.grade_utility) }}</p>
|
||||||
|
<p>{{ display_star(comment.grade_interest) }}</p>
|
||||||
|
<p>{{ display_star(comment.grade_teaching) }}</p>
|
||||||
|
<p>{{ display_star(comment.grade_work_load) }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="grade-extension"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="comment">
|
||||||
|
<div class="anchor">
|
||||||
|
<a href="{{ url('pedagogy:ue_detail', ue_id=ue.id) }}#comment-{{ comment.id }}"><i class="fa fa-paragraph"></i></a>
|
||||||
|
</div>
|
||||||
|
{{ comment.comment|markdown }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="info">
|
||||||
|
{% if comment.is_reported %}
|
||||||
|
<p class="status-reported">
|
||||||
|
{% trans %}This comment has been reported{% endtrans %}
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if comment.author_id == user.id or user.has_perm("pedagogy.change_comment") %}
|
||||||
|
<button
|
||||||
|
class="btn btn-orange action"
|
||||||
|
hx-get="{{ url('pedagogy:comment_update', comment_id=comment.id) }}"
|
||||||
|
hx-swap="outerHTML"
|
||||||
|
hx-target="#comment-{{ comment.id }}"
|
||||||
|
>
|
||||||
|
<i class="fa fa-pencil"></i> {% trans %}Edit{% endtrans %}
|
||||||
|
</button>
|
||||||
|
{% endif %}
|
||||||
|
{% if comment.author_id == user.id or user.has_perm("pedagogy.delete_comment") %}
|
||||||
|
<form class="action"
|
||||||
|
hx-post="{{ url('pedagogy:comment_delete', comment_id=comment.id) }}"
|
||||||
|
hx-confirm='{% trans obj=object %}Are you sure you want to delete "{{ obj }}"?{% endtrans %}'
|
||||||
|
hx-swap="outerHTML"
|
||||||
|
hx-target="#comment-{{ comment.id }}"
|
||||||
|
>
|
||||||
|
{% csrf_token %}
|
||||||
|
<button class="btn btn-red action">
|
||||||
|
<i class="fa fa-trash-can"></i> {% trans %}Delete{% endtrans %}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="comment-end-bar">
|
||||||
|
<div class="report">
|
||||||
|
<p>
|
||||||
|
<a href="{{ url('pedagogy:comment_report', comment_id=comment.id) }}">
|
||||||
|
{% trans %}Report this comment{% endtrans %}
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="date"><p>{{ comment.publish_date.strftime('%d/%m/%Y') }}</p></div>
|
||||||
|
|
||||||
|
<div class="author"><p>{{ user_profile_link(comment.author) }}</p></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
<div class="leave-comment">
|
||||||
|
{% if form.is_creation %}
|
||||||
|
<details class="accordion" id="leave_comment" {% if form.errors %}open{% endif %}>
|
||||||
|
<summary>{% trans %}Leave comment{% endtrans %}</summary>
|
||||||
|
<div class="accordion-content">
|
||||||
|
{% endif %}
|
||||||
|
<form
|
||||||
|
hx-post="{{ action }}"
|
||||||
|
{% if form.is_creation %}
|
||||||
|
hx-target="#comments"
|
||||||
|
hx-swap="afterbegin"
|
||||||
|
{% else %}
|
||||||
|
hx-target="closest .leave-comment"
|
||||||
|
hx-swap="outerHTML"
|
||||||
|
{% endif %}
|
||||||
|
hx-disabled-elt="find input[type='submit']"
|
||||||
|
>
|
||||||
|
{% csrf_token %}
|
||||||
|
<div class="leave-comment-grid-container">
|
||||||
|
<div class="form-stars">
|
||||||
|
{{ form.non_field_errors() }}
|
||||||
|
{{ form.author.errors }}
|
||||||
|
{{ form.ue.errors }}
|
||||||
|
|
||||||
|
{{ form.author }}
|
||||||
|
{{ form.ue }}
|
||||||
|
|
||||||
|
<div class="input-stars">
|
||||||
|
<label for="{{ form.grade_global.id_for_label }}">{{ form.grade_global.label }} :</label>
|
||||||
|
{{ form.grade_global.errors }}
|
||||||
|
{{ form.grade_global }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="input-stars">
|
||||||
|
<label for="{{ form.grade_utility.id_for_label }}">{{ form.grade_utility.label }} :</label>
|
||||||
|
{{ form.grade_utility.errors }}
|
||||||
|
{{ form.grade_utility }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="input-stars">
|
||||||
|
<label for="{{ form.grade_interest.id_for_label }}">{{ form.grade_interest.label }} :</label>
|
||||||
|
{{ form.grade_interest.errors }}
|
||||||
|
{{ form.grade_interest }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="input-stars">
|
||||||
|
<label for="{{ form.grade_teaching.id_for_label }}">{{ form.grade_teaching.label }} :</label>
|
||||||
|
{{ form.grade_teaching.errors }}
|
||||||
|
{{ form.grade_teaching }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="input-stars">
|
||||||
|
<label for="{{ form.grade_work_load.id_for_label }}">{{ form.grade_work_load.label }} :</label>
|
||||||
|
{{ form.grade_work_load.errors }}
|
||||||
|
{{ form.grade_work_load }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-comment">
|
||||||
|
<label for="{{ form.comment.id_for_label }}">{{ form.comment.label }} :</label>
|
||||||
|
{{ form.comment.errors }}
|
||||||
|
{{ form.comment }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p class="right">
|
||||||
|
<input type="submit" value="{% trans %}Comment{% endtrans %}" />
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% if form.is_creation %}
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<div
|
||||||
|
hx-get="{{ request.get_full_path() }}"
|
||||||
|
hx-swap="outerHTML"
|
||||||
|
hx-target="this"
|
||||||
|
hx-trigger="CommentUpdate from:body"
|
||||||
|
>
|
||||||
|
<div class="ue-details-container">
|
||||||
|
<div class="grade">
|
||||||
|
<p>{% trans %}Global grade{% endtrans %}</p>
|
||||||
|
<p>{% trans %}Utility{% endtrans %}</p>
|
||||||
|
<p>{% trans %}Interest{% endtrans %}</p>
|
||||||
|
<p>{% trans %}Teaching{% endtrans %}</p>
|
||||||
|
<p>{% trans %}Work load{% endtrans %}</p>
|
||||||
|
</div>
|
||||||
|
<div class="grade-stars">
|
||||||
|
<p>{{ display_star(object.grade_global_average) }}</p>
|
||||||
|
<p>{{ display_star(object.grade_utility_average) }}</p>
|
||||||
|
<p>{{ display_star(object.grade_interest_average) }}</p>
|
||||||
|
<p>{{ display_star(object.grade_teaching_average) }}</p>
|
||||||
|
<p>{{ display_star(object.grade_work_load_average) }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="ue-infos">
|
||||||
|
<p><b>{% trans %}Objectives{% endtrans %}</b></p>
|
||||||
|
<p>{{ object.objectives|markdown }}</p>
|
||||||
|
<p><b>{% trans %}Program{% endtrans %}</b></p>
|
||||||
|
<p>{{ object.program|markdown }}</p>
|
||||||
|
<p><b>{% trans %}Earned skills{% endtrans %}</b></p>
|
||||||
|
<p>{{ object.skills|markdown }}</p>
|
||||||
|
<p><b>{% trans %}Key concepts{% endtrans %}</b></p>
|
||||||
|
<p>{{ object.key_concepts|markdown }}</p>
|
||||||
|
<p><b>{% trans %}UE manager: {% endtrans %}</b>{{ object.manager }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
{% if object.has_user_already_commented(user) %}
|
||||||
|
<div class="leave-comment-not-allowed">
|
||||||
|
<p>{% trans %}You already posted a comment on this UE. If you want to comment again, please modify or delete your previous comment.{% endtrans %}</p>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if comments %}
|
||||||
|
<h2>{% trans %}Comments{% endtrans %}</h2>
|
||||||
|
<br>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if not object.has_user_already_commented(user) and user.has_perm("pedagogy.add_uecomment") %}
|
||||||
|
{{ add_comment_form }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
</div>
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
{% extends "core/base.jinja" %}
|
|
||||||
{% from "core/macros.jinja" import user_profile_link %}
|
|
||||||
{% from "pedagogy/macros.jinja" import display_star %}
|
{% from "pedagogy/macros.jinja" import display_star %}
|
||||||
|
|
||||||
|
{% if is_fragment %}
|
||||||
|
{% include "pedagogy/fragments/ue_detail.jinja" %}
|
||||||
|
{% else %}
|
||||||
|
{% extends "core/base.jinja" %}
|
||||||
|
|
||||||
{% block additional_css %}
|
{% block additional_css %}
|
||||||
<link rel="stylesheet" href="{{ static('pedagogy/css/pedagogy.scss') }}">
|
<link rel="stylesheet" href="{{ static('pedagogy/css/pedagogy.scss') }}">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -11,6 +14,7 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<div class="pedagogy">
|
<div class="pedagogy">
|
||||||
<div id="ue_detail">
|
<div id="ue_detail">
|
||||||
<button onclick='(function(){
|
<button onclick='(function(){
|
||||||
@@ -55,166 +59,16 @@
|
|||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
<div class="ue-details-container">
|
{% include "pedagogy/fragments/ue_detail.jinja" %}
|
||||||
<div class="grade">
|
|
||||||
<p>{% trans %}Global grade{% endtrans %}</p>
|
|
||||||
<p>{% trans %}Utility{% endtrans %}</p>
|
|
||||||
<p>{% trans %}Interest{% endtrans %}</p>
|
|
||||||
<p>{% trans %}Teaching{% endtrans %}</p>
|
|
||||||
<p>{% trans %}Work load{% endtrans %}</p>
|
|
||||||
</div>
|
|
||||||
<div class="grade-stars">
|
|
||||||
<p>{{ display_star(object.grade_global_average) }}</p>
|
|
||||||
<p>{{ display_star(object.grade_utility_average) }}</p>
|
|
||||||
<p>{{ display_star(object.grade_interest_average) }}</p>
|
|
||||||
<p>{{ display_star(object.grade_teaching_average) }}</p>
|
|
||||||
<p>{{ display_star(object.grade_work_load_average) }}</p>
|
|
||||||
</div>
|
|
||||||
<div class="ue-infos">
|
|
||||||
<p><b>{% trans %}Objectives{% endtrans %}</b></p>
|
|
||||||
<p>{{ object.objectives|markdown }}</p>
|
|
||||||
<p><b>{% trans %}Program{% endtrans %}</b></p>
|
|
||||||
<p>{{ object.program|markdown }}</p>
|
|
||||||
<p><b>{% trans %}Earned skills{% endtrans %}</b></p>
|
|
||||||
<p>{{ object.skills|markdown }}</p>
|
|
||||||
<p><b>{% trans %}Key concepts{% endtrans %}</b></p>
|
|
||||||
<p>{{ object.key_concepts|markdown }}</p>
|
|
||||||
<p><b>{% trans %}UE manager: {% endtrans %}</b>{{ object.manager }}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<br>
|
|
||||||
{% if object.has_user_already_commented(user) %}
|
|
||||||
<div id="leave_comment_not_allowed">
|
|
||||||
<p>{% trans %}You already posted a comment on this UE. If you want to comment again, please modify or delete your previous comment.{% endtrans %}</p>
|
|
||||||
</div>
|
|
||||||
{% elif user.has_perm("pedagogy.add_uecomment") %}
|
|
||||||
<details class="accordion" id="leave_comment" {% if form.errors %}open{%endif%}>
|
|
||||||
<summary>{% trans %}Leave comment{% endtrans %}</summary>
|
|
||||||
<div class="accordion-content">
|
|
||||||
<form action="{{ url('pedagogy:ue_detail', ue_id=object.id) }}" method="post" enctype="multipart/form-data">
|
|
||||||
{% csrf_token %}
|
|
||||||
<div class="leave-comment-grid-container">
|
|
||||||
<div class="form-stars">
|
|
||||||
{{ form.non_field_errors() }}
|
|
||||||
{{ form.author.errors }}
|
|
||||||
{{ form.ue.errors }}
|
|
||||||
|
|
||||||
{{ form.author }}
|
|
||||||
{{ form.ue }}
|
|
||||||
|
|
||||||
<div class="input-stars">
|
|
||||||
<label for="{{ form.grade_global.id_for_label }}">{{ form.grade_global.label }} :</label>
|
|
||||||
{{ form.grade_global.errors }}
|
|
||||||
{{ form.grade_global }}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="input-stars">
|
|
||||||
<label for="{{ form.grade_utility.id_for_label }}">{{ form.grade_utility.label }} :</label>
|
|
||||||
{{ form.grade_utility.errors }}
|
|
||||||
{{ form.grade_utility }}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="input-stars">
|
|
||||||
<label for="{{ form.grade_interest.id_for_label }}">{{ form.grade_interest.label }} :</label>
|
|
||||||
{{ form.grade_interest.errors }}
|
|
||||||
{{ form.grade_interest }}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="input-stars">
|
|
||||||
<label for="{{ form.grade_teaching.id_for_label }}">{{ form.grade_teaching.label }} :</label>
|
|
||||||
{{ form.grade_teaching.errors }}
|
|
||||||
{{ form.grade_teaching }}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="input-stars">
|
|
||||||
<label for="{{ form.grade_work_load.id_for_label }}">{{ form.grade_work_load.label }} :</label>
|
|
||||||
{{ form.grade_work_load.errors }}
|
|
||||||
{{ form.grade_work_load }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-comment">
|
|
||||||
<label for="{{ form.comment.id_for_label }}">{{ form.comment.label }} :</label>
|
|
||||||
{{ form.comment.errors }}
|
|
||||||
{{ form.comment }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<p><input type="submit" value="{% trans %}Comment{% endtrans %}" /></p>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</details>
|
|
||||||
{% endif %}
|
|
||||||
<br>
|
|
||||||
|
|
||||||
{% if comments %}
|
|
||||||
<h2>{% trans %}Comments{% endtrans %}</h2>
|
|
||||||
{% for comment in comments %}
|
{% for comment in comments %}
|
||||||
<div id="{{ comment.id }}" class="comment-container">
|
<section id="comments">
|
||||||
|
{% include "pedagogy/fragments/ue_comment.jinja" %}
|
||||||
<div class="grade-block">
|
</section>
|
||||||
<div class="grade-type">
|
|
||||||
<p>{% trans %}Global grade{% endtrans %}</p>
|
|
||||||
<p>{% trans %}Utility{% endtrans %}</p>
|
|
||||||
<p>{% trans %}Interest{% endtrans %}</p>
|
|
||||||
<p>{% trans %}Teaching{% endtrans %}</p>
|
|
||||||
<p>{% trans %}Work load{% endtrans %}</p>
|
|
||||||
</div>
|
|
||||||
<div class="grade-stars">
|
|
||||||
<p>{{ display_star(comment.grade_global) }}</p>
|
|
||||||
<p>{{ display_star(comment.grade_utility) }}</p>
|
|
||||||
<p>{{ display_star(comment.grade_interest) }}</p>
|
|
||||||
<p>{{ display_star(comment.grade_teaching) }}</p>
|
|
||||||
<p>{{ display_star(comment.grade_work_load) }}</p>
|
|
||||||
</div>
|
|
||||||
<div class="grade-extension"></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="comment">
|
|
||||||
<div class="anchor">
|
|
||||||
<a href="{{ url('pedagogy:ue_detail', ue_id=ue.id) }}#{{ comment.id }}"><i class="fa fa-paragraph"></i></a>
|
|
||||||
</div>
|
|
||||||
{{ comment.comment|markdown }}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="info">
|
|
||||||
{% if comment.is_reported %}
|
|
||||||
<p class="status-reported">
|
|
||||||
{% trans %}This comment has been reported{% endtrans %}
|
|
||||||
</p>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if comment.author_id == user.id or user.has_perm("pedagogy.change_comment") %}
|
|
||||||
<p class="actions">
|
|
||||||
<a href="{{ url('pedagogy:comment_update', comment_id=comment.id) }}">
|
|
||||||
{% trans %}Edit{% endtrans %}
|
|
||||||
</a>
|
|
||||||
{% endif %}
|
|
||||||
{% if comment.author_id == user.id or user.has_perm("pedagogy.delete_comment") %}
|
|
||||||
<a href="{{ url('pedagogy:comment_delete', comment_id=comment.id) }}">
|
|
||||||
{% trans %}Delete{% endtrans %}
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="comment-end-bar">
|
|
||||||
<div class="report">
|
|
||||||
<p>
|
|
||||||
<a href="{{ url('pedagogy:comment_report', comment_id=comment.id) }}">
|
|
||||||
{% trans %}Report this comment{% endtrans %}
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="date"><p>{{ comment.publish_date.strftime('%d/%m/%Y') }}</p></div>
|
|
||||||
|
|
||||||
<div class="author"><p>{{ user_profile_link(comment.author) }}</p></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
{% endif %}
|
||||||
|
|||||||
+14
-2
@@ -24,12 +24,14 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from pedagogy.views import (
|
from pedagogy.views import (
|
||||||
|
UECommentCreateView,
|
||||||
UECommentDeleteView,
|
UECommentDeleteView,
|
||||||
|
UECommentDetailView,
|
||||||
UECommentReportCreateView,
|
UECommentReportCreateView,
|
||||||
UECommentUpdateView,
|
UECommentUpdateView,
|
||||||
UECreateView,
|
UECreateView,
|
||||||
UEDeleteView,
|
UEDeleteView,
|
||||||
UEDetailFormView,
|
UEDetailView,
|
||||||
UEGuideView,
|
UEGuideView,
|
||||||
UEModerationFormView,
|
UEModerationFormView,
|
||||||
UEUpdateView,
|
UEUpdateView,
|
||||||
@@ -38,7 +40,17 @@ from pedagogy.views import (
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
# Urls displaying the actual application for visitors
|
# Urls displaying the actual application for visitors
|
||||||
path("", UEGuideView.as_view(), name="guide"),
|
path("", UEGuideView.as_view(), name="guide"),
|
||||||
path("ue/<int:ue_id>/", UEDetailFormView.as_view(), name="ue_detail"),
|
path("ue/<int:ue_id>/", UEDetailView.as_view(), name="ue_detail"),
|
||||||
|
path(
|
||||||
|
"ue/<int:ue_id>/comment",
|
||||||
|
UECommentCreateView.as_view(),
|
||||||
|
name="comment_create",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"comment/<int:comment_id>/",
|
||||||
|
UECommentDetailView.as_view(),
|
||||||
|
name="comment_detail",
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"comment/<int:comment_id>/edit/",
|
"comment/<int:comment_id>/edit/",
|
||||||
UECommentUpdateView.as_view(),
|
UECommentUpdateView.as_view(),
|
||||||
|
|||||||
+73
-31
@@ -24,11 +24,13 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||||
from django.db.models import Exists, OuterRef
|
from django.db.models import Exists, OuterRef
|
||||||
|
from django.http import HttpResponse
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django.urls import reverse, reverse_lazy
|
from django.urls import reverse, reverse_lazy
|
||||||
from django.views.generic import (
|
from django.views.generic import (
|
||||||
CreateView,
|
CreateView,
|
||||||
DeleteView,
|
DeleteView,
|
||||||
|
DetailView,
|
||||||
FormView,
|
FormView,
|
||||||
TemplateView,
|
TemplateView,
|
||||||
UpdateView,
|
UpdateView,
|
||||||
@@ -36,7 +38,7 @@ from django.views.generic import (
|
|||||||
|
|
||||||
from core.auth.mixins import PermissionOrAuthorRequiredMixin
|
from core.auth.mixins import PermissionOrAuthorRequiredMixin
|
||||||
from core.models import Notification, User
|
from core.models import Notification, User
|
||||||
from core.views import DetailFormView
|
from core.views.mixins import AllowFragment, FragmentMixin, UseFragmentsMixin
|
||||||
from pedagogy.forms import (
|
from pedagogy.forms import (
|
||||||
UECommentForm,
|
UECommentForm,
|
||||||
UECommentModerationForm,
|
UECommentModerationForm,
|
||||||
@@ -46,37 +48,56 @@ from pedagogy.forms import (
|
|||||||
from pedagogy.models import UE, UEComment, UECommentReport
|
from pedagogy.models import UE, UEComment, UECommentReport
|
||||||
|
|
||||||
|
|
||||||
class UEDetailFormView(PermissionRequiredMixin, DetailFormView):
|
class UECommentCreateView(PermissionRequiredMixin, FragmentMixin, CreateView):
|
||||||
"""Display every comment of an UE and detailed infos about it.
|
model = UEComment
|
||||||
|
template_name = "pedagogy/fragments/ue_comment_form.jinja"
|
||||||
Allow to comment the UE.
|
|
||||||
"""
|
|
||||||
|
|
||||||
model = UE
|
|
||||||
pk_url_kwarg = "ue_id"
|
|
||||||
template_name = "pedagogy/ue_detail.jinja"
|
|
||||||
form_class = UECommentForm
|
form_class = UECommentForm
|
||||||
permission_required = "pedagogy.view_ue"
|
permission_required = "pedagogy.add_uecomment"
|
||||||
|
object = None # Avoid initialisation bug with FragmentMixin
|
||||||
|
|
||||||
|
@property
|
||||||
|
def ue(self):
|
||||||
|
if hasattr(self, "_ue"):
|
||||||
|
return self._ue
|
||||||
|
self._ue = get_object_or_404(UE, id=self.kwargs.get("ue_id"))
|
||||||
|
return self._ue
|
||||||
|
|
||||||
def has_permission(self):
|
def has_permission(self):
|
||||||
if self.request.method == "POST" and not self.request.user.has_perm(
|
if self.ue.has_user_already_commented(self.request.user):
|
||||||
"pedagogy.add_uecomment"
|
|
||||||
):
|
|
||||||
# if it's a POST request, the user is trying to add a new UEComment
|
|
||||||
# thus he also needs the "add_uecomment" permission
|
|
||||||
return False
|
return False
|
||||||
return super().has_permission()
|
return super().has_permission()
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
def get_form_kwargs(self):
|
||||||
kwargs = super().get_form_kwargs()
|
kwargs = super().get_form_kwargs()
|
||||||
kwargs["author_id"] = self.request.user.id
|
kwargs["author_id"] = self.request.user.id
|
||||||
kwargs["ue_id"] = self.object.id
|
kwargs["ue_id"] = self.ue.id
|
||||||
kwargs["is_creation"] = True
|
kwargs["is_creation"] = True
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
def form_valid(self, form):
|
def get_context_data(self, **kwargs):
|
||||||
form.save()
|
return super().get_context_data(**kwargs) | {
|
||||||
return super().form_valid(form)
|
"action": reverse("pedagogy:comment_create", kwargs={"ue_id": self.ue.id})
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
return reverse("pedagogy:comment_detail", kwargs={"comment_id": self.object.id})
|
||||||
|
|
||||||
|
|
||||||
|
class UEDetailView(
|
||||||
|
PermissionRequiredMixin, UseFragmentsMixin, AllowFragment, DetailView
|
||||||
|
):
|
||||||
|
"""Display every comment of an UE and detailed infos about it."""
|
||||||
|
|
||||||
|
model = UE
|
||||||
|
pk_url_kwarg = "ue_id"
|
||||||
|
template_name = "pedagogy/ue_detail.jinja"
|
||||||
|
permission_required = "pedagogy.view_ue"
|
||||||
|
fragments = {
|
||||||
|
"add_comment_form": UECommentCreateView,
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_fragment_data(self):
|
||||||
|
return {"add_comment_form": {"ue_id": self.object.id}}
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
return super().get_context_data(**kwargs) | {
|
return super().get_context_data(**kwargs) | {
|
||||||
@@ -85,22 +106,33 @@ class UEDetailFormView(PermissionRequiredMixin, DetailFormView):
|
|||||||
.annotate_is_reported()
|
.annotate_is_reported()
|
||||||
.select_related("author")
|
.select_related("author")
|
||||||
.order_by("-publish_date")
|
.order_by("-publish_date")
|
||||||
)
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_success_url(self):
|
|
||||||
# once the new ue comment has been saved
|
class UECommentDetailView(PermissionRequiredMixin, DetailView):
|
||||||
# redirect to the same page we are currently
|
model = UEComment
|
||||||
return self.request.path
|
pk_url_kwarg = "comment_id"
|
||||||
|
template_name = "pedagogy/fragments/ue_comment.jinja"
|
||||||
|
permission_required = "pedagogy.view_ue"
|
||||||
|
context_object_name = "comment"
|
||||||
|
|
||||||
|
def dispatch(self, *args, **kwargs):
|
||||||
|
res: HttpResponse = super().dispatch(*args, **kwargs)
|
||||||
|
res.headers["HX-Trigger"] = "CommentUpdate"
|
||||||
|
return res
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
return super().get_context_data(**kwargs) | {"ue": self.object.ue}
|
||||||
|
|
||||||
|
|
||||||
class UECommentUpdateView(PermissionOrAuthorRequiredMixin, UpdateView):
|
class UECommentUpdateView(PermissionOrAuthorRequiredMixin, AllowFragment, UpdateView):
|
||||||
"""Allow edit of a given comment."""
|
"""Allow edit of a given comment."""
|
||||||
|
|
||||||
model = UEComment
|
model = UEComment
|
||||||
form_class = UECommentForm
|
form_class = UECommentForm
|
||||||
pk_url_kwarg = "comment_id"
|
pk_url_kwarg = "comment_id"
|
||||||
template_name = "core/edit.jinja"
|
template_name = "pedagogy/fragments/ue_comment_form.jinja"
|
||||||
permission_required = "pedagogy.change_uecomment"
|
permission_required = "pedagogy.change_uecomment"
|
||||||
author_field = "author"
|
author_field = "author"
|
||||||
|
|
||||||
@@ -111,11 +143,18 @@ class UECommentUpdateView(PermissionOrAuthorRequiredMixin, UpdateView):
|
|||||||
kwargs["is_creation"] = False
|
kwargs["is_creation"] = False
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
return super().get_context_data(**kwargs) | {
|
||||||
|
"action": reverse(
|
||||||
|
"pedagogy:comment_update", kwargs={"comment_id": self.object.id}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse("pedagogy:ue_detail", kwargs={"ue_id": self.object.ue_id})
|
return reverse("pedagogy:comment_detail", kwargs={"comment_id": self.object.id})
|
||||||
|
|
||||||
|
|
||||||
class UECommentDeleteView(PermissionOrAuthorRequiredMixin, DeleteView):
|
class UECommentDeleteView(PermissionOrAuthorRequiredMixin, AllowFragment, DeleteView):
|
||||||
"""Allow to delete a given comment."""
|
"""Allow to delete a given comment."""
|
||||||
|
|
||||||
model = UEComment
|
model = UEComment
|
||||||
@@ -124,8 +163,11 @@ class UECommentDeleteView(PermissionOrAuthorRequiredMixin, DeleteView):
|
|||||||
permission_required = "pedagogy.delete_uecomment"
|
permission_required = "pedagogy.delete_uecomment"
|
||||||
author_field = "author"
|
author_field = "author"
|
||||||
|
|
||||||
def get_success_url(self):
|
def form_valid(self, form):
|
||||||
return reverse("pedagogy:ue_detail", kwargs={"ue_id": self.object.ue_id})
|
self.object.delete()
|
||||||
|
response = HttpResponse(status=200)
|
||||||
|
response.headers["HX-Trigger"] = "CommentUpdate"
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
class UEGuideView(PermissionRequiredMixin, TemplateView):
|
class UEGuideView(PermissionRequiredMixin, TemplateView):
|
||||||
|
|||||||
Reference in New Issue
Block a user