Пример #1
0
def events(meeting_id, printout_type):
    meeting = sugar.get_object_or_404(Meeting, id=meeting_id)
    categ = flask.request.args.get('category')
    page = int(flask.request.args.get('page', 1))
    additional_params = ""

    categs, categ_ids = get_categories_for_printouts(meeting, categ)
    if categ:
        additional_params += '&category=' + categ

    filters = {'meeting_flags_%s' % printout_type: '1'}
    order_by = [("category", "ASC"),
                ("(t1.data -> 'printout_representing')", "ASC"),
                ("(t1.data -> 'personal_last_name')", "ASC"),]

    fields = [R("category", "category"),
              R("t1.data", "data"),
              R("t2.data", "meeting_data"),
              R("t2.person_id", "id")]

    events = meeting.get_events()
    event_ids = [e.id for e in events]
    person_ids = [pe.person.id for pe in PersonEvent.select().where(PersonEvent.event << event_ids)]
    persons_query = (Person.select(fields).order_by(*order_by)
       .where(Person.id << person_ids))

    if not getattr(flask.g, 'pdf_compatible', None):
        persons_query = persons_query.paginate(page, PER_PAGE)

    persons_query = sugar.append_persons_query(persons_query, meeting_id,
                                               categories=categ_ids,
                                               filters=filters)
    count = persons_query.count()
    paginator = sugar.Paginator(per_page=PER_PAGE, page=page, count=count)

    page_info = {
        'today': datetime.now(),
        'title': 'List of %s participants in events' % (
            'announced' if printout_type == 'verified' else 'attending'),
        'meeting_description': _get_meeting_description(meeting, 'E'),
        'url': 'printouts.events',
        'type': printout_type,
        'print_url': flask.url_for('printouts.print_task_celery',
                                    meeting_id=meeting.id,
                                    view_name='events',
                                    printout_type=printout_type),
    }

    return {
        'page_info': page_info,
        'persons': persons_query,
        'paginator': paginator,
        'events': events,
        'count': count,
        'meeting': meeting,
        'categories': categs,
        'categories_map': dict(categs),
        'filter_category': categ,
        'additional_params': additional_params,
        'colspan': 4 + events.count(),
    }
Пример #2
0
def participants(meeting_id):
    meeting = get_object_or_404(Meeting, id=meeting_id)

    fields = [R('t1.id', 'id'), R('t1.data', 'data'),
              R('t2.data', 'meeting_data')]
    persons = (Person.select(fields).join(PersonMeeting)
                     .where(meeting=meeting_id))

    events = [(i.id, i.decoded_data['description_E'])
              for i in meeting.get_events()]
    questions = [(i.id, i.decoded_data['title_E'])
                 for i in meeting.get_questions()]

    ParticipantForm = get_participant_form(meeting.data['info_type'])
    form = ParticipantForm(meeting=meeting)

    columns = [
        'personal_name_title', 'personal_last_name', 'personal_first_name',
        'category',
        'personal_badge_name', 'personal_address', 'personal_place',
        'personal_country', 'personal_phone', 'personal_cellular',
        'personal_fax', 'personal_email', 'representing_country',
        'representing_organization', 'personal_language',
        'representing_region',
    ]
    if isinstance(form, CMSParticipantForm):
        columns.extend([
            'birth_date', 'nationality', 'passport_number',
            'passport_expiration_date', 'functional_title', 'special_diet'
        ])
    columns.extend([
        'meeting_flags_attended', 'meeting_flags_sponsored',
        'meeting_flags_credentials', 'meeting_flags_approval',
        'meeting_flags_invitation', 'meeting_flags_verified',
        'meeting_flags_statute'
    ])
    if isinstance(form, CMSParticipantForm):
        columns.extend(['request_funding', 'request_letter',
                        'funding_accepted'])

    header = []
    for k in columns:
        if form._fields.get(k):
            header.append(str(form._fields[k].label.text))
        else:
            header.append(k.replace('_', ' ').capitalize())
    header.extend([i[1] for i in events])
    header.extend([i[1] for i in questions])

    rows = []
    for p in persons:
        data = dict(p.decoded_data)
        category_id = p.category_id(meeting_id=meeting_id)
        category = get_person_category_or_None(meeting_id, category_id)
        data['category'] = category.get_verbose_name()
        data['representing_country'] = (p.representing_country and
                                        unicode(p.representing_country))
        data['personal_country'] = (p.personal_country and
                                    unicode(p.personal_country))
        data['representing_region'] = p.region
        data['personal_language'] = p.language()

        data['meeting_flags_attended'] = p.meeting_data.get(
            'meeting_flags_attended') and '*'
        data['meeting_flags_sponsored'] = p.meeting_data.get(
            'meeting_flags_sponsored') and '*'
        data['meeting_flags_credentials'] = p.meeting_data.get(
            'meeting_flags_credentials') and '*'
        data['meeting_flags_approval'] = p.meeting_data.get(
            'meeting_flags_approval') and '*'
        data['meeting_flags_invitation'] = p.meeting_data.get(
            'meeting_flags_invitation') and '*'
        data['meeting_flags_verified'] = p.meeting_data.get(
            'meeting_flags_verified') and '*'
        data['meeting_flags_statute'] = p.meeting_data.get(
            'meeting_flags_statute') and '*'
        data['personal_fee'] = p.meeting_data.get(
            'personal_fee') and '*'
        if 'request_funding' in columns:
            data['request_funding'] = p.meeting_data.get(
                'request_funding') and '*'
        if 'funding_accepted' in columns:
            data['funding_accepted'] = p.meeting_data.get(
                'funding_accepted') and '*'
        if 'request_letter' in columns:
            data['request_letter'] = p.meeting_data.get(
                'request_letter') and '*'

        for e in events:
            if (PersonEvent.select().where(person=p.id, event=e[0])
               .count() > 0):
                data[e[1]] = '*'
        for q in questions:
            if (PersonQuestion.select().where(person=p.id, question=q[0])
               .count() > 0):
                data[q[1]] = '*'

        for key in data.keys():
            if key in EXCLUDE_PARTICIPANT_FIELDS:
                data.pop(key, None)

        rows.append([data.get(k) or '' for k in columns] +
                    [data.get(i[1]) or '' for i in events] +
                    [data.get(i[1]) or '' for i in questions])

    return Response(
        generate_excel(header, rows),
        mimetype='application/vnd.ms-excel',
        headers={'Content-Disposition': 'attachment; filename=%s.xls'
                 % 'registration'})