예제 #1
0
    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:maja_newsletter_mailinglist_change',
                    args=[new_mailing.pk]))
예제 #2
0
    def importation(self, request):
        """Import contacts from a VCard"""
        opts = self.model._meta

        if request.POST:
            source = request.FILES.get('source') or \
                     StringIO.StringIO(request.POST.get('source', ''))
            if not request.user.is_superuser and USE_WORKGROUPS:
                workgroups = request_workgroups(request)
            else:
                workgroups = []
            inserted = import_dispatcher(source, request.POST['type'],
                                         workgroups)
            if inserted:
                contacts_imported.send(sender=self,
                                       source=source,
                                       type=request.POST['type'])

            self.message_user(
                request,
                _('%s contacts succesfully imported.') % inserted)

        context = {
            'title': _('Contact importation'),
            'opts': opts,
            'app_label': opts.app_label
        }

        return render_to_response('newsletter/contact_import.html', context,
                                  RequestContext(request))
예제 #3
0
    def save_model(self, request, newsletter, form, change):
        workgroups = []
        if not newsletter.pk and not request.user.is_superuser \
               and USE_WORKGROUPS:
            workgroups = request_workgroups(request)

        if newsletter.content.startswith('http://'):
            if CAN_USE_PREMAILER:
                try:
                    premailer = Premailer(newsletter.content.strip())
                    newsletter.content = premailer.transform()
                except PremailerError:
                    self.message_user(
                        request,
                        _('Unable to download HTML, due to errors within.'))
            else:
                self.message_user(request,
                                  _('Please install lxml for parsing an URL.'))
        if not request.user.has_perm('newsletter.can_change_status'):
            newsletter.status = form.initial.get('status', Newsletter.DRAFT)

        newsletter.save()

        for workgroup in workgroups:
            workgroup.newsletters.add(newsletter)
예제 #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()

        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:maja_newsletter_mailinglist_change',
                    args=[new_mailing.pk]))
예제 #5
0
    def importation(self, request):
        """Import contacts from a VCard"""
        opts = self.model._meta

        if request.POST:
            source = request.FILES.get('source') or \
                     StringIO.StringIO(request.POST.get('source', ''))
            if not request.user.is_superuser and USE_WORKGROUPS:
                workgroups = request_workgroups(request)
            else:
                workgroups = []
            inserted = import_dispatcher(source, request.POST['type'],
                                         workgroups)
            if inserted:
                contacts_imported.send(sender=self, source=source,
                                       type=request.POST['type'])

            self.message_user(request, _('%s contacts succesfully imported.') % inserted)

        context = {'title': _('Contact importation'),
                   'opts': opts,
                   'app_label': opts.app_label}

        return render_to_response('newsletter/contact_import.html',
                                  context, RequestContext(request))
예제 #6
0
    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:maja_newsletter_mailinglist_change',
                                            args=[new_mailing.pk]))
예제 #7
0
 def save_model(self, request, mailinglist, form, change):
     workgroups = []
     if not mailinglist.pk and not request.user.is_superuser \
            and USE_WORKGROUPS:
         workgroups = request_workgroups(request)
     mailinglist.save()
     for workgroup in workgroups:
         workgroup.mailinglists.add(mailinglist)
예제 #8
0
 def save_model(self, request, contact, form, change):
     workgroups = []
     if not contact.pk and not request.user.is_superuser \
            and USE_WORKGROUPS:
         workgroups = request_workgroups(request)
     contact.save()
     for workgroup in workgroups:
         workgroup.contacts.add(contact)
예제 #9
0
 def save_model(self, request, contact, form, change):
     workgroups = []
     if not contact.pk and not request.user.is_superuser \
            and USE_WORKGROUPS:
         workgroups = request_workgroups(request)
     contact.save()
     for workgroup in workgroups:
         workgroup.contacts.add(contact)
예제 #10
0
 def save_model(self, request, mailinglist, form, change):
     workgroups = []
     if not mailinglist.pk and not request.user.is_superuser \
            and USE_WORKGROUPS:
         workgroups = request_workgroups(request)
     mailinglist.save()
     for workgroup in workgroups:
         workgroup.mailinglists.add(mailinglist)
예제 #11
0
    def save_model(self, request, newsletter, form, change):
        workgroups = []
        if not newsletter.pk and not request.user.is_superuser \
               and USE_WORKGROUPS:
            workgroups = request_workgroups(request)

        if newsletter.content.startswith('http://'):
            if CAN_USE_PREMAILER:
                try:
                    premailer = Premailer(newsletter.content.strip())
                    newsletter.content = premailer.transform()
                except PremailerError:
                    self.message_user(request, _('Unable to download HTML, due to errors within.'))
            else:
                self.message_user(request, _('Please install lxml for parsing an URL.'))
        if not request.user.has_perm('newsletter.can_change_status'):
            newsletter.status = form.initial.get('status', Newsletter.DRAFT)

        newsletter.save()

        for workgroup in workgroups:
            workgroup.newsletters.add(newsletter)
예제 #12
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()

        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:maja_newsletter_mailinglist_change',
                                            args=[new_mailing.pk]))