Example #1
0
    def handle(self, *args, **options):
        (user_file, message_base, logfilename, ratestr) = args

        users = [u.strip() for u in open(user_file).readlines()]

        message = lookup_template('main', 'emails/' + message_base +
                                  "_body.txt").render()
        subject = lookup_template('main', 'emails/' + message_base +
                                  "_subject.txt").render().strip()
        rate = int(ratestr)

        self.log_file = open(logfilename, "a+", buffering=0)

        i = 0
        for users in chunks(users, rate):
            emails = [(subject, message, settings.DEFAULT_FROM_EMAIL, [u])
                      for u in users]
            self.hard_log(" ".join(users))
            send_mass_mail(emails, fail_silently=False)
            time.sleep(1)
            print datetime.datetime.utcnow().isoformat(), i
            i = i + len(users)
            # Emergency interruptor
            if os.path.exists("/tmp/stopemails.txt"):
                self.log_file.close()
                sys.exit(-1)
        self.log_file.close()
Example #2
0
 def handle(self, *args, **options):
     #text = open(args[0]).read()
     #subject = open(args[1]).read()
     users = User.objects.all()
     text = lookup_template('main', 'email/' + args[0] + ".txt").render()
     subject = lookup_template('main', 'email/' + args[0] + "_subject.txt").render().strip()
     for user in users:
         if user.is_active:
             user.email_user(subject, text)
Example #3
0
 def handle(self, *args, **options):
     #text = open(args[0]).read()
     #subject = open(args[1]).read()
     users = User.objects.all()
     text = lookup_template('main', 'email/' + args[0] + ".txt").render()
     subject = lookup_template('main', 'email/' + args[0] +
                               "_subject.txt").render().strip()
     for user in users:
         if user.is_active:
             user.email_user(subject, text)
Example #4
0
def render_to_string(template_name, dictionary, context=None, namespace='main'):

    # see if there is an override template defined in the microsite
    template_name = microsite.get_template_path(template_name)

    context_instance = Context(dictionary)
    # add dictionary to context_instance
    context_instance.update(dictionary or {})
    # collapse context_instance to a single dictionary for mako
    context_dictionary = {}
    context_instance['settings'] = settings
    context_instance['EDX_ROOT_URL'] = settings.EDX_ROOT_URL
    context_instance['marketing_link'] = marketing_link

    # In various testing contexts, there might not be a current request context.
    if edxmako.middleware.REQUEST_CONTEXT.context is not None:
        for d in edxmako.middleware.REQUEST_CONTEXT.context:
            context_dictionary.update(d)
    for d in context_instance:
        context_dictionary.update(d)
    if context:
        context_dictionary.update(context)
    # fetch and render template
    template = lookup_template(namespace, template_name)
    return template.render_unicode(**context_dictionary)
Example #5
0
def render_to_string(template_name, dictionary, context=None, namespace='main'):

    # see if there is an override template defined in the microsite
    template_name = microsite.get_template_path(template_name)

    context_instance = Context(dictionary)
    # add dictionary to context_instance
    context_instance.update(dictionary or {})
    # collapse context_instance to a single dictionary for mako
    context_dictionary = {}
    context_instance['settings'] = settings
    context_instance['EDX_ROOT_URL'] = settings.EDX_ROOT_URL
    context_instance['marketing_link'] = marketing_link
    context_instance['is_any_marketing_link_set'] = is_any_marketing_link_set
    context_instance['is_marketing_link_set'] = is_marketing_link_set

    # In various testing contexts, there might not be a current request context.
    request_context = get_template_request_context()
    if request_context:
        for item in request_context:
            context_dictionary.update(item)
    for item in context_instance:
        context_dictionary.update(item)
    if context:
        context_dictionary.update(context)

    # "Fix" CSRF token by evaluating the lazy object
    KEY_CSRF_TOKENS = ('csrf_token', 'csrf')
    for key in KEY_CSRF_TOKENS:
        if key in context_dictionary:
            context_dictionary[key] = unicode(context_dictionary[key])

    # fetch and render template
    template = lookup_template(namespace, template_name)
    return template.render_unicode(**context_dictionary)
Example #6
0
def render_to_string(template_name, dictionary, context=None, namespace='main'):

    # see if there is an override template defined in the microsite
    template_name = microsite.get_template_path(template_name)

    context_instance = Context(dictionary)
    # add dictionary to context_instance
    context_instance.update(dictionary or {})
    # collapse context_instance to a single dictionary for mako
    context_dictionary = {}
    context_instance['settings'] = settings
    context_instance['EDX_ROOT_URL'] = settings.EDX_ROOT_URL
    context_instance['marketing_link'] = marketing_link

    # In various testing contexts, there might not be a current request context.
    request_context = get_template_request_context()
    if request_context:
        for item in request_context:
            context_dictionary.update(item)
    for item in context_instance:
        context_dictionary.update(item)
    if context:
        context_dictionary.update(context)

    # "Fix" CSRF token by evaluating the lazy object
    KEY_CSRF_TOKENS = ('csrf_token', 'csrf')
    for key in KEY_CSRF_TOKENS:
        if key in context_dictionary:
            context_dictionary[key] = unicode(context_dictionary[key])

    # fetch and render template
    template = lookup_template(namespace, template_name)
    return template.render_unicode(**context_dictionary)
