Пример #1
0
def weekly_sales_report_notice(sender, provider, dates, data, **kwargs):
    recipients, bcc = _notified_recipients(provider,
                                           "weekly_sales_report_created")
    if SEND_EMAIL and recipients:
        app = get_current_app()
        site = get_current_site()
        frm = site.get_from_email()
        # if from is empty the following command will fail
        if not frm:
            raise Exception(
                "Please fill the DEFAULT_FROM_EMAIL option in settings")

        prev_week, _ = dates
        last_sunday = prev_week[-1]
        date = last_sunday.strftime("%A %b %d, %Y")

        # XXX using the provider in templates is incorrect. "Any questions
        # or comments..." should show DjaoDjin support email address.
        get_email_backend(connection=site.get_email_connection()).send(
            from_email=frm,
            recipients=recipients,
            bcc=bcc,
            template='notification/weekly_sales_report_created.eml',
            context={
                'broker': get_broker(),
                'provider': provider,
                # Without ``app`` we don't set the color correctly in
                # in notification/base.html, thus ending with an error
                # in premailer.
                'app': app,
                'table': data,
                'date': date
            })
Пример #2
0
def user_registered_notice(sender, user, **kwargs):
    """
    A new user has registered (frictionless or completely)
    """
    LOGGER.debug("[signal] user_registered_notice(user=%s)", user)
    if not SEND_EMAIL:
        return
    broker = get_broker()
    app = get_current_app()
    site = get_current_site()
    if settings.FEATURES_DEBUG:
        back_url = site.as_absolute_uri()
        get_email_backend(connection=site.get_email_connection()).send(
            from_email=site.get_from_email(),
            recipients=[user.email],
            template='notification/user_welcome.eml',
            context={
                'broker': get_broker(),
                'app': app,
                'user': get_user_context(user),
                'back_url': back_url
            })
    recipients, bcc = _notified_recipients(broker, "user_registered_notice")
    if recipients:
        get_email_backend(connection=site.get_email_connection()).send(
            from_email=site.get_from_email(),
            recipients=recipients,
            bcc=bcc,
            template='notification/user_registered.eml',
            context={
                'broker': get_broker(),
                'app': app,
                'user': get_user_context(user)
            })
Пример #3
0
def organization_updated_notice(sender, organization, changes, user, **kwargs):
    if not changes:
        return
    #pylint:disable=unused-variable
    recipients, notused = _notified_recipients(
        organization, 'organization_updated')
    LOGGER.info("%s updated", organization,
        extra={'event': 'update-fields', 'organization': str(organization),
               'changes': changes})
    if SEND_EMAIL and recipients:
        broker = get_broker()
        site = get_current_site()
        app = get_current_app()
        broker_recipients, broker_bcc = _notified_recipients(
        broker, 'organization_updated')
        reply_to = None
        if broker.email and broker.email != site.get_from_email():
            reply_to = broker.email
        _send_notification_email(site, recipients,
            'notification/organization_updated.eml',
            reply_to=reply_to, bcc=broker_recipients + broker_bcc,
            context={
                'broker': broker, 'app': app,
                'user': get_user_context(user),
                'organization': organization, 'changes': changes,
                'urls':{
                    'user': {
                        'profile': site.as_absolute_uri(reverse(
                            'users_profile', args=(user,)))},
                    'organization': {
                        'profile': site.as_absolute_uri(reverse(
                            'saas_organization_profile', args=(organization,)))}
                }})
Пример #4
0
def weekly_sales_report_notice(sender, provider, dates, data, **kwargs):
    recipients, bcc = _notified_recipients(provider,
                                           "weekly_sales_report_created")
    if SEND_EMAIL and recipients:
        prev_week, notused = dates  #pylint:disable=unused-variable
        last_sunday = prev_week[-1]
        date = last_sunday.strftime("%A %b %d, %Y")

        app = get_current_app()
        site = get_current_site()
        # XXX using the provider in templates is incorrect. "Any questions
        # or comments..." should show DjaoDjin support email address.
        _send_notification_email(
            site,
            recipients,
            'notification/weekly_sales_report_created.eml',
            bcc=bcc,
            context={
                'broker': get_broker(),
                'provider': provider,
                # Without ``app`` we don't set the color correctly in
                # in notification/base.html, thus ending with an error
                # in premailer.
                'app': app,
                'table': data,
                'date': date
            })
