Esempio n. 1
0
def _get_persons_in_categories(meeting_id, categories, person_type, **kwargs):
    from playhouse.postgres_ext import  R
    from peewee import EmptyResultException
    page = kwargs.pop('page', 1)
    limited = kwargs.pop('limited', True)

    filters = {'meeting_flags_verified': '1'}
    fields = [R('id', 'id'), R('data', 'data'), R('category', 'category')]
    order_by = ('category', 'ASC')

    if person_type == 'person':
        persons_query = models.Person.select(fields).order_by(order_by)
    else:
        persons_query = models.MediaPerson.select(fields).order_by(order_by)

    if limited:
        offset = (int(page) - 1) * PER_PAGE
        persons_query = persons_query.limit(PER_PAGE).offset(offset)

    if person_type == 'person':
        persons_query = sugar.append_persons_query(
            persons_query, meeting_id, categories=categories, filters=filters)
    else:
         persons_query = sugar.append_media_query(
            persons_query, meeting_id, categories=categories)

    try:
        total = persons_query.count()
    except EmptyResultException:
        total = 0
    return persons_query, total
Esempio n. 2
0
def provisional_pdf(meeting_id, printout_type):
    meeting = sugar.get_object_or_404(Meeting, id=meeting_id)
    filters = {'meeting_flags_%s' % printout_type: '1'}
    categs, categ_ids = get_categories_for_printouts(meeting, None, all=True)
    order_by = [("category", "ASC"),
                ("(t1.data -> 'printout_representing')", "ASC"),
                ("(t1.data -> 'personal_last_name')", "ASC"),]
    fields = [R('t1.data', 'data'), R('category', 'category'),
              R('t1.data-> \'printout_representing\'', 'printout_representing')]
    persons = (Person.select(fields)
                     .group_by("category")
                     .group_by("t1.data -> 'printout_representing'")
                     .group_by("t1.data")
                     .order_by(*order_by)
    )
    persons = sugar.append_persons_query(persons, meeting_id,
                                         categories=categ_ids)

    page_info =  {
        'title': 'Provisional list as entered by participant',
        'meeting_description': _get_meeting_description(meeting, 'E'),
        'type': printout_type,
        'today': datetime.now(),
    }

    return {
        'meeting': meeting,
        'persons': persons,
        'page_info': page_info,
        'count': persons.count(),
    }
Esempio n. 3
0
def document_distribution(meeting_id, printout_type):
    meeting = sugar.get_object_or_404(Meeting, id=meeting_id)
    languages = [(k,v) for k,v in refdata.language.items()]
    categ = flask.request.args.get('category')
    page = int(flask.request.args.get('page', 1))
    lang = flask.request.args.get('language')
    additional_params = ""

    categs, categ_ids = get_categories(meeting, categ,
                                       stat=['Party', 'Observer'])
    if categ:
        additional_params += '&category=' + categ

    filters = {'meeting_flags_%s' % printout_type: '1'}
    if lang:
        filters['personal_language'] = lang

    order_by = [("category", "ASC"),
                ("(t1.data -> 'printout_representing')", "ASC")]
    fields = [R('t1.data-> \'printout_representing\'', 'printout_representing'),
              R('t1.data-> \'personal_language\'', 'personal_language'),
              R("t2.category", "category")]

    persons_query = Person.select(fields).order_by(*order_by)
    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(),
        "meeting_description": _get_meeting_description(meeting, 'E'),
        "title": "Distribution of documents",
        "url": "printouts.document_distribution",
        "type": printout_type,
        "print_url": flask.url_for("printouts.print_task_celery",
                                    meeting_id=meeting.id,
                                    view_name="document_distribution",
                                    printout_type=printout_type),
    }

    categories_map = dict(categs)
    categories_map['2'] = 'Party'

    return {
        "page_info": page_info,
        "languages": languages,
        "languages_map": dict(languages),
        "meeting": meeting,
        "persons": persons_query,
        "categories": categs,
        "categories_map": categories_map,
        "filter_category": categ,
        "filter_language": lang,
        "additional_params": additional_params,
        "hide_filters": True,
    }
