def event_list_download(request): if not request.GET.has_key("event_id"): raise Http400("Request GET is missing the event_id.") try: event = Event.objects.get(id=request.GET["event_id"]) except Event.DoesNotExist: raise Http404("Event with the id %d" % request.GET['event_id']) else: list = request.GET['event_list'] if not request.GET.has_key('export_format'): raise Http400("The request is missing the file format.") if request.GET['export_format'] == core_enums.CSV: response = HttpResponse(mimetype='text/csv') filename = "%s.csv" % export_event_list_csv(response, event, list) #elif request.GET['export_format'] == core_enums.XLS: # response = HttpResponse(mimetype="application/ms-excel") # filename = export_event_list_xls(response, event, list) elif request.GET['export_format'] == core_enums.TEXT: response = HttpResponse(mimetype="text/plain") filename = "%s.txt" % export_event_list_text(response, event, list) else: raise Http500("The file format % isn't one we support." % request.GET['export_format']) response[ 'Content-Disposition'] = 'attachment; filename="%s"' % filename return response
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
def employer_student_comment(request): if not request.POST.has_key('student_id'): raise Http400("Request POST is missing the student_id") if not request.POST.has_key('comment'): raise Http400("Request POST is missing the comment.") student = Student.objects.get(id=request.POST['student_id']) comment = request.POST['comment'] try: student_comment = EmployerStudentComment.objects.get(student=student, employer=request.user.recruiter.employer) except EmployerStudentComment.DoesNotExist: EmployerStudentComment.objects.create(employer = request.user.recruiter.employer, student=student, comment=comment) else: student_comment.comment = comment student_comment.save() return HttpResponse()
def employer_students_remove_star(request): if not request.POST.has_key('student_ids'): raise Http400("Request POST is missing the student_ids.") for id in request.POST['student_ids'].split('~'): student = Student.objects.get(id=id) if student in request.user.recruiter.employer.starred_students.all(): request.user.recruiter.employer.starred_students.remove(student) return HttpResponse()
def employer_student_event_attendance(request): if not request.GET.has_key('student_id'): raise Http400("Request GET is missing the student_id.") context={} student = Student.objects.visible().get(id=request.GET['student_id']) context['events'] = request.user.recruiter.employer.events_attending.filter(attendee__student=student) context['student'] = student return context
def check_campus_org_uniqueness(request): if not request.GET.has_key("name"): raise Http400("Request GET is missing the name.") try: CampusOrg.objects.get(name=request.GET.get("name")) return HttpResponse(simplejson.dumps(False), mimetype="application/json") except CampusOrg.DoesNotExist: return HttpResponse(simplejson.dumps(True), mimetype="application/json")
def student_increment_resume_view_count(request): if not request.POST.has_key("student_id"): raise Http400("Request POST is missing the student_id.") student = Student.objects.get(id=request.POST['student_id']) if request.user.recruiter.employer.name != "Umeqo": student.studentstatistics.resume_view_count += 1 student.studentstatistics.save() return HttpResponse()
def check_language_uniqueness(request): if not request.GET.has_key("name"): raise Http400("Request GET is missing the name.") if Language.objects.filter(name=request.GET["name"]).exists(): return HttpResponse(simplejson.dumps(False), mimetype="application/json") else: return HttpResponse(simplejson.dumps(True), mimetype="application/json")
def employer_logo(request): if not request.GET.has_key("employer_name"): raise Http400("Request GET is missing the employer_name.") name = request.GET['employer_name'] try: e = Employer.objects.get(name=name) except: raise Http404("Employer with name %s does not exist" % name) return {'employer': e}
def check_employer_uniqueness(request): if not request.GET.has_key("name"): raise Http400("Request is missing the name.") try: Employer.objects.get(name=request.GET['name']) data = False except Employer.DoesNotExist: data = True return HttpResponse(simplejson.dumps(data), mimetype="application/json")
def check_event_name_uniqueness(request): if not request.GET.has_key("name"): raise Http400("Request GET is missing the name.") try: Event.objects.get(name=request.GET["name"]) return HttpResponse(simplejson.dumps(False), mimetype="application/json") except Event.DoesNotExist: return HttpResponse(simplejson.dumps(True), mimetype="application/json")
def check_email_availability(request): if not request.GET.has_key("email"): raise Http400("Request GET is missing the email.") try: User.objects.get(email=request.GET["email"]) return HttpResponse(simplejson.dumps(False), mimetype="application/json") except User.DoesNotExist: return HttpResponse(simplejson.dumps(True), mimetype="application/json")
def employer_student_toggle_star(request): if not request.POST.has_key('student_id'): raise Http400("Request POST is missing the student_id.") student = Student.objects.get(id=request.POST['student_id']) if student in request.user.recruiter.employer.starred_students.all(): request.user.recruiter.employer.starred_students.remove(student) data = {'action':employer_enums.UNSTARRED} else: request.user.recruiter.employer.starred_students.add(student) data = {'action':employer_enums.STARRED} return HttpResponse(simplejson.dumps(data), mimetype="application/json")
def campus_org_info_dialog(request, extra_context = None): if not request.GET.has_key('campus_org_id'): raise Http400("Request is missing the campus_org_id.") try: id = request.GET['campus_org_id'] campus_org = CampusOrg.objects.get(id=id) except CampusOrg.DoesNotExist: raise Http404("Campus organization with id %s doesn't exist." % id) context = {} context['campus_org'] = campus_org context.update(extra_context or {}) return context
def check_website(request): if not request.GET.has_key("website"): raise Http400("Request GET is missing the website.") url_validator = URLValidator(verify_exists=False) website = request.GET.get("website", "") try: url_validator(website) return HttpResponse(simplejson.dumps(True), mimetype="application/json") except ValidationError: return HttpResponse(simplejson.dumps(False), mimetype="application/json")
def employer_resume_book_remove_students(request): if not request.POST.has_key('student_ids'): raise Http400("Request is missing the student_ids.") try: resume_book = ResumeBook.objects.get(recruiter = request.user.recruiter, delivered=False) except ResumeBook.DoesNotExist: resume_book = ResumeBook.objects.create(recruiter = request.user.recruiter) if request.POST['student_ids']: for student_id in request.POST['student_ids'].split('~'): student = Student.objects.get(id=student_id) if student in resume_book.students.visible(): resume_book.students.remove(student) return HttpResponse()
def employer_resume_book_deliver(request, form_class=DeliverResumeBookForm, extra_context=None): context = {'form':form_class(initial={'emails':request.user.email})} if not request.GET.has_key("resume_book_id"): raise Http400("Request GET is missing the resume_book_id.") if request.GET["resume_book_id"]: try: resume_book = ResumeBook.objects.get(id=request.GET["resume_book_id"]) except ResumeBook.DoesNotExist: raise Http400("No resume book exists with id of %s" % request.GET["resume_book_id"]) else: try: resume_book = ResumeBook.objects.get(recruiter=request.user.recruiter, delivered=False) except ResumeBook.DoesNotExist: raise Http400("There isn't a resume book ready to be delivered.") resume_book_size = get_resume_book_size(resume_book) context['resume_book'] = resume_book context['resume_book_size'] = resume_book_size context['max_resume_book_size_as_attachment'] = s.RESUME_BOOK_MAX_SIZE_AS_ATTACHMENT if resume_book_size > s.RESUME_BOOK_MAX_SIZE_AS_ATTACHMENT: context['disable_email_delivery'] = True context.update(extra_context or {}) return context
def employer_resume_book_delete(request, extra_context = None): if request.method == "POST": if not request.POST.has_key("resume_book_id"): raise Http400("Request POST is missing the resume_book_id.") try: ResumeBook.objects.get(id=request.POST["resume_book_id"]).delete() except ResumeBook.DoesNotExist: raise Http404("No resume book exists with id of %s" % request.POST["resume_book_id"]) return HttpResponse() else: context = {} context.update(extra_context or {}) return context
def event_list_export_completed(request, extra_context=None): if not request.GET.has_key("event_list"): raise Http400("Filename is missing from the request.") if not request.GET.has_key("event_id"): raise Http400("Request GET is missing the event_id.") id = request.GET["event_id"] try: event = Event.objects.get(id=id) except Event.DoesNotExist: return Http404("Event with the id %s does not exist." % id) list = request.GET['event_list'] if list == "all": filename = "%s Respondees" % (event.name) elif list == "rsvps": filename = "%s RSVPs" % (event.name) elif list == "dropped_resumes": filename = "%s Resume Drops" % (event.name) elif list == "attendees": filename = "%s Attendees" % (event.name) context = {'filename': filename} context.update(extra_context or {}) return context
def event_drop(request, event_id): try: event = Event.objects.get(id=event_id) except Event.DoesNotExist: raise Http404("Event with id %d does not exist." % event_id) if not request.POST.has_key("drop"): raise Http400("Request POST is missing the boolean drop.") if request.POST["drop"] == "true": DroppedResume.objects.get_or_create(event=event, student=request.user.student) else: DroppedResume.objects.filter(event=event, student=request.user.student).delete() return HttpResponse()
def employer_details(request, extra_content=None): if not request.GET.has_key("id"): raise Http400("Request is missing the employer id.") try: employer = Employer.objects.get(id=request.GET['id']) except: return Http404("Employer with id {0} not found".format(request.GET['id'])) subscriptions = request.user.student.subscriptions.all() context = { 'employer': employer, 'subbed': employer in subscriptions } context.update(get_employer_upcoming_events_context(employer, request.user)) return context
def check_employer_campus_org_slug_uniqueness(request): if not request.GET.has_key("slug"): raise Http400("Request GET is missing the slug.") data = False campusorg = None employer = None if is_campus_org(request.user): campusorg = request.user.campusorg elif is_recruiter(request.user): employer = request.user.recruiter.employer if not employer_campus_org_slug_exists( request.GET["slug"], campusorg=campusorg, employer=employer): data = True return HttpResponse(simplejson.dumps(data), mimetype="application/json")
def events_check_short_slug_uniqueness(request): if not request.GET.has_key("short_slug"): raise Http400("Request GET is missing the short_slug.") data = {'used': False} if is_campus_org(request.user): if Event.objects.filter(short_slug=request.GET['short_slug'], owner=request.user).exists(): data['used'] = True elif is_recruiter(request.user): if Event.objects.filter(short_slug=request.GET['short_slug'], owner__recruiter__employer=request.user. recruiter.employer).exists(): data['used'] = True return HttpResponse(simplejson.dumps(data), mimetype="application/json")
def employer_resume_book_email(request, extra_context=None): if not request.POST.has_key('emails'): raise Http400("Request POST is missing the emails.") if request.POST.has_key("resume_book_id") and request.POST['resume_book_id']: redelivering = True try: resume_book = ResumeBook.objects.get(id=request.POST["resume_book_id"]) except ResumeBook.DoesNotExist: raise Http404("No resume book exists with id of %s" % request.POST["resume_book_id"]) else: redelivering = False try: resume_book, created = ResumeBook.objects.get_or_create(recruiter = request.user.recruiter, delivered=False) except ResumeBook.MultipleObjectsReturned: resume_books = ResumeBook.objects.filter(recruiter=request.user.recruiter, delivered=False) for i, rb in enumerate(resume_books): if i != 0: rb.delete() else: resume_book = rb reg = re.compile(r"\s*[;, \n]\s*") recipients = reg.split(request.POST['emails']) site = get_current_site(request) subject = "[%s] Resume Book Delivery" % (site.name) f = open("%s%s" % (s.MEDIA_ROOT, resume_book.resume_book.name), "rb") content = f.read() if request.POST.has_key('name') and request.POST['name']: filename = request.POST['name'] else: filename = os.path.basename(resume_book.name) context = get_basic_email_context() context['deliverer_fullname'] = "%s %s" % (request.user.first_name, request.user.last_name) context['deliverer_email'] = request.user.email for recipient in recipients: context['first_name'] = recipient.split("@")[0] text_email_body = render_to_string('resume_book_email_body.txt', context) html_email_body = render_to_string('resume_book_email_body.html', context) send_email(subject, text_email_body, recipients, html_email_body, "%s.pdf" % (filename), content, "application/pdf") if redelivering: resume_book.last_updated = datetime.now() else: resume_book.name = filename resume_book.delivered = True resume_book.save() context = {} context.update(extra_context or {}) return context
def employer_subscribe(request): if not request.POST.has_key("id"): raise Http400("Request is missing the id.") id = request.POST["id"] try: employer = Employer.objects.get(id=id) except Employer.DoesNotExist: raise Http404("Employer with id %s was not found." % id) if employer in request.user.student.subscriptions.all(): request.user.student.subscriptions.remove(employer) else: request.user.student.subscriptions.add(employer) # Update index employer.save() return HttpResponse()
def get_location_guess(request): if not request.has_key("query"): raise Http400("Request GET is missing the query.") sqs = SearchQuerySet().models(Location) sqs = search(sqs, request.GET.get('query', ""))[:10] if not sqs or len(sqs) > 1: data = {'single': False, 'query': request.GET['query']} else: loc = sqs[0].object data = { 'single': True, 'latitude': loc.latitude, 'longitude': loc.longitude } return HttpResponse(simplejson.dumps(data), mimetype="application/json")
def event_raffle_winner(request, extra_context=None): if not request.GET.has_key("event_id"): raise Http400("Request GET is missing the event_id") data = {} winners = Attendee.objects.filter(event__id=request.GET['event_id'], won_raffle=False) if winners.exists(): winner = winners[0] winner.won_raffle = True winner.save() if winner.student: email = winner.student.user.email winner.student.studentstatistics.raffles_won += 1 winner.student.studentstatistics.save() else: email = winner.email data['name'] = winner.name data['email'] = email return HttpResponse(simplejson.dumps(data), mimetype="application/json")
def faq(request, extra_context=None): if request.method == "POST": if not request.POST.has_key("question_id"): raise Http400("Request POST is missing 'question_id'.") q = Question.objects.get(id=request.POST["question_id"]) q.click_count += 1 q.save() return HttpResponse() else: context = {'topics': []} for topic in Topic.objects.all(): questions = filter_faq_questions(request.user, topic.question_set.visible()) if questions: context['topics'].append({ 'name': topic, 'questions': questions }) context.update(extra_context or {}) return context
def employer_resume_book_add_students(request): if not request.POST.has_key('student_ids'): raise Http400("Request POST is missing the student_ids.") try: resume_book = ResumeBook.objects.get(recruiter = request.user.recruiter, delivered=False) if len(resume_book.students.visible()) >= s.RESUME_BOOK_CAPACITY: raise Http403("You already have the max number (%d) of allowed students in you resumebook!" % (s.RESUME_BOOK_CAPACITY)) except ResumeBook.DoesNotExist: resume_book = ResumeBook.objects.create(recruiter = request.user.recruiter) employer = request.user.recruiter.employer unlocked_students = get_unlocked_students(employer, request.META['has_at_least_premium']) if request.POST['student_ids']: for id in request.POST['student_ids'].split('~'): student = Student.objects.get(id=id) if student in unlocked_students: if student not in resume_book.students.visible(): resume_book.students.add(student) if request.user.recruiter.employer.name != "Umeqo": student.studentstatistics.add_to_resumebook_count += 1 student.studentstatistics.save() return HttpResponse()
def employer_resume_book_toggle_student(request): if not request.POST.has_key('student_id'): raise Http400("Request POST is missing the student_id.") student = Student.objects.get(id=request.POST['student_id']) try: resume_book = ResumeBook.objects.get(recruiter = request.user.recruiter, delivered=False) except ResumeBook.DoesNotExist: resume_book = ResumeBook.objects.create(recruiter = request.user.recruiter) data = {} if student in resume_book.students.visible(): resume_book.students.remove(student) data['action'] = employer_enums.REMOVED else: employer = request.user.recruiter.employer if student in get_unlocked_students(employer, request.META['has_at_least_premium']): if len(resume_book.students.visible()) >= s.RESUME_BOOK_CAPACITY: raise Http403("You already have the max number (%d) of allowed students in you resumebook!" % (s.RESUME_BOOK_CAPACITY)) resume_book.students.add(student) if not request.user.recruiter.employer.name != "Umeqo": student.studentstatistics.add_to_resumebook_count += 1 student.studentstatistics.save() data['action'] = employer_enums.ADDED return HttpResponse(simplejson.dumps(data), mimetype="application/json")