def week(some_date, autoescape=None): return year_and_week(some_date)[1]
def week_url(self): return reverse('baljan.views.call_duty_week', args=year_and_week(self.when) )
def high_score(request, year=None, week=None): if year is None or week is None: year, week = year_and_week() else: year = int(year) week = int(week) tpl = {} today = date.today() end_offset = relativedelta(hours=23, minutes=59, seconds=59) end_of_today = today + end_offset interval_starts = [ (relativedelta(days=1), _("Today")), (relativedelta(days=7), _("Last %d Days") % 7), (relativedelta(days=30), _("Last %d Days") % 30), (relativedelta(days=90), _("Last %d Days") % 90), (relativedelta(days=2000), _("Forever")), ] if request.GET.has_key('format'): format = request.GET['format'] high_scores = [] for delta, title in interval_starts: high_scores.append({ 'consumers': stats.top_consumers( end_of_today - delta, end_of_today, simple=True )[:20], 'title': title, }) if format == 'json': return HttpResponse( simplejson.dumps({'high_scores': high_scores}), mimetype='text/plain', ) else: return HttpResponse("INVALID FORMAT", mimetype='text/plain') fetched_stats = [] fetched_section_stats = [] if settings.STATS_CACHE: for cache_key in stats.CACHE_KEYS: got = cache.get(cache_key) if got is not None: fetched_stats += got for cache_key in stats.CACHE_KEYS_GROUP: got = cache.get(cache_key) if got is not None: fetched_section_stats += got else: s = stats.Stats() intervals = ['today', 'yesterday', 'this_week'] intervals += ['last_week', 'this_semester', 'total'] fetched_stats = [s.get_interval(i) for i in intervals] ss = stats.SectionStats() intervals = ['today', 'yesterday', 'this_week'] intervals += ['last_week', 'this_semester', 'total'] fetched_section_stats = [ss.get_interval(i) for i in intervals] tpl['stats'] = fetched_stats tpl['section_stats'] = fetched_section_stats return render_to_response('baljan/high_score.html', tpl, context_instance=RequestContext(request))
def current_week(): return BoardWeek(*year_and_week())
def call_duty_week(request, year=None, week=None): user = request.user if year is None or week is None: year, week = year_and_week() plan = planning.BoardWeek.current_week() else: year = int(year) week = int(week) plan = planning.BoardWeek(year, week) oncall_ids = [[str(oc.id) for oc in sh] for sh in plan.oncall()] dom_ids = plan.dom_ids() real_ids = dict(zip(dom_ids, plan.shift_ids())) oncall = dict(zip(dom_ids, oncall_ids)) avails = plan.available() uids = [str(u.id) for u in avails] pics = [] for pic in [u.get_profile().picture for u in avails]: if pic: pics.append("%s%s" % (settings.MEDIA_URL, pic)) else: pics.append(False) id_pics = dict(zip(uids, pics)) names = [u.get_full_name() for u in avails] initials = all_initials(avails) id_initials = dict(zip(uids, initials)) disp_names = ["%s (%s)" % (name, inits) for name, inits in zip(names, initials)] disp_names = [htmlents(dn) for dn in disp_names] disp_names = [" ".join(dn.split()) for dn in disp_names] id_disp_names = dict(zip(uids, disp_names)) drag_ids = ['drag-%s' % i for i in initials] drags = [] for drag_id, disp_name, pic in zip(drag_ids, disp_names, pics): if pic: drags.append('<span id="%s"><img src="%s" title="%s"/></span>' % (drag_id, pic, disp_name)) else: drags.append('<span id="%s">%s</span>' % (drag_id, disp_name)) id_drags = dict(zip(uids, drags)) if request.method == 'POST' and request.is_ajax(): initial_users = dict(zip(initials, avails)) dom_id_shifts = dict(zip(dom_ids, plan.shifts)) for dom_id, shift in zip(dom_ids, plan.shifts): old_users = User.objects.filter(oncallduty__shift=shift).distinct() new_users = [] if request.POST.has_key(dom_id): new_users = [initial_users[x] for x in request.POST[dom_id].split('|')] for old_user in old_users: if not old_user in new_users: shift.oncallduty_set.filter(user=old_user).delete() for new_user in new_users: if not new_user in old_users: o, created = baljan.models.OnCallDuty.objects.get_or_create( shift=shift, user=new_user ) assert created messages.add_message(request, messages.SUCCESS, _("Your changes were saved.")) return HttpResponse(simplejson.dumps({'OK':True})) adjacent = adjacent_weeks(week_dates(year, week)[0]) tpl = {} tpl['week'] = week tpl['year'] = year tpl['prev_y'] = adjacent[0][0] tpl['prev_w'] = adjacent[0][1] tpl['next_y'] = adjacent[1][0] tpl['next_w'] = adjacent[1][1] tpl['real_ids'] = simplejson.dumps(real_ids) tpl['oncall'] = simplejson.dumps(oncall) tpl['drags'] = simplejson.dumps(id_drags) tpl['initials'] = simplejson.dumps(id_initials) tpl['pictures'] = simplejson.dumps(id_pics) tpl['uids'] = simplejson.dumps(uids) return render_to_response('baljan/call_duty_week.html', tpl, context_instance=RequestContext(request))