コード例 #1
0
    def build_email_content(self, contact):
        """Generate the mail for a contact"""
        uidb36, token = tokenize(contact)
        context = Context({
            'contact': contact,
            'domain': Site.objects.get_current().domain,
            'newsletter': self.newsletter,
            'tracking_image_format': TRACKING_IMAGE_FORMAT,
            'uidb36': uidb36,
            'token': token
        })
        content = self.newsletter_template.render(context)
        if TRACKING_LINKS:
            content = track_links(content, context)
        link_site = render_to_string('newsletter/newsletter_link_site.html',
                                     context)
        content = body_insertion(content, link_site)

        if INCLUDE_UNSUBSCRIPTION:
            unsubscription = render_to_string(
                'newsletter/newsletter_link_unsubscribe.html', context)
            content = body_insertion(content, unsubscription, end=True)
        if TRACKING_IMAGE:
            image_tracking = render_to_string(
                'newsletter/newsletter_image_tracking.html', context)
            content = body_insertion(content, image_tracking, end=True)
        return smart_unicode(content)
コード例 #2
0
    def build_email_content(self, contact):
        """Generate the mail for a contact"""
        uidb36, token = tokenize(contact)
        context = Context({'contact': contact,
                           'domain': Site.objects.get_current().domain,
                           'newsletter': self.newsletter,
                           'uidb36': uidb36, 'token': token})

        content = self.newsletter_template.render(context)
        if TRACKING_LINKS:
            content = track_links(content, context)
        link_site = render_to_string('newsletter/newsletter_link_site.html', context)
        #content = body_insertion(content, link_site)
        content = insert_tag(content,'table','viewbrowser',link_site)

        if INCLUDE_UNSUBSCRIPTION:
            unsubscription = render_to_string('newsletter/newsletter_link_unsubscribe.html', context)
            content = insert_tag(content,'span','unsubscribe', unsubscription)
            viewbrowser = render_to_string('newsletter/newsletter_link_viewbrowser.html', context)
            content = insert_tag(content,'span','viewbrowser', viewbrowser)
            subscription = render_to_string('newsletter/newsletter_link_subscribe.html', context)
            content = insert_tag(content,'span','subscribe', subscription)
        if TRACKING_IMAGE:
            image_tracking = render_to_string('newsletter/newsletter_image_tracking.html', context)
            content = body_insertion(content, image_tracking, end=True)
        return smart_unicode(content)
コード例 #3
0
def render_newsletter(request, slug, context):
    """Return a newsletter in HTML format"""
    newsletter = get_object_or_404(Newsletter, slug=slug)
    context.update({'newsletter': newsletter,
                    'domain': Site.objects.get_current().domain})

    content = render_string(newsletter.content, context)
    title = render_string(newsletter.title, context)
    if TRACKING_LINKS:
        content = track_links(content, context)
    unsubscription = render_file('newsletter/newsletter_link_unsubscribe.html', context)
    # --- template --- start --------------------------------------------------
    if USE_TEMPLATE:
        content =  render_to_string(
            'mailtemplates/{0}/{1}'.format(newsletter.template,'index.html'),
            {
                'content': content,
                'link_site': '',
                'unsubscription': unsubscription
            }
        )
        #insert image_tracking
    else:
        content = body_insertion(content, unsubscription, end=True)
    # --- template --- end ----------------------------------------------------

    return render_to_response('newsletter/newsletter_detail.html',
                              {'content': content,
                               'title': title,
                               'object': newsletter},
                              context_instance=RequestContext(request))
コード例 #4
0
def render_newsletter(request, slug, context):
    """Return a newsletter in HTML format"""
    newsletter = get_object_or_404(Newsletter, slug=slug)
    context.update({
        'newsletter': newsletter,
        'domain': Site.objects.get_current().domain
    })

    content = render_string(newsletter.content, context)
    title = render_string(newsletter.title, context)
    if TRACKING_LINKS:
        content = track_links(content, context)
    unsubscription = render_file('newsletter/newsletter_link_unsubscribe.html',
                                 context)
    # --- template --- start --------------------------------------------------
    if USE_TEMPLATE:
        content = render_to_string(
            'mailtemplates/{0}/{1}'.format(newsletter.template, 'index.html'),
            {
                'content': content,
                'link_site': '',
                'unsubscription': unsubscription
            })
        #insert image_tracking
    else:
        content = body_insertion(content, unsubscription, end=True)
    # --- template --- end ----------------------------------------------------

    return render_to_response('newsletter/newsletter_detail.html', {
        'content': content,
        'title': title,
        'object': newsletter
    },
                              context_instance=RequestContext(request))