Esempio n. 4
0
def observers(meeting_id, printout_type):
    # flask.g.pdf_compatible = True
    meeting = sugar.get_object_or_404(Meeting, id=meeting_id)
    categ = flask.request.args.get('category')
    page = int(flask.request.args.get('page', 1))
    events = meeting.get_events()
    additional_params = ""

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

    # filters = {}
    filters = {'meeting_flags_%s' % printout_type: '1'}

    order_by = [("category", "ASC"),
                ("(t1.data -> 'printout_representing')", "ASC"),
                ("(t1.data -> 'personal_last_name')", "ASC"),]
    fields = [R("t1.id", "id"),
              R("t1.data", "data"),
              R("t2.data", "meeting_data"),
              R("t2.category", "category")]

    persons_query = (Person.select(fields).order_by(*order_by))
    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 = {
        'title': 'List of announced observers (by organization)',
        'meeting_description': _get_meeting_description(meeting, 'E'),
        'url': 'printouts.observers',
        'type': printout_type,
        'print_url': flask.url_for('printouts.print_task_celery',
                                    meeting_id=meeting.id,
                                    view_name='observers',
                                    printout_type=printout_type)
    }

    return {
        'meeting': meeting,
        'events': events,
        'page_info': page_info,
        'persons': persons_query,
        'paginator': paginator,
        'count': count,
        'categories': categs,
        'categories_map': dict(categs),
        'filter_category': categ,
        'additional_params': additional_params,
        'colspan': 7 + events.count(),
    }
Esempio n. 5
0
def pigeon_holes(meeting_id, printout_type, download=False):
    meeting = sugar.get_object_or_404(Meeting, id=meeting_id)
    languages = [(k,v) for k,v in refdata.language.items()]
    categ = flask.request.args.get('category')
    page = int(flask.request.args.get('page', 1))
    lang = flask.request.args.get('language')
    additional_params = ""

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

    filters = {'meeting_flags_%s' % printout_type: '1'}
    if lang:
        filters['personal_language'] = lang
    order_by = [('printout_representing', 'ASC')]

    fields = [R('t1.data-> \'printout_representing\'', 'printout_representing'),
              R('t1.data-> \'personal_language\'', 'personal_language'),
              R("t2.category", "category")]

    persons_query = Person.select(fields).order_by(*order_by)
    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(),
        "meeting_description": _get_meeting_description(meeting, 'E'),
        "title": "Pigeon holes (%s)" % ('announced' if printout_type == 'verified' else 'attending'),
        "url": "printouts.pigeon_holes",
        "type": printout_type,
        "print_url": flask.url_for("printouts.print_task_celery",
                                    meeting_id=meeting.id,
                                    view_name="pigeon_holes",
                                    printout_type=printout_type),
    }

    categories_map = dict(categs)
    categories_map[2] = 'Party'

    return {
        "page_info": page_info,
        "categories": categs,
        "categories_map": categories_map,
        "languages": languages,
        "languages_map": dict(languages),
        "persons": persons_query,
        "meeting": meeting,
        "filter_category": categ,
        "filter_language": lang,
        "paginator": paginator,
        "additional_params": additional_params,
        "hide_filters": True,
    }
Esempio n. 6
0
def capitalize_names(meeting_id):
    session = database.get_session()
    persons = models.Person.select()
    persons = sugar.append_persons_query(persons, meeting_id)
    for p in persons:
        p.data["personal_first_name"] = schema.common.clean_and_cap(p.data["personal_first_name"])
        p.data["personal_last_name"] = schema.common.clean_and_cap(p.data["personal_last_name"], is_last_name=True)
        p.save()
    session.commit()
