Exemple #1
0
def AddNewProject(request):

    if 'login' in request.session:
            user=User.objects.get(login=request.session['login'])
            f = forms.ProjectRegisterForm(prefix='project')
            fr = forms.ProjectPerks(prefix='perk')
            context = RequestContext(request, {'formset': f, 'form1': fr})
            if request.method == 'POST':
                f = forms.ProjectRegisterForm(request.POST, prefix='project')
                p = Project()
                if(f.is_valid()):
                    p.title = f.cleaned_data['title']
                    p.short_description = f.cleaned_data['short_description']
                    p.funding_goal = f.cleaned_data['funding_goal']
                    p.full_description = f.cleaned_data['description']
                    p.category = f.cleaned_data['category']
                    p.user =user
                    Project.save(p)
                    if (request.FILES.getlist('file')!=""):
                        if(not os.path.exists(p.title)):
                            os.mkdir(p.title)
                        for file in request.FILES.getlist('file'):
                            l = open(p.title+'\\'+file.name, 'wb+')
                            for chunk in file.chunks():
                                l.write(chunk)
                            l.close()
                            atachment=Atachment()
                            atachment.url=p.title+'\\'+file.name
                            atachment.project=p
                            Atachment.save(atachment)
                    for urlfile in request.POST.getlist('urlfile'):
                        atachment=Atachment()
                        atachment.url=urlfile
                        atachment.project=p
                        Atachment.save(atachment)
                    j=0
                    perkvalue=Perk()
                    for perk in request.POST.getlist('perk'):

                        if j==0:
                            perkvalue.project=p
                            perkvalue.title= perk
                            j+=1
                        elif j==1:
                            perkvalue.description=perk
                            j+=1
                        elif j==2:
                            j+=1
                            perkvalue.amount= int(perk)
                        else:
                            j=0
                            if int(perk)>0:
                                perkvalue.number_available=int(perk)
                            perkvalue.save()
                            perkvalue=Perk()
                return redirect('/', request)
            else:
                return render_to_response('AddNewProject.html', context)
    else:
        return redirect('/logowanie', request)
Exemple #2
0
def AddNewProject(request):
    f = forms.ProjectRegisterForm(prefix='project')
    fr = forms.ProjectPerks(prefix='perk')
    context = RequestContext(request, {'formset': f, 'form1': fr})
    if request.method == 'POST':
        f = forms.ProjectRegisterForm(request.POST, prefix='project')
        fr = forms.ProjectPerks(request.POST, prefix='perk')
        if f.is_valid():
            p = Project()
            p.title = f.cleaned_data['title']
            p.short_description = f.cleaned_data['short_description']
            p.funding_goal = f.cleaned_data['funding_goal']
            p.full_description = f.cleaned_data['description']
            p.category = f.cleaned_data['category']
            p.user_id = 1
            Project.save(p)
            return redirect('/', request)
    else:
        return render_to_response('AddNewProject.html', context)