Exemple #1
0
def show(request, event_id):
    from webinars_web.webinars import models as wm
    hub = wm.Hub.ensure(request.marketplace.hub_id)

    try:
        event = wm.Event.objects.select_related('account','account__hub').get(pk=event_id)
    except:
        return HttpResponseNotFound()
    if event.account.hub_id != hub.id:
        return HttpResponseForbidden()

    registrants = event.registrant_set.select_related('cms_form').extra(
        select = { 'durationx': 'IF(ISNULL(stopped_at) OR ISNULL(started_at), NULL, stopped_at-started_at)' },
        order_by = ['-durationx']
    )
    for r in registrants:
        r.event = event
    lps = [lp for lp in wm.LandingPage.objects.filter(cms_form__event=event)]
    forms_to_lps = {}
    for lp in lps:
        forms_to_lps.setdefault(lp.cms_form.guid,[]).append(lp)
    for r in registrants:
        if r.effective_duration:
            if not r.cms_form or r.cms_form.is_sync_target:
                r.landing_pages = []
            else:
                r.landing_pages = forms_to_lps[r.cms_form.guid]

    now = time()
    if event._time_ended_at or event.ends_at < now:
        partitioned_registrants = utils.partition(registrants, lambda r: bool(r.started_at and r.stopped_at), [True, False])
        return render_to_response('events/show.djml', {
            'event': event,
            'future': False,
            'registrants': registrants,
            'registrants_count': len(registrants),
            'attendees': partitioned_registrants[True],
            'attendees_count': len(partitioned_registrants[True]),
            'noshows': partitioned_registrants[False],
            'noshows_count': len(partitioned_registrants[False]),
            'MARKETPLACE_SLUG': settings.MARKETPLACE_SLUG,
        }, context_instance=RequestContext(request))
    else:
        return render_to_response('events/show.djml', {
            'event': event,
            'future': True,
            'registrants': registrants,
            'registrants_count': len(registrants),
            'MARKETPLACE_SLUG': settings.MARKETPLACE_SLUG,
        }, context_instance=RequestContext(request))
Exemple #2
0
def bucket_events(hub):
    from webinars_web.webinars import models as wm
    events = wm.Event.objects.filter(
            account__hub=hub, deleted_at__isnull=True).select_related('current_sync','account').extra(
                    select={'registrant_count': 'SELECT COUNT(*) FROM webinars_registrant WHERE webinars_registrant.event_id=webinars_event.id'}).extra(
                    select={'attendant_count': 'SELECT COUNT(*) FROM webinars_registrant WHERE webinars_registrant.event_id=webinars_event.id AND started_at IS NOT NULL'})
    events = sorted(events, key=attrgetter('starts_at'), reverse=True)
    event_ids_form_ids = [(ef.event_id, ef.cms_form_id) for ef in  wm.EventForm.objects.filter(event__in=wm.Event.objects.filter(account__hub=hub, deleted_at__isnull=True), cms_form__is_sync_target=False)]
    event_id_to_form_ids_map = {}
    for event_id, form_id in event_ids_form_ids:
        event_id_to_form_ids_map.setdefault(event_id,[]).append(form_id)
    form_ids_lps = [(lp.cms_form_id, lp) for lp in wm.LandingPage.objects.filter(cms_form__in=set(ef[1] for ef in event_ids_form_ids))]
    form_id_to_lp_map = {}
    for form_id, lp in form_ids_lps:
        form_id_to_lp_map.setdefault(form_id,[]).append(lp)
    for event in events: #TODO: this is creating an 2N+1 situation-- need to refactor!
        event.landing_pages = []
        for form_id in event_id_to_form_ids_map.get(event.id,[]):
            event.landing_pages.extend(form_id_to_lp_map[form_id])

    now = time()
    return utils.partition(events, lambda e: (e.ended_at < now), [True,False])