Esempio n. 7
0
def admission_of_observers(meeting_id, printout_type, download=False):
    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(meeting, categ, stat=['Observer'])
    categ_ids = [c for c in categ_ids if c in (70, 80, 90, 91)]
    if categ:
        additional_params += '&category=' + categ

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

    persons_query = Person.select(fields).order_by(*order_by)
    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(),
        "meeting_description": {'E': _get_meeting_description(meeting, 'E'),
                                'S':_get_meeting_description(meeting, 'S'),
                                'F':_get_meeting_description(meeting, 'F'),
        },
        "title": u"ADMISSION OF OBSERVERS / ADMISIÓN DE OBSERVADORES / ADMISSION DES OBSERVATEURS",
        "url": "printouts.admission_of_observers",
        "type": printout_type,
        "download": download,
        "print_url": flask.url_for("printouts.print_task_celery",
                                    meeting_id=meeting.id,
                                    view_name="admission_of_observers",
                                    printout_type=printout_type),
    }

    return {
        "meeting": meeting,
        "page_info": page_info,
        "paginator": paginator,
        "persons": persons_query,
        "filter_category": categ,
        "categories": categs,
        "categories_map": dict(categs),
        "additional_params": additional_params,
        "hide_filters": True,
    }
Esempio n. 8
0
def delegations(meeting_id, printout_type):
    # flask.g.pdf_compatible = True
    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(meeting, categ,
                                       stat=['Party', 'Observer'])
    if categ:
        additional_params += '&category=' + categ

    # filters = {}
    filters = {'meeting_flags_%s' % printout_type: '1'}

    order_by = [("category", "ASC"),
                ("(t1.data -> 'printout_representing')", "ASC")]
    fields = [R('t1.data-> \'printout_representing\'', 'printout_representing'),
              R("t2.category", "category")]

    persons_query = Person.select(fields).order_by(*order_by)
    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 = {
        'title': 'List of delegations (to prepare the meeting room)',
        'meeting_description': _get_meeting_description(meeting, 'E'),
        'url': 'printouts.delegations',
        'type': printout_type,
        'print_url': flask.url_for('printouts.print_task_celery',
                                    meeting_id=meeting.id,
                                    view_name='delegations',
                                    printout_type=printout_type)
    }

    categories_map = dict(categs)
    categories_map['2'] = 'Party'

    return {
        'meeting': meeting,
        'page_info': page_info,
        'persons': persons_query,
        'paginator': paginator,
        'count': count,
        'categories': categs,
        'categories_map': categories_map,
        'filter_category': categ,
        'additional_params': additional_params,
    }
Esempio n. 9
0
def settings_category_delete(meeting_id, category_id):
    meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id)

    try:
        category_meeting = models.CategoryMeeting.select().where(
            meeting_id=meeting_id,
            category_id=category_id).join(models.Category).get()
        #NOTE do not allow 'Visitor' category deletion if it's going to stay like this
        if category_meeting.category.data['id'] in (None, 999):
            flask.abort(404)
        category_meeting.delete_instance()

        persons = models.Person.select().where(data__contains={
            'personal_category': category_meeting.category.data['id'],
        })
        persons = sugar.append_persons_query(persons, meeting_id)
        for person in persons:
            person.data['personal_category'] = '999'
            person.save()
    except models.CategoryMeeting.DoesNotExist:
        flask.abort(404)

    return flask.json.dumps({'status': 'success'})