Пример #5
0
def user_activated_notice(sender, user, verification_key, request, **kwargs):
    """
    A new user has activated his account. We have a complete profile
    and active email address now.
    """
    for role in get_role_model().objects.filter(grant_key=verification_key):
        role.grant_key = None
        role.save()

    broker = get_broker()
    site = get_current_site()
    recipients, bcc = _notified_recipients(broker)
    app = get_current_app()
    LOGGER.debug(
        "[signal] user_activated_notice(user=%s, verification_key=%s)", user,
        verification_key)
    if SEND_EMAIL:
        get_email_backend(connection=app.get_connection()).send(
            from_email=app.get_from_email(),
            recipients=recipients,
            bcc=bcc,
            template='notification/user_activated.eml',
            context={
                'request': request,
                'broker': get_broker(),
                'app': app,
                'user': get_user_context(user),
                'urls': {
                    'user': {
                        'profile':
                        site.as_absolute_uri(
                            reverse('users_profile', args=(user, )))
                    }
                }
            })
Пример #6
0
def fail_self_provider(request, user=None, roledescription=None):
    """
    Same decorator as saas.requires_self_provider with the added permissions
    that managers of the site database itself are also able to access
    profiles of registered yet unsubscribed ``Organization``.
    """
    site = get_current_site()
    if site.db_name and site.db_name != DEFAULT_DB_ALIAS:
        # We have a separate database so it is OK for a manager
        # of the site to access registered ``Organization`` which
        # are not subscribed yet.
        if _has_valid_access(request, [get_current_broker()]):
            return False
    try:
        app = get_current_app()
        #pylint:disable=unused-variable
        redirect, matched, session = check_matched(request,
                                                   app,
                                                   prefixes=DEFAULT_PREFIXES)
    except NoRuleMatch:
        # By default, we are looking for provider.
        redirect = fail_self_provider_default(request,
                                              user=user,
                                              roledescription=roledescription)
    return redirect
Пример #7
0
def subscribe_req_created_notice(sender, subscription, reason=None,
                                      request=None, **kwargs):
    if subscription.request_key:
        user_context = get_user_context(request.user if request else None)
        organization = subscription.organization
        if organization.email:
            site = get_current_site()
            app = get_current_app()
            LOGGER.debug("[signal] subscribe_req_created_notice("\
                         " subscription=%s, reason=%s)", subscription, reason)
            if SEND_EMAIL:
                _send_notification_email(site, [organization.email],
                    'notification/subscription_request_created.eml',
                    reply_to=user_context['email'],
                    context={
                        'broker': get_broker(), 'app': app,
                        'back_url': site.as_absolute_uri(reverse(
                            'subscription_request_accept', args=(
                                organization, subscription.request_key,))),
                        'organization': organization,
                        'plan': subscription.plan,
                        'reason': reason if reason is not None else "",
                        'user': user_context})
        else:
            LOGGER.warning(
                "%s will not be notified of a subscription request to %s"\
                " because e-mail address is invalid.",
                organization, subscription.plan)
Пример #8
0
def subscribe_req_accepted_notice(sender,
                                  subscription,
                                  request_key,
                                  request=None,
                                  **kwargs):
    subscriber = subscription.organization
    recipients, bcc = _notified_recipients(subscriber,
                                           "subscribe_req_accepted_notice")
    LOGGER.debug("[signal] subscribe_req_accepted_notice("\
        " subscription=%s, request_key=%s)", subscription, request_key)
    if SEND_EMAIL and recipients:
        site = get_current_site()
        app = get_current_app()
        user_context = get_user_context(request.user if request else None)
        _send_notification_email(
            site,
            recipients,
            'notification/subscription_request_accepted.eml',
            reply_to=user_context['email'],
            bcc=bcc,
            context={
                'broker':
                get_broker(),
                'app':
                app,
                'back_url':
                site.as_absolute_uri(
                    reverse('organization_app', args=(subscriber, ))),
                'organization':
                subscriber,
                'plan':
                subscription.plan,
                'user':
                user_context
            })
