def get_target(self, mail): """ gets the link target by evaluating the string using the email content """ from pennyblack.models import Newsletter if self.identifier != '': return Newsletter.get_view_link(self.identifier) template = Template(self.link_target) return template.render(Context(mail.get_context()))
def get_target_for_job(self, job): """ gets the link target by evaluating the string using the email content """ from pennyblack.models import Newsletter, Mail if self.identifier != '': return Newsletter.get_view_link(self.identifier) template = Template(self.link_target) # make a fake mail context, since there's no actual mail here mail = Mail(job=job) return template.render(Context(mail.get_context()))
def render(self, context): from pennyblack.models import Newsletter if 'mail' not in context: return u'#' mail = context['mail'] newsletter = mail.job.newsletter if newsletter.is_workflow(): job = newsletter.get_default_job() else: job = mail.job try: link = job.links.get(identifier=self.identifier) except job.links.model.DoesNotExist: link = Newsletter.add_view_link_to_job(self.identifier, job) return context['base_url'] + reverse('pennyblack.redirect_link', args=(mail.mail_hash, link.link_hash))
def setUp(self): try: self.ContentCls = getattr( Newsletter, '%s_set' % TextOnlyNewsletterContent.__name__.lower() ).related.related_model except AttributeError: self.ContentCls = Newsletter.create_content_type( TextOnlyNewsletterContent, regions=('notexists',) ) self.content = self.ContentCls(text='<a href="http://www.test.com">link</a>') self.link = reverse( 'pennyblack.redirect_link', kwargs={'mail_hash': '{{mail.mail_hash}}', 'link_hash': '1234'}).replace('%7B', '{').replace('%7D', '}') self.job = self.Job(self.link)
def setUp(self): try: self.ContentCls = getattr( Newsletter, '%s_set' % TextOnlyNewsletterContent.__name__.lower() ).related.related_model except AttributeError: self.ContentCls = Newsletter.create_content_type( TextOnlyNewsletterContent, regions=('notexists', )) self.content = self.ContentCls( text='<a href="http://www.test.com">link</a>') self.link = reverse('pennyblack.redirect_link', kwargs={ 'mail_hash': '{{mail.mail_hash}}', 'link_hash': '1234' }).replace('%7B', '{').replace('%7D', '}') self.job = self.Job(self.link)
from woodstock.models.extendable import ExtendableMixin from woodstock.models.attendance import Attendance from woodstock.models.event_part import EventPart from woodstock.models.person import Person from woodstock.models.participant import Participant from woodstock.models.event import Event from woodstock.models.group import Group from woodstock.models.invitee import Invitee from woodstock.models.salutation import Salutation __all__ = ('Attendance', 'Event', 'EventPart', 'Group', 'Invitee', 'Participant', 'Salutation') # register view links from pennyblack.models import Newsletter from woodstock.views.ics import event_parts_email_view Newsletter.register_view_link('woodstock.event_parts_ics', event_parts_email_view)
from pennyblack.models import Newsletter from pennyblack.content.richtext import TextOnlyNewsletterContent, \ TextWithImageNewsletterContent Newsletter.register_templates({ 'key': 'base', 'title': 'Generic Newsletter', 'path': 'pennyblack/base_newsletter.html', 'regions': ( ('main', 'Main Region'), ), }) Newsletter.create_content_type(TextOnlyNewsletterContent) Newsletter.create_content_type(TextWithImageNewsletterContent)
def test_is_valid(self): n = Newsletter() self.assertFalse(n.is_valid(), "Empty Newsletter can not be valid.") n.subject = 'some text' self.assertTrue(n.is_valid(), "Newsletter should be valid now.")
return self.name @property def member_count(self): return self.subscribers.active().count() def get_member_count(self): return self.member_count get_member_count.short_description = "Member Count" def get_newsletter_receiver_collections(self): """ Every Group has only one collection """ return (('all', {}),) def get_receiver_queryset(self): """ Return all group members """ return self.subscribers.active() class SubscriberGroupAdmin(JobUnitAdmin): list_display = ('__unicode__', 'get_member_count') # register view links from pennyblack.models import Newsletter from pennyblack.module.subscriber.views import unsubscribe Newsletter.register_view_link('subscriber.unsubscribe', unsubscribe)
def __unicode__(self): return self.name @property def member_count(self): return self.subscribers.active().count() def get_member_count(self): return self.member_count get_member_count.short_description = _("Member Count") def get_newsletter_receiver_collections(self): """ Every Group has only one collection """ return (('all', {}),) def get_receiver_queryset(self): """ Return all group members """ return self.subscribers.active() class SubscriberGroupAdmin(JobUnitAdmin): list_display = ('__unicode__', 'get_member_count') # register view links Newsletter.register_view_link('subscriber.unsubscribe', unsubscribe)
def member_count(self): return self.subscribers.active().count() def get_member_count(self): return self.member_count get_member_count.short_description = "Member Count" def get_newsletter_receiver_collections(self): """ Every Group has only one collection """ return (("all", {}),) def get_receiver_queryset(self): """ Return all group members """ return self.subscribers.active() class SubscriberGroupAdmin(JobUnitAdmin): list_display = ("__unicode__", "get_member_count") # register view links from pennyblack.models import Newsletter from pennyblack.module.subscriber.views import unsubscribe Newsletter.register_view_link("subscriber.unsubscribe", unsubscribe)
('main', _('Main content area')), ('featured', _('Featured Image')), ('teaser', _('Teaser')), ) Entry.create_content_type(RichTextContent, cleanse=cleanse_html, regions=('main','teaser')) Entry.create_content_type(MediaFileContent, TYPE_CHOICES=( ('default', _('default')), )) Entry.create_content_type(VideoContent, regions=('main', 'teaser')) ### NEWSLETTERS ### Newsletter.register_templates({ 'key': 'base', 'title': 'Youth Seed Newsletter', 'path': 'youthseed/ys-newsletter.html', 'regions': ( ('main', 'Main Region'), ) }) Newsletter.create_content_type(TextOnlyNewsletterContent) Newsletter.create_content_type(TextWithImageNewsletterContent) ### CUSTOM ### from django.db import models from django import forms from django.template.loader import render_to_string class CarouselContent(models.Model): images = models.ManyToManyField(MediaFile)