Esempio n. 1
0
 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)
    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]))
    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()
        db_engine = settings.DATABASES['default']['ENGINE']
        if settings.DATABASES['default']['ENGINE'].find('sqlite3') > -1 \
            or settings.DATABASES['default']['ENGINE'].index('django.contrib.gis.db.backends.spatialite') > -1:
            messages.warning(
                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]))
Esempio n. 4
0
    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:
            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]))
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
Esempio n. 6
0
    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)