diff --git a/src/fellchensammlung/admin.py b/src/fellchensammlung/admin.py index 990890d..3d0380a 100644 --- a/src/fellchensammlung/admin.py +++ b/src/fellchensammlung/admin.py @@ -3,7 +3,7 @@ from django.contrib import admin from .models import User, Language, Text from .models import Animal, Species, RescueOrganization, AdoptionNotice, Location, Rule, Image, ModerationAction, \ - Report, Member + Report, Member, Comment # Define an inline admin descriptor for Employee model @@ -33,3 +33,4 @@ admin.site.register(Report) admin.site.register(ModerationAction) admin.site.register(Language) admin.site.register(Text) +admin.site.register(Comment) diff --git a/src/fellchensammlung/management/commands/populate_db.py b/src/fellchensammlung/management/commands/populate_db.py index d224c7f..12e2364 100644 --- a/src/fellchensammlung/management/commands/populate_db.py +++ b/src/fellchensammlung/management/commands/populate_db.py @@ -6,7 +6,8 @@ from django.core.files import File from fellchensammlung import baker_recipes from model_bakery import baker -from fellchensammlung.models import AdoptionNotice, Species, Animal, Image, ModerationAction, User, Member, Rule, Report +from fellchensammlung.models import AdoptionNotice, Species, Animal, Image, ModerationAction, User, Member, Rule, \ + Report, Comment class Command(BaseCommand): @@ -24,7 +25,6 @@ class Command(BaseCommand): except AdoptionNotice.DoesNotExist: pass - rescue1 = baker.make_recipe( 'fellchensammlung.rescue_org' ) @@ -88,5 +88,12 @@ class Command(BaseCommand): mod1.trust_level = Member.MODERATOR mod1.save() + comment1 = baker.make(Comment, user=admin1, text="This is a comment", adoption_notice=adoption1) + comment2 = baker.make(Comment, + user=mod1, + text="This is a reply", + adoption_notice=adoption1, + reply_to=comment1) + def handle(self, *args, **options): self.populate_db() diff --git a/src/fellchensammlung/migrations/0002_comment.py b/src/fellchensammlung/migrations/0002_comment.py new file mode 100644 index 0000000..dd6f3d0 --- /dev/null +++ b/src/fellchensammlung/migrations/0002_comment.py @@ -0,0 +1,56 @@ +# Generated by Django 5.0.6 on 2024-06-03 19:22 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("fellchensammlung", "0001_initial"), + ] + + operations = [ + migrations.CreateModel( + name="Comment", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("created_at", models.DateTimeField(auto_now_add=True)), + ("text", models.TextField(verbose_name="Inhalt")), + ( + "adoption_notice", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to="fellchensammlung.adoptionnotice", + verbose_name="AdoptionNotice", + ), + ), + ( + "reply_to", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.CASCADE, + to="fellchensammlung.comment", + verbose_name="Antwort auf", + ), + ), + ( + "user", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to="fellchensammlung.member", + verbose_name="Nutzer*in", + ), + ), + ], + ), + ] diff --git a/src/fellchensammlung/models.py b/src/fellchensammlung/models.py index 5f7a974..d8fb334 100644 --- a/src/fellchensammlung/models.py +++ b/src/fellchensammlung/models.py @@ -44,7 +44,7 @@ class Image(models.Model): @property def as_html(self): - return f'{ self.alt_text }' + return f'{self.alt_text}' class Species(models.Model): @@ -116,6 +116,10 @@ class AdoptionNotice(models.Model): def animals(self): return Animal.objects.filter(adoption_notice=self) + @property + def comments(self): + return Comment.objects.filter(adoption_notice=self) + def get_absolute_url(self): """Returns the url to access a detailed page for the animal.""" return reverse('adoption-notice-detail', args=[str(self.id)]) @@ -350,3 +354,17 @@ class Text(models.Model): def __str__(self): return f"{self.title} ({self.language})" + + +class Comment(models.Model): + """ + Class to store comments in markdown content + """ + user = models.ForeignKey(Member, on_delete=models.CASCADE, verbose_name=_('Nutzer*in')) + created_at = models.DateTimeField(auto_now_add=True) + adoption_notice = models.ForeignKey(AdoptionNotice, on_delete=models.CASCADE, verbose_name=_('AdoptionNotice')) + text = models.TextField(verbose_name="Inhalt") + reply_to = models.ForeignKey("self", verbose_name="Antwort auf", blank=True, null=True, on_delete=models.CASCADE) + + def __str__(self): + return f"{self.user} at {self.created_at.strftime('%H:%M %d.%m.%y')}: {self.text:.10}" diff --git a/src/fellchensammlung/static/fellchensammlung/css/styles.css b/src/fellchensammlung/static/fellchensammlung/css/styles.css index ba43007..bcbed39 100644 --- a/src/fellchensammlung/static/fellchensammlung/css/styles.css +++ b/src/fellchensammlung/static/fellchensammlung/css/styles.css @@ -60,7 +60,7 @@ th { background-color: var(--secondary-light-two); } -h1 { +h1, h2 { word-wrap: break-word; color: var(--text-one); text-shadow: 2px 2px var(--shadow-one); @@ -410,4 +410,21 @@ form { display: inline-block; float: none; } +} + +.container-comments { + display: flex; + flex-wrap: wrap; + background: var(--background-two); + border-radius: 8px; + padding: 5px; +} + +.comment { + flex: 1 100%; + margin: 10px; + border-radius: 8px; + padding: 5px; + background: var(--background-three); + color: var(--text-two); } \ No newline at end of file diff --git a/src/fellchensammlung/templates/fellchensammlung/details/detail_adoption_notice.html b/src/fellchensammlung/templates/fellchensammlung/details/detail_adoption_notice.html index 57f6144..0cbbd52 100644 --- a/src/fellchensammlung/templates/fellchensammlung/details/detail_adoption_notice.html +++ b/src/fellchensammlung/templates/fellchensammlung/details/detail_adoption_notice.html @@ -37,9 +37,6 @@ {% endif %}

-
- {% for animal in adoption_notice.animals %} - {% include "fellchensammlung/partials/partial-animal-card.html" %} - {% endfor %} -
+ {% include "fellchensammlung/partials/partial-comment-section.html" %} + {% endblock %} diff --git a/src/fellchensammlung/templates/fellchensammlung/partials/partial-comment-section.html b/src/fellchensammlung/templates/fellchensammlung/partials/partial-comment-section.html new file mode 100644 index 0000000..f2a1240 --- /dev/null +++ b/src/fellchensammlung/templates/fellchensammlung/partials/partial-comment-section.html @@ -0,0 +1,13 @@ +{% load i18n %} + +
+

{% translate 'Comments' %}

+ {% if adoption_notice.comments %} + {% for comment in adoption_notice.comments %} + {% include "fellchensammlung/partials/partial-comment.html" %} + {% endfor %} + {% else %} + {% translate 'Noch keine Kommentare' %} + {% endif %} + +
\ No newline at end of file diff --git a/src/fellchensammlung/templates/fellchensammlung/partials/partial-comment.html b/src/fellchensammlung/templates/fellchensammlung/partials/partial-comment.html new file mode 100644 index 0000000..e763aac --- /dev/null +++ b/src/fellchensammlung/templates/fellchensammlung/partials/partial-comment.html @@ -0,0 +1,13 @@ +{% load i18n %} +{% load custom_tags %} +
+
+ {{ comment.user }} + {{ comment.created_at }} +
+

+ {{ comment.text | render_markdown }} +

+ + +