Пример #1
0
def index(request, template_name="playaevents/index.html"):
    badyears = [str(y) for y in range(2006, 2009)]
    years = Year.objects.exclude(year__in=badyears).order_by("-year")

    user = request.user
    if user and type(user) != AnonymousUser:
        my_events = PlayaEvent.objects.filter(year=get_current_year(True), creator=user)
        my_events = True if my_events.count() > 0 else False
    else:
        my_events = False

    log.debug("my_events %s", my_events)
    ctx = RequestContext(request, {"years": years, "my_events": my_events})

    return render_to_response(template_name, ctx)
Пример #2
0
def playa_event_search(request, year_year):

    if year_year is not None:
        if year_year == 'all':
            log.debug('searching all years')
            year = None
        else:
            year_year = str(year_year)
            log.debug('year = %s', year_year)
            year = get_object_or_404(Year, year=year_year)
    else:
        year = get_current_year()

    searchtext = request.GET.get('search', None)
    if searchtext is None:
        raise Http404('No search text sent')

    events = PlayaEvent.objects.search(searchtext, year=year_year)
    ids = [event.pk for event in events]
    ids = tuple(ids)
    filters = { 'event__id__in' : ids }

    if year is not None:
        filters['start_time__range'] = (year.event_start, year.event_end)

    occurrences = Occurrence.objects.select_related().filter(
        **filters).order_by('start_time')

    occ = [(dt, list(items))
              for dt, items in
              itertools.groupby(occurrences, lambda o: o.start_time.date())]


    ctx = RequestContext(
        request,
        {
            'searchtext' : searchtext,
            'searchtext_q' : urlquote_plus(searchtext),
            'year' : year,
            'events' : occ,
         })
    return render_to_response('playaevents/search.html', ctx)
Пример #3
0
def playa_events_by_day(
    request, year_year, playa_day=1, template="playaevents/playa_events_by_day.html", queryset=None
):
    """
    View a day's worth of playa events

    Context parameters:

    year_year: The 4 digit year
    playa_day: The current day of the festival, defined as the index into a
        list from event_start to event_end, starting with 1
    """

    year = get_object_or_404(Year, year=year_year)
    previous = int(year.year) - 1
    next = int(year.year) + 1

    event_date_list = year.daterange()
    log.debug("year daterange: %s", event_date_list)

    # Normalize playa_day to start at 0
    playa_day = int(playa_day) - 1

    date_ct = len(event_date_list) - 1

    if playa_day < 0:
        return HttpResponseBadRequest("Bad Request: No such playa day=%s", playa_day + 1)

    if playa_day > date_ct:
        return HttpResponseBadRequest("Bad Request: No such playa day=%s", playa_day + 1)

    playa_day_dt = event_date_list[playa_day]
    log.debug("playa_day: %s", playa_day_dt)
    previous_playa_day = playa_day - 1
    next_playa_day = playa_day + 1

    if previous_playa_day < 0:
        previous_playa_day = None
        previous_playa_day_dt = None
    else:
        previous_playa_day_dt = event_date_list[previous_playa_day]

    if next_playa_day > date_ct:
        next_playa_day = None
        next_playa_day_dt = None
    else:
        next_playa_day_dt = event_date_list[next_playa_day]

    if queryset:
        queryset = queryset._clone()
    else:
        queryset = Occurrence.objects.select_related().filter(
            event__playaevent__moderation="A", event__playaevent__list_online=True
        )

    dt_begin = datetime.combine(playa_day_dt, time(0))
    dt_end = datetime.combine(playa_day_dt, time(23, 30))

    occurrences = queryset.filter(start_time__range=(dt_begin, dt_end)).order_by(
        "-event__playaevent__all_day", "start_time"
    )

    # This is an optimization to avoid making 2 trips to the database. We want
    # a list of all the events that are all, and another with those that are
    # not.
    #
    # The below will cause 2 database round trips.
    # all_day_occurrences = occurrences.filter(event__playaevent__all_day=True)
    # timed_occurrences = occurrences.filter(event__playaevent__all_day=False)
    #
    # Instead, if we do an iterator over the original queryset, we can group
    # them in memory. It's important to sort the original queryset by all_day,
    # since it would otherwise cause strange results from itertools.groupby

    by_all_day = dict(
        [
            (all_day, list(items))
            for all_day, items in itertools.groupby(occurrences, lambda o: o.event.playaevent.all_day)
        ]
    )

    all_day_occurrences = by_all_day.setdefault(True)
    timed_occurrences = by_all_day.setdefault(False)
    curr_year = get_current_year()
    is_current_year = int(curr_year) == int(year_year)

    log.debug("year = %s, current_year = %s, current = %s", year, curr_year, is_current_year)

    if previous_playa_day is not None:
        previous_playa_day += 1

    if next_playa_day is not None:
        next_playa_day += 1

    data = dict(
        year=year,
        playa_day=playa_day,
        is_current_year=is_current_year,
        day=playa_day_dt,
        next=next,
        previous=previous,
        next_day=next_playa_day,
        next_day_dt=next_playa_day_dt,
        prev_day=previous_playa_day,
        prev_day_dt=previous_playa_day_dt,
        event_dates=event_date_list,
        all_day_occ=all_day_occurrences,
        timed_occ=timed_occurrences,
    )

    log.debug("data: %s %s %s", playa_day, previous_playa_day, next_playa_day)

    return render_to_response(template, data, context_instance=RequestContext(request))
Пример #4
0
from django.conf.urls.defaults import patterns, include, handler500, url
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.contrib import admin
from playaevents.utilities import get_current_year
admin.autodiscover()

handler500 # Pyflakes

curryear = get_current_year()

urlpatterns = patterns(
    '',
    url(r'^$', 'playaevents.views.index',
        name="index"),

    url(r'^admin/', include(admin.site.urls)),

    url(r'^api/0.2/', include('playaevents.api.urls')),

    url(r'^accounts/profile/create/$',
        'profiles.views.create_profile',
        name='profiles_create_profile'),

    url(r'^accounts/profile/edit/$',
        'profiles.views.edit_profile',
        name='profiles_edit_profile'),

    url(r'^accounts/profile/$',
        'bmprofile.views.my_profile',
Пример #5
0
def is_current_year(year):
    return str(year) == str(get_current_year())