add archive view, get_absolute_url method and fileupload

This commit is contained in:
2021-06-13 21:17:16 +00:00
parent c65deb644f
commit 0ba27ed6bb
4 changed files with 79 additions and 28 deletions

View File

@@ -1,6 +1,7 @@
from django.contrib import admin
from django.db.models import F
from .models import TopicGroup, Topic, Documentation, Document
from .models import TopicGroup, Topic, Documentation, Document, FileUpload
from .forms import TopicGroupAdminForm, TopicAdminForm, DocumentationAdminForm, DocumentAdminForm
@@ -12,6 +13,13 @@ class DocumentationInline(admin.TabularInline):
verbose_name_plural = "Dokument-Übersicht"
class FileUploadInline(admin.TabularInline):
model = FileUpload
extra = 0
verbose_name = "Dokument"
verbose_name_plural = "Do­ku­men­ten­samm­lung"
class TopicInline(admin.TabularInline):
model = Topic
form = TopicAdminForm
@@ -27,7 +35,8 @@ class TopicGroupAdmin(admin.ModelAdmin):
search_fields = ("title", )
inlines = (TopicInline,)
list_display = ["title", "order",]
list_display = ["title", "order"]
ordering = [F("order").asc(nulls_last=True)]
def save_model(self, request, obj, form, change):
obj.created_by = request.user
@@ -38,10 +47,11 @@ class TopicAdmin(admin.ModelAdmin):
form = TopicAdminForm
model = Topic
search_fields = ("title",)
inlines = (DocumentationInline,)
inlines = (DocumentationInline, )
list_filter = ["archive",]
list_display = ["title", "topic_group", "archive",]
list_filter = ["topic_group", "archive"]
list_display = ["title", "topic_group", "archive"]
ordering = ["archive"]
def save_model(self, request, obj, form, change):
obj.created_by = request.user

View File

