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 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 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 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 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 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 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 label(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) country_names = [] if person.data['personal_country']: country_names = refdata.translated_country_names[ person.data['personal_country']] return { 'person': person, 'meeting': meeting, 'country_names': country_names, }
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 avatar(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) photo = person.data.get('photo') if photo: filename = flask.current_app.config['UPLOADED_PHOTOS_DEST'] / photo image = Image.open(filename) image.thumbnail((32, 32), Image.ANTIALIAS) image_file = tempfile.NamedTemporaryFile() image.save(image_file, 'JPEG') image_file.seek(0) else: flask.abort(404) return flask.send_file(image_file, as_attachment=True, attachment_filename=photo)
def label_print(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) country_names = [] if person.data['personal_country']: country_names = refdata.translated_country_names[ person.data['personal_country']] pdf = sugar.generate_pdf_from_html( flask.render_template('participant/person_label_simple.html', **{ 'person': person, 'country_names': country_names, }) ) return flask.Response(response=pdf, mimetype='application/pdf')
def envelope(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) secretariat = refdata.secretariat country_names = [] try: country_names = \ refdata.translated_country_names[ person.data['personal_country']] except KeyError: pass return { 'secretariat': secretariat, 'person': person, 'meeting': meeting, 'country_names': country_names, }
def crop_photo_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 = { 'crop_url': flask.url_for('.crop_photo', meeting_id=meeting.id, person_id=person.id), 'cancel_url': flask.url_for('.view', meeting_id=meeting.id, person_id=person.id), 'revert_url': flask.url_for('participant.revert_photo', meeting_id=meeting.id, person_id=person.id), } return { 'meeting': meeting, 'person': person, 'page_info': page_info, }
def badge(meeting_id, person_id, person_type): from printouts import _get_meeting_description 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) person.photo_url = person.image_file return { 'person': person, 'meeting': meeting, 'category': person.category_model(meeting.id), 'meeting_description': _get_meeting_description(meeting, 'E'), 'badge': badge, 'person_type': person_type, }
def view(meeting_id, person_id, from_page): 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), } RegistrationForm = get_registration_form(meeting.data['info_type']) registration_form = RegistrationForm(meeting=meeting) event_form = EventCitesForm(meeting_model=meeting, person=person) question_form = QuestionCitesForm(meeting_model=meeting, person=person) return { 'meeting': meeting, 'person': person, 'page_info': page_info, 'from_page': from_page, 'event_form': event_form, 'question_form': question_form, 'registration_form': registration_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 if badge and badge == 'nostripe': color = 'all-white' else: category = person.category_model(meeting.id) color = category.data['badge_color'].replace(' ', '-') filename = color + '-left.png' if not app.config['BADGES_LOGOS'].joinpath(filename).exists(): generate_badge_logo(color) # save badge as html context = dict(meeting=meeting, person=person, path=app.root_path, background_path=app.config['UPLOADED_BACKGROUNDS_DEST'], badge_logo_path=app.config['BADGES_LOGOS'], 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 media_file_delete(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) 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) url = flask.url_for('participant.view', meeting_id=meeting.id, person_id=person.id) else: flask.abort(400) app = flask.current_app if person.data.get(file_type): try: app.config['UPLOADED_FILES_DEST'].joinpath( person.data[file_type]).unlink() except OSError: pass person.data.pop(file_type, None) person.save() return flask.json.dumps({'status': 'success', 'url': url})
def credentials(meeting_id, person_id): meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) fees = meeting.get_fees person = sugar.get_person_or_404(meeting_id, person_id) category = sugar.get_person_category_or_404(meeting_id, person_id=person_id) labeled = schema.labels_for_values(person.decoded_data, meeting_id, in_participant_language=True, category=category) 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) return { 'meeting': meeting, 'category': category, 'phrases': phrases, 'person': person, 'labeled': labeled, 'credentials_strings': refdata.credentials_strings, 'event_form': event_form, }
def remove_photo(meeting_id, person_id): meeting = schema.Meeting.get_or_404(meeting_id) person = sugar.get_person_or_404(meeting_id, person_id) return _remove_photo(meeting, person)
def rotate_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) return _rotate_photo(meeting, person)
def send_mail(meeting_id, person_id): app = flask.current_app meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) session = database.get_session() person = sugar.get_person_or_404(meeting_id, person_id) lang_code = person.decoded_data['personal_language'] or 'en' labeled = schema.labels_for_values(person.data, meeting_id, in_participant_language=True) category = person.category_model(meeting_id) cc_addresses = [] phrases = {p.data['name']: p for p in meeting.get_phrases} event_form = EventCitesForm(meeting_model=meeting, person=person) if flask.request.method == "POST": mail = Mail(app) form_data = flask.request.form.to_dict() if form_data['mail_to'].find(',') != -1: to_addresses = form_data['mail_to'].split(',') if form_data.get('mail_cc'): cc_addresses = form_data['mail_cc'].split(',') else: to_addresses = form_data["mail_to"].split(";") if form_data.get('mail_cc'): cc_addresses = form_data["mail_cc"].split(";") # populate schema with data from POST mail_schema = schema.MailSchema.from_flat(form_data) to_member_schema = mail_schema['to'].member_schema cc_member_schema = mail_schema['cc'].member_schema for address in to_addresses: mail_schema['to'].append(to_member_schema(address)) for address in cc_addresses: mail_schema['cc'].append(cc_member_schema(address)) if mail_schema.validate(): # flatten schema mail_data = {} mail_data.update(mail_schema.flatten()) mail_data['mail_to'] = to_addresses mail_data['mail_cc'] = cc_addresses # construct recipients from "to" recipients = mail_data['mail_to'] # send email msg = Message(mail_data['mail_subject'], sender = meeting.decoded_data['info_admin_email'], recipients=recipients, cc=mail_data['mail_cc'], body=mail_data['mail_message']) # 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, 'meeting': meeting, 'credentials_strings': refdata.credentials_strings, 'labeled': labeled, 'phrases': phrases, 'category': category, 'event_form': event_form, }) ) msg.attach('registration_details.pdf', 'application/pdf', pdf) mail.send(msg) # log mail mail_log_data = { 'date': date.today(), 'meeting_id': meeting.id, 'person_id': person_id, 'type': 'single_mail', } mail_log_data.update(mail_data) mail_log_schema = schema.MailLogSchema.from_flat(mail_log_data) 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() # update acknowledged date person.update_meeting_flags(meeting_id, { 'meeting_flags_acknowledged': str(datetime.now().replace( second=0, microsecond=0)) }) if app.config['MAIL_SUPPRESS_SEND']: flask.flash(u'This is a demo, no real email was sent', 'info') else: # flash a success message success_msg = u'Mail sent to %d recipients.' % ( len(to_addresses) + len(cc_addresses)) flask.flash(success_msg, 'success') return flask.redirect( flask.url_for('participant.send_mail', meeting_id=meeting_id, person_id=person_id)) else: flask.flash(u'Errors in mail information', 'error') else: # create a schema with default data mail_schema = schema.MailSchema({ 'to': [person.data['personal_email']], 'subject': phrases['EM_Subj'].decoded_data['description_%s' % lang_code], 'message': '\n\n\n%s' % phrases['Intro'].decoded_data['description_%s' % lang_code], }) return { 'mk': sugar.MarkupGenerator( app.jinja_env.get_template('widgets/widgets_mail.html') ), 'person': person, 'category': category, 'mail_schema': mail_schema, 'meeting': meeting, 'phrases': phrases, }
def crop_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('.view', meeting_id=meeting.id, person_id=person.id) return _crop_photo(meeting, person, url)