Example #1
0
def approve_userapplication(request, application_id):
    application = get_object_or_404(UserApplication, pk=application_id)
    if not request.user.get_profile() in application.project.leaders.all():
        return HttpResponseForbidden('<h1>Access Denied</h1>')
    if application.state != Application.WAITING_FOR_LEADER:
        return render_to_response('applications/unable_to_approve.html', {'application': application}, context_instance=RequestContext(request))

    if request.method == 'POST':
        form = LeaderApproveUserApplicationForm(request.POST, instance=application)
        if form.is_valid():
            application = form.save()

            if settings.ADMIN_APPROVE_ACCOUNTS:
                application.state = Application.WAITING_FOR_ADMIN
                application.save()
                send_notify_admin(application, request.user.get_full_name())
                log(request.user, application.application_ptr, 2, 'Leader approved application')
                return HttpResponseRedirect(reverse('kg_userapplication_pending', args=[application.id]))

            application.approve()
            send_account_approved_email(application)
            log(request.user, application.application_ptr, 2, 'Application fully approved')
            return HttpResponseRedirect(reverse('kg_userapplication_complete', args=[application.id]))
    else:
        form = LeaderApproveUserApplicationForm(instance=application)

    return render_to_response('applications/approve_application.html', {'form': form, 'application': application}, context_instance=RequestContext(request))
Example #2
0
def approve_userapplication(request, application_id):
    application = get_object_or_404(UserApplication, pk=application_id)

    if application.state != Application.WAITING_FOR_ADMIN:
        raise Http404

    if request.method == 'POST':
        form = LeaderApproveUserApplicationForm(request.POST, instance=application)
        if form.is_valid():
            application = form.save()
            person = application.approve()
            send_account_approved_email(application)
            messages.success(request, "Application approved successfully")
            log(request.user, application.application_ptr, 2, 'Application fully approved')
            return HttpResponseRedirect(person.get_absolute_url())
    else:
        form = LeaderApproveUserApplicationForm(instance=application)

    return render_to_response('applications/approve_application.html', {'form': form, 'application': application}, context_instance=RequestContext(request))