Ejemplo n.º 1
0
def contributor_profile_edit(request):
    """Edit user's/Coordinators profile.

Arguments:
- `request`:
"""
    context = RequestContext(request)
    print request.user
    user = get_object_or_404(User, username=request.user)
    old_username = user.username
    print user.first_name
    print user.last_name

    contributor = get_object_or_404(Contributor, user=request.user)
    
    
    if request.method == 'POST':
        print "We've a request to register"
        contributorform = ContributorForm(data=request.POST, instance=contributor)
        userform = UserForm(data=request.POST, instance=user)

        if contributorform.is_valid() and userform.is_valid():
            print "Forms are Valid"
            user = userform.save(commit=False)
            if old_username == user.username:
                print "Username unchanged"
            else:
                print "Username changed!. Deactivating old user."
                old_username = get_object_or_404(User, username=old_username)
                old_username.is_active = False
                old_username.save()
            # print user.username
            # print user.first_name
            # print user.last_name
            user.set_password(user.password)
            user.save()

            contributor = contributorform.save(commit=False)
            # print coordinator.contact
            if 'picture' in request.FILES:
                contributor.picture = request.FILES['picture']
            contributor.user = User.objects.get(username=user.username)
            contributor.save()

            
            messages.success(request, "Profile updated successfully.")
            return HttpResponseRedirect('/contributor/profile/edit_success')
        else:
            if contributorform.errors or userform.errors:
                print contributorform.errors, userform.errors
    else:
        # aakashcentreform = AakashCentreForm(instance=aakashcentre)
        contributorform = ContributorForm()
        userform = UserForm()

    context_dict = {'contributorform': contributorform,
                    'userform': userform}
    return render_to_response('contributor_profile_edit.html', context_dict, context)
Ejemplo n.º 2
0
def contributor_profile_edit(request):
    """
    Argument:

    `request`: Request form contributor to edit his profile.

    Edit user's/Coordinators profile.

    """
    context = RequestContext(request)
    print request.user
    user = get_object_or_404(User, username=request.user)
    old_username = user.username
    print user.first_name
    print user.last_name
    contributor = get_object_or_404(Contributor, user=request.user)
    if request.method == 'POST':
        print "We've a request to register"
        contributorform = ContributorForm(data=request.POST,
                                          instance=contributor)
        userform = UserForm(data=request.POST, instance=user)
        if contributorform.is_valid() and userform.is_valid():
            print "Forms are Valid"
            user = userform.save(commit=False)
            if old_username != user.username:
                messages.error(request, 'Username cant be changed')
                context_dict = {
                    'contributorform': contributorform,
                    'userform': userform
                }
                return render_to_response('contributor_profile_edit.html',
                                          context_dict, context)
            user.set_password(user.password)
            user.save()
            contributor = contributorform.save(commit=False)
            if 'picture' in request.FILES:
                contributor.picture = request.FILES['picture']
            contributor.user = User.objects.get(username=user.username)
            contributor.save()
            messages.success(request, "Profile updated successfully.")
        else:
            if contributorform.errors or userform.errors:
                print contributorform.errors, userform.errors
    else:
        contributorform = ContributorForm(instance=contributor)
        userform = UserForm(instance=user)
    context_dict = {'contributorform': contributorform, 'userform': userform}
    return render_to_response('contributor_profile_edit.html',
                              context_dict, context)
Ejemplo n.º 3
0
def contributor_signup(request):
        
	"""Request for new contributor to signup"""
	context = RequestContext(request)
	registered = False
	if request.method == 'POST':
	        print "we have a request to register"    
		user_form = UserForm(data=request.POST)
	        contributor_form = ContributorForm(data=request.POST)
	        if user_form.is_valid() and contributor_form.is_valid():
			user = user_form.save()
                	print "Forms are Valid"
            		print user.username
            		print user.first_name
            		user.set_password(user.password)
			user.is_active = False
           		user.save()

                        contributor = contributor_form.save(commit=False)
			contributor.user = user

                        if 'picture' in request.FILES:
                		contributor.picture = request.FILES['picture']
			if 'validation_docs' in request.FILES:
	                	contributor.validation_docs=request.FILES['validation_docs']
                      	contributor.save()                       
			registered = True
                        email_subject="New Contributor has registered"
	                email_message="""
New Contributor has registered.
	    	
Details:
Name:""" + user.first_name + """  """ + user.last_name + """"
Email:""" + user.email + """
Waiting for your your approval"""
			#send_mail(email_subject, email_message, '*****@*****.**', ['*****@*****.**'],fail_silently=False)
			messages.success(request,"Form successfully submitted. Waiting for activation  from admin.")
			return HttpResponseRedirect(reverse('webapp.views.contributor_signup'))
	        else:
			if contributor_form.errors or user_form.errors:
				print user_form.errors, contributor_form.errors
	else:
		contributor_form = ContributorForm()
		user_form = UserForm()	
           
        context_dict = {'user_form':user_form, 'contributor_form': contributor_form, 'registered': registered}
        return render_to_response('webapp/contributor_signup.html', context_dict, context)
