def joke_edit(request, pk): joke = Joke.objects.get(id = pk) if request.method == 'POST': form = AddJokeForm(request.POST) if form.is_valid(): joke.joke_text = form.cleaned_data['joke'] joke.tags = form.cleaned_data['tags'] joke.save() return HttpResponseRedirect("/home/") else: form = AddJokeForm() return render_to_response('addjoke.html', { "state": '1', "form": form, }, context_instance=RequestContext(request)) return HttpResponseRedirect(request.META.get('HTTP_REFERER','/'))
def addjoke(request): if isinstance(request.user,AnonymousUser) : return HttpResponseRedirect("/home/") if request.method == 'POST': form = AddJokeForm(request.POST) if form.is_valid(): newjoke = Joke() newjoke.joke_text = form.cleaned_data['joke'] newjoke.tags = form.cleaned_data['tags'] newjoke.accepted = 0 newjoke.rate = 0 newjoke.number_of_grades = 0 newjoke.author = request.user.get_username() newjoke.published_date = date.today() newjoke.save() return HttpResponseRedirect("/home/") else: form = AddJokeForm() return render_to_response('addjoke.html', { "state": '1', "form": form, }, context_instance=RequestContext(request))