Пример #1
0
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")
Пример #2
0
def event_checkin_count(request):
    data = {
        'count':
        len(get_attendees(Event.objects.get(id=request.GET["event_id"])))
    }
    return HttpResponse(simplejson.dumps(data), mimetype="application/json")
Пример #3
0
def event_page(request, id, slug, extra_context=None):
    if is_student(request.user) and not request.user.student.profile_created:
        return redirect('student_profile')
    try:
        event = Event.objects.get(pk=id)
    except:
        raise Http404("Event with id '%s' does not exist." % id)
    if not event.is_public:
        if not request.user.is_authenticated():
            raise Http403(
                "This event is private. You do not have permission to view it."
            )
        elif is_campus_org(request.user):
            if request.user != event.owner:
                raise Http403(
                    "This event is private. You do not have permission to view it."
                )
        elif is_recruiter(request.user):
            if request.user != event.owner and request.user.recruiter.employer not in event.attending_employers.all(
            ):
                raise Http403(
                    "This event is private. You do not have permission to view it."
                )
        elif is_student(request.user):
            try:
                Invitee.objects.get(event=event, student=request.user.student)
            except:
                raise Http403(
                    "This event is private. You do not have permission to view it."
                )

    current_site = Site.objects.get(id=s.SITE_ID)

    page_url = 'http://' + current_site.domain + event.get_absolute_url()
    #google_description is the description + stuff to link back to umeqo
    google_description = event.description + '\n\nRSVP and more at %s' % page_url

    context = {
        'page_url': page_url,
        'DOMAIN': current_site.domain,
        'current_site': "http://" + current_site.domain,
        'google_description': google_description
    }

    if len(event.audience.all()) > 0:
        context['audience'] = event.audience.all()

    if is_campus_org(event.owner):
        context['campus_org_event'] = True
        context['attending_employers'] = event.attending_employers
        if is_campus_org(request.user):
            context['can_edit'] = (event.owner == request.user)
            context['show_admin'] = (event.owner == request.user)
            context['recruiters_with_access'] = map(
                lambda x: {
                    'name': "%s %s" % (x.first_name, x.last_name),
                    'email': x.email
                },
                User.objects.filter(
                    recruiter__employer__in=event.attending_employers.all()).
                order_by("first_name"))
        elif is_recruiter(request.user):
            context[
                'show_admin'] = request.user.recruiter.employer in event.attending_employers.all(
                )
    elif is_recruiter(event.owner):
        if is_recruiter(request.user):
            context[
                'can_edit'] = request.user.recruiter in event.owner.recruiter.employer.recruiter_set.all(
                )
            context[
                'show_admin'] = request.user.recruiter in event.owner.recruiter.employer.recruiter_set.all(
                )

    if context.has_key('show_admin'):
        attendees = get_attendees(event)
        rsvps = get_rsvps(event)
        context['invitees'] = get_invitees(event)

        if event.is_drop:
            dropped_resumes = get_dropped_resumes(event)
        else:
            dropped_resumes = []

        if not event.is_public:
            no_rsvps = get_no_rsvps(event)
        else:
            no_rsvps = []

        context.update({
            'rsvps': rsvps,
            'no_rsvps': no_rsvps,
            'dropped_resumes': dropped_resumes,
            'attendees': attendees
        })

    # Increase the view count if we're not admin, a campus org or a recruiter (aka for now just student & anonymous)
    if not is_campus_org(request.user) and not is_recruiter(
            request.user) and not request.user.is_staff:
        event.view_count += 1
        event.save()

    if is_student(request.user):
        responded, attending, dropped_resume, attended, event = event_map(
            event, request.user)
        context['responded'] = responded
        context['attending'] = attending
        context['dropped_resume'] = dropped_resume
        context['attended'] = attended
    else:
        context['email_delivery_type'] = core_enums.EMAIL
    context['event'] = event
    context.update(extra_context or {})
    return context
Пример #4
0
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")
Пример #5
0
def event_checkin_count(request):
    data = {'count':len(get_attendees(Event.objects.get(id=request.GET["event_id"])))}
    return HttpResponse(simplejson.dumps(data), mimetype="application/json")
Пример #6
0
def event_page(request, id, slug, extra_context=None):
    if is_student(request.user) and not request.user.student.profile_created:
        return redirect('student_profile')
    try:
        event = Event.objects.get(pk=id)
    except:
        raise Http404("Event with id '%s' does not exist." % id)
    if not event.is_public:
        if not request.user.is_authenticated():
            raise Http403("This event is private. You do not have permission to view it.")
        elif is_campus_org(request.user):
            if request.user != event.owner:
                raise Http403("This event is private. You do not have permission to view it.")
        elif is_recruiter(request.user):
            if request.user != event.owner and request.user.recruiter.employer not in event.attending_employers.all():
                raise Http403("This event is private. You do not have permission to view it.")
        elif is_student(request.user):
            try:
                Invitee.objects.get(event=event, student=request.user.student)
            except:
                raise Http403("This event is private. You do not have permission to view it.")

    current_site = Site.objects.get(id=s.SITE_ID)

    page_url = 'http://' + current_site.domain + event.get_absolute_url()
    #google_description is the description + stuff to link back to umeqo
    google_description = event.description + '\n\nRSVP and more at %s' % page_url
    
    context = {
        'page_url': page_url,
        'DOMAIN': current_site.domain,
        'current_site':"http://" + current_site.domain,
        'google_description': google_description
    }
        
    if len(event.audience.all()) > 0:
        context['audience'] = event.audience.all()
    
    if is_campus_org(event.owner):
        context['campus_org_event'] = True
        context['attending_employers'] = event.attending_employers
        if is_campus_org(request.user):
            context['can_edit'] = (event.owner == request.user)
            context['show_admin'] = (event.owner == request.user)
            context['recruiters_with_access'] = map(lambda x: {'name':"%s %s" % (x.first_name, x.last_name), 'email': x.email}, User.objects.filter(recruiter__employer__in=event.attending_employers.all()).order_by("first_name"))
        elif is_recruiter(request.user):
            context['show_admin'] = request.user.recruiter.employer in event.attending_employers.all()
    elif is_recruiter(event.owner):
        if is_recruiter(request.user):
            context['can_edit'] = request.user.recruiter in event.owner.recruiter.employer.recruiter_set.all()
            context['show_admin'] = request.user.recruiter in event.owner.recruiter.employer.recruiter_set.all()
    
    if context.has_key('show_admin'):
        attendees = get_attendees(event)
        rsvps =  get_rsvps(event)
        context['invitees'] = get_invitees(event)
        
        if event.is_drop:
            dropped_resumes = get_dropped_resumes(event)
        else:
            dropped_resumes = []

        if not event.is_public:
            no_rsvps = get_no_rsvps(event)
        else:
            no_rsvps = []
            
        context.update({
        'rsvps':rsvps,
        'no_rsvps': no_rsvps,
        'dropped_resumes': dropped_resumes,
        'attendees': attendees
        });
    
    # Increase the view count if we're not admin, a campus org or a recruiter (aka for now just student & anonymous)
    if not is_campus_org(request.user) and not is_recruiter(request.user) and not request.user.is_staff:
        event.view_count += 1
        event.save()
    
    if is_student(request.user):
        responded, attending, dropped_resume, attended, event = event_map(event, request.user)
        context['responded'] = responded
        context['attending'] = attending
        context['dropped_resume'] = dropped_resume
        context['attended'] = attended
    else:
        context['email_delivery_type'] = core_enums.EMAIL
    context['event'] = event
    context.update(extra_context or {})
    return context