feat: Add comments to adoption notices
This commit is contained in:
parent
a16098f648
commit
e77a936c30
@ -3,7 +3,7 @@ from django.contrib import admin
|
|||||||
from .models import User, Language, Text
|
from .models import User, Language, Text
|
||||||
|
|
||||||
from .models import Animal, Species, RescueOrganization, AdoptionNotice, Location, Rule, Image, ModerationAction, \
|
from .models import Animal, Species, RescueOrganization, AdoptionNotice, Location, Rule, Image, ModerationAction, \
|
||||||
Report, Member
|
Report, Member, Comment
|
||||||
|
|
||||||
|
|
||||||
# Define an inline admin descriptor for Employee model
|
# Define an inline admin descriptor for Employee model
|
||||||
@ -33,3 +33,4 @@ admin.site.register(Report)
|
|||||||
admin.site.register(ModerationAction)
|
admin.site.register(ModerationAction)
|
||||||
admin.site.register(Language)
|
admin.site.register(Language)
|
||||||
admin.site.register(Text)
|
admin.site.register(Text)
|
||||||
|
admin.site.register(Comment)
|
||||||
|
@ -6,7 +6,8 @@ from django.core.files import File
|
|||||||
from fellchensammlung import baker_recipes
|
from fellchensammlung import baker_recipes
|
||||||
from model_bakery import baker
|
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):
|
class Command(BaseCommand):
|
||||||
@ -24,7 +25,6 @@ class Command(BaseCommand):
|
|||||||
except AdoptionNotice.DoesNotExist:
|
except AdoptionNotice.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
rescue1 = baker.make_recipe(
|
rescue1 = baker.make_recipe(
|
||||||
'fellchensammlung.rescue_org'
|
'fellchensammlung.rescue_org'
|
||||||
)
|
)
|
||||||
@ -88,5 +88,12 @@ class Command(BaseCommand):
|
|||||||
mod1.trust_level = Member.MODERATOR
|
mod1.trust_level = Member.MODERATOR
|
||||||
mod1.save()
|
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):
|
def handle(self, *args, **options):
|
||||||
self.populate_db()
|
self.populate_db()
|
||||||
|
56
src/fellchensammlung/migrations/0002_comment.py
Normal file
56
src/fellchensammlung/migrations/0002_comment.py
Normal file
@ -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",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
@ -44,7 +44,7 @@ class Image(models.Model):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def as_html(self):
|
def as_html(self):
|
||||||
return f'<img src="{ MEDIA_URL }/{ self.image }" alt="{ self.alt_text }">'
|
return f'<img src="{MEDIA_URL}/{self.image}" alt="{self.alt_text}">'
|
||||||
|
|
||||||
|
|
||||||
class Species(models.Model):
|
class Species(models.Model):
|
||||||
@ -116,6 +116,10 @@ class AdoptionNotice(models.Model):
|
|||||||
def animals(self):
|
def animals(self):
|
||||||
return Animal.objects.filter(adoption_notice=self)
|
return Animal.objects.filter(adoption_notice=self)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def comments(self):
|
||||||
|
return Comment.objects.filter(adoption_notice=self)
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
"""Returns the url to access a detailed page for the animal."""
|
"""Returns the url to access a detailed page for the animal."""
|
||||||
return reverse('adoption-notice-detail', args=[str(self.id)])
|
return reverse('adoption-notice-detail', args=[str(self.id)])
|
||||||
@ -350,3 +354,17 @@ class Text(models.Model):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.title} ({self.language})"
|
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}"
|
||||||
|
@ -60,7 +60,7 @@ th {
|
|||||||
background-color: var(--secondary-light-two);
|
background-color: var(--secondary-light-two);
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1, h2 {
|
||||||
word-wrap: break-word;
|
word-wrap: break-word;
|
||||||
color: var(--text-one);
|
color: var(--text-one);
|
||||||
text-shadow: 2px 2px var(--shadow-one);
|
text-shadow: 2px 2px var(--shadow-one);
|
||||||
@ -411,3 +411,20 @@ form {
|
|||||||
float: none;
|
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);
|
||||||
|
}
|
@ -37,9 +37,6 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="container-cards">
|
{% include "fellchensammlung/partials/partial-comment-section.html" %}
|
||||||
{% for animal in adoption_notice.animals %}
|
|
||||||
{% include "fellchensammlung/partials/partial-animal-card.html" %}
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
<div class="container-comments">
|
||||||
|
<h2>{% translate 'Comments' %}</h2>
|
||||||
|
{% if adoption_notice.comments %}
|
||||||
|
{% for comment in adoption_notice.comments %}
|
||||||
|
{% include "fellchensammlung/partials/partial-comment.html" %}
|
||||||
|
{% endfor %}
|
||||||
|
{% else %}
|
||||||
|
{% translate 'Noch keine Kommentare' %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
</div>
|
@ -0,0 +1,13 @@
|
|||||||
|
{% load i18n %}
|
||||||
|
{% load custom_tags %}
|
||||||
|
<div class="comment">
|
||||||
|
<div class="comment-header">
|
||||||
|
<b>{{ comment.user }}</b>
|
||||||
|
{{ comment.created_at }}
|
||||||
|
</div>
|
||||||
|
<p>
|
||||||
|
{{ comment.text | render_markdown }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
Loading…
Reference in New Issue
Block a user