Beispiel #1
0
def register(request):
    if request.user.is_authenticated():       # is a section tool
        return HttpResponseRedirect('/profile/')      
    if request.method=='POST': 
        form=RegiForm(request.POST )
        if form.is_valid():
            customer=models.Customer(username=form.cleaned_data['username'], email=form.cleaned_data['email'], description=form.cleaned_data['description'],
                                      phone=form.cleaned_data['phone'], isWorker=form.cleaned_data['isWorker'])
            customer.set_password( form.cleaned_data['password'])
            customer.save()
            if form.cleaned_data['isWorker']:                      # check checkbox value
                    for g in request.POST.getlist('keyword'):
                        genre=JobGenre.objects.get(pk=g)
                        gen=WorkerGenre(worker=customer,genre=genre)
                        gen.save()
            loginForm=LoginForm()           
            return render_to_response('login.html',{'form':loginForm,'text':'færdig med at registere, du kan nu logge in'},context_instance=RequestContext(request))
        else:
            return render_to_response('register.html', {'form':form}, context_instance=RequestContext(request))
    else:
        form=RegiForm() # a blank form
        return render_to_response('register.html', {'form':form}, context_instance=RequestContext(request))
Beispiel #2
0
def edit(request, slug):
    customer=Customer.objects.get(slug=slug)
    if request.user.id != customer.id:
        html="<html><body>du har ikke den id.</body></html>"
        return HttpResponse(html)
    else:
        customer=Customer.objects.get(slug=slug)
        existed_email=customer.email
        keyword=WorkerGenre.objects.filter(worker=customer.id)
        keyword_list=[]
        for k in keyword:
            keyword_list.append(k.genre) 
      
        if request.method=='POST':
            form=ChangeProfile(request.POST,request.FILES,initial={'first_name':customer.first_name, 'last_name':customer.last_name,
                                    'email':customer.email,'description':customer.description,'picture':customer.picture,
                                    'phone':customer.phone,'isWorker':customer.isWorker,'keyword':keyword_list}, existed_email=existed_email,)
            if form.is_valid():
                if customer.isWorker:
                    if form.cleaned_data['isWorker']:
                        print " her is yes yes"
                        editCustomer(customer, form)
                        keyword.delete()
                        for k in request.POST.getlist('keyword'):
                            jg=JobGenre.objects.get(pk=k)
                            wg=WorkerGenre(worker=customer,genre=jg)
                            wg.save()
                        
                    else:
                        print " her is yes no"
                        editCustomer(customer, form)  
                        keyword.delete()    
                        id=str(customer.id)
                        print " here is the customer id"+id

                else:
                    print " her is no yes"
                    if form.cleaned_data['isWorker']:
                        editCustomer(customer, form)
                        for k in request.POST.getlist('keyword'):
                            jg=JobGenre.objects.get(pk=k)
                            wg=WorkerGenre(worker=customer,genre=jg)
                            wg.save()         
                    else:
                        print " her is no no"
                        editCustomer(customer, form)
                return render_to_response('edit.html',{'customer':customer, 'form':form,'text':'dit profil er blevet ændret'}, context_instance=RequestContext(request))            
            else:     
                return render_to_response('edit.html',{'customer':customer, 'form':form}, context_instance=RequestContext(request))             
        else: 
            form=ChangeProfile(initial={'first_name':customer.first_name, 'last_name':customer.last_name,
                                    'email':customer.email,'description':customer.description,'picture':customer.picture,
                                    'phone':customer.phone,'isWorker':customer.isWorker,'keyword':keyword_list}, existed_email=existed_email)          
            return render_to_response('edit.html',{'customer':customer, 'form':form}, context_instance=RequestContext(request))