Пример #9
0
def get_current_app(request=None):
    """
    Returns the provider ``rules.App`` as read in the active database
    for the ``rules`` and ``pages`` application.
    """
    # If we don't write the code as such, we might end-up generating
    # an extra SQL query every time ``get_current_app`` is called.
    thread_local_site = get_current_site()
    app = getattr(thread_local_site, 'app', None)
    if thread_local_site and not app:
        app_model = get_app_model()
        try:
            thread_local_site.app = app_model.objects.get(
                slug=thread_local_site.slug)
        except app_model.DoesNotExist:
            #pylint:disable=protected-access
            msg = "No %s with slug '%s' can be found." % (
                app_model._meta.object_name, thread_local_site.slug)
            if request is not None:
                LOGGER.exception("get_current_app: %s",
                                 msg,
                                 extra={'request': request})
            else:
                LOGGER.exception("get_current_app: %s", msg)
            raise Http404(msg)
        app = thread_local_site.app
    return app
Пример #10
0
 def get_context_data(self, **kwargs):
     context = super(AppDashboardView, self).get_context_data(**kwargs)
     context.update({
         'site_available_at_url':
         build_absolute_uri(self.request, site=get_current_site().db_object)
     })
     return context
Пример #11
0
def role_request_created_notice(sender, role, reason=None, **kwargs):
    organization = role.organization
    user = role.user
    if user.email != organization.email:
        if user.email:
            site = get_current_site()
            app = get_current_app()
            LOGGER.debug("[signal] role_request_created_notice("\
                "organization=%s, user=%s, reason=%s)",
                organization, user, reason)
            if SEND_EMAIL:
                _send_notification_email(
                    site, [organization.email],
                    'notification/role_request_created.eml',
                    reply_to=user.email,
                    context={
                        'broker':
                        get_broker(),
                        'app':
                        app,
                        'back_url':
                        site.as_absolute_uri(
                            reverse('saas_role_list', args=(organization, ))),
                        'organization':
                        organization,
                        'reason':
                        reason if reason is not None else "",
                        'user':
                        get_user_context(user)
                    })
        else:
            LOGGER.warning(
                "%s will not be notified of role request to %s"\
                " because e-mail address is invalid.", user, organization)
Пример #12
0
def expires_soon_notice(sender, subscription, nb_days, **kwargs):
    broker = get_broker()
    broker_recipients, broker_bcc = _notified_recipients(
        broker, 'expires_soon')
    if subscription.organization.email:
        site = get_current_site()
        app = get_current_app()
        back_url = "%s?plan=%s" % (site.as_absolute_uri(
            reverse('saas_organization_cart',
                    args=(subscription.organization, ))), subscription.plan)
        LOGGER.debug("[signal] expires_soon_notice("\
                     " subscription=%s, nb_days=%s)", subscription, nb_days)
        if SEND_EMAIL:
            recipients, bcc = _notified_recipients(subscription.organization,
                                                   'expires_soon')
            get_email_backend(connection=app.get_connection()).send(
                from_email=app.get_from_email(),
                recipients=recipients,
                reply_to=broker_recipients[0],
                bcc=bcc + broker_recipients + broker_bcc,
                template='notification/expires_soon.eml',
                context={
                    'broker': get_broker(),
                    'app': app,
                    'back_url': back_url,
                    'nb_days': nb_days,
                    'organization': subscription.organization,
                    'plan': subscription.plan,
                    'provider': subscription.plan.organization
                })
    else:
        LOGGER.warning(
            "%s will not be notified of soon expired subscription"\
            " because e-mail address is invalid.", subscription.organization)
Пример #13
0
def claim_code_notice(sender, subscriber, claim_code, user, **kwargs):
    cart_items = CartItem.objects.by_claim_code(claim_code)
    provider = CartItem.objects.provider(cart_items)
    LOGGER.debug("[signal] claim_code_notice(subscriber=%s, claim_code=%s,"\
        " user=%s)", subscriber, claim_code, user)
    if SEND_EMAIL:
        # XXX We don't use `_notified_recipients` here as an attempt
        # only have one person respnsible for using the claim code.
        site = get_current_site()
        app = get_current_app()
        _send_notification_email(site, [subscriber.email],
                                 'notification/claim_code_generated.eml',
                                 reply_to=user.email,
                                 context={
                                     'broker': get_broker(),
                                     'app': app,
                                     'urls': {
                                         'cart':
                                         site.as_absolute_uri(
                                             reverse('saas_cart'))
                                     },
                                     'subscriber': subscriber,
                                     'provider': provider,
                                     'claim_code': claim_code,
                                     'cart_items': cart_items,
                                     'user': get_user_context(user)
                                 })
