コード例 #1
0
def post_new(request):
    if request.method == "POST":
        form = PostForm(request.POST)
        if form.is_valid():
            title = request.POST.get("title")
            try:
                if Post.objects.get(title=title):
                    default_data = {}
                    title = request.POST.get("title")
                    objectforthetitle = Post.objects.get(title=title)
                    default_data[
                        objectforthetitle.title] = objectforthetitle.htmltext
                    return render(request, 'webapp/post_detail.html', {
                        'default_data': default_data,
                        'pk': objectforthetitle.pk
                    })
            except ObjectDoesNotExist:
                post = form.save(commit=False)
                post.author = request.user
                post.published_date = timezone.now()
                post.save()
                return redirect('post_detail', pk=post.pk)

    else:
        form = PostForm()
    return render(request, 'webapp/post_edit.html', {'form': form})
コード例 #2
0
def post_edit(request, pk):
    post = get_object_or_404(Post, pk=pk)
    if request.method == "POST":
        form = PostForm(request.POST, instance=post)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = request.user
            post.published_date = timezone.now()
            post.save()

            return redirect('post_detail', pk=post.pk)
    else:
        form = PostForm()
    return render(request, 'webapp/post_edit.html', {'form': form})
コード例 #3
0
ファイル: views.py プロジェクト: droptableuser/wombii-webapp
def home(request):
    user_id=request.session.get('_auth_user_id')
    form = PostForm()
    if request.method == 'POST':
        form = PostForm(request.POST)
        if form.is_valid():
            #form.save(commit=False)
            share = Share()
            share.receiver = MyUser.objects.get(username= request.POST.get('form_receiver'))
            share.sender = MyUser.objects.get(id=user_id)
            share.link = request.POST.get('link')
            share.date = date.today()
            share.save()
        else:
            print form.errors
    else:
        form = PostForm()

    links = Share.objects.filter(receiver=user_id)
    return render(request, 'wombii/home.html', {'form': form, 'links': links})
コード例 #4
0
ファイル: views.py プロジェクト: khushbu14/dcms
def submit_post(request):
	""" Create a form to submit post.
	"""
	context = RequestContext(request)

	if request.POST:
		postform = PostForm(data=request.POST)  # creating a new instance for using it
		if postform.is_valid():
			postform.save(commit=True)
			return HttpResponseRedirect('/webapp/blog')
		else:
			print postform.errors
	else:
		postform = PostForm()
		print postform
	
	context_dict = {
		'postform': postform,
	}
	return render_to_response("webapp/submitpost.html", context_dict , context)
コード例 #5
0
def submit_post(request):
    """ Create a form to submit post.
	"""
    context = RequestContext(request)

    if request.POST:
        postform = PostForm(
            data=request.POST)  # creating a new instance for using it
        if postform.is_valid():
            postform.save(commit=True)
            return HttpResponseRedirect('/webapp/blog')
        else:
            print postform.errors
    else:
        postform = PostForm()
        print postform

    context_dict = {
        'postform': postform,
    }
    return render_to_response("webapp/submitpost.html", context_dict, context)