Compare commits

...

4 Commits

Author SHA1 Message Date
dcacff303d fix after changing null -> blank
All checks were successful
continuous-integration/drone/push Build is passing
2023-02-17 15:20:22 +01:00
c84ae1334e Add extra test case 2023-02-17 15:12:18 +01:00
1abc910621 Fix movievote inlining in admin 2023-02-17 15:07:47 +01:00
5895714fd5 Fix null -> blank 2023-02-17 15:07:21 +01:00
7 changed files with 31 additions and 9 deletions

View File

@ -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 %} &ndash; {% if vote.vote == 1 %}👍{% elif vote.vote == 0 %}No opinion{% elif vote.vote == -1 %}👎{%endif%}{% if vote.comment is not None %} &ndash; {{vote.comment}}{% endif %}</li>
<li>{{vote.user.username}} {% if vote.seen %}(seen){% endif %} &ndash; {% if vote.vote == 1 %}👍{% elif vote.vote == 0 %}No opinion{% elif vote.vote == -1 %}👎{%endif%}{% if vote.comment != "" %} &ndash; {{vote.comment}}{% endif %}</li>
{% endfor %}
</ul>
{% endif %}

View File

@ -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):

View 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,
),
]

View File

@ -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}"

View File

@ -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):

View File

@ -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, "")

View File

@ -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'))