Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
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)