Example #1
0
def contrib_viewall(request):
    """
    View to display all contributions
    """
    is_loggedin, username = get_session_variables(request)
    contrib_list = Contribution.objects.all()
    contrib_org = {}
    if contrib_list:
        for contrib in contrib_list:
            if contrib.org_name not in contrib_org.keys():
                contrib_org[contrib.org_name] = 0

        for contrib in contrib_list:
            contrib_org[contrib.org_name] += 1
    
    if contrib_list:
        return render_to_response('achievement/contrib_viewall.html', \
                {'is_loggedin':logged_in(request), \
                'username':username, \
                'contrib_list':contrib_list, 'contrib_org':contrib_org}, \
                RequestContext(request))
    else:
        return render_to_response('achievement/noview.html', \
                {'is_loggedin':is_loggedin, \
                'username':username, \
                'type': 'Contribution'}, \
                RequestContext(request))
Example #2
0
def contest_won_viewall(request):
    """
    View to display all Contest Won
    """
    is_loggedin, username = get_session_variables(request)
    contest_list = Contest_won.objects.all()

    if contest_list:
        contest_participant_list = []
        for contest_won_obj in contest_list:
            c_id = contest_won_obj.contest_id
            c_p_objs = Contest_won_participant.objects. \
                filter(contest_id=c_id)
            contest_participant_list.extend(c_p_objs)

        return render(request, 'achievement/contest_viewall.html', \
                                  {'is_loggedin': is_loggedin, \
                                   'username': username, \
                                   'contest_list': contest_list, \
                                   'contest_participant_list': contest_participant_list}, \
                                  RequestContext(request))
    else:
        return render(request, 'achievement/noview.html', \
                                  {'is_loggedin': is_loggedin, \
                                   'username': username, \
                                   'type': 'Contest\'s won'}, \
                                  RequestContext(request))
Example #3
0
def contrib_viewall(request):
    """
    View to display all contributions
    """
    is_loggedin, username = get_session_variables(request)
    contrib_list = Contribution.objects.all()
    contrib_org = {}
    if contrib_list:
        for contrib in contrib_list:
            if contrib.org_name not in contrib_org.keys():
                contrib_org[contrib.org_name] = 0

        for contrib in contrib_list:
            contrib_org[contrib.org_name] += 1

    if contrib_list:
        return render(
            request, 'achievement/contrib_viewall.html', {
                'is_loggedin': request.user.is_authenticated(),
                'username': username,
                'contrib_list': contrib_list,
                'contrib_org': contrib_org
            }, RequestContext(request))
    else:
        return render(
            request, 'achievement/noview.html', {
                'is_loggedin': is_loggedin,
                'username': username,
                'type': 'Contribution'
            }, RequestContext(request))
Example #4
0
def contest_won_viewall(request):
    """
    View to display all Contest Won
    """
    is_loggedin, username = get_session_variables(request)
    contest_list = Contest_won.objects.all()

    if contest_list:	
        contest_participant_list = []
        for contest_won_obj in contest_list:	
            c_id = contest_won_obj.contest_id
            c_p_objs = Contest_won_participant.objects. \
                    filter(contest_id = c_id)
            contest_participant_list.extend(c_p_objs)

        return render_to_response('achievement/contest_viewall.html', \
                {'is_loggedin':is_loggedin, \
                'username':username, \
                'contest_list':contest_list, \
                'contest_participant_list':contest_participant_list}, \
                RequestContext(request))
    else:
        return render_to_response('achievement/noview.html', \
                {'is_loggedin':is_loggedin, \
                'username':username, \
                'type': 'Contest\'s won'}, \
                RequestContext(request))
Example #5
0
def contrib_viewall(request):
    """
    View to display all contributions
    """
    is_loggedin, username = get_session_variables(request)
    contrib_list = Contribution.objects.all()
    contrib_org = {}
    if contrib_list:
        for contrib in contrib_list:
            if contrib.org_name not in contrib_org.keys():
                contrib_org[contrib.org_name] = 0

        for contrib in contrib_list:
            contrib_org[contrib.org_name] += 1

    if contrib_list:
        return render_to_response('achievement/contrib_viewall.html', \
                {'is_loggedin':logged_in(request), \
                'username':username, \
                'contrib_list':contrib_list, 'contrib_org':contrib_org}, \
                RequestContext(request))
    else:
        return render_to_response('achievement/noview.html', \
                {'is_loggedin':is_loggedin, \
                'username':username, \
                'type': 'Contribution'}, \
                RequestContext(request))
Example #6
0
 def get(self, request, *args, **kwargs):
     self.object = None
     self.object_list = Proposal.objects.all()
     context = self.get_context_data(object_list=self.object_list)
     is_loggedin, username = get_session_variables(self.request)
     if is_loggedin is False:
         return redirect('login')
     return self.render_to_response(context)
Example #7
0
def insert_contribution(request):
    """
    View to add new Contribution.
    Models used: Achievement, Contribution
    """
    try:
        is_loggedin, username = get_session_variables(request)
        # User is not logged in
        if not request.user.is_authenticated():
            return HttpResponseRedirect('/register/login')

        # User is logged in
        else:
            if request.method == 'POST':
                form = AddContributionForm(request.POST)

                # Invalid form imput
                if not form.is_valid():
                    error = "Invalid inputs"
                    return render(
                        request, 'achievement/new_contribution.html', {
                            'form': form,
                            'error': error,
                            'is_loggedin': is_loggedin,
                            'username': username
                        }, RequestContext(request))

                # Form is valid
                else:
                    # Get the new achievement_id
                    achievement_id = get_achievement_id(request)
                    achievement_type = "contribution"

                    # Saving inputs
                    achievement_obj = Achievement(achievement_id, \
                                                  achievement_type, \
                                                  username)
                    achievement_obj.save()
                    contribution_obj = form.save(commit=False)
                    contribution_obj.achievement_id = achievement_obj
                    contribution_obj.achieve_typ = achievement_type
                    user_obj = get_object_or_404(User_info, username=username)
                    contribution_obj.username = user_obj
                    contribution_obj.save()
                    return render(request, 'achievement/success.html', \
                                              {'achievement_type': achievement_type, \
                                               'is_loggedin': is_loggedin, \
                                               'username': username}, \
                                              RequestContext(request))
            # Method is not POST
            else:
                return render(request, 'achievement/new_contribution.html', \
                                          {'form': AddContributionForm, \
                                           'is_loggedin': is_loggedin, \
                                           'username': username}, \
                                          RequestContext(request))
    except KeyError:
        return error_key(request)
