diff --git a/app/templates/given-rating.html b/app/templates/given-rating.html index 6cf80b3ca6f55eaf26a42c3bec3dea02e7303dc1..80223ca99684e9279f3dca3a67d691db11bf9fce 100644 --- a/app/templates/given-rating.html +++ b/app/templates/given-rating.html @@ -89,6 +89,7 @@ <th scope="col">Judul Materi</th> <th scope="col">Tanggal</th> <th scope="col">Rating</th> + <th scope="col">Keterangan</th> </tr> </thead> <tbody> @@ -98,6 +99,9 @@ <td><a href="/materi/1/">{{ i.materi.title }}</a></td> <td>{{ i.timestamp }}</td> <td>{{ i.score }}</td> + <td> + <a href="/edit/{{ i.score }}"><span class="glyphicon glyphicon-pencil" >Edit</span></a> + </td> </tr> {% endfor %} diff --git a/app/tests.py b/app/tests.py index 8b0583fd0f4d2594e66be93e314eb6462744c9e8..530364f51d2ab7eca4a66f1578002c844675677f 100644 --- a/app/tests.py +++ b/app/tests.py @@ -49,7 +49,7 @@ from app.forms import SuntingProfilForm, year_choices, GuestBookForm from app.utils.fileManagementUtil import (get_random_filename, remove_image_exifdata) from app.utils.PasswordValidator import PasswordPolicyValidator -from app.views import UploadMateriHTML, add_rating_materi +from app.views import UploadMateriHTML, add_rating_materi, edit_rating_materi from .models import (Category, Comment, DislikeComment, DownloadStatistics, Like, LikeComment, Materi, Rating, RatingContributor, @@ -2338,6 +2338,10 @@ class RatingMateriTest(TestCase): def test_rating_materi_url_use_add_rating_materi_function(self): found = resolve(self.url_rate) self.assertEqual(found.func, add_rating_materi) + + def test_rating_materi_url_use_edit_rating_materi_function(self): + found = resolve(self.url_rate) + self.assertEqual(found.func, add_rating_materi) def test_rating_materi_get_method_should_return_403_forbidden(self): response = self.client.get(self.url_rate) @@ -2589,6 +2593,11 @@ class RatingContributorTest(TransactionTestCase): score=3, contributor=self.contributor, user=self.anonymous) self.assertEqual(1, RatingContributor.objects.count()) + def test_edit_rating_contributor(self): + RatingContributor.objects.create( + score=3, contributor=self.contributor, user=self.anonymous) + self.assertEqual(1, RatingContributor.objects.count()) + def test_add_rating_contributor_should_failed_when_negative(self): with self.assertRaises(ValidationError): RatingContributor.objects.create( diff --git a/app/urls.py b/app/urls.py index fb1e0e927cfe413948fbf74502277c0c6d6859fe..d64ca7cbb99b4116a9e2c6ab8566e4bfc303c95b 100644 --- a/app/urls.py +++ b/app/urls.py @@ -40,6 +40,7 @@ urlpatterns = [ path("profil/<str:email>/", KatalogPerKontributorView.as_view(), name="katalog-per-kontributor"), path("materi/rate/", views.add_rating_materi, name="rate-materi"), + path("edit/rate/", views.edit_rating_materi, name="edit-materi"), path("materi/<int:pk>/save-to-gdrive/", views.save_to_gdrive, name="save-to-gdrive"), path("favorite/", MateriFavorite.as_view(), name="favorite"), diff --git a/app/views.py b/app/views.py index 699bd8ae7afda5124c725aa3d7ffb6aa7dc43022..f61b0a72997f202f72d0e0a178cdbcfb7aae52e1 100644 --- a/app/views.py +++ b/app/views.py @@ -331,8 +331,10 @@ def add_rating_materi(request): {"success": True, "msg": "Rating successfully created", "rating_score": rating_score}, status=201 ) return JsonResponse({"success": False, "msg": "Forbidden"}, status=403) - - + +def edit_rating_materi(request, pk): + rating = get_object_or_404(Rating, pk=pk) + def download_materi(request, pk): materi = get_object_or_404(Materi, pk=pk) path = materi.content.path