Compare commits
4 Commits
87086cdce9
...
dcacff303d
Author | SHA1 | Date | |
---|---|---|---|
dcacff303d | |||
c84ae1334e | |||
1abc910621 | |||
5895714fd5 |
@ -14,7 +14,7 @@
|
||||
<p>Total score: {{ movie.score }}, seen by: {{ movie.seen_score }}.
|
||||
<ul>
|
||||
{% for vote in votes %}
|
||||
<li>{{vote.user.username}} {% if vote.seen %}(seen){% endif %} – {% if vote.vote == 1 %}👍{% elif vote.vote == 0 %}No opinion{% elif vote.vote == -1 %}👎{%endif%}{% if vote.comment is not None %} – {{vote.comment}}{% endif %}</li>
|
||||
<li>{{vote.user.username}} {% if vote.seen %}(seen){% endif %} – {% if vote.vote == 1 %}👍{% elif vote.vote == 0 %}No opinion{% elif vote.vote == -1 %}👎{%endif%}{% if vote.comment != "" %} – {{vote.comment}}{% endif %}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
@ -3,7 +3,8 @@ from django.contrib import admin
|
||||
from . import models
|
||||
|
||||
class MovieVoteInline(admin.StackedInline):
|
||||
model = models.MovieVote()
|
||||
model = models.MovieVote
|
||||
extra = 0
|
||||
|
||||
class MovieAdmin(admin.ModelAdmin):
|
||||
fields = [
|
||||
@ -11,6 +12,9 @@ class MovieAdmin(admin.ModelAdmin):
|
||||
]
|
||||
readonly_fields = ("score",)
|
||||
list_display = ["name", "watched", "suggested_by", "score"]
|
||||
inlines = [
|
||||
MovieVoteInline
|
||||
]
|
||||
|
||||
@admin.display(description="Score")
|
||||
def score(self, instance):
|
||||
|
19
watchlist/migrations/0008_alter_movievote_comment.py
Normal file
19
watchlist/migrations/0008_alter_movievote_comment.py
Normal file
@ -0,0 +1,19 @@
|
||||
# Generated by Django 4.1.5 on 2023-02-17 14:06
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('watchlist', '0007_alter_movie_csfd_id_alter_movie_imdb_id'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='movievote',
|
||||
name='comment',
|
||||
field=models.TextField(blank=True, default=''),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
@ -49,7 +49,7 @@ class MovieVote(models.Model):
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
vote = models.IntegerField(choices=Vote.choices, default=Vote.NOVOTE)
|
||||
seen = models.BooleanField(default=False, null=True)
|
||||
comment = models.TextField(null=True)
|
||||
comment = models.TextField(blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.user.username}'s vote for {self.movie.name}"
|
||||
|
@ -68,7 +68,8 @@ class CSFDIDTest(TestCase):
|
||||
urls = [
|
||||
("https://www.csfd.cz/film/1-predevsim-nikomu-neublizim/recenze/", "1"),
|
||||
("https://www.csfd.cz/film/969361-velryba/prehled/", "969361"),
|
||||
("https://www.csfd.cz/film/370706-daredevil/galerie/?page=20", "370706")
|
||||
("https://www.csfd.cz/film/370706-daredevil/galerie/?page=20", "370706"),
|
||||
("https://www.csfd.cz/film/370706", "370706")
|
||||
]
|
||||
for url, result in urls:
|
||||
with self.subTest(url=url, result=result):
|
||||
|
@ -166,10 +166,10 @@ class VoteTests(TestCase):
|
||||
with self.subTest(comment=comment):
|
||||
response = self.client.post(reverse('watchlist:vote', args=(m.id,)), data={"vote": "0", "comment": comment})
|
||||
mv = m.movievote_set.get(user=self.user)
|
||||
self.assertEqual(mv.comment, None if comment == "" else comment)
|
||||
self.assertEqual(mv.comment, comment)
|
||||
with self.subTest(comment=None):
|
||||
response = self.client.post(reverse('watchlist:vote', args=(m.id,)), data={"vote": "0"})
|
||||
mv = m.movievote_set.get(user=self.user)
|
||||
self.assertEqual(mv.comment, None)
|
||||
self.assertEqual(mv.comment, "")
|
||||
|
||||
|
||||
|
@ -56,9 +56,7 @@ def vote(request, pk):
|
||||
user_vote.vote = request.POST['vote']
|
||||
user_vote.seen = request.POST.get('seen', False) == "on"
|
||||
comment = request.POST.get('comment', '').strip()
|
||||
if comment != '' or user_vote.comment is not None:
|
||||
if comment == '':
|
||||
comment = None
|
||||
if comment != '' or user_vote.comment != "":
|
||||
user_vote.comment = comment
|
||||
user_vote.save()
|
||||
return HttpResponseRedirect(reverse('watchlist:index'))
|
||||
|
Loading…
Reference in New Issue
Block a user