Example #1
0
def edit(category_id=None):
    page_info = {}

    if category_id:
        category = sugar.get_object_or_404(models.Category, id=category_id)
        form = forms.CategoryForm(obj=category.data_as_attributes())
        page_info['page'] = 'edit'
    else:
        category = models.Category()
        category.data = {}
        form = forms.CategoryForm()
        page_info['page'] = 'add'

    if flask.request.method == 'POST':
        if form.validate():
            form.save(category)
            flask.flash('Category saved', 'success')
            return flask.redirect(flask.url_for('.home'))
        else:
            flask.flash('Errors in category information', 'error')


    return {
        'category': category,
        'form': form,
        'page_info': page_info,
    }
Example #2
0
def update_representing():
    for person in models.Person.select():
        meeting = sugar.get_object_or_404(models.Meeting, id=1)
        category = meeting.get_category(person.category_id(meeting.id))
        person.data['printout_representing'] = person.rep(meeting) or ''
        person.data['room'] = category.data['room'] or ''
        person.save()
Example #3
0
def home(meeting_id):
    meeting = sugar.get_object_or_404(Meeting, id=meeting_id)
    if not meeting.with_funding:
        abort(404)
    return {
        'meeting': meeting,
    }
Example #4
0
def delete(category_id):
    category_meetings = models.CategoryMeeting.select().where(
        category_id=category_id).join(models.Meeting)
    if category_meetings.count() > 0:
        return flask.render_template('categories/category_meetings.html',
            category_meetings=category_meetings)
    else:
        category = sugar.get_object_or_404(models.Category, id=category_id)
        category.delete_instance()
    return flask.Response('Ok')
Example #5
0
def delete_file(category_id):
    category = sugar.get_object_or_404(models.Category, id=category_id)
    app = flask.current_app
    filename =  category.data.pop('background', None)
    file_path = app.config['UPLOADED_BACKGROUNDS_DEST'] / filename
    try:
        file_path.unlink()
        category.save()
    except OSError:
        pass
    return flask.Response()
Example #6
0
    def query(self, options, meeting_id):
        meeting = sugar.get_object_or_404(Meeting, id=meeting_id)
        search = options['search']
        order_by = options.get('order_by')

        fields = [R('t1.id', 'id'), R('t1.data','data'),
                  R('t2.category', 'category'),
                  R('t2.data', 'meeting_data')]
        results = (
            Person.select(fields).join(PersonMeeting)
                  .where(meeting=meeting_id)
                  .where(R('t2.data @> (%s)', {'request_funding': '1'}))
                  .limit(options['limit'])
                  .offset(options['offset'])
        )

        if order_by and not options['count']:
            order_by_column = self.COLUMNS.get(order_by[0], order_by[0])
            order_by_dir = order_by[1].upper()
            if order_by_column == 'category':
                results = results.order_by(("(t2.category)", order_by_dir))
            else:
                results = results.order_by(
                    ("(t2.data -> '%s')" % order_by_column, order_by_dir))

        if search:
            search = sugar.util.rescape(unidecode(search.lower()))
            results = results.where(sugar.data_like('_text_for_search',
                search, table='t1'))

        if options['count']:
            return results.count()

        def render_column(person):
            if person.meeting_data.get('funding_accepted', False):
                return '<i class="icon-ok"></i>'

        def table_row(person, meeting):
            cat = sugar.get_person_category_or_404(meeting_id,
                category_id=person.category_id(meeting.id))
            url = url_for('participant.view', meeting_id=meeting.id,
                          person_id=person.id, from_page='funding.home')
            link = "<a href='%s'>%s</a>" % (jinja2.escape(url), person.name)
            return {
                'id': person.id,
                'name': link,
                'category': cat.data['name_E'],
                'funding_accepted': render_column(person),
            }
        return (table_row(person, meeting) for person in results)
Example #7
0
def edit(setting_id):
    setting = sugar.get_object_or_404(models.Setting, id=setting_id)
    form = forms.SettingsForm(obj=setting.data_as_attributes())

    if flask.request.method == 'POST':
        if form.validate():
            form.save(setting)
            flask.flash('Settings information saved', 'success')
            return flask.redirect(flask.url_for('.home'))

    return {
        'setting': setting,
        'form': form,
    }
Example #8
0
    def data_as_attributes(self, meeting_id):
        from cites.sugar import get_object_or_404
        keys = [k for k in self.data.keys() if k not in self.NOT_ALLOWED]
        data = dict(self.decoded_data)
        for i in self.NOT_ALLOWED:
            data.pop(i, None)

        person_meeting = get_object_or_404(PersonMeeting,
            meeting=meeting_id, person=self.id)
        keys.append('personal_category')
        keys.extend([k for k in person_meeting.data.keys()])

        data['personal_category'] = person_meeting.category
        data.update(person_meeting.data)
        Data = namedtuple('Data', set(keys))
        data = Data(**data)
        return data
Example #9
0
def meeting_type_edit(meeting_type_id=None):
    if meeting_type_id:
        meeting_type = sugar.get_object_or_404(MeetingType, id=meeting_type_id)
        form = MeetingTypeForm(obj=meeting_type)
    else:
        meeting_type = None
        form = MeetingTypeForm()

    if request.method == 'POST':
        if form.validate():
            form.save()
            flash('Meeting type saved', 'success')
            return redirect(url_for('.meeting_types'))

    return {
        'meeting_type': meeting_type,
        'form': form,
    }
Example #10
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'})