Example #1
0
def view_event(request, slug):
    """View event view."""
    event = get_object_or_404(Event, slug=slug)
    attendees = event.attendees.exclude(groups__name='Mozillians')
    event_url = reverse('events_view_event', kwargs={'slug': slug})
    email_att_initial = {
        'subject': event.name,
        'body': '%s\n%s' % (event.name, settings.SITE_URL + event_url)}
    email_att_form = EmailUsersForm(attendees, initial=email_att_initial)

    if request.method == 'POST':
        if not request.user.is_authenticated():
            messages.error(request, 'Permission Denied')
            return redirect('main')

        event_comment = EventComment(event=event, user=request.user)
        event_comment_form = forms.EventCommentForm(request.POST,
                                                    instance=event_comment)
        if event_comment_form.is_valid():
            event_comment_form.save()
            messages.success(request, 'Comment saved')

            # provide new clean form
            event_comment_form = forms.EventCommentForm()
    else:
        event_comment_form = forms.EventCommentForm()

    return render(request, 'view_event.html',
                  {'event': event, 'email_attendees_form': email_att_form,
                   'similar_events': event.get_similar_events(),
                   'comments': event.eventcomment_set.all(),
                   'event_comment_form': event_comment_form,
                   'event_comment_form_url': event_url})
Example #2
0
def view_event(request, slug):
    """View event view."""
    event = get_object_or_404(Event, slug=slug)
    attendees = event.attendees.exclude(groups__name='Mozillians')
    event_url = reverse('events_view_event', kwargs={'slug': slug})
    email_att_initial = {
        'subject': event.name,
        'body': '%s\n%s' % (event.name, settings.SITE_URL + event_url)
    }
    email_att_form = EmailUsersForm(attendees, initial=email_att_initial)

    # Display a message if the event owner needs to submit post event data
    if (request.user == event.owner and event.is_past_event
            and event.has_new_metrics and not any([
                metric.outcome
                for metric in event.eventmetricoutcome_set.all()
            ])):
        msg = render_to_string('includes/view_post_event_metrics.jinja',
                               {'event': event})
        messages.info(request, mark_safe(msg))

    if request.method == 'POST':
        if not request.user.is_authenticated():
            messages.error(request, 'Permission Denied')
            return redirect('main')

        event_comment = EventComment(event=event, user=request.user)
        event_comment_form = forms.EventCommentForm(request.POST,
                                                    instance=event_comment)
        if event_comment_form.is_valid():
            event_comment_form.save()
            messages.success(request, 'Comment saved')
            statsd.incr('events.create_comment')

            # provide new clean form
            event_comment_form = forms.EventCommentForm()
    else:
        event_comment_form = forms.EventCommentForm()

    return render(
        request, 'view_event.jinja', {
            'event': event,
            'email_attendees_form': email_att_form,
            'similar_events': event.get_similar_events(),
            'comments': event.eventcomment_set.all(),
            'event_comment_form': event_comment_form,
            'event_comment_form_url': event_url
        })