Ejemplo n.º 4
0
def contributor_profile_edit(request):
    """Edit user's/Coordinators profile.

Arguments:
- `request`:
"""
    context = RequestContext(request)
    print request.user
    user = get_object_or_404(User, username=request.user)
    old_username = user.username
    print user.first_name
    print user.last_name

    contributor = get_object_or_404(Contributor, user=request.user)

    if request.method == 'POST':
        print "We've a request to register"
        contributorform = ContributorForm(data=request.POST,
                                          instance=contributor)
        userform = UserForm(data=request.POST, instance=user)

        if contributorform.is_valid() and userform.is_valid():
            print "Forms are Valid"
            user = userform.save(commit=False)
            if old_username == user.username:
                print "Username unchanged"
            else:
                print "Username changed!. Deactivating old user."
                old_username = get_object_or_404(User, username=old_username)
                old_username.is_active = False
                old_username.save()
            # print user.username
            # print user.first_name
            # print user.last_name
            user.set_password(user.password)
            user.save()

            contributor = contributorform.save(commit=False)
            # print coordinator.contact
            if 'picture' in request.FILES:
                contributor.picture = request.FILES['picture']
            contributor.user = User.objects.get(username=user.username)
            contributor.save()

            messages.success(request, "Profile updated successfully.")
            return HttpResponseRedirect('/contributor/profile/edit_success')
        else:
            if contributorform.errors or userform.errors:
                print contributorform.errors, userform.errors
    else:
        # aakashcentreform = AakashCentreForm(instance=aakashcentre)
        contributorform = ContributorForm()
        userform = UserForm()

    context_dict = {'contributorform': contributorform, 'userform': userform}
    return render_to_response('contributor_profile_edit.html', context_dict,
                              context)
Ejemplo n.º 5
0
def contributor_signup(request):
    """Request for new contributor to signup"""
    context = RequestContext(request)
    registered = False
    if request.method == 'POST':
        print "we have a request to register"
        user_form = UserForm(data=request.POST)
        contributor_form = ContributorForm(data=request.POST)
        if user_form.is_valid() and contributor_form.is_valid():
            user = user_form.save()
            print "Forms are Valid"
            print user.username
            print user.first_name
            user.set_password(user.password)
            user.is_active = False
            user.save()

            contributor = contributor_form.save(commit=False)
            contributor.user = user

            if 'picture' in request.FILES:
                contributor.picture = request.FILES['picture']
            if 'validation_docs' in request.FILES:
                contributor.validation_docs = request.FILES['validation_docs']
            contributor.save()
            registered = True
            email_subject = "New Contributor has registered"
            email_message = """
New Contributor has registered.
	    	
Details:
Name:""" + user.first_name + """  """ + user.last_name + """"
Email:""" + user.email + """
Waiting for your your approval"""
            #send_mail(email_subject, email_message, '*****@*****.**', ['*****@*****.**'],fail_silently=False)
            messages.success(
                request,
                "Form successfully submitted. Waiting for activation  from admin."
            )
            return HttpResponseRedirect(
                reverse('webapp.views.contributor_signup'))
        else:
            if contributor_form.errors or user_form.errors:
                print user_form.errors, contributor_form.errors
    else:
        contributor_form = ContributorForm()
        user_form = UserForm()

    context_dict = {
        'user_form': user_form,
        'contributor_form': contributor_form,
        'registered': registered
    }
    return render_to_response('webapp/contributor_signup.html', context_dict,
                              context)
Ejemplo n.º 6
0
def contributor_profile_edit(request):
    """
    Argument:

    `request`: Request form contributor to edit his profile.

    Edit user's/Coordinators profile.

    """
    context = RequestContext(request)
    print request.user
    user = get_object_or_404(User, username=request.user)
    old_username = user.username
    print user.first_name
    print user.last_name
    contributor = get_object_or_404(Contributor, user=request.user)
    if request.method == 'POST':
        print "We've a request to register"
        contributorform = ContributorForm(data=request.POST,
                                          instance=contributor)
        userform = UserForm(data=request.POST, instance=user)
        if contributorform.is_valid() and userform.is_valid():
            print "Forms are Valid"
            user = userform.save(commit=False)
            if old_username != user.username:
                messages.error(request, 'Username cant be changed')
                context_dict = {
                    'contributorform': contributorform,
                    'userform': userform
                }
                return render_to_response('contributor_profile_edit.html',
                                          context_dict, context)
            user.set_password(user.password)
            user.save()
            contributor = contributorform.save(commit=False)
            if 'picture' in request.FILES:
                contributor.picture = request.FILES['picture']
            contributor.user = User.objects.get(username=user.username)
            contributor.save()
            messages.success(request, "Profile updated successfully.")
        else:
            if contributorform.errors or userform.errors:
                print contributorform.errors, userform.errors
    else:
        contributorform = ContributorForm(instance=contributor)
        userform = UserForm(instance=user)
    context_dict = {'contributorform': contributorform, 'userform': userform}
    return render_to_response('contributor_profile_edit.html', context_dict,
                              context)
