def check_request_funding(meeting_id): sugar.get_object_or_404(models.Meeting, id=meeting_id) category_id = flask.request.form['category_id'] country_code = flask.request.form['country_code'] resp = {'request_funding': False} category = sugar.get_person_category_or_404( meeting_id, category_id=category_id ) try: country = models.Country.get(data__contains={'iso': country_code}) except models.Country.DoesNotExist: country = None if category.data.get('request_funding', False): resp['request_funding'] = True if category.data.get('credentials_file', False): resp['credentials_file'] = True if (category.data.get('request_funding_with_country', False) and country and country.data.get('request_funding', False)): resp['request_funding'] = True if (category.data.get('credentials_file_with_country', False) and country and country.data.get('request_funding', False)): resp['credentials_file'] = True return flask.jsonify(resp)
def settings_category_add(meeting_id): sugar.get_object_or_404(models.Meeting, id=meeting_id) categories = flask.request.form.getlist('categories') for categ in categories: models.CategoryMeeting.create(meeting_id=meeting_id, category_id=categ) return flask.redirect(flask.url_for('.settings_category_index', meeting_id=meeting_id))
def event_delete(meeting_id, event_id): meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) event = sugar.get_object_or_404(models.Event, id=event_id) event.delete_instance() return flask.jsonify({ 'status': 'success', 'url': flask.url_for('.events', meeting_id=meeting_id) })
def questions_delete(meeting_id, question_id): sugar.get_object_or_404(models.Meeting, id=meeting_id) question = sugar.get_object_or_404(models.Question, id=question_id, meeting_id=meeting_id) question.delete_instance() return flask.jsonify({ 'status': 'success', 'url': flask.url_for('.questions', meeting_id=meeting_id) })
def update_attendance(meeting_id, person_id, field): meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) person = sugar.get_person_or_404(meeting_id, person_id) person_meeting = sugar.get_object_or_404(models.PersonMeeting, person=person_id, meeting=meeting_id) status = person_meeting.data['meeting_flags_%s' % field] person_meeting.data['meeting_flags_%s' % field] = '1' if not status else '' person_meeting.save() return flask.jsonify({'status': 'success'})
def settings_fee_index(meeting_id): meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) fees = meeting.get_fees return { 'fees': fees, 'meeting': meeting, }
def questions(meeting_id): meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) questions = meeting.get_questions() return { 'meeting': meeting, 'questions': questions }
def media_file(meeting_id, file_type, media_person_id=None, person_id=None): meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) if media_person_id: person = sugar.get_media_person_or_404(meeting_id, media_person_id) redirect_url = flask.url_for('.view', meeting_id=meeting.id, media_person_id=person.id) elif person_id: person = sugar.get_person_or_404(meeting_id, person_id) redirect_url = flask.url_for('participant.view', meeting_id=meeting.id, person_id=person.id) else: flask.abort(400) app = flask.current_app media_file = flask.request.files[file_type] if media_file: # delete old file if person.data.get(file_type): try: app.config['UPLOADED_FILES_DEST'].joinpath( person.data[file_type]).unlink() except OSError: pass filename = '%s_%s.' % ( secure_filename(person.decoded_data['personal_last_name']), file_type) media_file_name = files.save(media_file, name=filename) if media_file else '' person.data[file_type] = media_file_name person.save() return flask.redirect(redirect_url)
def envelope_print(meeting_id, person_id): app = flask.current_app meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) person = sugar.get_person_or_404(meeting_id, person_id) secretariat = refdata.secretariat temp = path(tempfile.mkdtemp()) flask.g.pdf_compatible = True country_names = [] try: country_names = refdata.translated_country_names[ person.data['personal_country']] except KeyError: pass context = dict(meeting=meeting, person=person, path=app.root_path, secretariat=secretariat, country_names=country_names) return sugar.render_pdf('participant/person_envelope.html', temp=temp, height='6.4in', width='9.0in', context=context, filename=secure_filename(person.name), use_wkhtmltopdf=True)
def badge_misc_pdf(meeting_id, badge_type): meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) temp = path(tempfile.mkdtemp()) app = flask.current_app if badge_type == 'visitor': category = models.Category.select().where( data__contains={'name_E': 'Visitor'}).get() elif badge_type == 'security': category = models.Category.select().where( data__contains={'name_E': 'Security'}).get() elif badge_type == 'exhibitor': category = models.Category.select().where( data__contains={'name_E': 'Exhibitor'}).get() elif badge_type == 'host_government': category = models.Category.select().where( data__contains={'name_E': 'Host Government'}).get() elif badge_type == 'local_staff': category = models.Category.select().where( data__contains={'name_E': 'Local staff'}).get() else: flask.abort(400) context = { 'meeting': meeting, 'category': category, 'badge_type': badge_type, 'path': app.root_path, 'background_path': app.config['UPLOADED_BACKGROUNDS_DEST'], } return sugar.render_pdf('participant/badge_misc_simple.html', temp=temp, height="2.15in", width="3.4in", context=context, filename=sugar.random_string(6), use_wkhtmltopdf=True)
def badge_misc(meeting_id, badge_type): meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) if badge_type == 'visitor': category = models.Category.select().where( data__contains={'name_E': 'Visitor'}).get() elif badge_type == 'security': category = models.Category.select().where( data__contains={'name_E': 'Security'}).get() elif badge_type == 'exhibitor': category = models.Category.select().where( data__contains={'name_E': 'Exhibitor'}).get() elif badge_type == 'host_government': category = models.Category.select().where( data__contains={'name_E': 'Host Government'}).get() elif badge_type == 'local_staff': category = models.Category.select().where( data__contains={'name_E': 'Local staff'}).get() else: flask.abort(400) return { 'meeting': meeting, 'category': category, 'badge_type': badge_type, }
def revert_photo(meeting_id, person_id): meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) person = sugar.get_person_or_404(meeting_id, person_id) url = flask.url_for('participant.crop_photo_view', meeting_id=meeting.id, person_id=person.id) return _revert_photo(meeting, person, url)
def view_pdf(meeting_id, person_id): meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) person = sugar.get_person_or_404(meeting_id, person_id) labeled = schema.common.labels_for_values(person.data, meeting_id) category = sugar.get_person_category_or_404(meeting_id, category_id=person.category_id(meeting.id)) phrases = {p.data['name']: p for p in meeting.get_phrases} event_form = EventCitesForm(meeting_model=meeting, person=person) # render form in participant language participant_lang = {"E": "en", "S": "es", "F": "fr"}.get(person.lang, "E") sugar.set_lang(participant_lang) pdf = sugar.generate_pdf_from_html( flask.render_template('participant/credentials.html', **{ 'person': person, 'category': category, 'meeting': meeting, 'labeled': labeled, 'phrases': phrases, 'credentials_strings': refdata.credentials_strings, 'event_form': event_form, }) ) return flask.Response(response=pdf, mimetype='application/pdf')
def view(meeting_id, person_id): meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) person = sugar.get_person_or_404(meeting_id, person_id) page_info = {} page_info['picture'] = { 'edit_url': flask.url_for('participant.edit_photo', meeting_id=meeting.id, person_id=person.id), 'remove_url': flask.url_for('participant.remove_photo', meeting_id=meeting.id, person_id=person.id), 'url': person.image_file, 'rotate_url': flask.url_for('participant.rotate_photo', meeting_id=meeting.id, person_id=person.id), 'crop_url': flask.url_for('participant.crop_photo_view', meeting_id=meeting.id, person_id=person.id), } event_form = EventCitesForm(meeting_model=meeting, person=person) return { 'meeting': meeting, 'person': person, 'page_info': page_info, 'event_form': event_form, }
def badge_print(meeting_id, person_id, person_type): app = flask.current_app meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) if person_type == 'person': person = sugar.get_person_or_404(meeting_id, person_id) else: person = sugar.get_media_person_or_404(meeting_id, person_id) badge = flask.request.args.get('badge', None) # create a temporary folder and save participant photo to disk temp = path(tempfile.mkdtemp()) photo = person.data.get('photo', None) if photo: person.photo_url = app.config['UPLOADED_PHOTOS_DEST'] / photo else: person.photo_url = None # save badge as html context = dict(meeting=meeting, person=person, path=app.root_path, background_path=app.config['UPLOADED_BACKGROUNDS_DEST'], badge=badge, person_type=person_type) return sugar.render_pdf("participant/person_badge_simple.html", temp=temp, height="2.15in", width="3.4in", context=context, filename=secure_filename(person.name), use_wkhtmltopdf=True)
def settings_phrases(meeting_id): session = database.get_session() meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) if flask.request.method == 'POST': form_data = dict(schema.PhraseSchema.from_defaults().flatten()) form_data.update(flask.request.form.to_dict()) phrase_schema = schema.PhraseSchema.from_flat(form_data) if phrase_schema.validate(): phrase = (models.Phrase.select() .where(data__contains={'id': str(phrase_schema['id'].value)}) .where(meeting=meeting_id).get()) phrase.data.clear() phrase.data.update(phrase_schema.flatten()) phrase.save() flask.flash('Phrase saved', 'success') else: flask.flash(u'Errors in phrase information', 'error') phrases = meeting.get_phrases return { 'language': refdata.language, 'phrases': phrases, 'meeting': meeting, }
def view(meeting_id, media_person_id): meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) person = sugar.get_media_person_or_404(meeting_id, media_person_id) page_info = {} page_info['picture'] = { 'edit_url': flask.url_for('.edit_photo', meeting_id=meeting.id, media_person_id=person.id), 'remove_url': flask.url_for('.remove_photo', meeting_id=meeting.id, media_person_id=person.id), 'url': person.image_file, 'rotate_url': flask.url_for('media_participant.rotate_photo', meeting_id=meeting.id, media_person_id=person.id), 'crop_url': flask.url_for('media_participant.crop_photo_view', meeting_id=meeting.id, media_person_id=person.id), } return { 'meeting': meeting, 'person': person, 'page_info': page_info, }
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(), }
def events(meeting_id): meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) events = meeting.get_events() return { 'meeting': meeting, 'events': events, }
def edit(meeting_id, person_id=None): meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) if person_id is None: person = models.Person() person_meeting = None template = 'participant/edit/create.html' subject = 'add-participant' event_form = EventCitesForm(meeting_model=meeting) person_data_as_attributes = None else: person = sugar.get_person_or_404(meeting_id, person_id) person_meeting = sugar.get_object_or_404(models.PersonMeeting, person=person_id, meeting=meeting_id) event_form = EventCitesForm(meeting_model=meeting, person=person) template = 'participant/edit/cites_edit.html' subject = 'edit-participant' person_data_as_attributes = person.data_as_attributes(meeting_id) ParticipantForm = get_participant_form(meeting.data['info_type']) form = ParticipantForm(meeting=meeting, obj=person_data_as_attributes) if flask.request.method == 'POST': if form.validate(): form.save(meeting, person, person_meeting) event_form.save(person) sugar.activity(meeting_id, subject, person.name, person.id) flask.flash('Person information saved', 'success') view_url = flask.url_for('participant.view', meeting_id=meeting.id, person_id=person.id) return flask.redirect(view_url) else: flask.flash('Errors in person information', 'error') return { 'template': template, 'form': form, 'event_form': event_form, 'person': person, 'person_id': person_id, 'meeting': meeting, }
def delete(meeting_id, person_id): meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) person = sugar.get_person_or_404(meeting_id, person_id) person_meeting = (models.PersonMeeting.select() .where(meeting_id=meeting_id, person_id=person_id).get()) person_meeting.delete_instance() sugar.activity(meeting_id, 'delete-participant', person.name, person.id) return flask.jsonify({'status': 'success'})
def settings_fee_edit(meeting_id, fee_id=None): app = flask.current_app meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) page_info = {} if flask.request.method == 'POST': form_data = dict(schema.FeeSchema.from_defaults().flatten()) form_data.update(flask.request.form.to_dict()) fee_schema = schema.FeeSchema.from_flat(form_data) if fee_id: fee = sugar.get_object_or_404(models.Fee, id=fee_id) else: fee = models.Fee() fee.data = {} fee.meeting = meeting_id if fee_schema.validate(): fee.data.update(fee_schema.flatten()) if not fee_id: fee.auto_increment_id() fee.save() flask.flash('Fee saved', 'success') return flask.redirect(flask.url_for('.settings_fee_index', meeting_id=meeting.id)) else: flask.flash(u'Errors in fee information', 'error') else: if fee_id: fee = sugar.get_object_or_404(models.Fee, id=fee_id) fee_schema = schema.FeeSchema() fee_schema.set_flat(fee.decoded_data) page_info['page'] = 'edit' else: fee_schema = schema.FeeSchema.from_defaults() page_info['page'] = 'add' return { 'meeting': meeting, 'fee_schema': fee_schema, 'page_info': page_info, 'mk': sugar.MarkupGenerator( app.jinja_env.get_template('widgets/widgets_edit.html') ), }
def print_task_celery(meeting_id, view_name, printout_type): meeting = sugar.get_object_or_404(Meeting, id=meeting_id) task = workers.render_printouts_pdf.delay(view_name, meeting_id, printout_type) task_status_url = flask.url_for('printouts.task_status', meeting_id=meeting.id, task_id=task.id) return flask.jsonify({ "task_id": task.id, "url": task_status_url })
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, }
def edit(staff_id=None): app = flask.current_app page_info = {} if staff_id: staff = sugar.get_object_or_404(models.Staff, id=staff_id) page_info["title"] = "Edit staff member" page_info["picture"] = { "edit_url": flask.url_for("staff.edit_photo", staff_id=staff_id), "remove_url": flask.url_for("staff.remove_photo", staff_id=staff.id), "url": flask.url_for("staff.photo", staff_id=staff.id), } else: staff = models.Staff() staff.data = {} page_info["title"] = "Add staff member" if flask.request.method == "POST": form_data = dict(schema.StaffSchema.from_defaults().flatten()) form_data.update(flask.request.form.to_dict()) staff_schema = schema.StaffSchema.from_flat(form_data) if staff_schema.validate(): is_admin = staff_schema['is_admin'].value staff.role = 'admin' if is_admin else 'viewer' if not staff_id: password = sugar.random_string(size=4) staff_schema['password'].set(sugar.make_hash(password)) _send_mail_to_user(staff_schema, password) staff.data.update(staff_schema.flatten()) staff.save() flask.flash("Staff saved", "success") location = flask.url_for("staff.home") return flask.redirect(location) else: flask.flash(u"Errors in staff information", "error") else: if staff_id: staff_schema = schema.StaffSchema.from_flat(staff.decoded_data) else: staff_schema = schema.StaffSchema() return { "mk": sugar.MarkupGenerator( app.jinja_env.get_template("widgets/widgets_edit.html") ), "staff_schema": staff_schema, "staff": staff, "staff_id": staff_id, "page_info": page_info, }
def settings_category_index(meeting_id): meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) existing_categories = [c.id for c in meeting.get_categories()] categories = [c for c in models.Category.select() if c.id not in existing_categories] return { 'meeting': meeting, 'categories': categories, }
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, }
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(), }
def documents(meeting_id): meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) documents = database.get_all('document') documents = [schema.Document.from_flat(d) for d in documents if int(d['meeting_id']) == meeting.id] return { 'meeting': meeting, 'documents': documents, }
def form(meeting_id): app = flask.current_app # render form in local language lang = flask.request.args.get('lang', 'en') if lang not in ('en', 'fr', 'es'): flask.abort(400) sugar.set_lang(lang) meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) form = MediaParticipantForm(meeting=meeting) response = {} if flask.request.method == 'POST': if form.validate(): media_person = models.MediaPerson() media_person.data = {} form.save(media_person) sugar.activity(meeting_id, "add-media-participant", media_person.name, media_person.id) if form.data['personal_email']: send_mail_to_media_participant(meeting, form, lang) # language will change here to english sugar.set_lang("en") refresh() send_mail_to_admin(meeting, form, media_person.id) phrase_lang = {'en': 'E', 'es': 'S', 'fr': 'F'}.get(lang, 'E') phrase = models.Phrase.select().where( data__contains={'name': 'Media registration confirmation'}, meeting=meeting_id).get() template = app.jinja_env.get_template('participant/form_success.html') response['data'] = template.render({ 'content': phrase.decoded_data['description_%s' % phrase_lang], }) return response['data'] else: log.warn("validation errors in media participant form", extra={'errors': form.errors, 'form_data': form.data}) template = app.jinja_env.get_template('participant/media_form.html') response['data'] = template.render({ 'meeting': meeting, 'form': form, }) return response['data']