示例#1
0
文件: views.py 项目: Dpetters/Umeqo
def student_quick_registration(request, form_class=StudentQuickRegistrationForm, extra_context=None):
    context = {}
    if request.method == "POST":
        data = {}
        form = form_class(data=request.POST, files=request.FILES)
        if form.is_valid():
            pdf_file_path = "student/student/quick_reg_resume_%s.pdf" %(datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S'))
            handle_uploaded_file(request.FILES['resume'], "%s%s" % (s.MEDIA_ROOT, pdf_file_path))
            
            # process_resume_data returns either an error or the keywords
            keywords, num =  extract_resume_keywords(pdf_file_path)
            
            # If the resume is not unparsable, then resume_parsing_results
            # contains the keywords
            if num == 0:
                data['unparsable_resume'] = True

            user_info =  {'username': request.POST['email'],
                          'first_name': request.POST['first_name'],
                          'last_name': request.POST['last_name'],
                          'email': request.POST['email'],
                          'password': request.POST['password']}
            student = register_student(request, **user_info)
            student.degree_program = DegreeProgram.objects.get(id=request.POST['degree_program'])
            student.graduation_month = request.POST['graduation_month']
            student.graduation_year = GraduationYear.objects.get(id=request.POST['graduation_year'])
            student.first_major = Course.objects.get(id=request.POST['first_major'])
            student.gpa = request.POST['gpa']
            file_content = file("%s%s" % (s.MEDIA_ROOT, pdf_file_path), "rb")
            student.resume.save(request.FILES['resume'].name, File(file_content))
            
            if keywords:
                student.keywords = keywords
            student.profile_created = True
            student.save()
            for attendee in Attendee.objects.filter(email=student.user.email):
                attendee.student = student
                attendee.save()
            event = Event.objects.get(id=request.POST['event_id'])
            action = request.POST['action']
            DroppedResume.objects.create(student=student, event=event)
            if action == "rsvp":
                RSVP.objects.create(student=student, event=event)
        else:
            data['errors'] = form.errors
        return HttpResponse(simplejson.dumps(data), mimetype="text/html")
    if not request.GET.has_key('event_id'):
        raise Http400("Request GET is missing the event_id.")
    if not request.GET.has_key('action'):
        raise Http400("Request GET is missing the action.")
    context['form'] = form_class(initial={'event_id':request.GET['event_id'], 'action':request.GET['action']})
    action = request.GET['action']
    if action=="rsvp":
        context['action'] = "RSVP"
    elif action=="drop":
        context['action'] = "drop resume"
    context.update(extra_context or {})
    return context
示例#2
0
文件: views.py 项目: Dpetters/Umeqo
def student_registration(request, backend = RegistrationBackend(), form_class = StudentRegistrationForm, success_url = 'student_registration_complete', extra_context = None):
    if not backend.registration_allowed(request):
        return redirect('student_registration_closed')
    if request.method == 'POST':
        form = form_class(data=request.POST)
        if form.is_valid():
            form.cleaned_data['username'] = form.cleaned_data['email']
            register_student(request, **form.cleaned_data)
            if request.is_ajax():
                data = {
                    'success_url': reverse(success_url),
                    'email': form.cleaned_data['email']
                }
                return HttpResponse(simplejson.dumps(data), mimetype="application/json")
            return redirect(success_url)
        else:
            if request.is_ajax():
                data = {'errors':form.errors}
                return HttpResponse(simplejson.dumps(data), mimetype="application/json")
    else:
        form = form_class()
    context = {'form':form}
    context.update(extra_context or {}) 
    return context