Ejemplo n.º 7
0
def contributor_signup(request):
    """
    Argument:

    `request`: Request from contributor to sign up.

    This function is used for a new contributor to sign up.

    `Usage`: ::

        # Create an instance for UserForm() and ContributotForm()
        user_form = UserForm(data=request.POST)
        contributor_form = ContributorForm(data=request.POST)
        if user_form.is_valid() and contributor_form.is_valid():
            user = user_form.save()
            # do stuff
        else:
            # do stuff
    """
    context = RequestContext(request)
    registered = False
    if request.method == "POST":
        print "we have a request to register"
        user_form = UserForm(data=request.POST)
        contributor_form = ContributorForm(data=request.POST)
        if user_form.is_valid() and contributor_form.is_valid():
            user = user_form.save()
            print "Forms are Valid"
            print user.username
            print user.first_name
            user.set_password(user.password)
            user.is_active = False
            user.save()
            contributor = contributor_form.save(commit=False)
            contributor.user = user
            if "picture" in request.FILES:
                contributor.picture = request.FILES["picture"]
            if "validation_docs" in request.FILES:
                contributor.validation_docs = request.FILES["validation_docs"]
            contributor.save()
            registered = True
            email_subject = "New Contributor has registered"
            email_message = (
                """
New Contributor has registered.
Details:
Name:"""
                + user.first_name
                + """  """
                + user.last_name
                + """"
Email:"""
                + user.email
                + """
Waiting for your your approval"""
            )
            # send_mail(email_subject, email_message, '*****@*****.**',
            #           ['*****@*****.**'],fail_silently=False)
            messages.success(
                request,
                "Form successfully submitted. Waiting for activation \
from admin.",
            )
            return HttpResponseRedirect(reverse("webapp.views.contributor_signup"))
        else:
            if contributor_form.errors or user_form.errors:
                print user_form.errors, contributor_form.errors
    else:
        contributor_form = ContributorForm()
        user_form = UserForm()
    context_dict = {"user_form": user_form, "contributor_form": contributor_form, "registered": registered}
    return render_to_response("webapp/contributor_signup.html", context_dict, context)
Ejemplo n.º 8
0
def contributor_signup(request):
    """
    Argument:

    `request`: Request from contributor to sign up.

    This function is used for a new contributor to sign up.

    `Usage`: ::

        # Create an instance for UserForm() and ContributotForm()
        user_form = UserForm(data=request.POST)
        contributor_form = ContributorForm(data=request.POST)
        if user_form.is_valid() and contributor_form.is_valid():
            user = user_form.save()
            # do stuff
        else:
            # do stuff
    """
    context = RequestContext(request)
    registered = False
    if request.method == 'POST':
        print "we have a request to register"
        user_form = UserForm(data=request.POST)
        contributor_form = ContributorForm(data=request.POST)
        if user_form.is_valid() and contributor_form.is_valid():
            user = user_form.save()
            print "Forms are Valid"
            print user.username
            print user.first_name
            user.set_password(user.password)
            user.is_active = False
            user.save()
            contributor = contributor_form.save(commit=False)
            contributor.user = user
            if 'picture' in request.FILES:
                contributor.picture = request.FILES['picture']
            if 'validation_docs' in request.FILES:
                contributor.validation_docs = request.FILES['validation_docs']
            contributor.save()
            registered = True
            email_subject = "New Contributor has registered"
            email_message = """
New Contributor has registered.
Details:
Name:""" + user.first_name + """  """ + user.last_name + """"
Email:""" + user.email + """
Waiting for your your approval"""
#send_mail(email_subject, email_message, '*****@*****.**',
#			['*****@*****.**'],fail_silently=False)
            messages.success(
                request,
                "Form successfully submitted. Waiting for activation \
from admin.")
            return HttpResponseRedirect(reverse('webapp.views.contributor_signup'))
        else:
            if contributor_form.errors or user_form.errors:
                print user_form.errors, contributor_form.errors
    else:
        contributor_form = ContributorForm()
        user_form = UserForm()
    context_dict = {
        'user_form': user_form,
        'contributor_form': contributor_form,
        'registered': registered,
    }
    return render_to_response('webapp/contributor_signup.html',
                              context_dict, context)