Fakultas Ilmu Komputer UI

Commit a987c69c authored by Nurma Ayu Wigati S. Subroto's avatar Nurma Ayu Wigati S. Subroto

Merge branch '1906438014-45' into 'master'

[#45] Update Rating

See merge request !115
parents bdacd895 3a3c5e56
Pipeline #60708 passed with stages
in 23 minutes and 55 seconds
......@@ -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 %}
......
......@@ -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(
......
......@@ -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"),
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment