def event_view(request, uid): "Return a detailed view for specific post" # Get the post. event = Event.objects.filter(uid=uid).first() if not event: messages.error(request, "Event does not exist.") return redirect("event_list") # user string users_str = auth.get_users_str() context = dict(event=event, users_str=users_str) return render(request, "event_view.html", context=context)
def job_view(request, uid): "Return a detailed view for specific post" # Get the post. job = Job.objects.filter(uid=uid).first() if not job: messages.error(request, "Job does not exist.") return redirect("job_list") # user string users_str = auth.get_users_str() context = dict(job=job, users_str=users_str) return render(request, "job_view.html", context=context)
def post_view(request, uid): "Return a detailed view for specific post" # Get the post. post = Post.objects.filter(uid=uid).select_related('root').first() if not post: messages.error(request, "Post does not exist.") return redirect("post_list") auth.update_post_views(post=post, request=request) if not post.is_toplevel: return redirect(post.get_absolute_url()) # Form used for answers form = forms.PostShortForm(user=request.user, post=post) if request.method == "POST": form = forms.PostShortForm(data=request.POST, user=request.user, post=post) if form.is_valid(): author = request.user content = form.cleaned_data.get("content") answer = auth.create_post(title=post.title, parent=post, author=author, content=content, ptype=Post.ANSWER, root=post.root) return redirect(answer.get_absolute_url()) messages.error(request, form.errors) # Build the comment tree . root, comment_tree, answers, thread = auth.post_tree(user=request.user, root=post.root) # user string users_str = auth.get_users_str() context = dict(post=root, tree=comment_tree, form=form, answers=answers, users_str=users_str) return render(request, "post_view.html", context=context)
def new_event(request): """ Creates a new event """ form = forms.EventForm(user=request.user) author = request.user tag_val = content = location = external_link = '' event_date = timezone.now() if request.method == "POST": form = forms.EventForm(data=request.POST, user=request.user) tag_val = form.data.get('tag_val') content = form.data.get('content', '') if form.is_valid(): # Create a new post by user title = form.cleaned_data.get('title') content = form.cleaned_data.get("content") tag_val = form.cleaned_data.get('tag_val') location = form.cleaned_data.get('location', '') external_link = form.cleaned_data.get('external_link', '') event_date = form.cleaned_data.get('event_date') event = auth.create_event(title=title, content=content, tag_val=tag_val, author=author, location=location, event_date=event_date, external_link=external_link) tasks.created_event.spool(eid=event.id) return redirect('event_list') # Action url for the form is the current view action_url = reverse("event_create") users_str = auth.get_users_str() context = dict(form=form, tab="new", tag_val=tag_val, action_url=action_url, content=content, users_str=users_str) return render(request, "new_event.html", context=context)
def new_post(request): """ Creates a new post """ form = forms.PostLongForm(user=request.user) author = request.user tag_val = content = '' if request.method == "POST": form = forms.PostLongForm(data=request.POST, user=request.user) tag_val = form.data.get('tag_val') content = form.data.get('content', '') if form.is_valid(): # Create a new post by user title = form.cleaned_data.get('title') content = form.cleaned_data.get("content") ptype = form.cleaned_data.get('post_type') tag_val = form.cleaned_data.get('tag_val') post = auth.create_post(title=title, content=content, ptype=ptype, tag_val=tag_val, author=author) tasks.created_post.spool(pid=post.id) return redirect(post.get_absolute_url()) # Action url for the form is the current view action_url = reverse("post_create") users_str = auth.get_users_str() context = dict(form=form, tab="new", tag_val=tag_val, action_url=action_url, content=content, users_str=users_str) return render(request, "new_post.html", context=context)