コード例 #1
0
ファイル: views.py プロジェクト: swiharta/radres
def fullcal(request):
  c = ConferenceResource()
  ce = ConfEventResource()

  ce_json = cache.get('ce_json')
  if not ce_json:
    today = date.today()
    first = date(today.year, today.month, 1)
    first_prev = (first - relativedelta(months=4))
    first_next = (first + relativedelta(months=8))
    start = date_to_timezone(first_prev + relativedelta(days=22)) # 23rd is earliest day possibly displayed = leap year with 3/1 on Saturday
    end = date_to_timezone(first_next + relativedelta(days=12)) # 13th is latest day possibly displayed = last day of current month on Sunday

    ce_json = get_initial_json(ce, start__gte=start, start__lt=end)
    cache.set('ce_json', ce_json, 86400) # 60s x 60min x 24h = 86400s

  c_json = cache.get('c_json')
  if not c_json:
    c_json = get_initial_json(c)
    cache.set('c_json', c_json, 2592000) # i think this is the maximum possible

  divs = SortedDict(DIV_CHOICES)

  return direct_to_template(request, 'radcal/fullcal.html', extra_context = {
             'ce_json': ce_json,
             'c_json': c_json,
             'divs': divs,
             }
  )
コード例 #2
0
ファイル: views.py プロジェクト: swiharta/radres
def call(request):
  ef = EventFilterResource()
  se = ShiftEventResource()
  ce = ConfEventResource()
  s = ShiftResource()
  c = ConferenceResource()
  u = radprofile.resources.UserResource()

  sub = taxonomy.resources.SubspecialtyResource()

  for key, resource in [('se_json', se), ('ce_json', ce)]:
    if not cache.get(key):
      today = date.today()
      first = date(today.year, today.month, 1)
      first_prev = (first - relativedelta(months=1))
      first_next = (first + relativedelta(months=2))
      start = date_to_timezone(first_prev + relativedelta(days=22)) # 23rd is earliest day possibly displayed = leap year with 3/1 on Saturday
      end = date_to_timezone(first_next + relativedelta(days=12)) # 13th is latest day possibly displayed = last day of current month on Sunday

      json = get_initial_json(resource, start__gte=start, start__lt=end)
      cache.set(key, json, 43200) # 60s x 60min x 24h = 86400s
  #
  for key, resource in [('s_json', s), ('c_json', c), ('sub_json', sub)]: #('u_json', u)
    if not cache.get(key):
      json = get_initial_json(resource)
      cache.set(key, json, 2592000) # i think this is the maximum possible

  if not cache.get('u_json'):
    u_json = get_initial_json(u)
    cache.set('u_json', u_json, 2592000) # i think this is the maximum possible
  #
  for key, resource in [('ef_json', ef)]:
    json = get_initial_json(resource)
    cache.set(key, json, 2592000) # i think this is the maximum possible

  return direct_to_template(request, 'radcal/call.html', extra_context = {
               'se_json': cache.get('se_json'),
               'ce_json': cache.get('ce_json'),
               's_json': cache.get('s_json'),
               'c_json': cache.get('c_json'),
               'u_json': cache.get('u_json'),
               'sub_json': cache.get('sub_json'),
               'ef_json': cache.get('ef_json'),
               'divs': SortedDict(DIV_CHOICES)
               }
  )
コード例 #3
0
ファイル: views.py プロジェクト: swiharta/radres
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)})