Ejemplo n.º 1
0
def prepare_group_conversation_message_notification(user, messages):
    first_message = messages[0]
    conversation = first_message.conversation
    group = conversation.target

    from_text = author_names(messages)
    reply_to_name = group.name
    conversation_name = group.name

    local_part = make_local_part(conversation, user)
    reply_to = formataddr(
        (reply_to_name, '{}@{}'.format(local_part,
                                       settings.SPARKPOST_RELAY_DOMAIN)))
    from_email = formataddr((from_text, settings.DEFAULT_FROM_EMAIL))

    return prepare_email(template='conversation_message_notification',
                         from_email=from_email,
                         user=user,
                         reply_to=[reply_to],
                         context={
                             'messages':
                             messages,
                             'conversation_name':
                             conversation_name,
                             'conversation_url':
                             group_wall_url(group),
                             'mute_url':
                             group_conversation_mute_url(group, conversation),
                         })
Ejemplo n.º 2
0
def prepare_group_thread_message_notification(user, messages):
    first_message = messages[0]
    conversation = first_message.conversation
    thread = first_message.thread

    thread_text_beginning = Truncator(thread.content).chars(num=60)

    from_text = author_names(messages)
    reply_to_name = thread.author.display_name
    conversation_name = thread_text_beginning

    local_part = make_local_part(conversation, user, thread)
    reply_to = formataddr(
        (reply_to_name, '{}@{}'.format(local_part,
                                       settings.SPARKPOST_RELAY_DOMAIN)))
    from_email = formataddr((from_text, settings.DEFAULT_FROM_EMAIL))

    return prepare_email(template='thread_message_notification',
                         from_email=from_email,
                         user=user,
                         reply_to=[reply_to],
                         context={
                             'messages':
                             messages,
                             'conversation_name':
                             conversation_name,
                             'thread_author':
                             thread.author,
                             'thread_message_content':
                             thread.content_rendered(truncate_words=40),
                             'thread_url':
                             thread_url(thread),
                             'mute_url':
                             thread_mute_url(thread),
                         })
Ejemplo n.º 3
0
def prepare_private_user_conversation_message_notification(user, messages):
    first_message = messages[0]
    conversation = first_message.conversation
    author = first_message.author
    reply_to_name = author.display_name

    local_part = make_local_part(conversation, user)
    reply_to = formataddr(
        (reply_to_name, '{}@{}'.format(local_part,
                                       settings.SPARKPOST_RELAY_DOMAIN)))
    from_email = formataddr((author.display_name, settings.DEFAULT_FROM_EMAIL))

    return prepare_email(template='conversation_message_notification',
                         from_email=from_email,
                         user=user,
                         reply_to=[reply_to],
                         context={
                             'messages':
                             messages,
                             'conversation_name':
                             author.display_name,
                             'conversation_url':
                             user_detail_url(author),
                             'mute_url':
                             user_conversation_mute_url(author, conversation),
                         })
Ejemplo n.º 4
0
def prepare_pickup_conversation_message_notification(user, messages):
    first_message = messages[0]
    conversation = first_message.conversation
    pickup = conversation.target
    group_tz = pickup.store.group.timezone

    language = user.language

    if not translation.check_for_language(language):
        language = 'en'

    with translation.override(language):
        with timezone.override(group_tz):
            weekday = format_date(
                pickup.date.astimezone(timezone.get_current_timezone()),
                'EEEE',
                locale=translation.to_locale(language),
            )
            time = format_time(
                pickup.date,
                format='short',
                locale=translation.to_locale(language),
                tzinfo=timezone.get_current_timezone(),
            )
            date = format_date(
                pickup.date.astimezone(timezone.get_current_timezone()),
                format='long',
                locale=translation.to_locale(language),
            )

            long_date = '{} {}, {}'.format(weekday, time, date)
            short_date = '{} {}'.format(weekday, time)

            reply_to_name = _('Pickup %(date)s') % {
                'date': short_date,
            }
            conversation_name = _('Pickup %(date)s') % {
                'date': long_date,
            }

            from_text = author_names(messages)

            local_part = make_local_part(conversation, user)
            reply_to = formataddr((reply_to_name, '{}@{}'.format(local_part, settings.SPARKPOST_RELAY_DOMAIN)))
            from_email = formataddr((from_text, settings.DEFAULT_FROM_EMAIL))

            return prepare_email(
                template='conversation_message_notification',
                from_email=from_email,
                user=user,
                reply_to=[reply_to],
                context={
                    'messages': messages,
                    'conversation_name': conversation_name,
                    'conversation_url': pickup_detail_url(pickup),
                    'mute_url': pickup_conversation_mute_url(pickup, conversation),
                }
            )
Ejemplo n.º 5
0
def prepare_group_application_message_notification(user, messages):
    first_message = messages[0]
    conversation = first_message.conversation
    application = conversation.target

    language = user.language

    if not translation.check_for_language(language):
        language = 'en'

    with translation.override(language):
        reply_to_name = application.user.display_name
        conversation_name = _(
            'New message in application of %(user_name)s to %(group_name)s'
        ) % {
            'user_name': application.user.display_name,
            'group_name': application.group.name,
        }
        if application.user == user:
            conversation_name = _(
                'New message in your application to %(group_name)s') % {
                    'group_name': application.group.name
                }

        from_text = author_names(messages)

        local_part = make_local_part(conversation, user)
        reply_to = formataddr(
            (reply_to_name, '{}@{}'.format(local_part,
                                           settings.SPARKPOST_RELAY_DOMAIN)))
        from_email = formataddr((from_text, settings.DEFAULT_FROM_EMAIL))

        return prepare_email(template='conversation_message_notification',
                             from_email=from_email,
                             user=user,
                             reply_to=[reply_to],
                             context={
                                 'messages':
                                 messages,
                                 'conversation_name':
                                 conversation_name,
                                 'conversation_url':
                                 group_application_url(application),
                                 'mute_url':
                                 group_application_mute_url(
                                     application, conversation),
                             })
Ejemplo n.º 6
0
def prepare_new_application_notification_email(user, application):
    applicant = application.user
    conversation = Conversation.objects.get_for_target(application)

    reply_to_name = applicant.display_name

    local_part = make_local_part(conversation, user)
    reply_to = formataddr(
        (reply_to_name, '{}@{}'.format(local_part,
                                       settings.SPARKPOST_RELAY_DOMAIN)))
    from_email = formataddr(
        (applicant.display_name, settings.DEFAULT_FROM_EMAIL))

    return prepare_email(template='new_application',
                         from_email=from_email,
                         user=user,
                         reply_to=[reply_to],
                         context={
                             'applicant':
                             applicant,
                             'group':
                             application.group,
                             'questions':
                             application.questions_rendered(),
                             'answers':
                             application.answers_rendered(),
                             'conversation_url':
                             group_application_url(application),
                             'mute_url':
                             group_application_mute_url(
                                 application, conversation),
                             'settings_url':
                             group_settings_url(application.group),
                             'group_applications_url':
                             group_applications_url(application.group),
                             'group_edit_url':
                             group_edit_url(application.group),
                         })