Example #1
0
def new(request):
  if request.method == 'POST': # form has been properly submitted
    p = BanksPost(creator=request.user)
    form = PostForm(request.POST, instance=p)

    if form.is_valid():
      form.save()
      messages.add_message(request, messages.SUCCESS, 'Post Created')
      return viewPost(request, p.slug)

    else:
      messages.add_message(request, messages.ERROR, "Error in Post")

  else:
    form = PostForm()

  return return_form(request, form, "Create new Post")
Example #2
0
def edit(request, slug):
  p = BanksPost.objects.get(slug=slug)

  if request.method == "POST":
    form = PostForm(request.POST, instance=p)

    if form.is_valid():
      form.save()
      messages.add_message(request, messages.SUCCESS, 'Post Successfully Edited')
      return viewPost(request, p.slug)

    else:
      messages.add_message(request, messages.ERROR, 'Error in Editing Post')

  else:
    form = PostForm(instance=p)

  return return_form(request, form, "Edit Post")