Пример #14
0
def processor_setup_error_notice(sender, provider, error_message, **kwargs):
    recipients, notused = _notified_recipients(provider,
                                               'processor_setup_error')
    if SEND_EMAIL and recipients:
        broker = get_broker()
        site = get_current_site()
        app = get_current_app()
        broker_recipients, broker_bcc = _notified_recipients(
            broker, 'processor_setup_error')
        reply_to = None
        if broker.email and broker.email != site.get_from_email():
            reply_to = broker.email
        _send_notification_email(site,
                                 recipients,
                                 'notification/processor_setup_error.eml',
                                 reply_to=reply_to,
                                 bcc=broker_recipients + broker_bcc,
                                 context={
                                     'broker': broker,
                                     'app': app,
                                     'organization': provider,
                                     'message': error_message,
                                     'urls': {
                                         'update_bank':
                                         site.as_absolute_uri(
                                             reverse('saas_update_bank',
                                                     args=(provider, ))),
                                     }
                                 })
Пример #15
0
def renewal_charge_failed_notice(sender, invoiced_items, total_price,
                                 final_notice, **kwargs):
    invoiced_items = list(invoiced_items)
    organization = (invoiced_items[0].dest_organization
        if invoiced_items else None)
    recipients, bcc = _notified_recipients(
        organization, 'renewal_charge_failed')
    LOGGER.debug("[signal] renewal_charge_failed_notice(invoiced_items=%s,"\
        " total_price=%s, final_notice=%s)",
        [invoiced_item.pk for invoiced_item in invoiced_items],
        total_price, final_notice)
    if SEND_EMAIL and recipients:
        broker = get_broker()
        broker_recipients, broker_bcc = _notified_recipients(broker,
            'renewal_charge_failed')
        app = get_current_app()
        site = get_current_site()
        context = {'broker': broker, 'app': app, 'provider': broker,
            'organization': organization, 'invoiced_items': invoiced_items,
            'total_price': total_price,
            'max_renewal_attempts': saas_settings.MAX_RENEWAL_ATTEMPTS,
            'final_notice': final_notice,
            'back_url': reverse('saas_organization_cart', args=(organization,))}
        reply_to = None
        if broker.email and broker.email != site.get_from_email():
            reply_to = broker.email
        _send_notification_email(site, recipients,
            'notification/renewal_charge_failed.eml',
            reply_to=reply_to, bcc=bcc + broker_recipients + broker_bcc,
            context=context)
Пример #16
0
def charge_updated_notice(sender, charge, user, **kwargs):
    from saas.mixins import get_charge_context  # Avoid import loop
    recipients, bcc = _notified_recipients(charge.customer, "charge_updated")
    if charge.is_paid:
        LOGGER.debug("[signal] charge_updated_notice(charge=%s, user=%s)",
                     charge, user)
        if SEND_EMAIL and recipients:
            broker = charge.broker
            broker_recipients, broker_bcc = _notified_recipients(
                broker, "charge_updated")
            context = get_charge_context(charge)
            if user and charge.created_by != user:
                context.update({'email_by': get_user_context(user)})
            app = get_current_app()
            site = get_current_site()
            context.update({
                'broker': get_broker(),
                'app': app,
                'urls': {
                    'charge': {
                        'created_by':
                        reverse('users_profile', args=(charge.created_by, ))
                    }
                }
            })
            reply_to = None
            if broker.email and broker.email != site.get_from_email():
                reply_to = broker.email
            _send_notification_email(site,
                                     recipients,
                                     'notification/charge_receipt.eml',
                                     reply_to=reply_to,
                                     bcc=bcc + broker_recipients + broker_bcc,
                                     context=context)