Example #8
0
def insert_intern(request):
    """
    View to add internship details
    Models used: Achievement, Intern
    """
    try:
        is_loggedin, username = get_session_variables(request)
        # User is not logged in
        if not logged_in(request):
            return HttpResponseRedirect('/register/login')

        # User is logged in
        else:
            if request.method == 'POST':
                form = AddInternForm(request.POST)

                # Invalid form imput
                if not form.is_valid():
                    error = "Invalid inputs"
                    return render_to_response('achievement/new_intern.html', \
                            {'form':form, \
                            'error':error, \
                            'is_loggedin':is_loggedin, \
                            'username':username}, \
                            RequestContext(request))

                # Form is valid
                else:
                    # Get the new achievement_id
                    achievement_id = get_achievement_id(request)	
                    achievement_type = "Intern"

                    # Saving inputs
                    achievement_obj = Achievement(achievement_id, \
                            achievement_type, \
                            username)
                    achievement_obj.save()
                    contribution_obj = form.save(commit = False)
                    contribution_obj.achievement_id = achievement_obj
                    contribution_obj.achieve_typ = achievement_type
                    user_obj = get_object_or_404(User_info, username = username)
                    contribution_obj.username = user_obj
                    contribution_obj.save()
                    return render_to_response('achievement/success.html', \
                            {'achievement_type':achievement_type, \
                            'is_loggedin':is_loggedin, \
                            'username':username}, \
                            RequestContext(request))
            # Method is not POST
            else:
                return render_to_response('achievement/new_intern.html', \
                        {'form': AddInternForm, \
                        'is_loggedin':is_loggedin, \
                        'username':username}, \
                        RequestContext(request))
    except KeyError:
        return error_key(request)
Example #9
0
def insert_icpc(request):
    """
    View to add ICPC details.
    Models used: Achievement, ACM_ICPC_detail
    """
    try:
        is_loggedin, username = get_session_variables(request)
        # User is not logged in
        if not request.user.is_authenticated():
            return HttpResponseRedirect('/register/login')

        # User is logged in
        else:
            if request.method == 'POST':
                form = AddIcpcForm(request.POST)

                # Invalid form imput
                if not form.is_valid():
                    error = "Invalid inputs/ Information already exists "
                    return render(request, 'achievement/new_icpc.html', \
                                              {'form': form, \
                                               'error': error, \
                                               'is_loggedin': is_loggedin, \
                                               'username': username}, \
                                              RequestContext(request))

                # Form is valid
                else:
                    # Get the new achievement_id
                    achievement_id = get_achievement_id(request)
                    achievement_type = "acm"

                    # Saving inputs
                    achievement_obj = Achievement(achievement_id, \
                                                  achievement_type, \
                                                  username)
                    achievement_obj.save()
                    icpc_obj = form.save(commit=False)
                    icpc_obj.achievement_id = achievement_obj
                    user_obj = get_object_or_404(User_info, username=username)
                    icpc_obj.username = user_obj
                    icpc_obj.save()
                    return render(request, 'achievement/success.html', \
                                              {'achievement_type': achievement_type, \
                                               'is_loggedin': is_loggedin, \
                                               'username': username}, \
                                              RequestContext(request))
            # Method is not POST
            else:
                return render(request, 'achievement/new_icpc.html', \
                                          {'form': AddIcpcForm, \
                                           'is_loggedin': is_loggedin, \
                                           'username': username}, \
                                          RequestContext(request))
    except KeyError:
        return error_key(request)
Example #10
0
def update_profile(request):
    try:
        is_loggedin, username = get_session_variables(request)
        # User is not logged in
        if not logged_in(request):
            return HttpResponseRedirect('/register/login')
        else:
            user_details = get_object_or_404(User_info, username=username)
            init_user_details = user_details.__dict__

            #If method is not POST
            if request.method != 'POST':
                #return form with old details
                return render_to_response('register/update_profile.html',\
                    {'form':UpdateProfileForm(init_user_details),\
                    'is_loggedin':is_loggedin, 'username':username},\
                    RequestContext(request))

            # If method is POST
            else:
                profile_update_form = UpdateProfileForm(request.POST)
                # Form is not valid
                if not profile_update_form.is_valid():
                    #return form with old details

                    print profile_update_form.cleaned_data
                    return render_to_response('register/update_profile.html',\
                        {'form':UpdateProfileForm(init_user_details),\
                        'is_loggedin':is_loggedin, 'username':username},\
                        RequestContext(request))
                # Form is valid:
                else:
                    user_details_form = profile_update_form.save(commit=False)
                    user_details_obj = get_object_or_404(User_info,
                                                         username=username)
                    user_details_obj.firstname = user_details_form.firstname
                    user_details_obj.lastname = user_details_form.lastname
                    user_details_obj.gender = user_details_form.gender
                    user_details_obj.contact = user_details_form.contact
                    user_details_obj.role = user_details_form.role
                    user_details_obj.blog_url = user_details_form.blog_url
                    user_details_obj.twitter_id = user_details_form.twitter_id
                    user_details_obj.bitbucket_id = user_details_form.topcoder_handle
                    user_details_obj.github_id = user_details_form.github_id
                    user_details_obj.bitbucket_id = user_details_form.bitbucket_id
                    user_details_obj.typing_speed = user_details_form.typing_speed
                    user_details_obj.interest = user_details_form.interest
                    user_details_obj.expertise = user_details_form.expertise
                    user_details_obj.goal = user_details_form.goal
                    #user_details_obj.email = user_details_form.email
                    user_details_obj.save()
                    redirect_url = "/register/profile/" + username + "/"
                    return HttpResponseRedirect(redirect_url)

    except KeyError:
        return error_key(request)
Example #11
0
def update_profile(request):
    try:
        is_loggedin, username = get_session_variables(request)
        # User is not logged in
        if not logged_in(request):
            return HttpResponseRedirect('/register/login')
        else:
            user_details = get_object_or_404(User_info, username = username)
            init_user_details = user_details.__dict__

            #If method is not POST 
            if request.method != 'POST':
                #return form with old details
                return render_to_response('register/update_profile.html',\
                    {'form':UpdateProfileForm(init_user_details),\
                    'is_loggedin':is_loggedin, 'username':username},\
                    RequestContext(request))

            # If method is POST
            else:
                profile_update_form = UpdateProfileForm(request.POST)
                # Form is not valid
                if not profile_update_form.is_valid():
                    #return form with old details

                    print profile_update_form.cleaned_data
                    return render_to_response('register/update_profile.html',\
                        {'form':UpdateProfileForm(init_user_details),\
                        'is_loggedin':is_loggedin, 'username':username},\
                        RequestContext(request))    
                # Form is valid:
                else:
                    user_details_form = profile_update_form.save(commit = False)
                    user_details_obj = get_object_or_404(User_info, username = username)
                    user_details_obj.firstname = user_details_form.firstname
                    user_details_obj.lastname = user_details_form.lastname
                    user_details_obj.gender = user_details_form.gender
                    user_details_obj.contact = user_details_form.contact
                    user_details_obj.role = user_details_form.role
                    user_details_obj.blog_url = user_details_form.blog_url
                    user_details_obj.twitter_id = user_details_form.twitter_id
                    user_details_obj.bitbucket_id = user_details_form.topcoder_handle
                    user_details_obj.github_id = user_details_form.github_id
                    user_details_obj.bitbucket_id = user_details_form.bitbucket_id
                    user_details_obj.typing_speed = user_details_form.typing_speed
                    user_details_obj.interest= user_details_form.interest
                    user_details_obj.expertise = user_details_form.expertise
                    user_details_obj.goal = user_details_form.goal
                    #user_details_obj.email = user_details_form.email
                    user_details_obj.save()  
                    redirect_url = "/register/profile/"+username+"/"
                    return HttpResponseRedirect(redirect_url)

    except KeyError:
        return error_key(request)
