Beispiel #1
0
def calendar(request, limit=10, template='event/tags/event_calendar.html'):
    """Render event calendar for the logged in user"""
    from event.templatetags.eventtags import gcal_url
    try:
        ctx = {}
        if not request.user.is_authenticated:
            if request.is_ajax():
                raise Http404
            return HttpResponseRedirect("%s?next=%s" % (reverse("login"), reverse("list_events")))
        ctx['next'] = request.META.get('HTTP_REFERER', reverse("list_events"))
        event_id = request.REQUEST.get("event_id", "");
        # If there's an event_id, we are on the event detail page
        event = event_id and get_or_none(Event.objects.active(), pk=event_id) or None
        events = Event.objects.active().filter(
            attendee__attendee_profile=request.user_profile
        ).distinct().order_by('event_date', 'event_start_time', 'pk')
        if settings.CALENDAR_FILTER_BY_LOCATION:
            events = events.filter(location__in=('destination', 'user-entered', request.location))
        ctx['calendar_count'] = events.count()
        if limit:
            events = events[:int(limit)]
        ctx['events'] = events
        if event:
            ctx['next'] = event.get_absolute_url()
            ctx['event'] = event
            ctx['gcal_url'] = gcal_url(event)
            if request.user_profile and request.user_profile.attendee_set.filter(event=event).count():
                ctx['show_remove_event'] =  True
            else:
                ctx['show_add_event'] =  True
            ctx['is_owner'] = request.user.is_authenticated() and \
                                        ((event.creator and request.user.id == event.creator.user.id) or \
                                        (request.user.id == event.artist.user_profile.user.id))
            ctx['is_admin'] = request.user.has_perm('event.can_manage_events')
        return render_view(request, template, ctx)
    except Exception, e:
        _log.exception(e)
        raise
Beispiel #2
0
def view(request, event_id, event=None, template='event/detail.html'):
    """Event detail view"""
    from event.templatetags.eventtags import gcal_url
    ctx = {}
    if not event:
        event = get_object_or_404(Event.visible_objects.select_related('creator__user', 'artist__user_profile__user', 'venue'), pk=event_id)
    sharer_id = request.session.get("sharer_profile_%s" % event.pk, None)
    if sharer_id:
        if settings.DEV_MODE or not request.user.is_authenticated() or (int(request.user.pk) != int(sharer_id)):
            sharer_profile = get_object_or_404(UserProfile.objects.active(), user__pk=sharer_id)
            ctx['sharer_profile'] = sharer_profile
    if event.location not in ('destination', 'user-entered'):
        location = event.location
        request.location = location # stick user to this location going forward
        request.location_name = settings.LOCATION_DATA.get(location, settings.EMPTY_LOCATION_DATA)[3]
        ctx['event_location_name'] = request.location_name
    ctx['is_owner'] = request.user.is_authenticated() and \
        ((event.creator and request.user.id == event.creator.user.id) or \
        (request.user.id == event.artist.user_profile.user.id))
    ctx['is_admin'] = request.user.has_perm('event.can_manage_events')
    # Event changes, if available, are shown only to the event owner and the admin.
    ctx['changes'] = False # (ctx['is_owner'] or ctx['is_admin']) and event.changed_version
    if not event.is_approved:
        # Only admins and event owners may see unapproved events.
        if not request.user.is_authenticated():
            return HttpResponseRedirect("%s?next=%s" % (reverse('login'), request.path))
        if not (ctx['is_owner'] or ctx['is_admin']):
            # We could return an HTTP forbidden response here but we don't want a malicious user
            # to know if a event even exists with this id.
            # So, we raise a 404 - Page Not Found instead.
            raise Http404
    if request.user.is_authenticated():
        event.is_attending = event.attendee_set.filter(attendee_profile=request.user_profile).count()
        share_url = event.get_short_url_for_sharer(request.user.pk)
        full_share_url = event.get_full_url_for_sharer(request.user.pk)
    else:
        share_url = event.get_short_url()
        full_share_url = event.get_absolute_url()
    ctx['full_share_url'] = full_share_url
    ctx['share_url'] = share_url
    ctx['share_url_or_none'] = len(share_url) < 25 and share_url or None
    ctx['e'] = event
    ctx['event'] = event
    if request.user.is_authenticated():
        ctx['comment_form'] = forms.EventCommentForm(author=request.user, target_instance=event)
    ctx['twitter_label'] = u'Tweet this show'
    ctx['twitter_status'] = settings.TWITTER_EVENT_STATUS_FORMAT % {'event_name':event.short_name_for_twitter, 'event_url':event.get_short_url()}
    ctx['interested_count'] = event.interested_count
    ctx['gcal_url'] = gcal_url(event)
    stats = event.stats
    if not ctx['is_owner']:
        stats.num_views = stats.num_views + 1
        stats.save()
    else:
        # set context if this is the event owner's first visit to this page
        stats.num_owner_views = stats.num_owner_views + 1
        stats.save()
    ctx['stats'] = stats
    ctx['is_owner_first_visit'] = (ctx['is_owner'] and stats.num_owner_views == 1)  # or settings.DEV_MODE
    ctx['needs_fbml'] = True
    ctx['interested'] = event.get_interested()
    return render_view(request, template, ctx)