当前位置: 首页>>代码示例>>Python>>正文


Python models.MailingList类代码示例

本文整理汇总了Python中emencia.django.newsletter.models.MailingList的典型用法代码示例。如果您正苦于以下问题:Python MailingList类的具体用法?Python MailingList怎么用?Python MailingList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MailingList类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: merge_mailinglist

    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]))
开发者ID:calendar42,项目名称:emencia-django-newsletter,代码行数:28,代码来源:mailinglist.py

示例2: create_mailinglist

    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]
        ))
开发者ID:strycore,项目名称:emencia-django-newsletter,代码行数:29,代码来源:contact.py

示例3: create_mailinglist

    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]))
开发者ID:drye,项目名称:emencia-django-newsletter,代码行数:15,代码来源:contact.py

示例4: create_contacts

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
开发者ID:easybit,项目名称:emencia-django-newsletter,代码行数:16,代码来源:importation.py

示例5: make_mailing_list

    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)
开发者ID:MechanisM,项目名称:imaginationforpeople,代码行数:18,代码来源:admin.py

示例6: create_contacts

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
开发者ID:strycore,项目名称:emencia-django-newsletter,代码行数:20,代码来源:importation.py

示例7: merge_mailinglist

    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,]))
开发者ID:korkakak,项目名称:emencia-django-newsletter,代码行数:20,代码来源:mailinglist.py

示例8: subscribe_resent_chapters

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)
        )
开发者ID:mrbichel,项目名称:cakewriter,代码行数:52,代码来源:views.py

示例9: make_mailing_list

 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)
开发者ID:mrbichel,项目名称:cakewriter,代码行数:40,代码来源:admin.py

示例10: create_contact

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()  
开发者ID:mrbichel,项目名称:cakewriter,代码行数:39,代码来源:models.py

示例11: test_subscribers_count

 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)
开发者ID:aaloy,项目名称:emencia-django-newsletter,代码行数:6,代码来源:tests.py


注:本文中的emencia.django.newsletter.models.MailingList类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。