add Create- and UpdateView, labels, link to tasks. change date format.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
from ckeditor_uploader.widgets import CKEditorUploadingWidget
|
||||
from django import forms
|
||||
from django.forms.widgets import HiddenInput
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from tasks.models import Task, TaskList
|
||||
from .models import TopicGroup, Topic, Documentation, Etherpad, FileUpload
|
||||
|
||||
|
||||
@@ -16,8 +18,15 @@ class TopicGroupAdminForm(forms.ModelForm):
|
||||
"title",
|
||||
"slug",
|
||||
"order",
|
||||
"short_description",
|
||||
]
|
||||
|
||||
labels = {
|
||||
"title": _("Titel"),
|
||||
"slug": _("Permalink"),
|
||||
"short_description": _("Kurzbeschreibung"),
|
||||
}
|
||||
|
||||
|
||||
class TopicAdminForm(forms.ModelForm):
|
||||
class Meta:
|
||||
@@ -25,12 +34,19 @@ class TopicAdminForm(forms.ModelForm):
|
||||
fields = [
|
||||
"title",
|
||||
"slug",
|
||||
"archive",
|
||||
"description",
|
||||
"topic_group",
|
||||
"task_list",
|
||||
"archive",
|
||||
"description",
|
||||
]
|
||||
|
||||
labels = {
|
||||
"title": _("Titel"),
|
||||
"slug": _("Permalink"),
|
||||
"task_list": _("Aufgabenbereich"),
|
||||
"description": _("Beschreibung"),
|
||||
}
|
||||
|
||||
widgets = {"description": CKEditorUploadingWidget(config_name="default")}
|
||||
|
||||
|
||||
@@ -44,6 +60,12 @@ class DocumentationAdminForm(forms.ModelForm):
|
||||
"description",
|
||||
]
|
||||
|
||||
labels = {
|
||||
"title": _("Titel"),
|
||||
"slug": _("Permalink"),
|
||||
"description": _("Beschreibung"),
|
||||
}
|
||||
|
||||
widgets = {"description": CKEditorUploadingWidget(config_name="default")}
|
||||
|
||||
|
||||
@@ -52,8 +74,8 @@ class EtherpadAdminForm(forms.ModelForm):
|
||||
model = Etherpad
|
||||
fields = [
|
||||
"title",
|
||||
"documentation",
|
||||
"date",
|
||||
"documentation",
|
||||
]
|
||||
|
||||
|
||||
@@ -75,6 +97,11 @@ class TopicInlineForm(forms.ModelForm):
|
||||
"slug",
|
||||
]
|
||||
|
||||
labels = {
|
||||
"title": _("Titel"),
|
||||
"slug": _("Permalink"),
|
||||
}
|
||||
|
||||
|
||||
class DocumentationInlineForm(forms.ModelForm):
|
||||
class Meta:
|
||||
@@ -84,16 +111,26 @@ class DocumentationInlineForm(forms.ModelForm):
|
||||
"slug",
|
||||
]
|
||||
|
||||
labels = {
|
||||
"title": _("Titel"),
|
||||
"slug": _("Permalink"),
|
||||
}
|
||||
|
||||
|
||||
class EtherpadInlineForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Etherpad
|
||||
fields = [
|
||||
"title",
|
||||
"documentation",
|
||||
"date",
|
||||
"documentation",
|
||||
]
|
||||
|
||||
labels = {
|
||||
"title": _("Titel"),
|
||||
"date": _("Datum"),
|
||||
}
|
||||
|
||||
|
||||
class FileUploadInlineForm(forms.ModelForm):
|
||||
class Meta:
|
||||
@@ -103,6 +140,96 @@ class FileUploadInlineForm(forms.ModelForm):
|
||||
"file_field",
|
||||
]
|
||||
|
||||
labels = {
|
||||
"title": _("Titel"),
|
||||
}
|
||||
|
||||
|
||||
class TopicCreateForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Topic
|
||||
fields = [
|
||||
"title",
|
||||
"slug",
|
||||
"description",
|
||||
"topic_group",
|
||||
]
|
||||
|
||||
labels = {
|
||||
"title": _("Titel"),
|
||||
"slug": _("Permalink"),
|
||||
"description": _("Beschreibung"),
|
||||
}
|
||||
|
||||
widgets = {
|
||||
"topic_group": HiddenInput,
|
||||
}
|
||||
|
||||
|
||||
class TopicUpdateForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Topic
|
||||
fields = [
|
||||
"title",
|
||||
"slug",
|
||||
"description",
|
||||
"topic_group",
|
||||
]
|
||||
|
||||
labels = {
|
||||
"title": _("Titel"),
|
||||
"slug": _("Permalink"),
|
||||
"description": _("Beschreibung"),
|
||||
}
|
||||
|
||||
widgets = {
|
||||
"topic_group": HiddenInput,
|
||||
}
|
||||
|
||||
|
||||
class DocumentationCreateForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Documentation
|
||||
|
||||
fields = [
|
||||
"title",
|
||||
"slug",
|
||||
"description",
|
||||
"topic",
|
||||
]
|
||||
|
||||
labels = {
|
||||
"title": _("Titel"),
|
||||
"slug": _("Permalink"),
|
||||
"description": _("Beschreibung"),
|
||||
}
|
||||
|
||||
widgets = {
|
||||
"topic": HiddenInput,
|
||||
}
|
||||
|
||||
|
||||
class DocumentationUpdateForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Documentation
|
||||
|
||||
fields = [
|
||||
"title",
|
||||
"slug",
|
||||
"description",
|
||||
"topic",
|
||||
]
|
||||
|
||||
labels = {
|
||||
"title": _("Titel"),
|
||||
"slug": _("Permalink"),
|
||||
"description": _("Beschreibung"),
|
||||
}
|
||||
|
||||
widgets = {
|
||||
"topic": HiddenInput,
|
||||
}
|
||||
|
||||
|
||||
class EtherpadForm(forms.ModelForm):
|
||||
class Meta:
|
||||
@@ -120,7 +247,8 @@ class EtherpadForm(forms.ModelForm):
|
||||
}
|
||||
|
||||
widgets = {
|
||||
"date": DateInput(format=("%d-%m-%Y")),
|
||||
"date": DateInput(format=("%Y-%m-%d")),
|
||||
"documentation": HiddenInput,
|
||||
}
|
||||
|
||||
|
||||
@@ -132,3 +260,7 @@ class FileUploadForm(forms.ModelForm):
|
||||
"file_field",
|
||||
"documentation",
|
||||
]
|
||||
|
||||
widgets = {
|
||||
"documentation": HiddenInput,
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ class TopicGroup(models.Model):
|
||||
title = models.CharField(verbose_name="Titel", max_length=128)
|
||||
slug = models.SlugField(max_length=10, unique=True)
|
||||
|
||||
short_description = models.TextField(null=True, blank=True)
|
||||
|
||||
order = models.PositiveSmallIntegerField(
|
||||
verbose_name="Reihenfolge", unique=True, null=True, blank=True
|
||||
)
|
||||
@@ -34,7 +36,7 @@ class TopicGroup(models.Model):
|
||||
return self.title
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("intern") + "#" + self.slug
|
||||
return reverse("intern:index") + "#" + self.slug
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.slug:
|
||||
@@ -68,7 +70,7 @@ class Topic(models.Model):
|
||||
return self.title
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("topic", kwargs={"slug": self.slug})
|
||||
return reverse("intern:topic", kwargs={"slug": self.slug})
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.slug:
|
||||
@@ -107,7 +109,7 @@ class Documentation(models.Model):
|
||||
"slug": self.slug,
|
||||
}
|
||||
|
||||
return reverse("docu", kwargs=kwargs)
|
||||
return reverse("intern:docu", kwargs=kwargs)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.slug:
|
||||
@@ -118,6 +120,8 @@ class Documentation(models.Model):
|
||||
|
||||
class Etherpad(models.Model):
|
||||
title = models.CharField(verbose_name="Titel", max_length=128)
|
||||
slug = models.SlugField(null=True, blank=True)
|
||||
|
||||
etherpad_key = models.CharField(max_length=50, blank=True)
|
||||
date = models.DateField(verbose_name="Datum", default=date.today)
|
||||
|
||||
@@ -143,11 +147,14 @@ class Etherpad(models.Model):
|
||||
+ "-"
|
||||
+ self.documentation.slug
|
||||
+ "-"
|
||||
+ slugify(self.title)
|
||||
+ self.slug
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
pad_name = slugify(self.__get_pad_name())
|
||||
if not self.slug:
|
||||
self.slug = slugify(self.title)
|
||||
|
||||
pad_name = self.__get_pad_name()
|
||||
|
||||
if len(pad_name) > 50:
|
||||
raise ValidationError(
|
||||
|
||||
@@ -1,13 +1,45 @@
|
||||
from django.urls import path
|
||||
|
||||
from . import apps
|
||||
from . import views
|
||||
from .views import EtherpadCreateView, FileUploadCreateView
|
||||
from .views import (
|
||||
DocumentationCreateView,
|
||||
DocumentationUpdateView,
|
||||
EtherpadCreateView,
|
||||
FileUploadCreateView,
|
||||
TaskCreateView,
|
||||
TopicCreateView,
|
||||
TopicUpdateView,
|
||||
)
|
||||
|
||||
|
||||
app_name = apps.InternConfig.name
|
||||
|
||||
urlpatterns = [
|
||||
path("", views.index, name="intern"),
|
||||
path("", views.index, name="index"),
|
||||
path(
|
||||
"<slug:topic_group>/topic-create/",
|
||||
TopicCreateView.as_view(),
|
||||
name="topic-create",
|
||||
),
|
||||
path("<slug:slug>/", views.show_topic, name="topic"),
|
||||
path(
|
||||
"<slug:slug>/update/",
|
||||
TopicUpdateView.as_view(),
|
||||
name="topic-update",
|
||||
),
|
||||
path(
|
||||
"<slug:slug>/docu-create/",
|
||||
DocumentationCreateView.as_view(),
|
||||
name="docu-create",
|
||||
),
|
||||
path("<slug:slug>/create/", TaskCreateView.as_view(), name="task-create"),
|
||||
path("<slug:topic_slug>/<slug:slug>/", views.show_docu, name="docu"),
|
||||
path(
|
||||
"<slug:topic_slug>/<slug:slug>/update/",
|
||||
DocumentationUpdateView.as_view(),
|
||||
name="docu-update",
|
||||
),
|
||||
path(
|
||||
"<slug:topic_slug>/<slug:slug>/etherpad-create/",
|
||||
EtherpadCreateView.as_view(),
|
||||
|
||||
@@ -6,14 +6,22 @@ from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.db.models import F, Q
|
||||
from django.http import HttpResponseRedirect, Http404
|
||||
from django.shortcuts import render
|
||||
from django.views.generic.edit import CreateView
|
||||
from django.urls import reverse
|
||||
from django.views.generic.edit import CreateView, UpdateView
|
||||
from django.urls import reverse_lazy, reverse
|
||||
|
||||
from authentications.decorators import authenticated_user
|
||||
from documents.api import get_pad_link
|
||||
from documents.etherpadlib import add_ep_cookie
|
||||
from tasks.forms import InternTaskCreateForm
|
||||
from tasks.models import Task
|
||||
from .forms import EtherpadForm, FileUploadForm
|
||||
from .forms import (
|
||||
DocumentationCreateForm,
|
||||
DocumentationUpdateForm,
|
||||
EtherpadForm,
|
||||
FileUploadForm,
|
||||
TopicCreateForm,
|
||||
TopicUpdateForm,
|
||||
)
|
||||
from .models import TopicGroup, Topic, Documentation, Etherpad, FileUpload
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -21,15 +29,15 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
@authenticated_user
|
||||
def index(request):
|
||||
topic = deque(
|
||||
Topic.objects.filter(archive=False).order_by(
|
||||
F("topic_group__order").asc(nulls_last=True), "topic_group", "title"
|
||||
)
|
||||
topic = 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))
|
||||
empty_topic_groups = TopicGroup.objects.filter(topic=None)
|
||||
archive_topic = Topic.objects.filter(archive=True)
|
||||
|
||||
context = {
|
||||
"topic": topic,
|
||||
"empty_topic_groups": empty_topic_groups,
|
||||
"archive_topic": archive_topic,
|
||||
}
|
||||
|
||||
@@ -42,7 +50,7 @@ def show_topic(request, slug=None):
|
||||
if not active_topic:
|
||||
raise Http404("wrong topic")
|
||||
|
||||
docu = deque(Documentation.objects.filter(topic__slug=slug).order_by("title"))
|
||||
docu = Documentation.objects.filter(topic__slug=slug).order_by("title")
|
||||
|
||||
tasks = None
|
||||
if active_topic.task_list:
|
||||
@@ -104,9 +112,9 @@ def show_docu(request, topic_slug=None, slug=None):
|
||||
form_add_etherpad = EtherpadForm(initial=initial)
|
||||
form_add_file = FileUploadForm(initial=initial)
|
||||
|
||||
files = deque(FileUpload.objects.filter(documentation=active_docu))
|
||||
files = FileUpload.objects.filter(documentation=active_docu)
|
||||
|
||||
docus = deque(Etherpad.objects.filter(documentation=active_docu).order_by("-date"))
|
||||
docus = Etherpad.objects.filter(documentation=active_docu).order_by("-date")
|
||||
etherpads = deque([])
|
||||
|
||||
# list of etherpad url-link of any etherpads
|
||||
@@ -138,6 +146,124 @@ def show_docu(request, topic_slug=None, slug=None):
|
||||
return response
|
||||
|
||||
|
||||
class TopicCreateView(LoginRequiredMixin, CreateView):
|
||||
model = Topic
|
||||
success_url = reverse_lazy("intern:index")
|
||||
template_name = "intern/topic/topic_create.html"
|
||||
form_class = TopicCreateForm
|
||||
|
||||
slug = None
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["topic_group"] = self.slug
|
||||
return context
|
||||
|
||||
def get_initial(self):
|
||||
self.slug = self.kwargs.get("topic_group")
|
||||
topic_group = TopicGroup.objects.filter(slug=self.slug).first()
|
||||
|
||||
context = {
|
||||
"topic_group": topic_group,
|
||||
}
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class TopicUpdateView(LoginRequiredMixin, UpdateView):
|
||||
model = Topic
|
||||
template_name = "intern/topic/topic_update.html"
|
||||
form_class = TopicUpdateForm
|
||||
|
||||
slug = None
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["slug"] = self.slug
|
||||
return context
|
||||
|
||||
def get_initial(self):
|
||||
self.slug = self.kwargs.get("slug")
|
||||
topic = Topic.objects.filter(slug=self.slug).first()
|
||||
|
||||
context = {
|
||||
"topic": topic,
|
||||
}
|
||||
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
context = {
|
||||
"slug": self.slug,
|
||||
}
|
||||
|
||||
return reverse("intern:topic", kwargs=context)
|
||||
|
||||
|
||||
class DocumentationCreateView(LoginRequiredMixin, CreateView):
|
||||
model = Documentation
|
||||
template_name = "intern/docu/docu_create.html"
|
||||
form_class = DocumentationCreateForm
|
||||
|
||||
slug = None
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["slug"] = self.slug
|
||||
return context
|
||||
|
||||
def get_initial(self):
|
||||
self.slug = self.kwargs.get("slug")
|
||||
topic = Topic.objects.filter(slug=self.slug).first()
|
||||
|
||||
context = {
|
||||
"topic": topic,
|
||||
}
|
||||
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
context = {
|
||||
"slug": self.slug,
|
||||
}
|
||||
|
||||
return reverse("intern:topic", kwargs=context)
|
||||
|
||||
|
||||
class DocumentationUpdateView(LoginRequiredMixin, UpdateView):
|
||||
model = Documentation
|
||||
template_name = "intern/docu/docu_update.html"
|
||||
form_class = DocumentationUpdateForm
|
||||
|
||||
topic_slug = None
|
||||
slug = None
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["topic_slug"] = self.topic_slug
|
||||
context["slug"] = self.slug
|
||||
return context
|
||||
|
||||
def get_initial(self):
|
||||
self.topic_slug = self.kwargs.get("topic_slug")
|
||||
self.slug = self.kwargs.get("slug")
|
||||
|
||||
active_docu = Documentation.objects.filter(slug=self.slug).first()
|
||||
context = {
|
||||
"documentation": active_docu,
|
||||
}
|
||||
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
context = {
|
||||
"topic_slug": self.topic_slug,
|
||||
"slug": self.slug,
|
||||
}
|
||||
|
||||
return reverse("intern:docu", kwargs=context)
|
||||
|
||||
|
||||
class EtherpadCreateView(LoginRequiredMixin, CreateView):
|
||||
model = Etherpad
|
||||
template_name = "intern/etherpad_create.html"
|
||||
@@ -156,7 +282,7 @@ class EtherpadCreateView(LoginRequiredMixin, CreateView):
|
||||
self.topic_slug = self.kwargs.get("topic_slug")
|
||||
self.slug = self.kwargs.get("slug")
|
||||
|
||||
active_docu = Documentation.objects.filter(slug=self.kwargs.get("slug")).first()
|
||||
active_docu = Documentation.objects.filter(slug=self.slug).first()
|
||||
context = {
|
||||
"documentation": active_docu,
|
||||
}
|
||||
@@ -169,7 +295,7 @@ class EtherpadCreateView(LoginRequiredMixin, CreateView):
|
||||
"slug": self.slug,
|
||||
}
|
||||
|
||||
return reverse("docu", kwargs=context)
|
||||
return reverse("intern:docu", kwargs=context)
|
||||
|
||||
|
||||
class FileUploadCreateView(LoginRequiredMixin, CreateView):
|
||||
@@ -204,4 +330,40 @@ class FileUploadCreateView(LoginRequiredMixin, CreateView):
|
||||
"slug": self.slug,
|
||||
}
|
||||
|
||||
return reverse("docu", kwargs=context)
|
||||
return reverse("intern:docu", kwargs=context)
|
||||
|
||||
|
||||
class TaskCreateView(LoginRequiredMixin, CreateView):
|
||||
model = Task
|
||||
template_name = "intern/task_create.html"
|
||||
form_class = InternTaskCreateForm
|
||||
|
||||
slug = None
|
||||
|
||||
def form_valid(self, form):
|
||||
form.instance.created_by = self.request.user
|
||||
# add_log_action(self.request, form, True)
|
||||
return super().form_valid(form)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["slug"] = self.slug
|
||||
return context
|
||||
|
||||
def get_initial(self):
|
||||
self.slug = self.kwargs.get("slug")
|
||||
topic = Topic.objects.filter(slug=self.slug).first()
|
||||
|
||||
context = {
|
||||
"topic": topic,
|
||||
"task_list": topic.task_list,
|
||||
}
|
||||
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
context = {
|
||||
"slug": self.slug,
|
||||
}
|
||||
|
||||
return reverse("intern:topic", kwargs=context)
|
||||
|
||||
Reference in New Issue
Block a user