Example #12
0
def update_article(request, achievement_id):
    """
    View to update the artciel information
    """
    try:
        is_loggedin, username = get_session_variables(request)
        # User is not logged in
        if not request.user.is_authenticated():
            return HttpResponseRedirect('/register/login')
        else:

            article = get_object_or_404(Article, achievement_id=achievement_id)
            init_article = article.__dict__

            # If method is not POST
            if request.method != 'POST':
                # return form with old details
                return render(request, 'achievement/update_article.html', \
                                          {'form': UpdateArticleForm(init_article), \
                                           'is_loggedin': is_loggedin, 'username': username}, \
                                          RequestContext(request))

            # If method is POST
            else:
                article_update_form = UpdateArticleForm(request.POST)
                # Form is not valid
                if not article_update_form.is_valid():
                    # return form with old details
                    return render(request, 'achievement/update_article.html', \
                                              {'form': UpdateArticleForm(init_article), \
                                               'is_loggedin': is_loggedin, 'username': username}, \
                                              RequestContext(request))
                    # Form is valid:
                else:
                    article_update = article_update_form.save(commit=False)
                    update_article_obj = get_object_or_404(Article,
                                                           username=username)
                    update_article_obj.area = article_update.area
                    update_article_obj.magazine_name = article_update.magazine_name
                    update_article_obj.title = article_update.title
                    update_article_obj.publication_date = article_update.publication_date
                    update_article_obj.save()
                    return render(request, 'achievement/success.html', \
                                              {'achievement_type': 'Update Article', \
                                               'is_loggedin': is_loggedin, \
                                               'username': username}, \
                                              RequestContext(request))

    except KeyError:
        return error_key(request)
Example #13
0
def update_intern(request, achievement_id):
    """
    View to update the artciel information
    """
    try:
        is_loggedin, username = get_session_variables(request)
        # User is not logged in
        if not request.user.is_authenticated():
            return HttpResponseRedirect('/register/login')
        else:

            internship = get_object_or_404(Intern,
                                           achievement_id=achievement_id)
            init_internship = internship.__dict__

            # If method is not POST
            if request.method != 'POST':
                # return form with old details
                return render(request, 'achievement/update_intern.html', \
                                          {'form': UpdateInternForm(init_internship), \
                                           'is_loggedin': is_loggedin, 'username': username}, \
                                          RequestContext(request))

            # If method is POST
            else:
                intern_update_form = UpdateInternForm(request.POST)
                # Form is not valid
                if not intern_update_form.is_valid():
                    # return form with old details
                    return render(request, 'achievement/update_intern.html', \
                                              {'form': UpdateInternForm(init_internship), \
                                               'is_loggedin': is_loggedin, 'username': username}, \
                                              RequestContext(request))
                    # Form is valid:
                else:
                    intern_update = intern_update_form.save(commit=False)
                    intern_article_obj = get_object_or_404(Intern,
                                                           username=username)
                    intern_article_obj.place = intern_update.place
                    intern_article_obj.intern_type = intern_update.intern_type
                    intern_article_obj.period = intern_update.period
                    intern_article_obj.save()
                    return render(request, 'achievement/success.html', \
                                              {'achievement_type': 'Update Internship', \
                                               'is_loggedin': is_loggedin, \
                                               'username': username}, \
                                              RequestContext(request))

    except KeyError:
        return error_key(request)
Example #14
0
def update_contribution(request, achievement_id):
    try:
        is_loggedin, username = get_session_variables(request)
        # User is not logged in
        if not request.user.is_authenticated():
            return HttpResponseRedirect('/register/login')
        else:
            # achievement_id = get_object_or_404(Achievement, username = user_name)
            contribution = get_object_or_404(Contribution,
                                             achievement_id=achievement_id)
            init_contribution = contribution.__dict__

            # If method is not POST
            if request.method != 'POST':
                # return form with old details
                return render(request, 'achievement/update_contrib.html', \
                                          {'form': UpdateContributionForm(init_contribution), \
                                           'is_loggedin': is_loggedin, 'username': username}, \
                                          RequestContext(request))

            # If method is POST
            else:
                contribution_update_form = UpdateContributionForm(request.POST)
                # Form is not valid
                if not contribution_update_form.is_valid():
                    # return form with old details
                    return render(request, 'achievement/update_contrib.html', \
                                              {'form': UpdateContributionForm(init_contribution), \
                                               'is_loggedin': is_loggedin, 'username': username}, \
                                              RequestContext(request))
                    # Form is valid:
                else:
                    contribution_update = contribution_update_form.save(
                        commit=False)
                    update_contribution_obj = get_object_or_404(
                        Contribution, username=username)
                    update_contribution_obj.bug_id = contribution_update.bug_id
                    update_contribution_obj.org_name = contribution_update.org_name
                    update_contribution_obj.bug_url = contribution_update.bug_url
                    update_contribution_obj.bug_description = contribution_update.bug_description
                    update_contribution_obj.save()
                    return render(request, 'achievement/success.html', \
                                              {'achievement_type': 'Update Contribution', \
                                               'is_loggedin': is_loggedin, \
                                               'username': username}, \
                                              RequestContext(request))

    except KeyError:
        return error_key(request)
Example #15
0
def update_article(request,achievement_id):
    """
    View to update the artciel information
    """
    try:
        is_loggedin, username = get_session_variables(request)
        # User is not logged in
        if not logged_in(request):
            return HttpResponseRedirect('/register/login')
        else:
            
            article = get_object_or_404(Article, achievement_id = achievement_id)
            init_article = article.__dict__

            #If method is not POST 
            if request.method != 'POST':
                #return form with old details
                return render_to_response('achievement/update_article.html',\
                    {'form':UpdateArticleForm(init_article),\
                    'is_loggedin':is_loggedin, 'username':username},\
                    RequestContext(request))

            # If method is POST
            else:
                article_update_form = UpdateArticleForm(request.POST)
                # Form is not valid
                if not article_update_form.is_valid():
                    #return form with old details
                    return render_to_response('achievement/update_article.html',\
                        {'form':UpdateArticleForm(init_article),\
                        'is_loggedin':is_loggedin, 'username':username},\
                        RequestContext(request)) 
                # Form is valid:
                else:
                    article_update = article_update_form.save(commit = False)
                    update_article_obj = get_object_or_404(Article, username = username)
                    update_article_obj.area = article_update.area
                    update_article_obj.magazine_name = article_update.magazine_name
                    update_article_obj.title = article_update.title
                    update_article_obj.publication_date = article_update.publication_date
                    update_article_obj.save()  
                    return render_to_response('achievement/success.html', \
                        {'achievement_type':'Update Article', \
                        'is_loggedin':is_loggedin, \
                        'username':username}, \
                        RequestContext(request))

    except KeyError:
        return error_key(request)
