add Create- and UpdateView, labels, link to tasks. change date format.
This commit is contained in:
@@ -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