Пример #17
0
def user_registered_notice(sender, user, **kwargs):
    """
    A new user has registered (frictionless or completely)
    """
    LOGGER.debug("[signal] user_registered_notice(user=%s)", user)
    if not SEND_EMAIL:
        return
    broker = get_broker()
    app = get_current_app()
    site = get_current_site()
    recipients, bcc = _notified_recipients(broker, "user_registered_notice")
    if hasattr(app, 'welcome_email') and app.welcome_email:
        back_url = site.as_absolute_uri()
        reply_to = None
        if broker.email and broker.email != site.get_from_email():
            reply_to = broker.email
        _send_notification_email(site, [user.email],
            'notification/user_welcome.eml',
            reply_to=reply_to, bcc=recipients + bcc, context={
                'broker': broker, 'app': app,
                'user': get_user_context(user),
                'back_url': back_url})
    if recipients:
        _send_notification_email(site, recipients,
            'notification/user_registered.eml',
            bcc=bcc, context={
                'broker': broker, 'app': app,
                'user': get_user_context(user)})
Пример #18
0
def order_executed_notice(sender, invoiced_items, user, **kwargs):
    invoiced_items = list(invoiced_items)
    organization = (invoiced_items[0].dest_organization
        if invoiced_items else None)
    recipients, bcc = _notified_recipients(organization, 'order_executed')
    LOGGER.debug("[signal] order_executed_notice(invoiced_items=%s, user=%s)",
        [invoiced_item.pk for invoiced_item in invoiced_items], user)
    if SEND_EMAIL and recipients:
        broker = get_broker()
        broker_recipients, broker_bcc = _notified_recipients(broker,
            'order_executed')
        app = get_current_app()
        site = get_current_site()
        context = {'broker': broker, 'app': app, 'provider': broker,
            'organization': organization, 'invoiced_items': invoiced_items,
            'created_by': user}
        if user:
            context.update({'urls': {'order': {'created_by':
                reverse('users_profile', args=(user,))}}})
        reply_to = None
        if broker.email and broker.email != site.get_from_email():
            reply_to = broker.email
        _send_notification_email(site, recipients,
            'notification/order_executed.eml',
            reply_to=reply_to, bcc=bcc + broker_recipients + broker_bcc,
            context=context)
Пример #19
0
def contact_requested_notice(sender, provider, user, reason, **kwargs):
    """
    Someone requested information through the contact form.
    """
    if provider is None:
        provider = get_broker()
    app = get_current_app()
    context = {'broker': get_broker(), 'app': app,
        'provider': provider, 'user': get_user_context(user),
        'reason': reason}
    if user.pk is not None:
        context.update({'urls': {'user': {'profile':
            reverse('users_profile', args=(user,))}}})
    recipients, bcc = _notified_recipients(provider, "contact_requested_notice")
    # We are hanlding `recipients` a bit differently here because contact
    # requests are usually meant to be sent to a ticketing system.
    if provider.email:
        recipients = [provider.email]
        bcc = recipients + bcc
    LOGGER.debug("[signal] contact_requested_notice(provider=%s, user=%s)",
        provider, user)
    if SEND_EMAIL and recipients:
        _send_notification_email(get_current_site(), recipients,
            'notification/user_contact.eml',
            reply_to=user.email, bcc=bcc, context=context)
Пример #20
0
        def _wrapped_view(request, *args, **kwargs):
            LOGGER.debug("Enters djaoapp.decorators.requires_self_provider")
            site = get_current_site()
            if site.db_name:
                # We have a separate database so it is OK for a manager
                # of the site to access profiles of ``User`` which
                # are not subscribed yet.
                if _has_valid_access(request, [get_current_broker()],
                                     strength):
                    return view_func(request, *args, **kwargs)
            try:
                app = get_current_app()
                #pylint:disable=unused-variable
                redirect_url, matched, session = check_matched(
                    request, app, prefixes=DEFAULT_PREFIXES)
                if redirect_url:
                    if isinstance(redirect_url, six.string_types):
                        return http.HttpResponseRedirect(redirect_url)
                    raise PermissionDenied()
            except NoRuleMatch:
                redirect_url = _fail_self_provider(request,
                                                   user=kwargs.get(
                                                       'user', None),
                                                   strength=strength)
                if redirect_url:
                    return redirect_or_denied(request, redirect_url,
                        redirect_field_name=redirect_field_name,
                        descr=_("%(auth)s has neither a direct"\
" relation to an organization connected to %(user)s nor a connection to one"\
" of the providers to such organization.") % {
                    'auth': request.user, 'user': kwargs.get('user', None)})
            return view_func(request, *args, **kwargs)