Example #16
0
def update_intern(request,achievement_id):
    """
    View to update the artciel information
    """
    try:
        is_loggedin, username = get_session_variables(request)
        # User is not logged in
        if not logged_in(request):
            return HttpResponseRedirect('/register/login')
        else:
            
            internship = get_object_or_404(Intern, achievement_id = achievement_id)
            init_internship = internship.__dict__

            #If method is not POST 
            if request.method != 'POST':
                #return form with old details
                return render_to_response('achievement/update_intern.html',\
                    {'form':UpdateInternForm(init_internship),\
                    'is_loggedin':is_loggedin, 'username':username},\
                    RequestContext(request))

            # If method is POST
            else:
                intern_update_form = UpdateInternForm(request.POST)
                # Form is not valid
                if not intern_update_form.is_valid():
                    #return form with old details
                    return render_to_response('achievement/update_intern.html',\
                        {'form':UpdateInternForm(init_internship),\
                        'is_loggedin':is_loggedin, 'username':username},\
                        RequestContext(request)) 
                # Form is valid:
                else:
                    intern_update = intern_update_form.save(commit = False)
                    intern_article_obj = get_object_or_404(Intern, username = username)
                    intern_article_obj.place = intern_update.place
                    intern_article_obj.intern_type = intern_update.intern_type
                    intern_article_obj.period = intern_update.period
                    intern_article_obj.save()  
                    return render_to_response('achievement/success.html', \
                        {'achievement_type':'Update Internship', \
                        'is_loggedin':is_loggedin, \
                        'username':username}, \
                        RequestContext(request))

    except KeyError:
        return error_key(request)
Example #17
0
def mypage(request):
    """
    An editable profile page for the user
    """
    if not logged_in(request):
        return HttpResponseRedirect('/register/login')
    
    else:
        is_loggedin, username = get_session_variables(request)
        name = User_info.objects.get(username=username)
        return render_to_response( \
                'register/mypages.html',
                {'username':username, \
                'firstname':name.firstname, \
                'is_loggedin':is_loggedin, \
                'lastname':name.lastname,},\
                RequestContext(request))
Example #18
0
def mypage(request):
    """
    An editable profile page for the user
    """
    if not logged_in(request):
        return HttpResponseRedirect('/register/login')

    else:
        is_loggedin, username = get_session_variables(request)
        name = User_info.objects.get(username=username)
        return render_to_response( \
                'register/mypages.html',
                {'username':username, \
                'firstname':name.firstname, \
                'is_loggedin':is_loggedin, \
                'lastname':name.lastname,},\
                RequestContext(request))
