當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。