feat: Add rules
This commit is contained in:
parent
1bcdbdbbf5
commit
079b2073a1
@ -29,6 +29,11 @@ class Command(BaseCommand):
|
|||||||
rat2 = baker.make(Animal, name="Rat2", adoption_notice=adoption1, species=rat)
|
rat2 = baker.make(Animal, name="Rat2", adoption_notice=adoption1, species=rat)
|
||||||
cat1 = baker.make(Animal, name="Cat1", adoption_notice=adoption2, species=cat)
|
cat1 = baker.make(Animal, name="Cat1", adoption_notice=adoption2, species=cat)
|
||||||
|
|
||||||
|
rule1 = baker.make(Rule, title="Be excellent ot each other", rule_text="This is **markdown**")
|
||||||
|
rule2 = baker.make(Rule,
|
||||||
|
title="Keep al least the minimum number of animals for species",
|
||||||
|
rule_text="This is not markdown")
|
||||||
|
|
||||||
User.objects.create_user('test', password='foobar')
|
User.objects.create_user('test', password='foobar')
|
||||||
User.objects.create_superuser(username="admin", password="admin")
|
User.objects.create_superuser(username="admin", password="admin")
|
||||||
|
|
||||||
|
21
src/fellchensammlung/migrations/0002_rule.py
Normal file
21
src/fellchensammlung/migrations/0002_rule.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# Generated by Django 5.0.3 on 2024-03-20 09:54
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('fellchensammlung', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Rule',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('title', models.CharField(max_length=200)),
|
||||||
|
('rule_text', models.TextField()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
@ -135,3 +135,16 @@ class MarkdownContent(models.Model):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
class Rule(models.Model):
|
||||||
|
"""
|
||||||
|
Class to store rules
|
||||||
|
"""
|
||||||
|
title = models.CharField(max_length=200)
|
||||||
|
|
||||||
|
# Markdown is allowed in rule text
|
||||||
|
rule_text = models.TextField()
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.title
|
||||||
|
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>{{ markdown_content.title }}</h1>
|
<h1>Rules</h1>
|
||||||
<p>{{ markdown_content.content|safe }}</p>
|
{% include "fellchensammlung/list-rules.html" %}
|
||||||
{% endblock %}
|
{% endblock %}
|
@ -0,0 +1,5 @@
|
|||||||
|
<div class="list-rules">
|
||||||
|
{% for rule in rules %}
|
||||||
|
{% include "fellchensammlung/partial-rule.html" %}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
@ -0,0 +1,3 @@
|
|||||||
|
{% load custom_tags %}
|
||||||
|
<h2>{{ rule.title }}</h2>
|
||||||
|
<p>{{ rule.rule_text | render_markdown }}</p>
|
@ -1,4 +1,8 @@
|
|||||||
|
import markdown
|
||||||
|
|
||||||
from django import template
|
from django import template
|
||||||
|
from django.template.defaultfilters import stringfilter
|
||||||
|
from django.utils.safestring import mark_safe
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
@ -26,4 +30,8 @@ def join_link(value, arg):
|
|||||||
def get_type(value):
|
def get_type(value):
|
||||||
return type(value)
|
return type(value)
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
@stringfilter
|
||||||
|
def render_markdown(value):
|
||||||
|
md = markdown.Markdown(extensions=["fenced_code"])
|
||||||
|
return mark_safe(md.convert(value))
|
||||||
|
@ -3,7 +3,7 @@ from django.http import HttpResponse
|
|||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
import markdown
|
import markdown
|
||||||
|
|
||||||
from fellchensammlung.models import AdoptionNotice, MarkdownContent, Animal
|
from fellchensammlung.models import AdoptionNotice, MarkdownContent, Animal, Rule
|
||||||
from .forms import AdoptionNoticeForm, AnimalForm
|
from .forms import AdoptionNoticeForm, AnimalForm
|
||||||
|
|
||||||
|
|
||||||
@ -64,10 +64,8 @@ def add_animal_to_adoption(request, adoption_notice_id):
|
|||||||
|
|
||||||
|
|
||||||
def about(request):
|
def about(request):
|
||||||
md = markdown.Markdown(extensions=["fenced_code"])
|
rules = Rule.objects.all()
|
||||||
markdown_content = MarkdownContent.objects.first()
|
context = {"rules": rules}
|
||||||
markdown_content.content = md.convert(markdown_content.content)
|
|
||||||
context = {"markdown_content": markdown_content}
|
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
"fellchensammlung/about.html",
|
"fellchensammlung/about.html",
|
||||||
|
Loading…
Reference in New Issue
Block a user