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))
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))
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))
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))
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,
                    'additional_objects': newsletter.additional_objects.all(),
                    })

    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)
    additional_content = render_file('newsletter/newsletter_additional_content.html', context)
    content = additional_insertion(content, additional_content)

    return render_to_response('newsletter/newsletter_detail.html',
                              {'content': content,
                               'title': title,
                               'object': newsletter},
                              context_instance=RequestContext(request))
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),
    )
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))