update template, wordings; add ep cookie
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import logging
|
||||
|
||||
from django.contrib import messages
|
||||
from django.db.models import F, Q
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
from documents.api import get_pad_link
|
||||
from documents.etherpadlib import add_ep_cookie
|
||||
from collections import deque
|
||||
|
||||
from .forms import DocumentForm
|
||||
@@ -12,12 +15,9 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def index(request):
|
||||
|
||||
topic_group = deque(TopicGroup.objects.all())
|
||||
topic = Topic.objects.all()
|
||||
topic = deque(Topic.objects.filter(archive=False).order_by(F('topic_group__order').asc(nulls_last=True), 'topic_group', 'title'))
|
||||
|
||||
context = {
|
||||
"topic_group": topic_group,
|
||||
"topic": topic,
|
||||
}
|
||||
|
||||
@@ -25,15 +25,10 @@ def index(request):
|
||||
|
||||
|
||||
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))
|
||||
docu = deque(Documentation.objects.filter(topic__slug=slug).order_by('title'))
|
||||
|
||||
context = {
|
||||
"topic_group": topic_group,
|
||||
"topic": topic,
|
||||
"active_topic": active_topic,
|
||||
"docus": docu,
|
||||
}
|
||||
@@ -41,10 +36,9 @@ def show_topic(request, slug=None):
|
||||
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()
|
||||
def show_docu(request, topic_slug=None, slug=None):
|
||||
active_docu = Documentation.objects.filter(Q(topic__slug=topic_slug) & Q(slug=slug)).first()
|
||||
active_topic = Topic.objects.filter(slug=topic_slug).first()
|
||||
|
||||
if request.method == "POST":
|
||||
if "btn_input" in request.POST:
|
||||
@@ -58,22 +52,28 @@ def show_docu(request, slug=None, foo=None):
|
||||
|
||||
return HttpResponseRedirect(request.path)
|
||||
|
||||
form = DocumentForm()
|
||||
docus = deque(Document.objects.filter(documentation=active_docu))
|
||||
else:
|
||||
for elem in list(form.errors.values()):
|
||||
messages.info(request, '; '.join(elem))
|
||||
|
||||
initial = {
|
||||
"title": active_docu.placeholder,
|
||||
}
|
||||
|
||||
form = DocumentForm(initial=initial)
|
||||
|
||||
docus = deque(Document.objects.filter(documentation=active_docu).order_by('-date'))
|
||||
documents = deque([])
|
||||
|
||||
# list of etherpad url-link of any documents
|
||||
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
|
||||
)
|
||||
documents.append(
|
||||
{
|
||||
"title": elem.title,
|
||||
"date": elem.date,
|
||||
"etherpad_key": get_pad_link(elem.etherpad_key),
|
||||
}
|
||||
)
|
||||
|
||||
context = {
|
||||
"formset": form,
|
||||
@@ -82,4 +82,11 @@ def show_docu(request, slug=None, foo=None):
|
||||
"documents": documents,
|
||||
}
|
||||
|
||||
return render(request, "intern/docu.html", context)
|
||||
response = render(request, "intern/docu.html", context)
|
||||
|
||||
try:
|
||||
response = add_ep_cookie(request, response)
|
||||
except Exception as e:
|
||||
logger.info("Etherpad Server doesn't work. Error: %s", e)
|
||||
|
||||
return response
|
||||
|
||||
Reference in New Issue
Block a user