1
0
Fork 0
mirror of https://github.com/Findus23/RPGnotes.git synced 2024-09-19 15:43:45 +02:00

add notes

This commit is contained in:
Lukas Winkler 2021-10-03 16:09:59 +02:00
parent 68106c44d4
commit 06a13a74c0
Signed by: lukas
GPG key ID: 54DE4D798D244853
13 changed files with 229 additions and 0 deletions

0
notes/__init__.py Normal file
View file

5
notes/admin.py Normal file
View file

@ -0,0 +1,5 @@
from django.contrib import admin
from notes.models import Note
admin.site.register(Note)

6
notes/apps.py Normal file
View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class NotesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'notes'

9
notes/forms.py Normal file
View file

@ -0,0 +1,9 @@
from django.forms import ModelForm
from notes.models import Note
class NoteForm(ModelForm):
class Meta:
model = Note
fields = ["name", "description_md", "parent"]

View file

@ -0,0 +1,60 @@
# Generated by Django 3.2.7 on 2021-10-03 14:08
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import simple_history.models
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Note',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('description_md', models.TextField(blank=True, verbose_name='Description')),
('description_html', models.TextField(blank=True, editable=False, verbose_name='Description (HTML)')),
('name', models.CharField(max_length=1000, verbose_name='Name')),
('slug', models.SlugField(editable=False, unique=True)),
('created', models.DateTimeField(auto_now_add=True)),
('last_modified', models.DateTimeField(auto_now=True)),
('parent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='children', to='notes.note', verbose_name='Part of')),
],
options={
'verbose_name': 'Note',
'verbose_name_plural': 'Notes',
'ordering': ['name'],
},
),
migrations.CreateModel(
name='HistoricalNote',
fields=[
('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
('description_md', models.TextField(blank=True, verbose_name='Description')),
('description_html', models.TextField(blank=True, editable=False, verbose_name='Description (HTML)')),
('name', models.CharField(max_length=1000, verbose_name='Name')),
('slug', models.SlugField(editable=False)),
('created', models.DateTimeField(blank=True, editable=False)),
('last_modified', models.DateTimeField(blank=True, editable=False)),
('history_id', models.AutoField(primary_key=True, serialize=False)),
('history_date', models.DateTimeField()),
('history_change_reason', models.CharField(max_length=100, null=True)),
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('parent', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='notes.note', verbose_name='Part of')),
],
options={
'verbose_name': 'historical Note',
'ordering': ('-history_date', '-history_id'),
'get_latest_by': 'history_date',
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
]

View file

26
notes/models.py Normal file
View file

@ -0,0 +1,26 @@
from django.db import models
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from tree_queries.fields import TreeNodeForeignKey
from tree_queries.models import TreeNode
from common.models import NameSlugModel, DescriptionModel, HistoryModel
class Note(TreeNode, NameSlugModel, DescriptionModel, HistoryModel):
parent = TreeNodeForeignKey(
"self",
blank=True,
null=True,
on_delete=models.CASCADE,
verbose_name=_("Part of"),
related_name="children",
)
class Meta:
ordering = ["name"]
verbose_name = _("Note")
verbose_name_plural = _("Notes")
def get_absolute_url(self):
return reverse('notedetail', args=[self.slug])

View file

@ -0,0 +1,56 @@
{% extends "tenantbase.html" %}
{% load i18n %}
{% load thumbutils %}
{% load thumbnail %}
{% load humanize %}
{% block content %}
<div class="row">
<div class="col-4">
<div class="list-group">
{% for p in roots %}
<a class="tree-{{ p.tree_depth }} list-group-item list-group-item-action {% if location.id == p.id %}active{% endif %}"
href="{{ p.get_absolute_url }}">
{{ p }}
</a>
{% endfor %}
</div>
<a class="btn btn-primary" href="{% url "locationadd" %}">{% translate "Add Location" %}</a>
</div>
<div class="col-8">
<div class="character-heading">
<h1>
{{ location.name }}
<a href="{% url "locationedit" location.slug %}">
edit
</a>
</h1>
<nav aria-label="breadcrumb" class="breadcrumbs">
<ol class="breadcrumb">
{% for ancestor in location.ancestors %}
<li class="breadcrumb-item">
<a href="{{ ancestor.get_absolute_url }}">{{ ancestor }}</a>
</li>
{% endfor %}
<li class="breadcrumb-item active" aria-current="page">
{{ location }}
</li>
</ol>
</nav>
</div>
<dl>
{% if location.part_of %}
<dt>{% translate "Part of" %}:</dt>
<dd><a href="{{ location.part_of.get_absolute_url }}">{{ location.part_of }}</a></dd>
{% endif %}
</dl>
{{ location.description_html|safe }}
<div>
<small>{% translate "Last updated" %}: {{ location.last_modified|naturaltime }}
{% translate "by" %} {{ location.history.first.history_user }} </small>
</div>
</div>
</div>
{% endblock %}

12
notes/urls.py Normal file
View file

@ -0,0 +1,12 @@
from django.urls import path
from notes import views
urlpatterns=[
path("", views.list_note_redirect, name="notelist"),
path("add", views.NoteCreateView.as_view(), name="noteadd"),
path("<slug:slug>", views.NoteDetailView.as_view(), name="notedetail"),
path("<slug:slug>/edit", views.NoteEditView.as_view(), name="noteedit"),
path("<slug:slug>/delete", views.NoteDeleteView.as_view(), name="notedelete"),
]

49
notes/views.py Normal file
View file

@ -0,0 +1,49 @@
# Create your views here.
from django.shortcuts import redirect
from django.urls import reverse_lazy
from django.views import generic
from notes.forms import NoteForm
from notes.models import Note
def list_note_redirect(request, *args, **kwargs):
first_note: Note = Note.objects.first()
if not first_note:
return redirect("noteadd")
return redirect(first_note)
class NoteDetailView(generic.DetailView):
template_name = "notes/detail.html"
model = Note
context_object_name = "note"
def get_context_data(self, **kwargs):
data = super().get_context_data(**kwargs)
data["roots"] = Note.objects.with_tree_fields()
return data
class NoteCreateView(generic.CreateView):
template_name = "loot/edit.html"
model = Note
form_class = NoteForm
context_object_name = "object"
class NoteEditView(generic.UpdateView):
template_name = "loot/edit.html"
model = Note
form_class = NoteForm
def get_context_data(self, **kwargs):
data = super().get_context_data(**kwargs)
data['edit'] = True
return data
class NoteDeleteView(generic.DeleteView):
template_name = "common/confirm_delete.html"
model = Note
success_url = reverse_lazy('notelist')

View file

@ -66,6 +66,7 @@ TENANT_APPS = (
'characters',
'loot',
'days',
'notes',
'common',
'simple_history',

View file

@ -15,6 +15,7 @@ urlpatterns = [
path('character/', include("characters.urls")),
path('day/', include("days.urls")),
path('location/', include("locations.urls")),
path('note/', include("notes.urls")),
path('loot/', include("loot.urls")),
path('', include("campaigns.urls"))
]

View file

@ -28,6 +28,10 @@
<a class="nav-link {% if url_name == 'locationdetail' %}active{% endif %}"
href="{% url "locationlist" %}">{% translate "Locations" %}</a>
</li>
<li class="nav-item">
<a class="nav-link {% if url_name == 'notedetail' %}active{% endif %}"
href="{% url "notelist" %}">{% translate "Notes" %}</a>
</li>
<li class="nav-item">
<a class="nav-link {% if url_name == 'daydetail' %}active{% endif %}"
href="{% url "daylist" %}">{% translate "Timeline" %}</a>