Example #7
0
def render_to_string(template_name,
                     dictionary,
                     context=None,
                     namespace='main',
                     request=None):
    """
    Render a Mako template to as a string.

    The following values are available to all templates:
        settings: the django settings object
        EDX_ROOT_URL: settings.EDX_ROOT_URL
        marketing_link: The :func:`marketing_link` function
        is_any_marketing_link_set: The :func:`is_any_marketing_link_set` function
        is_marketing_link_set: The :func:`is_marketing_link_set` function

    Arguments:
        template_name: The name of the template to render. Will be loaded
            from the template paths specified in configuration.
        dictionary: A dictionary of variables to insert into the template during
            rendering.
        context: A :class:`~django.template.Context` with values to make
            available to the template.
        namespace: The Mako namespace to find the named template in.
        request: The request to use to construct the RequestContext for rendering
            this template. If not supplied, the current request will be used.
    """

    template_name = get_template_path(template_name)

    context_instance = Context(dictionary)
    # add dictionary to context_instance
    context_instance.update(dictionary or {})
    # collapse context_instance to a single dictionary for mako
    context_dictionary = {}
    context_instance['settings'] = settings
    context_instance['EDX_ROOT_URL'] = settings.EDX_ROOT_URL
    context_instance['marketing_link'] = marketing_link
    context_instance['is_any_marketing_link_set'] = is_any_marketing_link_set
    context_instance['is_marketing_link_set'] = is_marketing_link_set

    # In various testing contexts, there might not be a current request context.
    request_context = get_template_request_context(request)
    if request_context:
        for item in request_context:
            context_dictionary.update(item)
    for item in context_instance:
        context_dictionary.update(item)
    if context:
        context_dictionary.update(context)

    # "Fix" CSRF token by evaluating the lazy object
    KEY_CSRF_TOKENS = ('csrf_token', 'csrf')
    for key in KEY_CSRF_TOKENS:
        if key in context_dictionary:
            context_dictionary[key] = unicode(context_dictionary[key])

    # fetch and render template
    template = lookup_template(namespace, template_name)
    return template.render_unicode(**context_dictionary)
Example #8
0
def render_to_string(template_name, dictionary, context=None, namespace='main', request=None):
    """
    Render a Mako template to as a string.

    The following values are available to all templates:
        settings: the django settings object
        EDX_ROOT_URL: settings.EDX_ROOT_URL
        marketing_link: The :func:`marketing_link` function
        is_any_marketing_link_set: The :func:`is_any_marketing_link_set` function
        is_marketing_link_set: The :func:`is_marketing_link_set` function

    Arguments:
        template_name: The name of the template to render. Will be loaded
            from the template paths specified in configuration.
        dictionary: A dictionary of variables to insert into the template during
            rendering.
        context: A :class:`~django.template.Context` with values to make
            available to the template.
        namespace: The Mako namespace to find the named template in.
        request: The request to use to construct the RequestContext for rendering
            this template. If not supplied, the current request will be used.
    """

    # see if there is an override template defined in the microsite
    template_name = microsite.get_template_path(template_name)

    context_instance = Context(dictionary)
    # add dictionary to context_instance
    context_instance.update(dictionary or {})
    # collapse context_instance to a single dictionary for mako
    context_dictionary = {}
    context_instance['settings'] = settings
    context_instance['EDX_ROOT_URL'] = settings.EDX_ROOT_URL
    context_instance['marketing_link'] = marketing_link
    context_instance['is_any_marketing_link_set'] = is_any_marketing_link_set
    context_instance['is_marketing_link_set'] = is_marketing_link_set

    # In various testing contexts, there might not be a current request context.
    request_context = get_template_request_context(request)
    if request_context:
        for item in request_context:
            context_dictionary.update(item)
    for item in context_instance:
        context_dictionary.update(item)
    if context:
        context_dictionary.update(context)

    # "Fix" CSRF token by evaluating the lazy object
    KEY_CSRF_TOKENS = ('csrf_token', 'csrf')
    for key in KEY_CSRF_TOKENS:
        if key in context_dictionary:
            context_dictionary[key] = unicode(context_dictionary[key])

    # fetch and render template
    template = lookup_template(namespace, template_name)
    return template.render_unicode(**context_dictionary)
    def handle(self, *args, **options):
        (user_file, message_base, logfilename, ratestr) = args

        users = [u.strip() for u in open(user_file).readlines()]

        message = lookup_template('main', 'emails/' + message_base + "_body.txt").render()
        subject = lookup_template('main', 'emails/' + message_base + "_subject.txt").render().strip()
        rate = int(ratestr)

        self.log_file = open(logfilename, "a+", buffering=0)

        i = 0
        for users in chunks(users, rate):
            emails = [(subject, message, settings.DEFAULT_FROM_EMAIL, [u]) for u in users]
            self.hard_log(" ".join(users))
            send_mass_mail(emails, fail_silently=False)
            time.sleep(1)
            print datetime.datetime.utcnow().isoformat(), i
            i = i + len(users)
            # Emergency interruptor
            if os.path.exists("/tmp/stopemails.txt"):
                self.log_file.close()
                sys.exit(-1)
        self.log_file.close()
Example #10
0
def render_mustache(template_name, dictionary, *args, **kwargs):
    template = lookup_template('main', template_name).source
    return pystache.render(template, dictionary)
Example #11
0
def render_mustache(template_name, dictionary, *args, **kwargs):
    template = lookup_template('main', template_name).source
    return pystache.render(template, dictionary)