Ejemplo n.º 1
0
def edituser(request,username):  
    user = request.user
    internaluser = InternalUser.objects.get(mainUserID = user.id)
    if request.method == "POST":
        print "1"
        userform = UserForm(data=request.POST, usertype=1, instance=user)
        print "2"
        print userform                
        internaluserform = InternalUserForm(request.POST, instance=internaluser)
        print "3"    
        print internaluserform    
        if userform.is_valid() and internaluserform.is_valid():
            print "4"            
            userform.save()
            print "5"            
            internaluserform.save()
            print "6"            
            return HttpResponseRedirect(reverse('ats:userprofile', args=(user.username,)))
        else:
            print "7"
            print userform.errors
            print internaluserform.errors            
            print "9" 
            return render(request,htmlPageMap['editUser'],{'userform':userform,'internaluserform':internaluserform,'userformerrors':userform.errors,'internaluserformerrors':internaluserform.errors})
    else:
        print "8"
        userform = UserForm(instance=user)        
        internaluserform = InternalUserForm(instance=internaluser)
        return render(request,htmlPageMap['editUser'],{'userform':userform,'internaluserform':internaluserform})
Ejemplo n.º 2
0
def adduser(request):    
    try:
        currentuser = request.user
        internaluser = InternalUser.objects.get(mainUserID = currentuser.id)
        if internaluser.usertype == 1:        
            if request.method == "POST":
                userform = UserForm(data=request.POST,usertype=1)
                internaluserform = InternalUserForm(request.POST)
                if userform.is_valid() and internaluserform.is_valid():     
                    password = request.POST.get('password')
                    confirmpassword = request.POST.get('confirmpassword')
                    if password != confirmpassword:
                        return render(request,htmlPageMap['adduser'],{'userform':userform, 'internaluserform':internaluserform, 'error_msg':'Passwords dont match'})
                    email = request.POST.get('email')
                    if email:
                        try:
                            user = User.objects.get(email=email)
                        except:
                            user = None
                        if user:#duplicate found
                            return render(request,htmlPageMap['adduser'],{'userform':userform, 'internaluserform':internaluserform, 'error_msg':'User with this email already exists.'})
                    
                    user = userform.save()
                    user.set_password(user.password)
                    user.save()
                    internaluser = internaluserform.save(commit=False)
                    internaluser.mainUserID = user
                    if 'profilepic' in request.FILES:
                        internaluser.profilepic = request.FILES['profilepic']
                    internaluser.save()
                        
                    return HttpResponseRedirect(reverse('ats:confirm', args=(user.id,)))
                else:
                    return render(request,htmlPageMap['adduser'],{'userform':userform, 'internaluserform':internaluserform, 'error_msg': str(userform.errors)+ "; " + str(internaluserform.errors) })        
            else:
                userform = UserForm()        
                internaluserform = InternalUserForm()
                return render(request,htmlPageMap['adduser'],{'userform':userform, 'internaluserform':internaluserform})
        else:
            return HttpResponseRedirect(reverse('ats:userprofile', args=(currentuser.username,)))
    except:
        print ("Exception Occured")