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") context = dict(form=form, tab="new", tag_val=tag_val, action_url=action_url, content=content) return render(request, "new_post.html", context=context)
def post_create(request, project=None, template="post_create.html", url="post_view", extra_context={}, filter_func=lambda x: x): "Make a new post" # Filter function ( filter_func ) is used to filter choices from the form # between sites. form = forms.PostLongForm(project=project, filter_func=filter_func) if request.method == "POST": form = forms.PostLongForm(data=request.POST, project=project, filter_func=filter_func) if form.is_valid(): # Create a new post by user post = form.save(author=request.user) if tasks.HAS_UWSGI: tasks.created_post(pid=post.id) return redirect( reverse(url, request=request, kwargs=dict(uid=post.uid))) context = dict(form=form, extra_tab="active", extra_tab_name="New Post", action_url=reverse("post_create")) context.update(extra_context) return render(request, template, context=context)