@@ -4,6 +4,7 @@ from datetime import date
from django.core.validators import ValidationError
from django.db import models
from django.db.models.constraints import UniqueConstraint
from django.urls import reverse
from django.utils import timezone
from django.utils.text import slugify
from django.utils.translation import gettext_lazy as _
@@ -15,7 +16,7 @@ logger = logging.getLogger(__name__)
class TopicGroup(models.Model):
title = models.CharField(verbose_name="Titel", max_length=128)
slug = models.SlugField(unique=True, blank=True)
slug = models.SlugField(max_length=10, unique=True)
order = models.PositiveSmallIntegerField(verbose_name="Reihenfolge", unique=True, null=True, blank=True)
@@ -25,19 +26,22 @@ class TopicGroup(models.Model):
verbose_name = "Themenbereich"
verbose_name_plural = "Themenbereiche"
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse("intern") + "#" + self.slug
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.title)
super().save(*args, **kwargs)
def __str__(self):
return self.title
class Topic(models.Model):
title = models.CharField(verbose_name="Titel", max_length=128)
slug = models.SlugField(unique=True, blank=True)
slug = models.SlugField(max_length=10, unique=True)
archive = models.BooleanField(verbose_name="Archiv", default=False)
@@ -51,19 +55,22 @@ class Topic(models.Model):
verbose_name = "Thema"
verbose_name_plural = "Themen"
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse("topic", kwargs={"slug": self.slug})
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.title)
super().save(*args, **kwargs)
def __str__(self):
return self.title
class Documentation(models.Model):
title = models.CharField(verbose_name="Titel", max_length=128)
slug = models.SlugField(blank=True)
slug = models.SlugField(max_length=10)
placeholder = models.CharField(verbose_name="Platzhalter", max_length=128, default="Titel")
description = models.TextField(null=True, blank=True)
@@ -72,19 +79,22 @@ class Documentation(models.Model):
objects = models.Manager()
def __str__(self):
return self.topic.title + " / " + self.title
def get_absolute_url(self):
return reverse("docu", kwargs={"topic_slug": self.topic.slug, "slug": self.slug})
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.title)
super().save(*args, **kwargs)
def __str__(self):
return self.topic.title + " / " + self.title
class Document(models.Model):
title = models.CharField(verbose_name="Titel", max_length=128)
etherpad_key = models.CharField(max_length=128, null=True, blank=True)
etherpad_key = models.CharField(max_length=50, blank=True)
date = models.DateField(verbose_name="Datum", default=date.today)
documentation = models.ForeignKey(Documentation, on_delete=models.CASCADE)
@@ -96,21 +106,17 @@ class Document(models.Model):
verbose_name_plural = "Dokumente"
constraints = [
UniqueConstraint(fields=['title', 'date'], name='unique_title_and_date'),
UniqueConstraint(fields=['title', 'date', 'documentation'], name='unique_document'),
]
'''
pre save signal
def clean(self):
pad_name = slugify(self.date + "-" + self.documentation.topic.slug + "-" + self.documentation.slug + "-" + slugify(self.title)
pad_name = slugify(str(self.date) + "-" + self.documentation.topic.slug + "-" + self.documentation.slug + "-" + slugify(self.title))
if len(pad_name) > 50:
print(pad_name)
raise ValidationError(
_('Name zum Erstellen des Etherpads ist zu lange - max. 50 Zeichen. (Länge: %(length)s) (Name: %(pad_name)s)'),
_('Name zum Erstellen des Etherpads ist zu lange - max. 50 Zeichen. (Länge: %(length)s, Name: %(pad_name)s)'),
params={'length': len(pad_name), 'pad_name': pad_name},
)
'''
)
def save(self, *args, **kwargs):
self.etherpad_key = createPadifNotExists(
@@ -121,3 +127,15 @@ class Document(models.Model):
def __str__(self):
return self.title
class FileUpload(models.Model):
title = models.CharField(verbose_name="Titel", max_length=128)
file_field = models.FileField(verbose_name="Dokument", upload_to="uploads/intern/files/")
documentation = models.ForeignKey(Documentation, on_delete=models.CASCADE)
objects = models.Manager()
def __str__(self):
return self.title

View File

@@ -16,9 +16,11 @@ logger = logging.getLogger(__name__)
def index(request):
topic = deque(Topic.objects.filter(archive=False).order_by(F('topic_group__order').asc(nulls_last=True), 'topic_group', 'title'))
archive_topic = deque(Topic.objects.filter(archive=True))
context = {
"topic": topic,
"archive_topic": archive_topic,
}
return render(request, "intern/index.html", context)
@@ -47,7 +49,7 @@ def show_docu(request, topic_slug=None, slug=None):
if form.is_valid():
docu = form.save(commit=False)
docu.created_by = request.user
docu.documentation = active_docu
# docu.documentation = active_docu
docu.save()
return HttpResponseRedirect(request.path)
@@ -58,6 +60,7 @@ def show_docu(request, topic_slug=None, slug=None):
initial = {
"title": active_docu.placeholder,
"documentation": active_docu,
}
form = DocumentForm(initial=initial)

View File

@@ -7,7 +7,7 @@
{% for topic in topic_list %}
<div class="internheader">
{{ topic.grouper.title }}
<h3>{{ topic.grouper.title }}<a class="headerlink" id="{{topic.list.0.topic_group.slug}}" href="#{{topic.list.0.topic_group.slug}}" title="Permalink to {{topic.grouper}}" style="color: lightgrey;"> #</a></h3>
</div>
<div class="grid-x grid-padding-x">
@@ -25,5 +25,25 @@
</div>
{% endfor %}
{% if archive_topic %}
<div class="internheader">
<h3>Archiv<a class="headerlink" id="archive" href="#archive" title="Permalink to Archiv" style="color: lightgrey;"> #</a></h3>
</div>
<div class="grid-x grid-padding-x">
{% for tp in archive_topic %}
<div class="cell large-2 medium-4 small-6">
<a href="{% url 'topic' tp.slug %}">
<div class="intern-topic">
<div class="intern-topic-text">
{{ tp.title }}
</div>
</div>
</a>
</div>
{% endfor %}
</div>
{% endif %}
</div>
{% endblock %}