Пример #21
0
        def _wrapped_view(request, *args, **kwargs):
            LOGGER.debug("Enters djaoapp.decorators.requires_provider_only")
            site = get_current_site()
            organization = kwargs.get('organization', None)
            if site.db_name:
                # We have a separate database so it is OK for a manager
                # of the site to access registered ``Organization`` which
                # are not subscribed yet.
                if _has_valid_access(request, [get_current_broker()],
                                     strength):
                    return view_func(request, *args, **kwargs)
            try:
                app = get_current_app()
                #pylint:disable=unused-variable
                redirect_url, matched, session = check_matched(
                    request, app, prefixes=DEFAULT_PREFIXES)
                if redirect_url:
                    if isinstance(redirect_url, six.string_types):
                        return http.HttpResponseRedirect(redirect_url)
                    raise PermissionDenied()
            except NoRuleMatch:
                # By default, we are looking for provider.
                slug = kwargs.get('charge', organization)
                redirect_url = _fail_provider_only(
                    request,
                    organization=slug,
                    roledescription=roledescription,
                    strength=strength)
                if redirect_url:
                    return redirect_or_denied(request, redirect_url,
                        redirect_field_name=redirect_field_name,
                        descr=_("%(auth)s is not a manager of one of"\
" %(organization)s providers.") % {'auth': request.user, 'organization': slug})
            return view_func(request, *args, **kwargs)
Пример #22
0
def user_activated_notice(sender, user, verification_key, request, **kwargs):
    """
    A new user has activated his account. We have a complete profile
    and active email address now.
    """
    broker = get_broker()
    recipients, bcc = _notified_recipients(broker, "user_activated_notice")
    LOGGER.debug(
        "[signal] user_activated_notice(user=%s, verification_key=%s)", user,
        verification_key)
    if SEND_EMAIL and recipients:
        site = get_current_site()
        app = get_current_app()
        _send_notification_email(site,
                                 recipients,
                                 'notification/user_activated.eml',
                                 bcc=bcc,
                                 context={
                                     'request': request,
                                     'broker': get_broker(),
                                     'app': app,
                                     'user': get_user_context(user),
                                     'urls': {
                                         'user': {
                                             'profile':
                                             site.as_absolute_uri(
                                                 reverse('users_profile',
                                                         args=(user, )))
                                         }
                                     }
                                 })
Пример #23
0
        def _wrapped_view(request, *args, **kwargs):
            site = get_current_site()
            if site.db_name:
                # We have a separate database so it is OK for a manager
                # of the site to access profiles of ``User`` which
                # are not subscribed yet.
                if _has_valid_access(request, [get_current_broker()],
                                     strength):
                    return view_func(request, *args, **kwargs)
            try:
                app = get_current_app()
                redirect_url, _, _ = check_matched(
                    request,
                    app,
                    prefixes=[
                        '/api/billing/', '/api/metrics/', '/api/profile/',
                        '/api/users/', '/billing/', '/metrics/', '/profile/',
                        '/users/'
                    ])
                if redirect_url:
                    if isinstance(redirect_url, six.string_types):
                        return http.HttpResponseRedirect(redirect_url)
                    raise PermissionDenied()
            except NoRuleMatch:
                if _fail_self_provider(request,
                                       user=kwargs.get('user', None),
                                       strength=strength):
                    raise PermissionDenied("%(auth)s has neither a direct"\
" relation to an organization connected to %(user)s nor a connection to one"\
"of the providers to such organization." % {
                    'auth': request.user, 'user': kwargs.get('user', None)})
            return view_func(request, *args, **kwargs)
Пример #24
0
def user_verification_notice(sender, user, request, back_url, expiration_days,
                             **kwargs):
    """
    A user has reset her password.
    """
    broker = get_broker()
    LOGGER.debug("[signal] user_verification_notice(user=%s, back_url=%s,"\
        " expiration_days=%s)", user, back_url, expiration_days)
    if SEND_EMAIL:
        app = get_current_app()
        site = get_current_site()
        _send_notification_email(
            site,
            [user.email],
            'notification/verification.eml',
            context={
                'request': request,
                # Without ``app`` we donot set the color correctly in
                # in notification/base.html, thus ending with an error
                # in premailer.
                'broker': get_broker(),
                'app': app,
                'provider': broker,
                'user': get_user_context(user),
                'back_url': back_url,
                'expiration_days': expiration_days
            })
