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)
    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)
        urlname = 'admin:%s_mailinglist_change' % self.opts.app_label
        return HttpResponseRedirect(reverse(urlname, args=[new_mailing.pk]))
    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)
        urlname = 'admin:%s_mailinglist_change' % self.opts.app_label
        return HttpResponseRedirect(reverse(urlname, args=[new_mailing.pk]))
    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, None)
            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,
                   #~ 'root_path': self.admin_site.root_path,  TODO: Investigate this further
                   'root_path': reverse('admin:index'),
                   'app_label': opts.app_label}

        return render_to_response('newsletter/contact_import.html', context, RequestContext(request))
Esempio n. 5
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)
Esempio n. 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)
        urlname = 'admin:%s_mailinglist_change' % self.opts.app_label
        return HttpResponseRedirect(reverse(urlname, args=[new_mailing.pk]))
Esempio n. 7
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)
        urlname = 'admin:%s_mailinglist_change' % self.opts.app_label
        return HttpResponseRedirect(reverse(urlname, args=[new_mailing.pk]))
Esempio n. 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)
Esempio n. 9
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, None)
            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,
            #~ 'root_path': self.admin_site.root_path,  TODO: Investigate this further
            'root_path': reverse('admin:index'),
            'app_label': opts.app_label
        }

        return render_to_response('newsletter/contact_import.html', context,
                                  RequestContext(request))
    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 not request.user.has_perm('emencia.can_change_status'):
            newsletter.status = form.initial.get('status', Newsletter.DRAFT)

        try:
            newsletter.save()
        except:
            self.message_user(request, _('Unable to download HTML, due to errors within.'))

        for workgroup in workgroups:
            workgroup.newsletters.add(newsletter)
Esempio n. 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 not request.user.has_perm('emencia.can_change_status'):
            newsletter.status = form.initial.get('status', Newsletter.DRAFT)

        try:
            newsletter.save()
        except:
            self.message_user(
                request, _('Unable to download HTML, due to errors within.'))

        for workgroup in workgroups:
            workgroup.newsletters.add(newsletter)
    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('emencia.can_change_status'):
            newsletter.status = form.initial.get('status', Newsletter.DRAFT)

        newsletter.save()

        for workgroup in workgroups:
            workgroup.newsletters.add(newsletter)