add post status and delete is_hidden
This commit is contained in:
@@ -14,7 +14,7 @@ from documents.api import get_pad_link
|
||||
from documents.etherpadlib import add_ep_cookie
|
||||
from members.models import Member, JobMember
|
||||
from .forms import PostSearchForm
|
||||
from .models import Post, FetMeeting, FileUpload
|
||||
from .models import Event, FetMeeting, FileUpload, Post
|
||||
from .utils import render_to_pdf
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ def index(request):
|
||||
compact_view = None
|
||||
fet_meeting_only = None
|
||||
|
||||
public_only = not request.user.is_authenticated
|
||||
|
||||
if request.method == "POST":
|
||||
if "btn_input" in request.POST:
|
||||
form = PostSearchForm(request.POST)
|
||||
@@ -53,12 +55,15 @@ def index(request):
|
||||
request, "Es kann nicht nur nach einem Monat gesucht werden."
|
||||
)
|
||||
|
||||
posts = deque(
|
||||
Post.objects.get_date_filtered_list(year, month, fet_meeting_only)
|
||||
posts = Post.objects.date_filtered_list(
|
||||
public_only,
|
||||
year,
|
||||
month,
|
||||
fet_meeting_only,
|
||||
)
|
||||
else:
|
||||
form = PostSearchForm()
|
||||
posts = deque(Post.objects.get_date_sorted_list())
|
||||
posts = Post.objects.date_sorted_list(public_only)
|
||||
|
||||
if posts:
|
||||
taglist = map(lambda post: post.tags, posts)
|
||||
@@ -75,20 +80,26 @@ def index(request):
|
||||
|
||||
|
||||
def calendar(request):
|
||||
"Kalender Ansicht ICS zur Verknüpfung mit Outlook"
|
||||
events = deque(Post.objects.get_all_posts_with_date())
|
||||
"""
|
||||
ICS-calendar for outlook, google calender,...
|
||||
"""
|
||||
# publish all events independent of authenticated user
|
||||
events = Event.all_events.published(False)
|
||||
|
||||
context = {
|
||||
"events": events,
|
||||
}
|
||||
|
||||
return render(
|
||||
request,
|
||||
"posts/fet_calendar.ics",
|
||||
{"events": events},
|
||||
content_type="text/calendar",
|
||||
request, "posts/fet_calendar.ics", context, content_type="text/calendar"
|
||||
)
|
||||
|
||||
|
||||
def tags(request, tag=""):
|
||||
posts = deque(Post.objects.get_visible_articles().filter(tags__name=tag))
|
||||
featured_post = Post.objects.get_visible_articles().filter(slug=tag).first()
|
||||
public_only = not request.user.is_authenticated
|
||||
|
||||
posts = Post.objects.published(public_only).filter(tags__name=tag)
|
||||
featured_post = Post.objects.published(public_only).filter(slug=tag).first()
|
||||
|
||||
job_members = JobMember.active_member.get_all_by_slug(slug=tag)
|
||||
|
||||
@@ -110,14 +121,14 @@ def tags(request, tag=""):
|
||||
return render(request, "posts/tag.html", context)
|
||||
|
||||
|
||||
def __get_post_object(id=None):
|
||||
def __get_post_object(id=None, public=True):
|
||||
post = None
|
||||
|
||||
try:
|
||||
if id.isdigit() or id is int:
|
||||
post = Post.objects.get(id=int(id))
|
||||
post = Post.objects.published(public).get(id=int(id))
|
||||
elif id != "" and id is not None:
|
||||
post = Post.objects.get(slug=id)
|
||||
post = Post.objects.published(public).get(slug=id)
|
||||
except Exception:
|
||||
logger.info("Wrong id '{}'".format(id))
|
||||
raise Http404("wrong post id")
|
||||
@@ -126,49 +137,51 @@ def __get_post_object(id=None):
|
||||
|
||||
|
||||
def show(request, id=None):
|
||||
p = __get_post_object(id)
|
||||
public_only = not request.user.is_authenticated
|
||||
post = __get_post_object(id, public_only)
|
||||
|
||||
files = deque(FileUpload.objects.filter(post=p))
|
||||
# files
|
||||
files = FileUpload.objects.filter(post=post)
|
||||
|
||||
post_author = Member.all_members.filter(username=p.author).first()
|
||||
author_image = None
|
||||
# author
|
||||
author = None
|
||||
|
||||
author_image = None
|
||||
post_author = Member.all_members.filter(username=post.author).first()
|
||||
if post_author:
|
||||
author_image = post_author.image["avatar"].url
|
||||
author = post_author
|
||||
author_image = post_author.image["avatar"].url
|
||||
|
||||
# etherpad links for agenda and protocol
|
||||
ep_agenda_link = "#"
|
||||
ep_protocol_link = "#"
|
||||
# set filename for pdf, not a nice solution
|
||||
filename_agenda = None
|
||||
filename_protocol = None
|
||||
|
||||
if p.has_agenda:
|
||||
ep_agenda_link = get_pad_link(p.agenda_key)
|
||||
if post.has_agenda:
|
||||
ep_agenda_link = get_pad_link(post.agenda_key)
|
||||
|
||||
if ep_agenda_link != "#":
|
||||
filename_agenda = p.slug + "-agenda.pdf"
|
||||
filename_agenda = post.slug + "-agenda.pdf"
|
||||
|
||||
if p.has_protocol:
|
||||
ep_protocol_link = get_pad_link(p.protocol_key)
|
||||
if post.has_protocol:
|
||||
ep_protocol_link = get_pad_link(post.protocol_key)
|
||||
|
||||
if ep_protocol_link != "#":
|
||||
filename_protocol = p.slug + "-protokoll.pdf"
|
||||
|
||||
related_posts = p.tags.similar_objects()
|
||||
filename_protocol = post.slug + "-protokoll.pdf"
|
||||
|
||||
related_posts = post.tags.similar_objects()
|
||||
# list of non 'is_hidden' posts for related_posts
|
||||
for obj in related_posts:
|
||||
if obj.is_hidden:
|
||||
if not obj.published:
|
||||
related_posts.remove(obj)
|
||||
|
||||
context = {
|
||||
"post": p,
|
||||
"post": post,
|
||||
"files": files,
|
||||
"author": author,
|
||||
"author_image": author_image,
|
||||
"next": __get_next_dict(p),
|
||||
"next": __next(post, public_only),
|
||||
"related_posts": related_posts[0:6],
|
||||
"ep_agenda_link": ep_agenda_link,
|
||||
"ep_protocol_link": ep_protocol_link,
|
||||
@@ -215,34 +228,33 @@ def show_pdf(request, html, filename):
|
||||
|
||||
|
||||
def show_pdf_agenda(request, id):
|
||||
p = __get_post_object(id)
|
||||
html = p.agenda_html
|
||||
post = __get_post_object(id)
|
||||
html = post.agenda_html
|
||||
|
||||
return show_pdf(request, html, p.slug + "-agenda")
|
||||
return show_pdf(request, html, post.slug + "-agenda")
|
||||
|
||||
|
||||
@authenticated_user
|
||||
def show_pdf_protocol(request, id):
|
||||
p = __get_post_object(id)
|
||||
html = p.protocol_html
|
||||
post = __get_post_object(id)
|
||||
html = post.protocol_html
|
||||
|
||||
return show_pdf(request, html, p.slug + "-protokoll")
|
||||
return show_pdf(request, html, post.slug + "-protokoll")
|
||||
|
||||
|
||||
def __get_next_dict(post=None):
|
||||
def __next(post=None, public=True):
|
||||
"""
|
||||
Helper function for getting next post
|
||||
"""
|
||||
# TODO: Docstring
|
||||
posts = None
|
||||
d = post.slug
|
||||
|
||||
if post:
|
||||
# TODO: bad implementation but it works!!
|
||||
if post.post_type == "N" or post.post_type == "E":
|
||||
posts = Post.articles.get_visible_articles()
|
||||
posts = Post.articles.date_sorted_list(public)
|
||||
elif post.post_type == "F":
|
||||
posts = FetMeeting.objects.get_queryset().order_by("-event_start")
|
||||
posts = FetMeeting.objects.published(public)
|
||||
|
||||
if posts:
|
||||
for k, v in enumerate(posts):
|
||||
|
||||
Reference in New Issue
Block a user