def send_email_strotime_granted(application):
    personJSON = get_person_from_web(application.person.uri)
    resourceJSON = get_resource_from_web(application.resource.uri)
    person_name = ""
    if personJSON["first_name"] and personJSON["last_name"]:
        person_name = personJSON["first_name"] + " " + personJSON["last_name"]
    if personJSON["email_address"]:
        application_status = format_application_status_for_email(application.status)

        resource_name = ""
        if resourceJSON["name"]:
            resource_name = resourceJSON["name"]

        slots = []
        for slot in application.slots:
            slots.append(format_slot_for_email(slot))
        message = render_template(
            "email_strotime_granted.txt",
            resource_name=resource_name,
            application_status=application_status,
            slots=slots,
            person_name=person_name,
        )
        resource_email = personJSON["email_address"]
        if message is not None and resource_email is not None:
            send_email_task.delay(u"Strøtime tildelt", u"*****@*****.**", [resource_email], message)
def format_slots_for_email(slots, application_type):
    formatted_slots = []
    for slot in slots:
        if application_type == "repeating":
            formatted_slots.append(format_repeating_slot_for_email(slot))
        else:
            formatted_slots.append(format_slot_for_email(slot))
    return formatted_slots
    def send_email_to_affected_applications(self, arrangement,
                                            affected_applications,
                                            message):
        arrangement_slots = []
        for arrangement_slot in arrangement.slots:
            arrangement_slots.append(format_slot_for_email(arrangement_slot))

        for affected_application in affected_applications:
            if affected_application.slots:
                resource_details = get_resource_from_web(affected_application.resource.uri)
                resource_name = resource_details['name']

                person_details = get_person_from_web(affected_application.person.uri)
                email_address = person_details['email_address']

                org_name = None
                if affected_application.organisation is not None:
                    org_details = get_organisation_from_web(affected_application.organisation.uri)
                    org_name = org_details.get('name')

                application_time = affected_application.application_time.strftime("%Y.%m.%d %H:%M:00")

                slots = []
                # Just create human readable text out of slots
                for slot in affected_application.slots:
                    if affected_application.get_type() == "repeating":
                        slots.append(format_repeating_slot_for_email(slot))
                    else:
                        slots.append(format_slot_for_email(slot))

                msg = render_template("email_arrangement_notification.txt",
                                      org_name=org_name,
                                      resource_name=resource_name,
                                      application_time=application_time,
                                      slots=slots,
                                      arrangement_slots=arrangement_slots,
                                      message=message)

                if email_address and msg is not None:
                    send_email_task.delay(u'Arrangement',
                                          u'*****@*****.**',
                                          [email_address],
                                           msg)
Ejemplo n.º 4
0
def generate_slots(application):
    if application.type == 'repeating':
        return [format_repeating_slot_for_email(slot)
                for slot in application.slots]
    else:
        return [format_slot_for_email(slot) for slot in application.slots]