Esempio n. 10
0
def send_mail(meeting_id):
    app = flask.current_app
    session = database.get_session()
    meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id)
    all_categories = meeting.get_categories()

    if flask.request.method == 'POST':
        mail = Mail(app)

        initial_form_data = flask.request.form
        form_data = initial_form_data.to_dict()

        categories = initial_form_data.getlist('mail_categories')
        categories = map(int, categories)

        mail_schema = schema.BulkMailSchema.from_flat(form_data)
        mail_schema['categories'].set(categories)
        mail_schema.set_category_labels(all_categories)

        if mail_schema.validate():
            mail_data = {}
            mail_data.update(mail_schema.flatten())

            mail_data['mail_categories'] = categories
            lang = form_data['mail_to']
            filters = {
                'personal_language': lang
            }
            if not categories:
                persons = (models.Person.select().where(data__contains=filters))
                persons = sugar.append_persons_query(persons, meeting_id)
                recipients = set([p.data['personal_email']
                              for p in persons if p.data.get('personal_email')])
            else:
                persons = (
                    models.Person.select().where(data__contains=filters)
                          .where(data_value_in('personal_category',
                                               map(str, categories)))
                )
                persons = sugar.append_persons_query(persons, meeting_id)
                recipients = set([p.data['personal_email']
                              for p in persons if p.data.get('personal_email')])

            with mail.connect() as conn:
                for person in recipients:
                    msg = Message(mail_data['mail_subject'],
                                  sender=meeting.data['info_admin_email'],
                                  recipients=[person],
                                  body=mail_data['mail_message'])
                    conn.send(msg)

            mail_log_data = {
                'date': date.today(),
                'meeting_id': meeting.id,
                'type': 'bulk_mail',
            }

            mail_log_data.update(mail_data)
            mail_log_schema = schema.BulkMailLogSchema.from_flat(mail_log_data)
            mail_log_schema.set_category_labels(all_categories)

            if mail_log_schema.validate():
                mail_log_row = database.new('mail_log')
                mail_log_row.update(mail_log_schema.flatten())
                session.save(mail_log_row)
                session.commit()

            language = refdata.language.get(lang)
            if app.config['MAIL_SUPPRESS_SEND']:
                flask.flash(u'This is a demo, no real email was sent', 'info')
            else:
                success_msg = u'Mail sent to all %s speakers' % language
                flask.flash(success_msg, 'success')

                return flask.redirect(flask.url_for('meeting.send_mail',
                                      meeting_id=meeting.id))
        else:
            flask.flash(u'Errors in mail information', 'error')

    else:
        mail_schema = schema.BulkMailSchema({})
        mail_schema.set_category_labels(all_categories)

    return {
        'mk': sugar.MarkupGenerator(
            app.jinja_env.get_template('widgets/widgets_mail.html')
        ),
        'meeting': meeting,
        'mail_schema': mail_schema,
    }
Esempio n. 11
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(),
    }
Esempio n. 12
0
def provisional(meeting_id, printout_type):
    # flask.g.pdf_compatible = True

    from schema import refdata
    meeting = sugar.get_object_or_404(Meeting, id=meeting_id)
    categ = flask.request.args.get('category')
    rep = flask.request.args.get('representing')
    page = int(flask.request.args.get('page', 1))
    additional_params = ""

    categs, categ_ids = get_categories_for_printouts(meeting, categ, all=True)
    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("t1.data", "data"),
        R("(t1.data -> 'printout_representing')", "printout_representing"),
        R("category", "category"),
    ]
    persons_query = Person.select(fields).order_by(*order_by)

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

    if rep:
        persons_query = persons_query.where(
            data__contains={'printout_representing': rep})

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


    representing_query = (
        Person.group_by([Count('*')], ['printout_representing'])
              .order_by(("printout_representing", "ASC"))
    )

    representing_query = sugar.append_persons_query(representing_query,
        meeting_id, categories=categ_ids)
    representing = [(r.printout_representing, r.printout_representing)
                    for r in representing_query]

    page_info =  {
        "title": "Provisional list as entered by participant",
        "meeting_description": _get_meeting_description(meeting, 'E'),
        "url": "printouts.provisional",
        "type": printout_type,
        "today": datetime.now(),
        "print_url": flask.url_for("printouts.print_task_celery",
                                    meeting_id=meeting.id,
                                    view_name="provisional_pdf",
                                    printout_type=printout_type),
    }

    return {
        "page_info": page_info,
        "persons": persons_query,
        "count": count,
        "meeting": meeting,
         "filter_category": categ,
         "representing": representing,
         "paginator": paginator,
         "categories": categs,
         "categories_map": dict(categs),
         "filter_category": categ,
         "filter_representing": rep,
         "additional_params": additional_params,
    }