Пример #25
0
def expires_soon_notice(sender, subscription, nb_days, **kwargs):
    LOGGER.debug("[signal] expires_soon_notice("\
                 " subscription=%s, nb_days=%s)", subscription, nb_days)
    recipients, bcc = _notified_recipients(subscription.organization,
                                           'expires_soon')
    if SEND_EMAIL and recipients:
        broker = get_broker()
        broker_recipients, broker_bcc = _notified_recipients(
            broker, 'expires_soon')
        site = get_current_site()
        app = get_current_app()
        back_url = "%s?plan=%s" % (site.as_absolute_uri(
            reverse('saas_organization_cart',
                    args=(subscription.organization, ))), subscription.plan)
        reply_to = None
        if broker.email and broker.email != site.get_from_email():
            reply_to = broker.email
        _send_notification_email(site,
                                 recipients,
                                 'notification/expires_soon.eml',
                                 reply_to=reply_to,
                                 bcc=bcc + broker_recipients + broker_bcc,
                                 context={
                                     'broker': get_broker(),
                                     'app': app,
                                     'back_url': back_url,
                                     'nb_days': nb_days,
                                     'organization': subscription.organization,
                                     'plan': subscription.plan,
                                     'provider': subscription.plan.organization
                                 })
Пример #26
0
def card_updated_notice(sender, organization, user, old_card, new_card,
                        **kwargs):
    recipients, bcc = _notified_recipients(organization, 'card_updated')
    LOGGER.debug("[signal] card_updated_notice(organization=%s, user=%s,"\
        "old_card=%s, new_card=%s)", organization, user, old_card, new_card)
    if SEND_EMAIL and recipients:
        broker = get_broker()
        broker_recipients, broker_bcc = _notified_recipients(
            broker, 'card_updated')
        app = get_current_app()
        site = get_current_site()
        if broker.email and broker.email != site.get_from_email():
            reply_to = broker.email
        _send_notification_email(site,
                                 recipients,
                                 'notification/card_updated.eml',
                                 reply_to=reply_to,
                                 bcc=bcc + broker_recipients + broker_bcc,
                                 context={
                                     'broker': broker,
                                     'app': app,
                                     'organization': organization,
                                     'user': get_user_context(user),
                                     'old_card': old_card,
                                     'new_card': new_card
                                 })
Пример #27
0
def claim_code_notice(sender, subscriber, claim_code, user, **kwargs):
    cart_items = CartItem.objects.by_claim_code(claim_code)
    provider = CartItem.objects.provider(cart_items)
    site = get_current_site()
    app = get_current_app()
    LOGGER.debug("[signal] claim_code_notice(subscriber=%s, claim_code=%s,"\
        " user=%s)", subscriber, claim_code, user)
    if SEND_EMAIL:
        get_email_backend(connection=app.get_connection()).send(
            from_email=app.get_from_email(),
            recipients=[subscriber.email],
            reply_to=user.email,
            template='notification/claim_code_generated.eml',
            context={
                'broker': get_broker(),
                'app': app,
                'urls': {
                    'cart': site.as_absolute_uri(reverse('saas_cart'))
                },
                'subscriber': subscriber,
                'provider': provider,
                'claim_code': claim_code,
                'cart_items': cart_items,
                'user': get_user_context(user)
            })
Пример #28
0
 def get_context_data(self, **kwargs):
     context = super(ThemePackageView, self).get_context_data(**kwargs)
     context.update({'notifications': self.get_notifications()})
     self.update_context_urls(
         context, {'send_test_email': reverse('api_notification_base')})
     context.update({
         'site_available_at_url':
         build_absolute_uri(self.request, site=get_current_site().db_object)
     })
     return context
