intern implementation

This commit is contained in:
2021-02-28 00:29:26 +00:00
committed by Patrick Mayr
parent 59191a0909
commit 7da778189d
15 changed files with 543 additions and 1 deletions

85
fet2020/intern/views.py Normal file
View File

@@ -0,0 +1,85 @@
import logging
from django.http import HttpResponseRedirect
from django.shortcuts import render
from documents.api import get_pad_link
from collections import deque
from .forms import DocumentForm
from .models import TopicGroup, Topic, Documentation, Document
logger = logging.getLogger(__name__)
def index(request):
topic_group = deque(TopicGroup.objects.all())
topic = Topic.objects.all()
context = {
"topic_group": topic_group,
"topic": topic,
}
return render(request, "intern/index.html", context)
def show_topic(request, slug=None):
topic_group = deque(TopicGroup.objects.all())
topic = deque(Topic.objects.all())
active_topic = Topic.objects.filter(slug=slug).first()
docu = deque(Documentation.objects.filter(topic__slug=slug))
context = {
"topic_group": topic_group,
"topic": topic,
"active_topic": active_topic,
"docus": docu,
}
return render(request, "intern/topic.html", context)
def show_docu(request, slug=None, foo=None):
active_docu = Documentation.objects.filter(slug=foo).first()
active_topic = Topic.objects.filter(slug=slug).first()
if request.method == "POST":
if "btn_input" 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()
return HttpResponseRedirect(request.path)
form = DocumentForm()
docus = deque(Document.objects.filter(documentation=active_docu))
documents = deque([])
for elem in docus:
try:
documents.append(
{
"title": elem.title,
"etherpad_key": get_pad_link(elem.etherpad_key),
}
)
except Exception as e:
logger.error(
"Can't get the agenda link from '%s'. Error: %s", elem.etherpad_key, e
)
context = {
"formset": form,
"active_topic": active_topic,
"active_docu": active_docu,
"documents": documents,
}
return render(request, "intern/docu.html", context)