Esempio n. 13
0
def list_of_all_participants(meeting_id, printout_type):
    from schema import refdata
    meeting = sugar.get_object_or_404(Meeting, id=meeting_id)
    categ = flask.request.args.get('category')
    rep = flask.request.args.get('representing')
    page = int(flask.request.args.get('page', 1))
    additional_params = ""

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

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

    if not getattr(flask.g, 'pdf_compatible', None):
        fields = [
            R("t1.data -> 'personal_first_name'", "personal_first_name"),
            R("t1.data -> 'personal_last_name'", "personal_last_name"),
            R("category", "category"),
            R("t1.data -> 'representing_organization_show'", "representing_organization_show"),
            R("t1.data -> 'representing_organization'", "representing_organization"),
            R("t1.data -> 'personal_address'", "personal_address"),
            R("t1.data -> 'personal_place'", "personal_place"),
            R("t1.data -> 'personal_email'", "personal_email"),
        ]
        persons_query = Person.select(fields).order_by(*order_by)

    persons_query = persons_query.paginate(page, PER_PAGE)
    if rep:
        persons_query = persons_query.where(
            data__contains={'printout_representing': rep})

    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)


    representing_query = (
        Person.group_by([Count('*')], ['printout_representing'])
              .order_by(("printout_representing", "ASC"))
    )

    representing_query = sugar.append_persons_query(representing_query,
        meeting_id, categories=categ_ids, filters=filters)
    representing = [(r.printout_representing, r.printout_representing)
                    for r in representing_query]

    page_info =  {
        "title": "List of participants / "
                 "Lista de participantes / "
                 "Liste des participants (%s)" % meeting.decoded_data['info_acronym'],
        "meeting_description": {'E': _get_meeting_description(meeting, 'E'),
                                'S':_get_meeting_description(meeting, 'S'),
                                'F':_get_meeting_description(meeting, 'F'),
        },
        "url": "printouts.list_of_all_participants",
        "type": printout_type,
        "today": datetime.now(),
        "print_url": flask.url_for("printouts.print_task_celery",
                                    meeting_id=meeting.id,
                                    view_name="list_of_all_participants_pdf",
                                    printout_type=printout_type),
    }

    return {
        "page_info": page_info,
        "persons": persons_query,
        "count": count,
        "meeting": meeting,
         "filter_category": categ,
         "representing": representing,
         "paginator": paginator,
         "categories": categs,
         "categories_map": dict(categs),
         "filter_category": categ,
         "filter_representing": rep,
         "additional_params": additional_params,
    }
Esempio n. 14
0
def credentials(meeting_id, printout_type):
    # flask.g.pdf_compatible = True
    meeting = sugar.get_object_or_404(Meeting, id=meeting_id)
    categ = flask.request.args.get('category')
    rep = flask.request.args.get('representing')
    page = int(flask.request.args.get('page', 1))
    additional_params = ""

    categs, categ_ids = get_categories(meeting, categ, stat=['Party'])
    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"),]

    if not getattr(flask.g, 'pdf_compatible', None):
        fields = [
            R("t1.data -> 'personal_first_name'", "personal_first_name"),
            R("t1.data -> 'personal_last_name'", "personal_last_name"),
            R("t1.data -> 'meeting_flags_credentials'", "meeting_flags_credentials"),
            R("category", "category"),
            R("t2.data", "meeting_data"),
            R("t1.data -> 'printout_representing'", "printout_representing"),
        ]
        persons_query = Person.select(fields).order_by(*order_by)
    else:
        fields = [
            R('t1.data -> \'personal_first_name\'', 'personal_first_name'),
            R('t1.data -> \'personal_last_name\'', 'personal_last_name'),
            R('t1.data-> \'printout_representing\'', 'printout_representing'),
            R('t2.data', 'meeting_data'),
            R("category", "category")]

        persons_query = Person.select(fields).order_by(*order_by)


    if not getattr(flask.g, 'pdf_compatible', None):
        persons_query = persons_query.paginate(page, PER_PAGE)
    if rep:
        persons_query = persons_query.where(
            data__contains={'printout_representing': rep})

    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 =  {
        "title": "List of credentials",
        "meeting_description": {'E': _get_meeting_description(meeting, 'E'),
                                'S':_get_meeting_description(meeting, 'S'),
                                'F':_get_meeting_description(meeting, 'F'),
        },
        "url": "printouts.credentials",
        "type": printout_type,
        "today": datetime.now(),
        "print_url": flask.url_for("printouts.print_task_celery",
                                    meeting_id=meeting.id,
                                    view_name="credentials",
                                    printout_type=printout_type),
    }

    credentials_categories_map = {
        '11': 'A',
        '12': 'B',
        '13': 'C',
    }

    return {
        "meeting": meeting,
        "page_info": page_info,
        "paginator": paginator,
        "persons": persons_query,
        "count": count,
        "categories": categs,
        "categories_map": dict(categs),
        "credentials_categories_map": credentials_categories_map,
        "filter_category": categ,
        "filter_representing": rep,
        "additional_params": additional_params,
    }
