feat: add language to text (former Markdown content

This commit is contained in:
moanos [he/him] 2024-04-14 13:26:21 +02:00
parent 698a4b7f54
commit 34d8862b47
2 changed files with 24 additions and 15 deletions

View File

@ -180,20 +180,6 @@ class Animal(models.Model):
return reverse('animal-detail', args=[str(self.id)]) return reverse('animal-detail', args=[str(self.id)])
class MarkdownContent(models.Model):
"""
Base class to store markdown content
"""
title = models.CharField(max_length=100)
content = models.TextField()
class Meta:
verbose_name_plural = "Markdown content"
def __str__(self):
return self.title
class Rule(models.Model): class Rule(models.Model):
""" """
Class to store rules Class to store rules
@ -339,3 +325,19 @@ class Member(models.Model):
def get_absolute_url(self): def get_absolute_url(self):
return reverse("member-detail", args=[str(self.user.id)]) return reverse("member-detail", args=[str(self.user.id)])
class Text(models.Model):
"""
Base class to store markdown content
"""
title = models.CharField(max_length=100)
content = models.TextField()
language = models.OneToOneField(Language, on_delete=models.PROTECT)
text_code = models.CharField(max_length=24, verbose_name="text_code", blank=True)
class Meta:
verbose_name_plural = "Markdown content"
def __str__(self):
return self.title

View File

@ -5,9 +5,10 @@ from django.contrib.auth.decorators import login_required
from .mail import mail_admins_new_report from .mail import mail_admins_new_report
from notfellchen import settings from notfellchen import settings
from fellchensammlung.models import AdoptionNotice, MarkdownContent, Animal, Rule, Image, Report, ModerationAction, \ from fellchensammlung.models import AdoptionNotice, Text, Animal, Rule, Image, Report, ModerationAction, \
Member Member
from .forms import AdoptionNoticeForm, AnimalForm, ImageForm, ReportForm from .forms import AdoptionNoticeForm, AnimalForm, ImageForm, ReportForm
from .models import Language
def index(request): def index(request):
@ -98,6 +99,12 @@ def add_animal_to_adoption(request, adoption_notice_id):
def about(request): def about(request):
rules = Rule.objects.all() rules = Rule.objects.all()
if request.user.is_authenticated:
lang = request.user.member.preferred_language
else:
lang = Language.objects.get(languagecode="de")
terms_of_service = Text.objects.get(text_code="terms_of_service", language=lang)
imprint = Text.objects.get(text_code="imprint", language=lang)
context = {"rules": rules} context = {"rules": rules}
return render( return render(
request, request,