Пример #29
0
def user_relation_added_notice(sender, role, reason=None, **kwargs):
    user = role.user
    organization = role.organization
    if user.email != organization.email:
        if user.email:
            back_url = reverse('organization_app', args=(organization, ))
            if has_invalid_password(user):
                if role.grant_key:
                    contact, _ = Contact.objects.get_or_create_token(
                        user, verification_key=role.grant_key)
                else:
                    # The User is already in the system but the account
                    # has never been activated.
                    contact, _ = Contact.objects.get_or_create_token(
                        user,
                        verification_key=organization.generate_role_key(user))
                user.save()
                back_url = "%s?next=%s" % (reverse(
                    'registration_activate',
                    args=(contact.verification_key, )), back_url)
            elif role.grant_key:
                back_url = reverse('saas_role_grant_accept',
                                   args=(user, role.grant_key))
            site = get_current_site()
            app = get_current_app()
            context = {
                'broker': get_broker(),
                'app': app,
                'back_url': site.as_absolute_uri(back_url),
                'organization': organization,
                'role': role.role_description.title,
                'reason': reason if reason is not None else "",
                'user': get_user_context(user)
            }
            reply_to = organization.email
            request_user = kwargs.get('request_user', None)
            if request_user:
                reply_to = request_user.email
                context.update(
                    {'request_user': get_user_context(request_user)})
            LOGGER.debug("[signal] user_relation_added_notice(role=%s,"\
                " reason=%s)", role, reason)
            if SEND_EMAIL:
                get_email_backend(connection=app.get_connection()).send(
                    from_email=app.get_from_email(),
                    recipients=[user.email],
                    reply_to=reply_to,
                    template=[("notification/%s_role_added.eml" %
                               role.role_description.slug),
                              "notification/role_added.eml"],
                    context=context)
        else:
            LOGGER.warning(
                "%s will not be notified being added to %s"\
                "because e-mail address is invalid.", user, organization)
Пример #30
0
def subscribe_grant_created_notice(sender,
                                   subscription,
                                   reason=None,
                                   invite=False,
                                   request=None,
                                   **kwargs):
    if subscription.grant_key:
        user_context = get_user_context(request.user if request else None)
        organization = subscription.organization
        if organization.email:
            site = get_current_site()
            app = get_current_app()
            back_url = site.as_absolute_uri(
                reverse('subscription_grant_accept',
                        args=(
                            organization,
                            subscription.grant_key,
                        )))
            manager = organization.with_role(saas_settings.MANAGER).first()
            # The following line could as well be `if invite:`
            if has_invalid_password(manager):
                # The User is already in the system but the account
                # has never been activated.
                contact, _ = Contact.objects.get_or_create_token(
                    manager,
                    verification_key=organization.generate_role_key(manager))
                manager.save()
                back_url = "%s?next=%s" % (reverse(
                    'registration_activate',
                    args=(contact.verification_key, )), back_url)
            LOGGER.debug("[signal] subscribe_grant_created_notice("\
                " subscription=%s, reason=%s, invite=%s)",
                subscription, reason, invite)
            if SEND_EMAIL:
                get_email_backend(connection=app.get_connection()).send(
                    from_email=app.get_from_email(),
                    recipients=[organization.email],
                    reply_to=user_context['email'],
                    template='notification/subscription_grant_created.eml',
                    context={
                        'broker': get_broker(),
                        'app': app,
                        'back_url': back_url,
                        'organization': organization,
                        'plan': subscription.plan,
                        'reason': reason if reason is not None else "",
                        'invite': invite,
                        'user': user_context
                    })
        else:
            LOGGER.warning(
                "%s will not be notified of a subscription grant to %s"\
                "because e-mail address is invalid.",
                organization, subscription.plan)
Пример #31
0
 def get_template_dirs(self, template_dirs=None):
     if template_dirs is None:
         template_dirs = self.searchpath
     current_site = get_current_site()
     if current_site:
         loader_template_dirs = []
         for template_dir in current_site.get_template_dirs():
             loader_template_dirs.append(safe_join(template_dir, 'jinja2'))
             loader_template_dirs.append(template_dir)
         template_dirs = loader_template_dirs + list(template_dirs)
     return template_dirs
Пример #32
0
 def searchpath(self, template_dirs=None):
     if not template_dirs:
         try:
             template_dirs = self.get_dirs() #pylint:disable=no-member
         except AttributeError: # django < 1.8
             template_dirs = settings.TEMPLATE_DIRS
     current_site = get_current_site()
     if current_site:
         loader_template_dirs = []
         for template_dir in current_site.get_template_dirs():
             loader_template_dirs.append(safe_join(template_dir, 'django'))
             loader_template_dirs.append(template_dir)
         template_dirs = loader_template_dirs + list(template_dirs)
     return template_dirs