예제 #1
0
def home(request):
    print "in uploader"
    if request.method=="POST":
        img = UploadForm(request.POST, request.FILES)       
        if img.is_valid():
            img.save()  
            return HttpResponseRedirect(reverse('imageupload'))
    else:
        img=UploadForm()
    images=Upload.objects.all()
    print "img: ", img
    print "images: ", images
    return render(request,'uploader/home.html',{'form':img,'images':images})
예제 #2
0
def create_design(request):
    if request.method == "POST":
        form = UploadForm(request.POST, request.FILES)
        if form.is_valid():
            slug = form.cleaned_data["slug"]
            form.save()
            design = Design.objects.get(slug__iexact=slug)
            design.owner = request.user
            design.save()
            return HttpResponseRedirect(WIKI_PREFIX_URL + "accounts/")
        else:
            return render_to_response("wiki/create_design.html", {"form": form})
    else:
        form = UploadForm()
        return render_to_response("wiki/create_design.html", {"form": form})
예제 #3
0
def home(request):
    print "in uploader"
    if request.method == "POST":
        img = UploadForm(request.POST, request.FILES)
        if img.is_valid():
            img.save()
            return HttpResponseRedirect(reverse('imageupload'))
    else:
        img = UploadForm()
    images = Upload.objects.all()
    print "img: ", img
    print "images: ", images
    return render(request, 'uploader/home.html', {
        'form': img,
        'images': images
    })
예제 #4
0
def create_design(request):
    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)
        if form.is_valid():
            slug = form.cleaned_data['slug']
            form.save()
            design = Design.objects.get(slug__iexact=slug)
            design.owner = request.user
            design.save()
            return HttpResponseRedirect(WIKI_PREFIX_URL + 'accounts/')
        else:
            return render_to_response('wiki/create_design.html',
                                      {'form': form})
    else:
        form = UploadForm()
        return render_to_response('wiki/create_design.html', {'form': form})
예제 #5
0
def UploadImg(request):

    if request.method == "POST":
        images = Upload.objects.all()
        event = UploadForm(request.POST, request.FILES)
        poll = UpPolls(request.POST, instance=Poll())
        cforms = [
            UpChoice(request.POST, prefix=str(x), instance=Choice())
            for x in range(0, 4)
        ]
        # choice1 = UpChoice1(request.POST, prefix='ch1')
        # choice2 = UpChoice2(request.POST, prefix='ch2')
        # choice3 = UpChoice3(request.POST, prefix='ch3')
        # choice4 = UpChoice4(request.POST, prefix='ch4')
        # # print "this is event",event
        # choices = FormVoteChoices(request.POST, request.FILES)
        for cf in cforms:
            print cf
        if event.is_valid() and poll.is_valid() and all(
            [cf.is_valid() for cf in cforms]):

            event.save()
            a = poll.save()
            for cf in cforms:
                new_choice = cf.save(commit=False)
                new_choice.poll = a
                new_choice.save()
                print "5555555555555555"

            # if a:
            # 	poll_list = Poll.objects.all()
            # 	print "poll: ",poll_list
            # 	print "Hello a: ",a
            # 	print "choice", choice.data['choice_text']

            # if choice.is_valid:
            #     c1 = Choice.objects.create(poll=a,choice_text=choice1.data['choice_text'],votes=0)
            #     c1.save()
            # else:
            #     print"not valid"

            # if choice2.is_valid:
            #     c2 = Choice.objects.create(poll=a,choice_text=choice2.data['choice_text'],votes=0)
            #     c2.save()
            # else:
            #     print"not valid"

            # if choice3.is_valid:
            #     c3 = Choice.objects.create(poll=a,choice_text=choice3.data['choice_text'],votes=0)
            #     c3.save()
            # else:
            #     print"not valid"

            # if choice4.is_valid:
            #     c4 = Choice.objects.create(poll=a,choice_text=choice4.data['choice_text'],votes=0)
            #     c4.save()
            # else:
            #     print"not valid"

            print "success"
            print request.user.username
            return HttpResponseRedirect('/')
    else:
        print "fail"
        event = UploadForm()
        poll = UpPolls(instance=Poll())
        cforms = [
            UpChoice(prefix=str(x), instance=Choice()) for x in range(0, 4)
        ]
        # choice2 = UpChoice2()
        # choice3 = UpChoice3()
        # choice4 = UpChoice4()
        # choices = FormVoteChoices()
        images = Upload.objects.all()
    return render(
        request, 'addEvent.html', {
            'form': event,
            'images': images,
            'username': request.user.username,
            'poll': poll,
            'choices': cforms
        })