Exemple #1
0
def attend(request, event_id, template='event/event_registration_form.html'):
    """Process event registration."""
    event = get_object_or_404(Event.objects.active(), pk=event_id)
    if event.attendee_set.filter(attendee=request.user).count():
        request.user.message_set.create(message=_('You have already added this show to your list.'))
        return HttpResponseRedirect(reverse('view_event', kwargs={'event_id':event.pk}))
    try:
        qualifies, reasons = event.is_user_qualified(request.user)
        user_profile=request.user.get_profile()
        data = None
        if qualifies and request.user.first_name and request.user.last_name:
            # Skip the form and directly register this event attendee.
            data = {'first_name':request.user.first_name, 
                    'last_name':request.user.last_name,
                    'birth_date':user_profile.birth_date,
                    'post_to_tweeter':request.REQUEST.get('post_to_tweeter', False)}
        if data or request.method == 'POST':
            if request.method == 'POST':
                data = request.POST
            form = forms.DirectAttendeeForm(data=data, event=event, user_profile=user_profile)
            if form.is_valid():
                attendee = form.save(commit=True)
                if not attendee:
                    return HttpResponseRedirect(reverse('view_event', kwargs={'event_id':event.pk}))
                if form.cleaned_data.get('post_to_tweeter', False):
                    # Post to Twitter
                    status = settings.TWITTER_EVENT_STATUS_FORMAT % {'event_name':event.short_name_for_twitter, 'event_url':event.get_short_url()}
                    post_to_twitter(request.user, status)
                _log.info('Attendee processed %s', attendee)
                if attendee.qty > 1:
                    request.user.message_set.create(message=_('This show has been added to your list.'))
                else:
                    request.user.message_set.create(message=_('This show has been added to your list.'))
                return HttpResponseRedirect(reverse('view_event', kwargs={'event_id':event_id}))
        else:
            form = forms.DirectAttendeeForm(event=event, user_profile=user_profile)
        ctx = {'event':event, 'c':event, 'form':form}
    except EventError, e:
        request.user.message_set.create(message=e.message)
        return HttpResponseRedirect(reverse('view_event', kwargs={'event_id':event.pk}))
Exemple #2
0
def post_status(request):
    mesg = None
    ret_ctx = {} # The return context sent to AJAX callers
    ret_ctx['success'] = False
    if request.method == 'POST':
        status = request.POST.get('status_text', '').strip()
        if not status:
            status = request.POST.get('status', '').strip()
        mesg = u"Status could not be posted to Twitter."
        if status:
            status = TWITTER_GENERAL_STATUS_FORMAT % {'status':status}
            posted = post_to_twitter(request.user, status)
            if posted:
                mesg = u"Status posted to Twitter!"
                ret_ctx['success'] = True
    if request.is_ajax():
        ret_ctx['message'] = mesg
        return HttpResponse(simplejson.dumps(ret_ctx), mimetype='application/json')
    if mesg:
        request.user.message_set.create(message=mesg)
    next = request.REQUEST.get('next', '')
    if not next:
        next = reverse('home')
    return HttpResponseRedirect(next)