Пример #1
0
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')
Пример #2
0
def view_pdf(person_id):
    app = flask.current_app
    pdf = sugar.generate_pdf_from_html(
        flask.render_template("participant/credentials.html", **{
            "person": schema.Person.get_or_404(person_id),
            "meeting_description": MEETING_DESCRIPTION,
            "meeting_address": MEETING_ADDRESS,
        })
    )
    return flask.Response(response=pdf, mimetype="application/pdf")
Пример #3
0
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')
Пример #4
0
def send_mail(person_id):
    app = flask.current_app
    session = database.get_session()

    person = schema.Person.get_or_404(person_id)
    phrases = {item["id"]: item["name"]  for item in
               schema._load_json("refdata/phrases.json")}

    if flask.request.method == "POST":
        mail = Mail(app)
        # populate schema with data from POST
        mail_schema = schema.MailSchema.from_flat(flask.request.form.to_dict())

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

            # construct recipients from "to"
            recipients = [mail_data["to"]]
            # recipients = ["*****@*****.**"]

            # send email
            msg = Message(mail_data["subject"], sender="*****@*****.**",
                          recipients=recipients, cc=[mail_data["cc"]],
                          body=mail_data["message"])

            pdf = sugar.generate_pdf_from_html(
                flask.render_template("participant/credentials.html", **{
                    "person": schema.Person.get_or_404(person_id),
                    "meeting_description": MEETING_DESCRIPTION,
                    "meeting_address": MEETING_ADDRESS,
                })
            )
            msg.attach("credentials.pdf", "application/pdf", pdf)
            mail.send(msg)

            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 %s" % mail_data["to"]
                if mail_data["cc"]:
                    success_msg += u" and to %s" % mail_data["cc"]
                flask.flash(success_msg, "success")

        else:
            flask.flash(u"Errors in mail information", "error")

    else:
        # create a schema with default data
        mail_schema = schema.MailSchema({
            "to": person["personal"]["email"],
            "subject": phrases["EM_Subj"],
            "message": "\n\n\n%s" % phrases["Intro"],
        })

    return {
        "mk": sugar.MarkupGenerator(
            app.jinja_env.get_template("widgets/widgets_mail.html")
        ),
        "person": person,
        "mail_schema": mail_schema,
    }
Пример #5
0
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,
    }