Esempio n. 15
0
def list_for_verification(meeting_id, printout_type='attended'):
    meeting = sugar.get_object_or_404(Meeting, id=meeting_id)
    categ = flask.request.args.get('category')
    rep = flask.request.args.get('representing')
    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 = [("(t1.data -> 'printout_representing')", "ASC"),
                ("(t1.data -> 'personal_last_name')", "ASC"),]

    if not getattr(flask.g, 'pdf_compatible', None):
        fields = [
            R("t1.data -> 'personal_first_name'", "personal_first_name"),
            R("t1.data -> 'personal_last_name'", "personal_last_name"),
            R("t1.data -> 'representing_organization_show'", "representing_organization_show"),
            R("t1.data -> 'representing_organization'", "representing_organization"),
            R("t1.data -> 'personal_address'", "personal_address"),
            R("t1.data -> 'personal_place'", "personal_place"),
            R("t1.data -> 'personal_email'", "personal_email"),
            R("t2.category", "category"),
        ]
        persons_query = Person.select(fields).order_by(*order_by)
    else:
        fields = [
            R("t1.data -> 'personal_first_name'", "personal_first_name"),
            R("t1.data -> 'personal_last_name'", "personal_last_name"),
            R("t1.data -> 'representing_organization'", "representing_organization"),
            R("t1.data -> 'personal_address'", "personal_address"),
            R("t1.data -> 'personal_place'", "personal_place"),
            R("t1.data -> 'personal_email'", "personal_email"),
        ]
        persons_query = (
            Person.group_by(fields, ['printout_representing', 'data'])
                   .order_by(("printout_representing", "ASC"),
                             ("personal_last_name", "ASC"))
        )

    if not getattr(flask.g, 'pdf_compatible', None):
        persons_query = persons_query.paginate(page, PER_PAGE)
    if rep:
        persons_query = persons_query.where(
            data__contains={'printout_representing': rep})

    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)

    representing_query = (
        Person.group_by([Count('*')], ['printout_representing'])
              .order_by(("printout_representing", "ASC"))
    )
    representing_query = sugar.append_persons_query(representing_query,
        meeting_id, categories=categ_ids, filters=filters)
    representing = [(r.printout_representing, r.printout_representing)
                    for r in representing_query]

    page_info = {
        "today": datetime.now(),
        "title": (u"List of participants for checking / \n"
                  u"Lista de participantes para verificar / \n"
                  u"Liste des participants pour vérification"),
        "url": "printouts.list_for_verification",
        "print_url": flask.url_for("printouts.print_task_celery",
                                    meeting_id=meeting.id,
                                    view_name="list_for_verification",
                                    printout_type=printout_type),
    }

    return {
        "page_info": page_info,
        "persons": persons_query,
        "filter_category": categ,
        "representing": representing,
        "paginator": paginator,
        "meeting": meeting,
        "categories": categs,
        "categories_map": dict(categs),
        "filter_category": categ,
        "filter_representing": rep,
        "additional_params": additional_params,
    }