Example #19
0
def mypage(request):
    """
    An editable profile page for the user
    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/register/login')

    else:
        is_loggedin, username = get_session_variables(request)
        name = User_info.objects.get(username=username)
        return render(
            request, 'register/mypages.html', {
                'username': username,
                'firstname': name.firstname,
                'is_loggedin': is_loggedin,
                'lastname': name.lastname,
            }, RequestContext(request))
Example #20
0
def update_contribution(request,achievement_id):
    try:
        is_loggedin, username = get_session_variables(request)
        # User is not logged in
        if not logged_in(request):
            return HttpResponseRedirect('/register/login')
        else:
            #achievement_id = get_object_or_404(Achievement, username = user_name)
            contribution = get_object_or_404(Contribution, achievement_id = achievement_id)
            init_contribution = contribution.__dict__

                #If method is not POST 
            if request.method != 'POST':
                #return form with old details
                return render_to_response('achievement/update_contrib.html',\
                    {'form':UpdateContributionForm(init_contribution),\
                    'is_loggedin':is_loggedin, 'username':username},\
                    RequestContext(request))

            # If method is POST
            else:
                contribution_update_form = UpdateContributionForm(request.POST)
                # Form is not valid
                if not contribution_update_form.is_valid():
                    #return form with old details
                    return render_to_response('achievement/update_contrib.html',\
                        {'form':UpdateContributionForm(init_contribution),\
                        'is_loggedin':is_loggedin, 'username':username},\
                        RequestContext(request)) 
                # Form is valid:
                else:
                    contribution_update = contribution_update_form.save(commit = False)
                    update_contribution_obj = get_object_or_404(Contribution, username = username)
                    update_contribution_obj.bug_id = contribution_update.bug_id
                    update_contribution_obj.org_name = contribution_update.org_name
                    update_contribution_obj.bug_url = contribution_update.bug_url
                    update_contribution_obj.bug_description = contribution_update.bug_description
                    update_contribution_obj.save()  
                    return render_to_response('achievement/success.html', \
                        {'achievement_type':'Update Contribution', \
                        'is_loggedin':is_loggedin, \
                        'username':username}, \
                        RequestContext(request))

    except KeyError:
        return error_key(request)
Example #21
0
def profile(request, user_name):
    """
    A view to display the profile (public)
    """
    is_loggedin, username = get_session_variables(request)
    user_object = get_object_or_404(User_info, \
            username = user_name)
    profile_image_object = ProfileImage.objects \
            .filter(username=user_object)
    user_email = user_object.email.replace('.', ' DOT ') \
            .replace('@', ' AT ')
    contributions = Contribution.objects.all() \
            .filter(username=user_name)[:3]
    articles = Article.objects.all() \
            .filter(username=user_name)[:3]
    gsoc = Gsoc.objects.all() \
            .filter(username=user_name)[:3]
    interns = Intern.objects.all() \
            .filter(username=user_name)[:3]
    speakers = Speaker.objects.all() \
            .filter(username=user_name)[:3]
    email = user_object.email
    icpc_achievement = ACM_ICPC_detail.objects.filter(participant1_email=email)| \
        ACM_ICPC_detail.objects.filter(participant2_email=email)| ACM_ICPC_detail.objects.filter(participant3_email=email)
    print icpc_achievement
    if profile_image_object:
        image_name = user_name + ".jpg"
    else:
        image_name = "default_image.jpeg"

    return render_to_response( \
            'register/profile.html', \
            {'is_loggedin':is_loggedin, \
            'username':username, \
            'user_object':user_object, \
            'user_email':user_email, \
            'user_email':user_email, \
            'gsoc':gsoc, \
            'interns':interns, \
            'speakers':speakers, \
            'image_name':image_name, \
            'articles':articles, \
            'contributions':contributions, \
            'icpc_achievement':icpc_achievement}, \
            RequestContext(request))
Example #22
0
def upload_images(request):
    """
    View to store upload images specific to an event.
    Models used: Folder, Image
    """
    try:
        is_loggedin, username = get_session_variables(request)

        # User is not logged in
        if not is_loggedin:
            return HttpResponseRedirect('/register/login')

        # User is logged in
        else:
            if request.method == 'POST':
                form = FolderForm(request.POST, request.FILES)

                # form is not valid
                if not form.is_valid():
                    error = "Invalid inputs"
                    return render(request, 'images/upload_images.html', \
                        {'form':form, 'error':error, }, \
                        RequestContext(request))

                # form is valid
                else:
                    cleaned_form_data = form.cleaned_data
                    folder_name = cleaned_form_data['folder_name']
                    # create a new folder
                    folder = form.save(commit=False)
                    folder.save()

                    # save images
                    image = request.FILES['image']
                    new_image_object = Image(img=image, \
                        folder_name = folder)
                    img_name = new_image_object.img.name
                    new_image_object.save()
                    return render(request, "images/success.html")
            else:
                return render(request, 'images/upload_images.html', \
                    {'form':FolderForm(), 'is_loggedin': is_loggedin },\
                     RequestContext(request))
    except KeyError:
        return error_key(request)
Example #23
0
def profile(request, user_name):
    """
    A view to display the profile (public)
    """
    is_loggedin, username = get_session_variables(request)
    user_object = get_object_or_404(User_info, \
            username = user_name)
    profile_image_object = ProfileImage.objects \
            .filter(username=user_object)
    user_email = user_object.email.replace('.', ' DOT ') \
            .replace('@', ' AT ')
    contributions = Contribution.objects.all() \
            .filter(username=user_name)[:3]
    articles = Article.objects.all() \
            .filter(username=user_name)[:3]
    gsoc = Gsoc.objects.all() \
            .filter(username=user_name)[:3]
    interns = Intern.objects.all() \
            .filter(username=user_name)[:3]
    speakers = Speaker.objects.all() \
            .filter(username=user_name)[:3]
    email = user_object.email
    icpc_achievement = ACM_ICPC_detail.objects.filter(participant1_email=email)| \
        ACM_ICPC_detail.objects.filter(participant2_email=email)| ACM_ICPC_detail.objects.filter(participant3_email=email)
    print icpc_achievement
    if profile_image_object:
       	image_name = user_name+".jpg"
    else:
       	image_name = "default_image.jpeg"

    return render_to_response( \
            'register/profile.html', \
            {'is_loggedin':is_loggedin, \
            'username':username, \
            'user_object':user_object, \
            'user_email':user_email, \
            'user_email':user_email, \
            'gsoc':gsoc, \
            'interns':interns, \
            'speakers':speakers, \
            'image_name':image_name, \
            'articles':articles, \
            'contributions':contributions, \
            'icpc_achievement':icpc_achievement}, \
            RequestContext(request))
Example #24
0
def upload_images(request):
    """
    View to store upload images specific to an event.
    Models used: Folder, Image
    """
    try:
        is_loggedin, username = get_session_variables(request)
        
        # User is not logged in
        if not is_loggedin:
            return HttpResponseRedirect('/register/login')
        
        # User is logged in
        else:
            if request.method == 'POST':
                form = FolderForm(request.POST, request.FILES)
    
                # form is not valid          
                if not form.is_valid():
                    error = "Invalid inputs"
                    return render_to_response('images/upload_images.html', \
                        {'form':form, 'error':error, }, \
                        RequestContext(request))
                
                # form is valid
                else:
                    cleaned_form_data = form.cleaned_data
                    folder_name = cleaned_form_data['folder_name']
                    # create a new folder
                    folder = form.save(commit=False)
                    folder.save()

                    # save images
                    image = request.FILES['image']
                    new_image_object = Image(img=image, \
                        folder_name = folder)
                    img_name = new_image_object.img.name 
                    new_image_object.save()
                    return render_to_response("images/success.html")
            else:
                return render_to_response('images/upload_images.html', \
                    {'form':FolderForm(), 'is_loggedin': is_loggedin },\
                     RequestContext(request))
    except KeyError:
        return error_key(request)
Example #25
0
def article_viewall(request):
    """
    View to display all articles published
    """
    is_loggedin, username = get_session_variables(request)
    article_list = Article.objects.all()

    if article_list:
        return render(request, 'achievement/article_viewall.html', \
                                  {'is_loggedin': is_loggedin, \
                                   'username': username, \
                                   'article_list': article_list}, \
                                  RequestContext(request))
    else:
        return render(request, 'achievement/noview.html', \
                                  {'is_loggedin': is_loggedin, \
                                   'username': username, \
                                   'type': 'Article'}, \
                                  RequestContext(request))
Example #26
0
def gsoc_viewall(request):
    """
    View to display all GSOCers
    """
    is_loggedin, username = get_session_variables(request)
    gsoc_list = Gsoc.objects.all()

    if gsoc_list:
        return render(request, 'achievement/gsoc_viewall.html', \
                                  {'is_loggedin': is_loggedin, \
                                   'username': username, \
                                   'gsoc_list': gsoc_list}, \
                                  RequestContext(request))
    else:
        return render(request, 'achievement/noview.html', \
                                  {'is_loggedin': is_loggedin, \
                                   'username': username, \
                                   'type': 'Gsoc'}, \
                                  RequestContext(request))
Example #27
0
def speaker_viewall(request):
    """
    View to display all Speakers
    """
    is_loggedin, username = get_session_variables(request)
    speaker_list = Speaker.objects.all()

    if speaker_list:
        return render(request, 'achievement/speaker_viewall.html', \
                                  {'is_loggedin': is_loggedin, \
                                   'username': username, \
                                   'speaker_list': speaker_list}, \
                                  RequestContext(request))
    else:
        return render(request, 'achievement/noview.html', \
                                  {'is_loggedin': is_loggedin, \
                                   'username': username, \
                                   'type': 'Speaker'}, \
                                  RequestContext(request))
Example #28
0
def gsoc_viewall(request):
    """
    View to display all GSOCers
    """
    is_loggedin, username = get_session_variables(request)
    gsoc_list = Gsoc.objects.all()

    if gsoc_list:
        return render_to_response('achievement/gsoc_viewall.html', \
                {'is_loggedin':is_loggedin, \
                'username':username, \
                'gsoc_list':gsoc_list}, \
                RequestContext(request))
    else:
        return render_to_response('achievement/noview.html', \
                {'is_loggedin':is_loggedin, \
                'username':username, \
                'type': 'Gsoc'}, \
                RequestContext(request))
Example #29
0
def intern_viewall(request):
    """
    View to display all internships done
    """
    is_loggedin, username = get_session_variables(request)
    intern_list = Intern.objects.all()

    if intern_list:
        return render(request, 'achievement/intern_viewall.html', \
                                  {'is_loggedin': is_loggedin, \
                                   'username': username, \
                                   'intern_list': intern_list}, \
                                  RequestContext(request))
    else:
        return render(request, 'achievement/noview.html', \
                                  {'is_loggedin': is_loggedin, \
                                   'username': username, \
                                   'type': 'Internship'}, \
                                  RequestContext(request))
Example #30
0
def speaker_viewall(request):
    """
    View to display all Speakers
    """
    is_loggedin, username = get_session_variables(request)
    speaker_list = Speaker.objects.all()

    if speaker_list:
        return render_to_response('achievement/speaker_viewall.html', \
                {'is_loggedin':is_loggedin, \
                'username':username, \
                'speaker_list':speaker_list}, \
                RequestContext(request))
    else:
        return render_to_response('achievement/noview.html', \
                {'is_loggedin':is_loggedin, \
                'username':username, \
                'type': 'Speaker'}, \
                RequestContext(request))
Example #31
0
def intern_viewall(request):
    """
    View to display all internships done
    """
    is_loggedin, username = get_session_variables(request)
    intern_list = Intern.objects.all()

    if intern_list:
        return render_to_response('achievement/intern_viewall.html', \
                {'is_loggedin':is_loggedin, \
                'username':username, \
                'intern_list':intern_list}, \
                RequestContext(request))
    else:
        return render_to_response('achievement/noview.html', \
                {'is_loggedin':is_loggedin, \
                'username':username, \
                'type': 'Internship'}, \
                RequestContext(request))
Example #32
0
def article_viewall(request):
    """
    View to display all articles published
    """
    is_loggedin, username = get_session_variables(request)
    article_list = Article.objects.all()

    if article_list:
        return render_to_response('achievement/article_viewall.html', \
                {'is_loggedin':is_loggedin, \
                'username':username, \
                'article_list':article_list}, \
                RequestContext(request))
    else:
        return render_to_response('achievement/noview.html', \
                {'is_loggedin':is_loggedin, \
                'username':username, \
                'type': 'Article'}, \
                RequestContext(request))
Example #33
0
def update_profile_pic(request):
    try:
        is_loggedin, username = get_session_variables(request)
        # User is not logged in
        if not logged_in(request):
            return HttpResponseRedirect('/register/login')
        else:
            user_details = get_object_or_404(User_info, username=username)
            init_user_details = user_details.__dict__

            #If method is not POST
            if request.method != 'POST':
                #return form with old details
                return render_to_response('register/update_profile_pic.html',\
                    {'form':UpdateProfileForm(init_user_details),\
                    'is_loggedin':is_loggedin, 'username':username},\
                    RequestContext(request))

            # If method is POST
            else:
                user_object = get_object_or_404(User_info, \
                        username=username)
                if 'image' in request.FILES:
                    try:
                        to_delete = ProfileImage.objects.filter(
                            username=username)
                        for obj in to_delete:
                            obj.delete()
                    except ProfileImage.DoesNotExist:
                        pass
                    profile_image = request.FILES['image']
                    profile_image_object = ProfileImage \
                            (image=profile_image, \
                            username=user_object)
                    profile_image_object.image.name = username + \
                                                    ".jpg"
                    profile_image_object.save()
                redirect_url = "/register/profile/" + username + "/"
                return HttpResponseRedirect(redirect_url)

    except KeyError:
        return error_key(request)
Example #34
0
def update_profile_pic(request):
    try:
        is_loggedin, username = get_session_variables(request)
        # User is not logged in
        if not logged_in(request):
            return HttpResponseRedirect('/register/login')
        else:
            user_details = get_object_or_404(User_info, username = username)
            init_user_details = user_details.__dict__

            #If method is not POST 
            if request.method != 'POST':
                #return form with old details
                return render_to_response('register/update_profile_pic.html',\
                    {'form':UpdateProfileForm(init_user_details),\
                    'is_loggedin':is_loggedin, 'username':username},\
                    RequestContext(request))

            # If method is POST
            else:
                user_object = get_object_or_404(User_info, \
                        username=username)
                if 'image' in request.FILES:
                    try:
                        to_delete = ProfileImage.objects.filter(username=username)
                        for obj in to_delete:
                            obj.delete()
                    except ProfileImage.DoesNotExist:
                        pass
                    profile_image = request.FILES['image']
                    profile_image_object = ProfileImage \
                            (image=profile_image, \
                            username=user_object)
                    profile_image_object.image.name = username + \
                                                    ".jpg"
                    profile_image_object.save()
                redirect_url = "/register/profile/"+username+"/"
                return HttpResponseRedirect(redirect_url)

    except KeyError:
        return error_key(request)
Example #35
0
def icpc_viewall(request):
    """
    View to display all ICPCers.
    """
    is_loggedin, username = get_session_variables(request)
    icpc_participants_list = []
    p_list= []
    icpc_list = ACM_ICPC_detail.objects.all().order_by('ranking')
    if icpc_list:

        for icpc_obj in icpc_list:
            
            team = icpc_obj.team_name
            member1 = [icpc_obj.participant1_name, \
                get_username_from_email(icpc_obj.participant1_email)]

            member2 = [icpc_obj.participant2_name, \
                get_username_from_email(icpc_obj.participant2_email)]

            member3 = [icpc_obj.participant3_name, \
                get_username_from_email(icpc_obj.participant3_email)]

            icpc_participant_list = [icpc_obj, member1,member2,member3]
            icpc_participants_list.append(icpc_participant_list)
            
        return render_to_response('achievement/icpc_viewall.html', \
            {'is_loggedin':logged_in(request), \
            'username':username, \
            'icpc_list':icpc_list,\
            'icpc_participants_list':icpc_participants_list}, RequestContext(request))

    else:
        return render_to_response('achievement/noview.html', \
                {'is_loggedin':logged_in(request), \
                'username':username, \
                'type': 'ACM ICPC Contest'}, \
                RequestContext(request))
Example #36
0
def icpc_viewall(request):
    """
    View to display all ICPCers.
    """
    is_loggedin, username = get_session_variables(request)
    icpc_participants_list = []
    p_list = []
    icpc_list = ACM_ICPC_detail.objects.all().order_by('ranking')
    if icpc_list:

        for icpc_obj in icpc_list:

            team = icpc_obj.team_name
            member1 = [icpc_obj.participant1_name, \
                get_username_from_email(icpc_obj.participant1_email)]

            member2 = [icpc_obj.participant2_name, \
                get_username_from_email(icpc_obj.participant2_email)]

            member3 = [icpc_obj.participant3_name, \
                get_username_from_email(icpc_obj.participant3_email)]

            icpc_participant_list = [icpc_obj, member1, member2, member3]
            icpc_participants_list.append(icpc_participant_list)

        return render_to_response('achievement/icpc_viewall.html', \
            {'is_loggedin':logged_in(request), \
            'username':username, \
            'icpc_list':icpc_list,\
            'icpc_participants_list':icpc_participants_list}, RequestContext(request))

    else:
        return render_to_response('achievement/noview.html', \
                {'is_loggedin':logged_in(request), \
                'username':username, \
                'type': 'ACM ICPC Contest'}, \
                RequestContext(request))
Example #37
0
def search(request):
    """
    Search view
    """
    is_loggedin, username = get_session_variables(request)
    search_field = request.GET['search_field']
    #if search field is empty
    if not search_field:
        return HttpResponseRedirect('/')

    #if search field is not empty
    else:
        result = []
        is_empty = True

        search_list = search_field.split(' ')
        for term in search_list:
            #search in the firstname and lastname of all members.
            rs_obj = User_info.objects \
                    .filter(Q(firstname__icontains=term) | \
                    Q(lastname__icontains=term))
            for result_object in rs_obj:
                if result_object not in result:
                    result.append(result_object)

        #if search result is not empty
        if result:
            is_empty = False

        return render_to_response( \
                'search_result.html', \
                {'is_empty':is_empty, \
                'is_loggedin':is_loggedin, \
                'username':username, \
                'result':result}, \
                RequestContext(request))
Example #38
0
def achieve_viewall(request):
    """
    View to display recent 5 achievements
    """
    is_loggedin, username = get_session_variables(request)
    contrib_list = []
    article_list = []
    gsoc_list = []
    speaker_list = []
    intern_list = []
    contest_participant_list = []
    icpc_participants_regional_list = []
    icpc_participants_final_list = []

    contrib_list_all = Contribution.objects.all()
    contrib_list = Contribution.objects.all()[:5]
    article_list = Article.objects.all()[:5]
    gsoc_list = Gsoc.objects.all()[:5]
    speaker_list = Speaker.objects.all()[:5]
    intern_list = Intern.objects.all()[:5]
    contest_list = Contest_won.objects.all()[:5]

    contrib_org = {}
    if contrib_list_all:
        for contrib in contrib_list_all:
            if contrib.org_name not in contrib_org.keys():
                contrib_org[contrib.org_name] = 0

        for contrib in contrib_list_all:
            contrib_org[contrib.org_name] += 1

    if contest_list:
        contest_participant_list = []
        for contest_won_obj in contest_list:
            c_id = contest_won_obj.contest_id
            c_p_objs = Contest_won_participant.objects.filter(contest_id=c_id)
            contest_participant_list.extend(c_p_objs)

    icpc_list_regionals = ACM_ICPC_detail.objects.filter(
        level='regional').order_by('ranking')[:2]
    if icpc_list_regionals:
        for icpc_obj in icpc_list_regionals:
            team = icpc_obj.team_name
            member1 = [
                icpc_obj.participant1_name,
                get_username_from_email(icpc_obj.participant1_email)
            ]

            member2 = [
                icpc_obj.participant2_name,
                get_username_from_email(icpc_obj.participant2_email)
            ]

            member3 = [
                icpc_obj.participant3_name,
                get_username_from_email(icpc_obj.participant3_email)
            ]

            icpc_participant_list = [icpc_obj, member1, member2, member3]
            icpc_participants_regional_list.append(icpc_participant_list)

    icpc_list_finals = ACM_ICPC_detail.objects.filter(
        level='finals').order_by('ranking')[:2]
    if icpc_list_finals:
        for icpc_obj in icpc_list_finals:
            team = icpc_obj.team_name
            member1 = [
                icpc_obj.participant1_name,
                get_username_from_email(icpc_obj.participant1_email)
            ]

            member2 = [
                icpc_obj.participant2_name,
                get_username_from_email(icpc_obj.participant2_email)
            ]

            member3 = [
                icpc_obj.participant3_name,
                get_username_from_email(icpc_obj.participant3_email)
            ]

            icpc_participant_list = [icpc_obj, member1, member2, member3]
            icpc_participants_final_list.append(icpc_participant_list)

    return render(request, 'achievement/achievement_viewall.html', \
                              {'username': username, \
                               'is_loggedin': is_loggedin, \
                               'contrib_list': contrib_list, \
                               'contrib_org': contrib_org, \
                               'article_list': article_list, \
                               'gsoc_list': gsoc_list, \
                               'speaker_list': speaker_list, \
                               'intern_list': intern_list, \
                               'contest_list': contest_list, \
                               'contest_participant_list': contest_participant_list, \
                               'icpc_participants_final_list': icpc_participants_final_list, \
                               'icpc_participants_regional_list': icpc_participants_regional_list}, \
                              RequestContext(request))
Example #39
0
 def form_valid(self, form):
     is_loggedin, username = get_session_variables(self.request)
     form.instance.created_by = User_info.objects.get(username=username)
     return super(ProposalCreateView, self).form_valid(form)
Example #40
0
 def get_context_data(self, **kwargs):
     context = super(ProposalUpdateView, self).get_context_data(**kwargs)
     is_loggedin, username = get_session_variables(self.request)
     if is_loggedin is False:
         return redirect('login')
     return context
Example #41
0
def achieve_viewall(request):
    """
    View to display recent 5 achievements
    """
    is_loggedin, username = get_session_variables(request)
    contrib_list = []
    article_list = []
    gsoc_list = []
    speaker_list = []
    intern_list = []
    contest_participant_list = []
    icpc_participants_regional_list = []
    icpc_participants_final_list = []

    contrib_list_all = Contribution.objects.all()
    contrib_list = Contribution.objects.all()[:5]
    article_list = Article.objects.all()[:5]
    gsoc_list = Gsoc.objects.all()[:5]
    speaker_list = Speaker.objects.all()[:5]
    intern_list = Intern.objects.all()[:5]
    contest_list = Contest_won.objects.all()[:5]

    
    contrib_org = {}
    if contrib_list_all:
        for contrib in contrib_list_all:
            if contrib.org_name not in contrib_org.keys():
                contrib_org[contrib.org_name] = 0

        for contrib in contrib_list_all:
            contrib_org[contrib.org_name] += 1

    if contest_list:	
        contest_participant_list = []
	for contest_won_obj in contest_list:	
	    c_id = contest_won_obj.contest_id
	    c_p_objs = Contest_won_participant.objects.filter(contest_id = c_id)
	    contest_participant_list.extend(c_p_objs)
    
    icpc_list_regionals = ACM_ICPC_detail.objects.filter(level='regional').order_by('ranking')[:2]
    if icpc_list_regionals:
        for icpc_obj in icpc_list_regionals:
            team = icpc_obj.team_name
            member1 = [icpc_obj.participant1_name, \
                get_username_from_email(icpc_obj.participant1_email)]

            member2 = [icpc_obj.participant2_name, \
                get_username_from_email(icpc_obj.participant2_email)]

            member3 = [icpc_obj.participant3_name, \
                get_username_from_email(icpc_obj.participant3_email)]

            icpc_participant_list = [icpc_obj, member1,member2,member3]
            icpc_participants_regional_list.append(icpc_participant_list)

    icpc_list_finals = ACM_ICPC_detail.objects.filter(level='finals').order_by('ranking')[:2]
    if icpc_list_finals:
        for icpc_obj in icpc_list_finals:
            team = icpc_obj.team_name
            member1 = [icpc_obj.participant1_name, \
                get_username_from_email(icpc_obj.participant1_email)]

            member2 = [icpc_obj.participant2_name, \
                get_username_from_email(icpc_obj.participant2_email)]

            member3 = [icpc_obj.participant3_name, \
                get_username_from_email(icpc_obj.participant3_email)]

            icpc_participant_list = [icpc_obj, member1,member2,member3]
            icpc_participants_final_list.append(icpc_participant_list)

    return render_to_response('achievement/achievement_viewall.html',\
		{'username':username, \
                'is_loggedin':is_loggedin, \
                'contrib_list':contrib_list, \
                'contrib_org':contrib_org,\
                'article_list':article_list, \
                'gsoc_list':gsoc_list, \
                'speaker_list':speaker_list, \
                'intern_list':intern_list, \
                'contest_list':contest_list, \
                'contest_participant_list':contest_participant_list, \
                'icpc_participants_final_list':icpc_participants_final_list, \
                'icpc_participants_regional_list':icpc_participants_regional_list}, \
                RequestContext(request))
Example #42
0
def change_password(request):
    """
    A view to change the password of a logged in user
    """
    try:
        is_loggedin, username = get_session_variables(request)
        if not is_loggedin:
            return HttpResponseRedirect("/register/login")
        # POST request 
        if request.method == 'POST':
            form = ChangePasswordForm(request.POST)

            # Form inputs are valid
            if form.is_valid():
                new_pass = request.POST['new_password']
               	old_password = hash_func(request.POST['old_password']) \
                                .hexdigest()
                new_password = hash_func(request.POST['new_password']) \
                                .hexdigest()
                confirm_new_password = hash_func(
                                request.POST['confirm_new_password']) \
                                .hexdigest()

                user_data = User_info.objects.get(username = username)
                actual_pwd = user_data.password
                
                # Given current and stored passwords same
                if old_password == actual_pwd:
                    # New and current passwords user provided are not same 
                    if new_password != actual_pwd:
                        # Repass and new pass are same
                        if new_password == confirm_new_password:
                            user_data.password = new_password
                            sendmail_after_pass_change( \
                                    username, \
                                    new_pass, \
                                    user_data.email)
                            user_data.save()
                            return render_to_response( \
                                    'register/pass_success.html',
                                    {'username': username, \
                                    'is_loggedin': is_loggedin}, \
                                    RequestContext(request))
                        # Repass and new pass are not same
                        else:
                            error = "New passwords doesn't match"
                            return render_to_response( \
                                    'register/change_password.html', 
                                    {'form':form, \
                                    'username' :username, \
                                    'is_loggedin':is_loggedin, \
                                    'error':error}, \
                                    RequestContext(request))
                    # New and current password user provided are same
                    else:
                        error = "Your old and new password are same. Please \
                                choose a different password"
                        return render_to_response( \
                                'register/change_password.html', 
                                {'form':form, \
                                'username':username, \
                                'is_loggedin':is_loggedin, \
                                'error':error}, \
                                RequestContext(request))
                # Given current and stored passwords are not same
                else:
                    error = "Current password and given password doesn't match"
                    return render_to_response( \
                            'register/change_password.html', 
                            {'form':form, \
                            'username':username, \
                            'is_loggedin':is_loggedin, \
                            'error':error}, \
                            RequestContext(request))
            # Form inputs is/are invalid
            else:
                form = ChangePasswordForm()

            return render_to_response( \
                    'register/change_password.html', 
                    {'form':form, \
                    'username':username, \
                    'is_loggedin':is_loggedin}, \
                    RequestContext(request))

        return render_to_response( \
                'register/change_password.html',
                {'username': username, \
                'is_loggedin': is_loggedin}, \
                RequestContext(request))

    except KeyError:
        return error_key(request)
Example #43
0
def change_password(request):
    """
    A view to change the password of a logged in user
    """
    try:
        is_loggedin, username = get_session_variables(request)
        if not is_loggedin:
            return HttpResponseRedirect("/register/login")
        # POST request
        if request.method == 'POST':
            form = ChangePasswordForm(request.POST)

            # Form inputs are valid
            if form.is_valid():
                new_pass = request.POST['new_password']
                old_password = hash_func(request.POST['old_password']) \
                                .hexdigest()
                new_password = hash_func(request.POST['new_password']) \
                                .hexdigest()
                confirm_new_password = hash_func(
                                request.POST['confirm_new_password']) \
                                .hexdigest()

                user_data = User_info.objects.get(username=username)
                actual_pwd = user_data.password

                # Given current and stored passwords same
                if old_password == actual_pwd:
                    # New and current passwords user provided are not same
                    if new_password != actual_pwd:
                        # Repass and new pass are same
                        if new_password == confirm_new_password:
                            user_data.password = new_password
                            sendmail_after_pass_change( \
                                    username, \
                                    new_pass, \
                                    user_data.email)
                            user_data.save()
                            return render_to_response( \
                                    'register/pass_success.html',
                                    {'username': username, \
                                    'is_loggedin': is_loggedin}, \
                                    RequestContext(request))
                        # Repass and new pass are not same
                        else:
                            error = "New passwords doesn't match"
                            return render_to_response( \
                                    'register/change_password.html',
                                    {'form':form, \
                                    'username' :username, \
                                    'is_loggedin':is_loggedin, \
                                    'error':error}, \
                                    RequestContext(request))
                    # New and current password user provided are same
                    else:
                        error = "Your old and new password are same. Please \
                                choose a different password"
                        return render_to_response( \
                                'register/change_password.html',
                                {'form':form, \
                                'username':username, \
                                'is_loggedin':is_loggedin, \
                                'error':error}, \
                                RequestContext(request))
                # Given current and stored passwords are not same
                else:
                    error = "Current password and given password doesn't match"
                    return render_to_response( \
                            'register/change_password.html',
                            {'form':form, \
                            'username':username, \
                            'is_loggedin':is_loggedin, \
                            'error':error}, \
                            RequestContext(request))
            # Form inputs is/are invalid
            else:
                form = ChangePasswordForm()

            return render_to_response( \
                    'register/change_password.html',
                    {'form':form, \
                    'username':username, \
                    'is_loggedin':is_loggedin}, \
                    RequestContext(request))

        return render_to_response( \
                'register/change_password.html',
                {'username': username, \
                'is_loggedin': is_loggedin}, \
                RequestContext(request))

    except KeyError:
        return error_key(request)