-
Notifications
You must be signed in to change notification settings - Fork 18
Add document reporting feature with modal UI #356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
157d228
Add document reporting feature with modal UI (Fixes #279)
C4ptainCrunch 4f684e1
Refactor report template to use Django 6 partials
C4ptainCrunch fc79ae0
Replace Bootstrap modal with native HTML <dialog> element
C4ptainCrunch e61a157
wip
C4ptainCrunch 3ffafb7
Refactor to use Hotwire Stimulus for modal dialog
C4ptainCrunch 0de2bc3
wip
C4ptainCrunch e022cd6
Address PR feedback on document report feature
C4ptainCrunch 65f2577
Add migration for DocumentReport model changes
C4ptainCrunch b93eb3a
Fix mypy type errors
C4ptainCrunch 403eedf
Squash migrations
C4ptainCrunch 0dfbb7b
Description -> Comment
C4ptainCrunch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Generated by Django 6.0 on 2025-12-25 19:59 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.conf import settings | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ( | ||
| "documents", | ||
| "0005_alter_vote_unique_together_alter_bulkdocuments_id_and_more", | ||
| ), | ||
| migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name="DocumentReport", | ||
| fields=[ | ||
| ( | ||
| "id", | ||
| models.BigAutoField( | ||
| auto_created=True, | ||
| primary_key=True, | ||
| serialize=False, | ||
| verbose_name="ID", | ||
| ), | ||
| ), | ||
| ( | ||
| "problem_type", | ||
| models.CharField( | ||
| choices=[ | ||
| ("wrong_module", "Ce document est dans le mauvais cours"), | ||
| ("wrong_title", "Le titre ou la description est erroné"), | ||
| ("low_quality", "Contenu de mauvaise qualité ou inutile"), | ||
| ("readability", "Problème de lisibilité"), | ||
| ("outdated", "Document obsolète"), | ||
| ("other", "Autre raison"), | ||
| ], | ||
| max_length=20, | ||
| verbose_name="Type de problème", | ||
| ), | ||
| ), | ||
| ( | ||
| "description", | ||
| models.TextField( | ||
| blank=True, default="", verbose_name="Description" | ||
| ), | ||
| ), | ||
| ("created", models.DateTimeField(auto_now_add=True)), | ||
| ( | ||
| "document", | ||
| models.ForeignKey( | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| related_name="reports", | ||
| to="documents.document", | ||
| verbose_name="Document", | ||
| ), | ||
| ), | ||
| ( | ||
| "user", | ||
| models.ForeignKey( | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| to=settings.AUTH_USER_MODEL, | ||
| verbose_name="Utilisateur", | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| {% extends "base.html" %} | ||
|
|
||
| {% block title %}Signaler {{ document.name }}{% endblock %} | ||
|
|
||
| {% block content %} | ||
| <div class="container-xl py-4"> | ||
| <div class="row justify-content-center"> | ||
| <div class="col-lg-8"> | ||
| {% include "documents/document_report.html#report_card" %} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| {% endblock content %} | ||
|
|
||
| {% partialdef report_modal %} | ||
| <dialog id="reportDialog" | ||
| data-controller="modal" | ||
| data-action="click->modal#clickOutside" | ||
| class="rounded shadow-lg border-0 p-0"> | ||
| {% include "documents/document_report.html#report_card" %} | ||
| </dialog> | ||
| {% endpartialdef %} | ||
|
|
||
| {% partialdef report_card %} | ||
| <div class="card"> | ||
| <div class="card-header"> | ||
| <h5 class="mb-0">Signaler un problème</h5> | ||
| </div> | ||
|
|
||
| <form action="{% url 'document_report' document.id %}" method="post"> | ||
| {% csrf_token %} | ||
|
|
||
| {{ form.non_field_errors }} | ||
| <div class="card-body"> | ||
| <div class="mb-3"> | ||
| {% load documents_tags %} | ||
| {% for choice_value, choice_label in form.fields.problem_type.choices %} | ||
| {% if choice_value %} | ||
| <div class="form-check mb-3"> | ||
| <input class="form-check-input" type="radio" name="problem_type" | ||
| id="problem_{{ choice_value }}" value="{{ choice_value }}" | ||
| {% if form.problem_type.value == choice_value %}checked{% endif %}> | ||
| <label class="form-check-label" for="problem_{{ choice_value }}"> | ||
| <div class="fw-semibold">{{ choice_label }}</div> | ||
| <div class="text-muted small"> | ||
| {{ choice_value|problem_type_description }} | ||
| </div> | ||
| </label> | ||
| </div> | ||
| {% endif %} | ||
| {% endfor %} | ||
| </div> | ||
|
|
||
| <div class="mb-3"> | ||
| <label for="id_description" class="form-label">Commentaire (optionnel) | ||
| <div class="form-text small"> | ||
| Tu peux ajouter des détails supplémentaires pour nous aider à comprendre le problème. | ||
| </div> | ||
| </label> | ||
|
|
||
| {{ form.description }} | ||
|
|
||
| </div> | ||
| </div> | ||
|
|
||
| <div class="card-footer d-flex gap-2 justify-content-end"> | ||
| <button type="button" data-action="click->modal#close" class="btn btn-outline-secondary">Annuler</button> | ||
| <button type="submit" class="btn btn-primary"> | ||
| Envoyer | ||
| </button> | ||
| </div> | ||
| </form> | ||
| </div> | ||
| {% endpartialdef %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| from django import template | ||
|
|
||
| from documents.models import DocumentReport | ||
|
|
||
| register = template.Library() | ||
|
|
||
|
|
||
| @register.filter | ||
| def problem_type_description(value: str) -> str: | ||
| """Get the detailed description for a problem type.""" | ||
| return DocumentReport.ProblemType.get_description(value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| from django.urls import reverse | ||
|
|
||
| import pytest | ||
|
|
||
| from catalog.models import Course | ||
| from documents.models import Document, DocumentReport | ||
| from users.models import User | ||
|
|
||
| pytestmark = pytest.mark.django_db | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def user(): | ||
| return User.objects.create_user( | ||
| netid="test_user", first_name="Test", last_name="User" | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def course(): | ||
| return Course.objects.create(name="Test Course", slug="test-course") | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def document(user, course): | ||
| return Document.objects.create( | ||
| name="Test Document", | ||
| user=user, | ||
| course=course, | ||
| state=Document.DocumentState.DONE, | ||
| ) | ||
|
|
||
|
|
||
| def test_document_report_view_post(client, user, document): | ||
| """Test POST request to document_report view""" | ||
| client.force_login(user) | ||
| url = reverse("document_report", args=[document.pk]) | ||
|
|
||
| response = client.post( | ||
| url, | ||
| { | ||
| "problem_type": DocumentReport.ProblemType.WRONG_MODULE, | ||
| "description": "Test description", | ||
| }, | ||
| ) | ||
|
|
||
| assert response.status_code == 302 # Redirect after successful submission | ||
| assert DocumentReport.objects.filter(document=document, user=user).exists() | ||
|
|
||
| report = DocumentReport.objects.get(document=document, user=user) | ||
| assert report.problem_type == DocumentReport.ProblemType.WRONG_MODULE | ||
| assert report.description == "Test description" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.