def shift_table(request): today = date.today() end = today + timedelta(weeks=10) days = daterange(today, end) day_events = group_by_date_sorted(ShiftEvent.objects.filter(date__gte=today, date__lte=end).order_by('date').select_related()) shifts = Shift.objects.all() return object_list(request, queryset=ShiftEvent.objects.all().select_related(), template_name="radcal/shift_table.html", # template_object_name="event", extra_context={'day_events': day_events, "shifts": shifts, 'days': days})# shift_formset})
def conferences(request): # returns html fragments for navigating weekly conferences today = date.today() if request.GET.get('sunday'): sunday_string = request.GET.get('sunday') sunday = datetime.strptime(sunday_string, '%m-%d-%y') saturday = sunday + timedelta(days=6) next_sunday = sunday + timedelta(days = 7) prev_sunday = sunday - timedelta(days = 7) conf_week = ConfEvent.objects.filter(start__gte=sunday, start__lte=saturday).order_by('start') conf_days = group_by_date_sorted(conf_week) else: prev_sunday = next_sunday = conf_days = [1,2] return direct_to_template(request, 'radcal/conf_week.html', extra_context = {'conferences':conf_days, 'prev_sunday': prev_sunday, 'next_sunday': next_sunday, 'today': today})
def home(request): today = date.today()# + timedelta(days = 1) tomorrow = today + timedelta(days = 1) today_weekday = today.weekday() # sunday = 6, monday = 0 sunday = date_to_timezone(today - timedelta(days = today_weekday+1)) saturday = date_to_timezone(today + timedelta(days = 5-today_weekday)) if today_weekday > 4: # if weekend, show conferences for next week sunday = sunday + timedelta(days = 7) saturday = saturday + timedelta(days = 7) next_sunday = sunday + timedelta(days = 7) prev_sunday = sunday - timedelta(days = 7) conf_week = cache.get('conf_week') if not conf_week: conf_week = ConfEvent.objects.filter(start__gte=sunday, start__lte=saturday).order_by('start') cache.set('conf_week', conf_week, 4800) if conf_week: conf_days = group_by_date_sorted(conf_week) else: conf_days = [] if request.GET.get('new_month'): month_string = request.GET.get('new_month') month = int(month_string.split(' ')[0]) year = int(month_string.split(' ')[1]) print month, year first = date(year, month, 1) else: first = date(today.year, today.month, 1) year = date.today().year month = date.today().month next_first = first + relativedelta(months=+1) horizon = today + timedelta(days = 7) updated = get_last_update_time() if request.user.is_authenticated(): user_events = ShiftEvent.objects.filter(user=request.user) cal_events = user_events.filter(date__gte=first,date__lt=next_first).order_by('date').select_related() upcoming_ids = get_upcoming_ids(request.user, user_events, today, horizon) user_conflict_ids = get_user_conflict_ids(request.user) user_agenda_ids = set(upcoming_ids) | set(user_conflict_ids) agenda = ShiftEvent.objects.filter(id__in=user_agenda_ids).order_by('date').select_related() htmlcal = UserCalendar(cal_events) htmlcal.setfirstweekday(6) # 6 = Sunday cal = htmlcal.formatmonth(year, month) # ---Below combines this week's conf_events and user shift_events into `conferences`--- # agenda_qsets = sorted(chain(conf_week, user_agenda),key=attrgetter('date'))= # conference_days = group_by_date(conf_week) # takes a QuerySet or sorted, chained QuerySets, as above # conferences = [] # week_list = [ sunday + timedelta(days=x) for x in range(0,7) ] # for weekday in week_list: # day = {'date': weekday, 'classes': weekday.strftime('%a ')} # if not weekday == today: # day['classes'] += 'inactive ' # else: # day['classes'] += 'active today ' # if weekday in conference_days: # events = [] # for event in conference_days[weekday]: # event.classes = event.get_classes() # events.append(event) # day['events'] = events # else: # day['classes'] += 'empty ' # day['events'] = [] # conferences.append(day) else: agenda = cal = user_conflict_ids = user_events = [1,2] # some stupid bug, these vars need to be iterables if request.GET.get('new_month') and request.is_ajax(): # returns new month html fragment for agenda calendar return direct_to_template(request, 'radcal/calendar.html', extra_context = {'calendar':mark_safe(cal)}) if request.is_ajax(): return HttpResponse(simplejson.dumps({'location': '/'}), mimetype="application/json") return direct_to_template(request, 'radres.html', extra_context = {'agenda': agenda, 'today': today, 'tomorrow': tomorrow,#'start': sunday, 'end': saturday, 'calendar': mark_safe(cal), 'conferences': conf_days,#'old_agenda': agenda, 'prev_sunday': prev_sunday, 'next_sunday': next_sunday, 'conflicts': user_conflict_ids, 'updated': updated, 'no_user_events': bool(not user_events)})