def clean_csv_file(self, ): if self.cleaned_data['csv_file'].content_type != "text/csv": raise ValidationError("Please upload a valid CSV file") open_csv_file = csv.DictReader(self.cleaned_data['csv_file']) for i, fieldname in enumerate(open_csv_file.fieldnames): open_csv_file.fieldnames[i] = fieldname.lower() if not "first name" in open_csv_file.fieldnames: raise ValidationError('The csv file you uploaded is missing the required "First Name" column.'); if not "last name" in open_csv_file.fieldnames: raise ValidationError('The csv file you uploaded is missing the required "Last Name" column.'); if not "employer" in open_csv_file.fieldnames: raise ValidationError('The csv file you uploaded is missing the required "Employer" column.'); if not "email" in open_csv_file.fieldnames: raise ValidationError('The csv file you uploaded is missing the required "Email" column.'); for i, row in enumerate(open_csv_file): if not row["first name"]: raise ValidationError('The recruiter at row #%s is missing his/her first name. Please fill it in and try again.' % i) if not row["last name"]: raise ValidationError('The recruiter at row #%s is missing his/her last name. Please fill it in and try again.' % i) if not row["employer"]: raise ValidationError('The recruiter at row #%s is missing his/her employer. Please fill it in and try again.' % i) if not row["email"]: raise ValidationError('The recruiter at row #%s is missing his/her email. Please fill it in and try again.' % i) else: if not is_valid_email(row["email"]): raise ValidationError('The recruiter at row #%s has an invalid email. Please fill it in and try again.' % i) return self.cleaned_data['csv_file']
def clean_csv_file(self, ): if self.cleaned_data['csv_file'].content_type != "text/csv": raise ValidationError("Please upload a valid CSV file") open_csv_file = csv.DictReader(self.cleaned_data['csv_file']) for i, fieldname in enumerate(open_csv_file.fieldnames): open_csv_file.fieldnames[i] = fieldname.lower() if not "first name" in open_csv_file.fieldnames: raise ValidationError( 'The csv file you uploaded is missing the required "First Name" column.' ) if not "last name" in open_csv_file.fieldnames: raise ValidationError( 'The csv file you uploaded is missing the required "Last Name" column.' ) if not "employer" in open_csv_file.fieldnames: raise ValidationError( 'The csv file you uploaded is missing the required "Employer" column.' ) if not "email" in open_csv_file.fieldnames: raise ValidationError( 'The csv file you uploaded is missing the required "Email" column.' ) for i, row in enumerate(open_csv_file): if not row["first name"]: raise ValidationError( 'The recruiter at row #%s is missing his/her first name. Please fill it in and try again.' % i) if not row["last name"]: raise ValidationError( 'The recruiter at row #%s is missing his/her last name. Please fill it in and try again.' % i) if not row["employer"]: raise ValidationError( 'The recruiter at row #%s is missing his/her employer. Please fill it in and try again.' % i) if not row["email"]: raise ValidationError( 'The recruiter at row #%s is missing his/her email. Please fill it in and try again.' % i) else: if not is_valid_email(row["email"]): raise ValidationError( 'The recruiter at row #%s has an invalid email. Please fill it in and try again.' % i) return self.cleaned_data['csv_file']
def event_checkin(request, event_id): event = Event.objects.get(pk=event_id) if request.method == 'GET': return HttpResponse(simplejson.dumps(get_attendees(event)), mimetype="application/json") else: email = request.POST.get('email', None).strip() if not is_valid_email(email): data = { 'valid': False, 'error': 'Please enter a valid .edu email!' } return HttpResponse(simplejson.dumps(data), mimetype="application/json") name = request.POST.get('name', None) student = None user = None if User.objects.filter(email=email).exists(): user = User.objects.get(email=email) if hasattr(user, 'student'): student = user.student if not name and not student: data = { 'valid': False, 'error': "This email isn't registered with Umeqo. Please enter your name!" } return HttpResponse(simplejson.dumps(data), mimetype="application/json") if Attendee.objects.filter(event=event, email=email).exists(): data = {'valid': False, 'error': 'You\'ve already checked in!'} return HttpResponse(simplejson.dumps(data), mimetype="application/json") if not name and user and user.student and user.student.first_name and user.student.last_name: name = "%s %s" % (user.student.first_name, user.student.last_name) attendee = Attendee(email=email, name=name, student=student, event=event) try: attendee.save() except IntegrityError: data = {'valid': False, 'error': 'Duplicate checkin!'} return HttpResponse(simplejson.dumps(data), mimetype="application/json") if not student or student and not student.profile_created: if not student: txt_email_body_template = 'checkin_follow_up_email_body.txt' html_email_body_template = 'checkin_follow_up_email_body.html' if student and not student.profile_created: txt_email_body_template = 'checkin_follow_up_profile_email_body.txt' html_email_body_template = 'checkin_follow_up_profile_email_body.html' first_name = None if name: first_name = name.split(" ")[0] context = Context({ 'first_name': first_name, 'event': event, 'campus_org_event': is_campus_org(event.owner) }) context.update(get_basic_email_context()) subject = ''.join( render_to_string('email_subject.txt', { 'message': "Event Check-In Follow-up" }, context).splitlines()) recipients = [email] txt_email_body = render_to_string(txt_email_body_template, context) html_email_body = render_to_string(html_email_body_template, context) send_email(subject, txt_email_body, recipients, html_email_body) output = {'valid': True, 'email': email} if student and student.first_name and student.last_name: output['name'] = student.first_name + ' ' + student.last_name else: output['name'] = name return HttpResponse(simplejson.dumps(output), mimetype="application/json")
def event_checkin(request, event_id): event = Event.objects.get(pk=event_id) if request.method == 'GET': return HttpResponse(simplejson.dumps(get_attendees(event)), mimetype="application/json") else: email = request.POST.get('email', None).strip() if not is_valid_email(email): data = { 'valid': False, 'error': 'Please enter a valid .edu email!' } return HttpResponse(simplejson.dumps(data), mimetype="application/json") name = request.POST.get('name', None) student = None user = None if User.objects.filter(email=email).exists(): user = User.objects.get(email=email) if hasattr(user, 'student'): student = user.student if not name and not student: data = { 'valid': False, 'error': "This email isn't registered with Umeqo. Please enter your name!" } return HttpResponse(simplejson.dumps(data), mimetype="application/json") if Attendee.objects.filter(event=event, email=email).exists(): data = { 'valid': False, 'error': 'You\'ve already checked in!' } return HttpResponse(simplejson.dumps(data), mimetype="application/json") if not name and user and user.student and user.student.first_name and user.student.last_name: name = "%s %s" % (user.student.first_name, user.student.last_name) attendee = Attendee(email=email, name=name, student=student, event=event) try: attendee.save() except IntegrityError: data = { 'valid': False, 'error': 'Duplicate checkin!' } return HttpResponse(simplejson.dumps(data), mimetype="application/json") if not student or student and not student.profile_created: if not student: txt_email_body_template = 'checkin_follow_up_email_body.txt' html_email_body_template = 'checkin_follow_up_email_body.html' if student and not student.profile_created: txt_email_body_template = 'checkin_follow_up_profile_email_body.txt' html_email_body_template = 'checkin_follow_up_profile_email_body.html' first_name = None if name: first_name = name.split(" ")[0] context = Context({'first_name':first_name, 'event':event, 'campus_org_event': is_campus_org(event.owner)}) context.update(get_basic_email_context()) subject = ''.join(render_to_string('email_subject.txt', { 'message': "Event Check-In Follow-up" }, context).splitlines()) recipients = [email] txt_email_body = render_to_string(txt_email_body_template, context) html_email_body = render_to_string(html_email_body_template, context) send_email(subject, txt_email_body, recipients, html_email_body) output = { 'valid': True, 'email': email } if student and student.first_name and student.last_name: output['name'] = student.first_name + ' ' + student.last_name else: output['name'] = name return HttpResponse(simplejson.dumps(output), mimetype="application/json")