本文整理汇总了Python中emencia.django.newsletter.models.MailingList.save方法的典型用法代码示例。如果您正苦于以下问题:Python MailingList.save方法的具体用法?Python MailingList.save怎么用?Python MailingList.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类emencia.django.newsletter.models.MailingList
的用法示例。
在下文中一共展示了MailingList.save方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: merge_mailinglist
# 需要导入模块: from emencia.django.newsletter.models import MailingList [as 别名]
# 或者: from emencia.django.newsletter.models.MailingList import save [as 别名]
def merge_mailinglist(self, request, queryset):
"""Merge multiple mailing list"""
if queryset.count() == 1:
self.message_user(request, _('Please select a least 2 mailing list.'))
return None
subscribers = {}
unsubscribers = {}
for ml in queryset:
for contact in ml.subscribers.all():
subscribers[contact] = ''
for contact in ml.unsubscribers.all():
unsubscribers[contact] = ''
when = str(datetime.now()).split('.')[0]
new_mailing = MailingList(name=_('Merging list at %s') % when,
description=_('Mailing list created by merging at %s') % when)
new_mailing.save()
new_mailing.subscribers = subscribers.keys()
new_mailing.unsubscribers = unsubscribers.keys()
if not request.user.is_superuser and USE_WORKGROUPS:
for workgroup in request_workgroups(request):
workgroup.mailinglists.add(new_mailing)
self.message_user(request, _('%s succesfully created by merging.') % new_mailing)
return HttpResponseRedirect(reverse('admin:newsletter_mailinglist_change',
args=[new_mailing.pk]))
示例2: create_mailinglist
# 需要导入模块: from emencia.django.newsletter.models import MailingList [as 别名]
# 或者: from emencia.django.newsletter.models.MailingList import save [as 别名]
def create_mailinglist(self, request, queryset):
"""Create a mailing list from selected contact"""
when = str(datetime.now()).split('.')[0]
new_mailing = MailingList(
name=_('New mailinglist at %s') % when,
description=_('New mailing list created in admin at %s') % when)
new_mailing.save()
if 'lite' in settings.DATABASES['default']['ENGINE']:
self.message_user(
request,
_('SQLite3 or a SpatialLite database type detected, ' \
'please note you will be limited to 999 contacts ' \
'per mailing list.')
)
try:
new_mailing.subscribers = queryset.all()
except DatabaseError:
new_mailing.subscribers = queryset.none()
if not request.user.is_superuser and USE_WORKGROUPS:
for workgroup in request_workgroups(request):
workgroup.mailinglists.add(new_mailing)
self.message_user(request, _('%s succesfully created.') % new_mailing)
return HttpResponseRedirect(reverse(
'admin:newsletter_mailinglist_change',
args=[new_mailing.pk]
))
示例3: subscribe_resent_chapters
# 需要导入模块: from emencia.django.newsletter.models import MailingList [as 别名]
# 或者: from emencia.django.newsletter.models.MailingList import save [as 别名]
def subscribe_resent_chapters(request):
errors = []
email = None
older_side = None
if 'email' in request.POST:
email = request.POST['email']
if 'next' in request.POST:
older_side = request.POST['next']
if not email:
errors.append('Please enter your email.')
elif is_valid_email(email)==False:
errors.append('The mail is not valid.')
else:
contact, created = Contact.objects.get_or_create(email=email,
defaults={'first_name':email,
'last_name': ''})
if created == False:
errors.append('The email is already subscribed.')
return render_to_response(
'email_error.html', {'errors': errors, 'email': email, 'older_side': older_side},
context_instance = RequestContext(request)
)
#all users is made ready for the ManytoManyField
subscribers=[]
contacts = Contact.objects.all()
for e in contacts:
subscribers.append(e)
#Create Maillist with all users
mailinglists = MailingList.objects.filter(name='All users')
if mailinglists.count() > 0:
mailinglist = mailinglists[0]
mpk = mailinglist.pk
new_mailing = MailingList(pk=mpk,
name='All users',
description='Mailinglist with all users',
creation_date=mailinglist.creation_date,
modification_date=mailinglist.modification_date,)
else:
new_mailing = MailingList(name='All users',
description='Mailinglist with all users')
new_mailing.save()
new_mailing.subscribers.add(*subscribers)
new_mailing.save()
if request.POST['next']:
return HttpResponseRedirect(request.POST['next'])
else:
return HttpResponseRedirect('/')
return render_to_response(
'email_error.html', {'errors': errors, 'email': email, 'older_side': older_side},
context_instance = RequestContext(request)
)
示例4: create_mailinglist
# 需要导入模块: from emencia.django.newsletter.models import MailingList [as 别名]
# 或者: from emencia.django.newsletter.models.MailingList import save [as 别名]
def create_mailinglist(self, request, queryset):
"""Create a mailing list from selected contact"""
when = str(datetime.now()).split('.')[0]
new_mailing = MailingList(name=_('New mailinglist at %s') % when,
description=_('New mailing list created in admin at %s') % when)
new_mailing.save()
new_mailing.subscribers = queryset.all()
if not request.user.is_superuser and USE_WORKGROUPS:
for workgroup in request_workgroups(request):
workgroup.mailinglists.add(new_mailing)
self.message_user(request, _('%s succesfully created.') % new_mailing)
return HttpResponseRedirect(reverse('admin:newsletter_mailinglist_change',
args=[new_mailing.pk]))
示例5: create_contacts
# 需要导入模块: from emencia.django.newsletter.models import MailingList [as 别名]
# 或者: from emencia.django.newsletter.models.MailingList import save [as 别名]
def create_contacts(contact_dicts, importer_name, workgroups=[]):
"""Create all the contacts to import and
associated them in a mailing list"""
inserted = 0
when = str(datetime.now()).split('.')[0]
mailing_list = MailingList(
name=_('Mailing list created by importation at %s') % when,
description=_('Contacts imported by %s.') % importer_name)
mailing_list.save()
for contact_dict in contact_dicts:
contact, created = create_contact(contact_dict, workgroups)
mailing_list.subscribers.add(contact)
inserted += int(created)
return inserted
示例6: make_mailing_list
# 需要导入模块: from emencia.django.newsletter.models import MailingList [as 别名]
# 或者: from emencia.django.newsletter.models.MailingList import save [as 别名]
def make_mailing_list(self, request, queryset):
from emencia.django.newsletter.models import Contact
from emencia.django.newsletter.models import MailingList
subscribers = []
for profile in queryset:
contact, created = Contact.objects.get_or_create(email=profile.user.email,
defaults={'first_name': profile.user.first_name,
'last_name': profile.user.last_name,
'content_object': profile})
subscribers.append(contact)
new_mailing = MailingList(name='New mailing list',
description='New mailing list created from admin/profile')
new_mailing.save()
new_mailing.subscribers.add(*subscribers)
new_mailing.save()
self.message_user(request, '%s succesfully created.' % new_mailing)
示例7: create_contacts
# 需要导入模块: from emencia.django.newsletter.models import MailingList [as 别名]
# 或者: from emencia.django.newsletter.models.MailingList import save [as 别名]
def create_contacts(contact_dicts, importer_name, mailing_list=None, segment=None):
"""Create all the contacts to import and
associated them in a mailing list"""
inserted = 0
when = str(datetime.now()).split(".")[0]
if not mailing_list:
mailing_list = MailingList(
name=_("Mailing list imported at %s") % when, description=_("Contacts imported by %s.") % importer_name
)
mailing_list.save()
for contact_dict in contact_dicts:
contact, created = create_contact(contact_dict)
mailing_list.subscribers.add(contact)
if segment:
segment.subscribers.add(contact)
inserted += int(created)
return inserted
示例8: merge_mailinglist
# 需要导入模块: from emencia.django.newsletter.models import MailingList [as 别名]
# 或者: from emencia.django.newsletter.models.MailingList import save [as 别名]
def merge_mailinglist(self, request, queryset):
"""Merge multiple mailing list"""
if queryset.count() == 1:
self.message_user(request, _('Please select a least 2 mailing list.'))
return None
contacts = {}
for ml in queryset:
for contact in ml.subscribers.all():
contacts[contact] = ''
when = str(datetime.now()).split('.')[0]
new_mailing = MailingList(name=_('Merging list at %s') % when,
description=_('Mailing list created by merging at %s') % when)
new_mailing.save()
new_mailing.subscribers = contacts.keys()
self.message_user(request, _('%s succesfully created by merging.') % new_mailing)
return HttpResponseRedirect(reverse('admin:newsletter_mailinglist_change',
args=[new_mailing.pk,]))
示例9: make_mailing_list
# 需要导入模块: from emencia.django.newsletter.models import MailingList [as 别名]
# 或者: from emencia.django.newsletter.models.MailingList import save [as 别名]
def make_mailing_list(self, request, queryset):
from emencia.django.newsletter.models import Contact
from emencia.django.newsletter.models import MailingList
subscribers = []
antal = 0
for profile in queryset:
contact_final = None
contact = None
try:
contact = Contact.objects.get(email=profile.email)
if contact:
if contact.content_object==None:
contact.content_object = profile
contact.first_name = profile.username
contact.save()
except ObjectDoesNotExist:
contact_final = Contact.objects.create(email=profile.email, first_name=profile.username, content_object=profile)
contact_final.save()
if contact_final:
antal += 1
contacts = Contact.objects.all()
for e in contacts:
subscribers.append(e)
mailinglists = MailingList.objects.filter(name='All users')
if mailinglists.count() > 0:
mailinglist = mailinglists[0]
mpk = mailinglist.pk
new_mailing = MailingList(pk=mpk,
name='All users',
description='Mailinglist with all users',
creation_date=mailinglist.creation_date,
modification_date=mailinglist.modification_date,)
else:
new_mailing = MailingList(name='All users',
description='Mailinglist with all users')
new_mailing.save()
new_mailing.subscribers.add(*subscribers)
new_mailing.save()
self.message_user(request, '%s succesfully created.' % antal)
示例10: create_contact
# 需要导入模块: from emencia.django.newsletter.models import MailingList [as 别名]
# 或者: from emencia.django.newsletter.models.MailingList import save [as 别名]
def create_contact(sender, **kwargs):
user = kwargs.get('instance')
created = kwargs.get('created')
if created:
#contact, created = Contact.objects.get_or_create(email=user.email,
# defaults={'first_name':user.username,
# 'last_name': '',
# 'content_object':user})
try:
contact = Contact.objects.get(email=user.email)
if contact:
if contact.content_object==None:
contact.content_object = user
contact.first_name = user.username
contact.save()
except ObjectDoesNotExist:
contact_final = Contact.objects.create(email=user.email, first_name=user.username, content_object=user)
contact_final.save()
#all users is made ready for the ManytoManyField
subscribers=[]
contacts = Contact.objects.all()
for e in contacts:
subscribers.append(e)
#Create Maillist with all users
mailinglists = MailingList.objects.filter(name='All users')
if mailinglists.count() > 0:
mailinglist = mailinglists[0]
mpk = mailinglist.pk
new_mailing = MailingList(pk=mpk,
name='All users',
description='Mailinglist with all users',
creation_date=mailinglist.creation_date,
modification_date=mailinglist.modification_date,)
else:
new_mailing = MailingList(name='All users',
description='Mailinglist with all users')
new_mailing.save()
new_mailing.subscribers.add(*subscribers)
new_mailing.save()
示例11: test_subscribers_count
# 需要导入模块: from emencia.django.newsletter.models import MailingList [as 别名]
# 或者: from emencia.django.newsletter.models.MailingList import save [as 别名]
def test_subscribers_count(self):
mailinglist = MailingList(name='Test MailingList')
mailinglist.save()
self.assertEquals(mailinglist.subscribers_count(), 0)
mailinglist.subscribers.add(self.contact_1, self.contact_2, self.contact_3)
self.assertEquals(mailinglist.subscribers_count(), 3)