예제 #1
0
파일: views.py 프로젝트: KwarcPL/joke
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','/'))
예제 #2
0
파일: views.py 프로젝트: KwarcPL/joke
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))