コード例 #5
0
def render_newsletter(request, slug, context):
    """Return a newsletter in HTML format"""
    newsletter = get_object_or_404(Newsletter, slug=slug)
    context.update({'newsletter': newsletter,
                    'domain': Site.objects.get_current().domain})
    
    if settings.NEWSLETTER_DJANGO_CMS_SUPPORT and 'cms' in settings.INSTALLED_APPS:
        from django.test.client import Client
        from cms.views import details
        from cms.models import Page
        
        #get the Django CMS page instance
        page = Page.objects.get(pk=int(newsletter.content))
        
        #get the page content
        c = Client()
        response = c.get(page.get_absolute_url(), HTTP_HOST=str(Site.objects.get_current()))
        
        content = unicode(render_string(unicode(response.content.decode('utf-8')), context))
    else:
        content = render_string(newsletter.content, context)
    
    
    title = render_string(newsletter.title, context)
    if TRACKING_LINKS:
        content = track_links(content, context)
    unsubscription = render_file('newsletter/newsletter_link_unsubscribe.html', context)
    
    content = body_insertion(content, unsubscription, end=True)
    
    return render_to_response('newsletter/newsletter_detail.html',
                              {'content': content,
                               'title': title,
                               'object': newsletter},
                              context_instance=RequestContext(request))
コード例 #6
0
def render_newsletter(request, slug, context):
    """Return a newsletter in HTML format"""
    newsletter = get_object_or_404(Newsletter, slug=slug)
    clusters = Cluster.objects.filter(publish=True).exclude(id='services')
    quote = Quote.objects.order_by('?')[0]
    smlinks = Socialmedialink.objects.all()
    context.update({'newsletter': newsletter,
                    'domain': Site.objects.get_current().domain,
                    'CLUSTERS':clusters,
                    'QUOTE':quote,
                    'SOCIALMEDIALINKS':smlinks,
                    'location':Location.objects.get(town='amsterdam'),
                    'YEAR': datetime.now().year,
                    'MEDIA_URL': settings.MEDIA_URL,})

    content = get_content(newsletter, context)
    #content = render_string(newsletter.content, context)
    title = render_string(newsletter.title, context)
    if TRACKING_LINKS:
        content = track_links(content, context)
    unsubscription = render_file('newsletter/newsletter_link_unsubscribe.html', context)
    content = insert_tag(content, 'span', 'unsubscribe', unsubscription)
    subscription = render_file('newsletter/newsletter_link_subscribe.html', context)
    content = insert_tag(content, 'span', 'subscribe', subscription)

    return render_to_response('includes/newsletter/newsletter_wrapper.html',
                              {'content': content,
                               'title': title,
                               'object': newsletter,
                               'CLUSTERS': clusters,},
                              context_instance=RequestContext(request))
コード例 #7
0
def render_newsletter(request, slug, context):
    """Return a newsletter in HTML format"""
    newsletter = get_object_or_404(Newsletter, slug=slug)
    context.update({
        'newsletter': newsletter,
        'domain': Site.objects.get_current().domain
    })

    content = render_string(newsletter.content, context)
    title = render_string(newsletter.title, context)
    if TRACKING_LINKS:
        content = track_links(content, context)
    # unsubscription = render_file('newsletter/newsletter_link_unsubscribe.html', context)
    # content = body_insertion(content, unsubscription, end=True)

    template = 'newsletter/newsletter_detail.html'
    if HTML_TEMPLATE or TEXT_TEMPLATE:
        template = SEND_PLAINTEXT and TEXT_TEMPLATE or HTML_TEMPLATE

    context.update({
        'content': content,
        'title': title,
        'object': newsletter,
        'PREVIEW': True
    })

    return render(request, template, context)
コード例 #8
0
    def build_email_content(self, contact):
        """Generate the mail for a contact"""
        # --- template --- start ----------------------------------------------
        link_site = unsubscription = image_tracking = ''
        # --- template --- end ------------------------------------------------

        uidb36, token = tokenize(contact)
        context = Context({'contact': contact,
                           'domain': Site.objects.get_current().domain,
                           'newsletter': self.newsletter,
                           'tracking_image_format': TRACKING_IMAGE_FORMAT,
                           'uidb36': uidb36, 'token': token})
        content = self.newsletter_template.render(context)
        if TRACKING_LINKS:
            content = track_links(content, context)
        link_site = render_to_string('newsletter/newsletter_link_site.html', context)

        # --- template --- start ----------------------------------------------
        if INCLUDE_UNSUBSCRIPTION:
            unsubscription = render_to_string(
                'newsletter/newsletter_link_unsubscribe.html',
                context
            )
        if TRACKING_IMAGE:
            image_tracking = render_to_string(
                'newsletter/newsletter_image_tracking.html',
                context
            )

        if USE_TEMPLATE:
            content =  render_to_string(
                'mailtemplates/{0}/{1}'.format(self.newsletter.template,'index.html'),
                {
                    'content': content,
                    'link_site': link_site,
                    'unsubscription': unsubscription
                }
            )
            #insert image_tracking
        else:
            content = body_insertion(content, link_site)
            if INCLUDE_UNSUBSCRIPTION:
                content = body_insertion(content, unsubscription, end=True)
            if TRACKING_IMAGE:
                content = body_insertion(content, image_tracking, end=True)

        # --- template --- end ------------------------------------------------

        return smart_unicode(content)
