def get_paginator(self, request, queryset, per_page, orphans=0, allow_empty_first_page=True): # Cloned # from conference.admin.TalkAdmin talks = cdata.talks_data(queryset.values_list('talk__id', flat=True)) self.cached_talks = dict([(x['id'], x) for x in talks]) sids = [s['id'] for t in talks for s in t['speakers']] profiles = cdata.profiles_data(sids) self.cached_profiles = dict([(x['id'], x) for x in profiles]) return super(P3TalkAdmin, self).get_paginator(request, queryset, per_page, orphans, allow_empty_first_page)
def get_paginator(self, request, queryset, per_page, orphans=0, allow_empty_first_page=True): # utilizzo dataaccess per fare una sola query verso il db, in questo # modo ho subito tutti i dati pronti (utile ad esempio per mostrare i # nomi degli speaker) talks = dataaccess.talks_data(queryset.values_list('id', flat=True)) self.cached_talks = dict([(x['id'], x) for x in talks]) sids = [ s['id'] for t in talks for s in t['speakers'] ] profiles = dataaccess.profiles_data(sids) self.cached_profiles = dict([(x['id'], x) for x in profiles]) return super(TalkAdmin, self).get_paginator(request, queryset, per_page, orphans, allow_empty_first_page)
def schedule_view_talks(self, conf): tids = [] if conf.code == settings.CONFERENCE: results = utils.voting_results() if results is not None: tids = map(lambda x: x[0], results) complete = models.Talk.objects\ .filter(conference=conf.code)\ .order_by('title')\ .values_list('id', flat=True) haystack = set(tids) missing = [] for c in complete: if c not in haystack: missing.append(c) return dataaccess.talks_data(missing + tids)
def warmup_conference_cache(conference=None): """ """ if conference is None: conference = settings.CONFERENCE_CONFERENCE qs = ConferenceModels.TalkSpeaker.objects\ .filter(talk__conference=conference)\ .values_list('talk', 'speaker') talks = set() speakers = set() for row in qs: talks.add(row[0]) speakers.add(row[1]) return { 'speakers': dict([ (x['id'], x) for x in dataaccess.profiles_data(speakers) ]), 'talks': dict([ (x['id'], x) for x in cdataaccess.talks_data(talks) ]), }
def conference_speakers_day(conf, code=None): from p3 import dataaccess from conference.dataaccess import talks_data from conference.dataaccess import events schedules = cmodels.Schedule.objects.filter(conference=conf) data = {} for s in schedules: people = dataaccess.profiles_data(s.speakers()\ .order_by('user__first_name', 'user__last_name')\ .values_list('user', flat=True)) people_data = [] for p in people: o = { 'uid': p['id'], 'email': p['email'], 'name': p['name'], 'phones': [p['phone']], 'talks': p['talks']['accepted'].get(conf, []), } people_data.append(o) data[s.date.strftime('%Y-%m-%d')] = people_data if code is None: output = [] for date, peoples in sorted(data.items()): output.append({ 'id': 'd%s' % date, 'title': date, 'total': len(peoples), }) return output else: people_data = data[code[1:]] conf_events = dict([(x['id'], x) for x in events(conf=conf)]) tracks = defaultdict(list) for p in people_data: tickets = [ tid for tid, _, fare, complete in dataaccess.all_user_tickets( p['uid'], conf) if complete and fare.startswith('SIM') ] if tickets: p['phones'].extend( models.TicketSIM.objects\ .filter(ticket__in=tickets)\ .values_list('number', flat=True)) p['phones'] = filter(None, p['phones']) for talk in talks_data(p['talks']): for event_id in talk['events_id']: if conf_events[event_id]['time'].date().strftime( '%Y-%m-%d') == code[1:]: for track in conf_events[event_id]['tracks']: if p not in tracks[track]: tracks[track].append(p) output = { 'columns': ( ('name', 'Name'), ('email', 'Email'), ('phones', 'Phones'), ('track', 'Track'), ), 'data': [], } data = output['data'] for track, people in sorted(tracks.items()): for x in people: data.append({ 'name': '<a href="%s">%s</a>' % (reverse('admin:auth_user_change', args=(x['uid'], )), x['name']), 'email': x['email'], 'uid': x['uid'], 'phones': ', '.join(x['phones']), 'track': track, }) return output
def conference_speakers_day(conf, code=None): from p3 import dataaccess from conference.dataaccess import talks_data from conference.dataaccess import events schedules = cmodels.Schedule.objects.filter(conference=conf) data = {} for s in schedules: people = dataaccess.profiles_data(s.speakers()\ .order_by('user__first_name', 'user__last_name')\ .values_list('user', flat=True)) people_data = [] for p in people: o = { 'uid': p['id'], 'email': p['email'], 'name': p['name'], 'phones': [p['phone']], 'talks': p['talks']['accepted'].get(conf, []), } people_data.append(o) data[s.date.strftime('%Y-%m-%d')] = people_data if code is None: output = [] for date, peoples in sorted(data.items()): output.append({ 'id': 'd%s' % date, 'title': date, 'total': len(peoples), }) return output else: people_data = data[code[1:]] conf_events = dict([(x['id'], x) for x in events(conf='ep2013')]) tracks = defaultdict(list) for p in people_data: tickets = [ tid for tid, _, fare, complete in dataaccess.all_user_tickets(p['uid'], conf) if complete and fare.startswith('SIM') ] if tickets: p['phones'].extend( models.TicketSIM.objects\ .filter(ticket__in=tickets)\ .values_list('number', flat=True)) p['phones'] = filter(None, p['phones']) for talk in talks_data(p['talks']): for event_id in talk['events_id']: if conf_events[event_id]['time'].date().strftime('%Y-%m-%d') == code[1:]: for track in conf_events[event_id]['tracks']: if p not in tracks[track]: tracks[track].append(p) output = { 'columns': ( ('name', 'Name'), ('email', 'Email'), ('phones', 'Phones'), ('track', 'Track'), ), 'data': [], } data = output['data'] for track, people in sorted(tracks.items()): for x in people: data.append({ 'name': '<a href="%s">%s</a>' % ( reverse('admin:auth_user_change', args=(x['uid'],)), x['name']), 'email': x['email'], 'uid': x['uid'], 'phones': ', '.join(x['phones']), 'track': track, }) return output
def conference_speakers_day(conf, code=None): from p3 import dataaccess from conference.dataaccess import talks_data from conference.dataaccess import events schedules = cmodels.Schedule.objects.filter(conference=conf) data = {} for s in schedules: people = dataaccess.profiles_data( s.speakers().order_by("user__first_name", "user__last_name").values_list("user", flat=True) ) people_data = [] for p in people: o = { "uid": p["id"], "email": p["email"], "name": p["name"], "phones": [p["phone"]], "talks": p["talks"]["accepted"].get(conf, []), } people_data.append(o) data[s.date.strftime("%Y-%m-%d")] = people_data if code is None: output = [] for date, peoples in sorted(data.items()): output.append({"id": "d%s" % date, "title": date, "total": len(peoples)}) return output else: people_data = data[code[1:]] conf_events = dict([(x["id"], x) for x in events(conf=conf)]) tracks = defaultdict(list) for p in people_data: tickets = [ tid for tid, _, fare, complete in dataaccess.all_user_tickets(p["uid"], conf) if complete and fare.startswith("SIM") ] if tickets: p["phones"].extend(models.TicketSIM.objects.filter(ticket__in=tickets).values_list("number", flat=True)) p["phones"] = filter(None, p["phones"]) for talk in talks_data(p["talks"]): for event_id in talk["events_id"]: if conf_events[event_id]["time"].date().strftime("%Y-%m-%d") == code[1:]: for track in conf_events[event_id]["tracks"]: if p not in tracks[track]: tracks[track].append(p) output = { "columns": (("name", "Name"), ("email", "Email"), ("phones", "Phones"), ("track", "Track")), "data": [], } data = output["data"] for track, people in sorted(tracks.items()): for x in people: data.append( { "name": '<a href="%s">%s</a>' % (reverse("admin:auth_user_change", args=(x["uid"],)), x["name"]), "email": x["email"], "uid": x["uid"], "phones": ", ".join(x["phones"]), "track": track, } ) return output