add fileupload, create views, detail view of task
This commit is contained in:
@@ -1,23 +1,31 @@
|
||||
import logging
|
||||
|
||||
from collections import deque
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.db.models import F, Q
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.http import HttpResponseRedirect, Http404
|
||||
from django.shortcuts import render
|
||||
from django.views.generic.edit import CreateView
|
||||
from django.urls import reverse
|
||||
|
||||
from authentications.decorators import authenticated_user
|
||||
from documents.api import get_pad_link
|
||||
from documents.etherpadlib import add_ep_cookie
|
||||
from collections import deque
|
||||
|
||||
from .forms import DocumentForm
|
||||
from tasks.models import Task
|
||||
from .forms import DocumentForm, FileUploadForm
|
||||
from .models import TopicGroup, Topic, Documentation, Document, FileUpload
|
||||
from authentications.decorators import authenticated_user
|
||||
|
||||
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 = 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 = {
|
||||
@@ -31,11 +39,26 @@ def index(request):
|
||||
@authenticated_user
|
||||
def show_topic(request, slug=None):
|
||||
active_topic = Topic.objects.filter(slug=slug).first()
|
||||
docu = deque(Documentation.objects.filter(topic__slug=slug).order_by('title'))
|
||||
if not active_topic:
|
||||
raise Http404("wrong topic")
|
||||
|
||||
docu = deque(Documentation.objects.filter(topic__slug=slug).order_by("title"))
|
||||
|
||||
tasks = None
|
||||
if active_topic.task_list:
|
||||
tasks = deque(
|
||||
Task.taskmanager.get_tasks(
|
||||
user=request.user.id,
|
||||
completed=False,
|
||||
task_list=active_topic.task_list,
|
||||
all_tasks=True,
|
||||
)
|
||||
)
|
||||
|
||||
context = {
|
||||
"active_topic": active_topic,
|
||||
"docus": docu,
|
||||
"tasks": tasks,
|
||||
}
|
||||
|
||||
return render(request, "intern/topic.html", context)
|
||||
@@ -43,34 +66,47 @@ def show_topic(request, slug=None):
|
||||
|
||||
@authenticated_user
|
||||
def show_docu(request, topic_slug=None, slug=None):
|
||||
active_docu = Documentation.objects.filter(Q(topic__slug=topic_slug) & Q(slug=slug)).first()
|
||||
active_docu = Documentation.objects.filter(
|
||||
Q(topic__slug=topic_slug) & Q(slug=slug)
|
||||
).first()
|
||||
if not active_docu:
|
||||
raise Http404("wrong docu")
|
||||
|
||||
active_topic = Topic.objects.filter(slug=topic_slug).first()
|
||||
|
||||
if request.method == "POST":
|
||||
if "btn_input" in request.POST:
|
||||
if "btn_etherpad" in request.POST:
|
||||
form = DocumentForm(request.POST)
|
||||
|
||||
if form.is_valid():
|
||||
docu = form.save(commit=False)
|
||||
docu.created_by = request.user
|
||||
# docu.documentation = active_docu
|
||||
docu.save()
|
||||
|
||||
form.save()
|
||||
return HttpResponseRedirect(request.path)
|
||||
|
||||
else:
|
||||
for elem in list(form.errors.values()):
|
||||
messages.info(request, '; '.join(elem))
|
||||
messages.info(request, "; ".join(elem))
|
||||
|
||||
if "btn_fileupload" in request.POST:
|
||||
form = FileUploadForm(request.POST, request.FILES)
|
||||
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return HttpResponseRedirect(request.path)
|
||||
|
||||
else:
|
||||
for elem in list(form.errors.values()):
|
||||
messages.info(request, "; ".join(elem))
|
||||
|
||||
initial = {
|
||||
"documentation": active_docu,
|
||||
}
|
||||
|
||||
form = DocumentForm(initial=initial)
|
||||
form_add_etherpad = DocumentForm(initial=initial)
|
||||
form_add_file = FileUploadForm(initial=initial)
|
||||
|
||||
files = deque(FileUpload.objects.filter(documentation=active_docu))
|
||||
|
||||
docus = deque(Document.objects.filter(documentation=active_docu).order_by('-date'))
|
||||
docus = deque(Document.objects.filter(documentation=active_docu).order_by("-date"))
|
||||
documents = deque([])
|
||||
|
||||
# list of etherpad url-link of any documents
|
||||
@@ -84,7 +120,8 @@ def show_docu(request, topic_slug=None, slug=None):
|
||||
)
|
||||
|
||||
context = {
|
||||
"formset": form,
|
||||
"form_add_etherpad": form_add_etherpad,
|
||||
"form_add_file": form_add_file,
|
||||
"active_topic": active_topic,
|
||||
"active_docu": active_docu,
|
||||
"documents": documents,
|
||||
@@ -99,3 +136,72 @@ def show_docu(request, topic_slug=None, slug=None):
|
||||
logger.info("Etherpad Server doesn't work. Error: %s", e)
|
||||
|
||||
return response
|
||||
|
||||
|
||||
class EtherpadCreateView(LoginRequiredMixin, CreateView):
|
||||
model = Document
|
||||
template_name = "intern/etherpad_create.html"
|
||||
form_class = DocumentForm
|
||||
|
||||
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.kwargs.get("slug")).first()
|
||||
context = {
|
||||
"documentation": active_docu,
|
||||
}
|
||||
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
context = {
|
||||
"topic_slug": self.topic_slug,
|
||||
"slug": self.slug,
|
||||
}
|
||||
|
||||
return reverse("docu", kwargs=context)
|
||||
|
||||
|
||||
class FileUploadCreateView(LoginRequiredMixin, CreateView):
|
||||
model = FileUpload
|
||||
template_name = "intern/file_create.html"
|
||||
form_class = FileUploadForm
|
||||
|
||||
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.kwargs.get("slug")).first()
|
||||
context = {
|
||||
"documentation": active_docu,
|
||||
}
|
||||
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
context = {
|
||||
"topic_slug": self.topic_slug,
|
||||
"slug": self.slug,
|
||||
}
|
||||
|
||||
return reverse("docu", kwargs=context)
|
||||
|
||||
Reference in New Issue
Block a user