コード例 #9
0
def render_newsletter(request, slug, context):
    """Return a newsletter in HTML format"""
    newsletter = get_object_or_404(Newsletter, slug=slug)
    context.update({'newsletter': newsletter,
                    'domain': Site.objects.get_current().domain})
    
    content = render_string(newsletter.content, context)
    if TRACKING_LINKS:
        content = track_links(content, context)
    unsubscription = render_file('newsletter/newsletter_link_unsubscribe.html', context)
    content = body_insertion(content, unsubscription, end=True)
        
    return render_to_response('newsletter/newsletter_detail.html',
                              {'content': content,
                               'object': newsletter},
                              context_instance=RequestContext(request))
コード例 #10
0
def render_newsletter(request, slug, context):
    """Return a newsletter in HTML format"""
    newsletter = get_object_or_404(Newsletter, slug=slug)
    context.update({"newsletter": newsletter, "domain": Site.objects.get_current().domain})

    content = render_string(newsletter.content, context)
    title = render_string(newsletter.title, context)
    if TRACKING_LINKS:
        content = track_links(content, context)
    if INCLUDE_UNSUBSCRIPTION:
        unsubscription = render_file("newsletter/newsletter_link_unsubscribe.html", context)
        content = body_insertion(content, unsubscription, end=True, insertion_id="unsubscribe-link")

    return render_to_response(
        "newsletter/newsletter_detail.html",
        {"content": content, "title": title, "object": newsletter},
        context_instance=RequestContext(request),
    )
コード例 #11
0
def render_newsletter(request, slug, context):
    """Return a newsletter in HTML format"""
    newsletter = get_object_or_404(Newsletter, slug=slug)
    context.update({
        'newsletter': newsletter,
        'domain': Site.objects.get_current().domain
    })

    content = render_string(newsletter.content, context)
    title = render_string(newsletter.title, context)
    if TRACKING_LINKS:
        content = track_links(content, context)
    #unsubscription = render_file('newsletter/newsletter_link_unsubscribe.html', context)
    #content = body_insertion(content, unsubscription, end=True)

    return render_to_response('newsletter/newsletter_detail.html', {
        'content': content,
        'title': title,
        'object': newsletter
    },
                              context_instance=RequestContext(request))
コード例 #12
0
ファイル: mailer.py プロジェクト: maisengasse/newsletter
    def build_email_content(self, contact, template=None, plain=False):
        """Generate the mail for a contact"""
        uidb36, token = tokenize(contact)
        domain = Site.objects.get_current().domain



        class FakeRequest(object):
            REQUEST = {
                'language' : 'de'
            }
            GET = {}
            session = {}
            user = AnonymousUser()
            current_page = None

        request = FakeRequest()
        try:
            from cms.plugin_rendering import ContentRenderer
            content_renderer = ContentRenderer(request=request)
        except ImportError:
            content_renderer = None

        NEWSLETTER_PORTAL_URL = getattr(settings, "NEWSLETTER_PORTAL_URL", settings.PORTAL_URL)
        context = {'contact': contact,
                           'domain': domain,
                           'request' : request,
                           'cms_content_renderer' : content_renderer,
                           'newsletter': self.newsletter,
                           'object': self.newsletter,
                           'uidb36': uidb36, 'token': token,
                           'PORTAL_URL' : settings.PORTAL_URL,
                           'NEWSLETTER_PORTAL_URL' : NEWSLETTER_PORTAL_URL,
                           'MEDIA_URL' : "http://" + domain + settings.MEDIA_URL,
                           'NEWSLETTER_MEDIA_URL' : NEWSLETTER_MEDIA_URL, }


        content = self.newsletter_template.render(SekizaiContext(context))

        if template:
            context.update({'content':content})
            try:
                content = render_to_string(template, context.flatten())
            except AttributeError:
                content = render_to_string(template, context)

        try:
            flat_context = context.flatten()
        except AttributeError:
            flat_context = context

        if not plain and TRACKING_LINKS:
            content = track_links(content, context)


        if not plain and INCLUDE_UNSUBSCRIPTION:
            unsubscription = render_to_string('newsletter/newsletter_link_unsubscribe.html', flat_context)
            content = body_insertion(content, unsubscription, end=True)

        if not plain and TRACKING_IMAGE:
           image_tracking = render_to_string('newsletter/newsletter_image_tracking.html', flat_context)
           content = body_insertion(content, image_tracking, end=True)


        return content