Ejemplo n.º 1
0
def lists(request):
    # update database
    user = request.user
    my_lists = request.user.mailinglist_set
    previous = set(my_lists.all())
    my_lists.clear()
    for mlist in models.MailingList.objects.all():
        if request.POST.has_key(mlist.list):
            my_lists.add(mlist)
    request.user.save()

    # update mailman
    now = set(my_lists.all())
    add, remove = now - previous, previous - now
    error = "Something else went wrong!"
    try:
        try:
            for list in add:
                mailman.subscribe_member(user, list)
            for list in remove:
                mailman.unsubscribe_member(user, list)
            return HttpResponseRedirect("/member/")
        except mailman.MailmanError, e:
            error = e.msg
    except ImportError:
        if not settings.DEBUG:
            error = "You don't have mailman installed and the site is running outside of DEBUG mode."
        else:
            error = "If mailman had been installed we would have added %s and removed %s" % (str(add), str(remove))
    return render_to_response(
        "memberinfo/request_error.html",
        {"name": "Mailing Lists", "error": error},
        context_instance=RequestContext(request, {}, [path_processor]),
    )
Ejemplo n.º 2
0
def sync_email_with_mailman_database(sender, instance, **kwargs):
    """
    Used to ensure that the mailman database stays faithful to
    the reinhardt one when an email address is updated

    Intended to be triggered pre_save, and act when a user changes
    their email address
    """
    mailman_logger.debug('sync_email_with_mailman_database called')
    mailman_logger.debug(instance)
    try:
        old_user = User.objects.get(id=instance.id)
    except User.DoesNotExist:
        old_user = instance

    lists = MailingList.objects.filter(users=instance)

    # silently update mailman list subscriptions
    # not sure what to do on mailman throwing an error here yet
    for l in lists:
        try:
            mailman_logger.debug('unsubscribing %s' % old_user.email)
            unsubscribe_member(old_user, l)
        except MailmanError: pass
        try:
            mailman_logger.debug('subscribing %s' % instance.email)
            subscribe_member(instance, l)
        except MailmanError: pass
Ejemplo n.º 3
0
def mailing_list_users_changed(sender, instance, action, **kwargs):
    """
    Acts as a callback when the many2many relation
    containing users for this list is updated.

    Attempts to commit to mailman before the
    reinhardt database is updated.
    """
    if action == "pre_add":
        users = User.objects.filter(id__in=kwargs['pk_set'])
        try:
            for user in users:
                subscribe_member(user, instance)
        # XXX: need to move away from wrapping the different types of
        # exception all in MailmanError
        #
        # preferably here we would check if we can commit all of the users
        # to the mailman database before trying to
        #
        # in the next version. :P -- monk
        except MailmanError: pass
    elif action == "pre_remove":
        users = User.objects.filter(id__in=kwargs['pk_set'])
        try:
            for user in users:
                unsubscribe_member(user, instance)
        except MailmanError: pass
Ejemplo n.º 4
0
 def export_to_mailman(self):
     """
     Convenience method used when you want to push all
     the users for this MailingList to its respective
     mailman list
     """
     try:
         for user in self.users():
             subscribe_member(user, self)
     except MailmanError: pass
Ejemplo n.º 5
0
def lists(request):
    # update database
    user = request.user
    my_lists = request.user.mailinglist_set
    previous = set(my_lists.all())
    my_lists.clear()
    for mlist in models.MailingList.objects.all():
        if request.POST.has_key(mlist.list):
            my_lists.add(mlist)
    request.user.save()

    # update mailman
    now = set(my_lists.all())
    add, remove = now - previous, previous - now
    error = "Something else went wrong!"
    try:
        try:
            for list in add:
                mailman.subscribe_member(user, list)
            for list in remove:
                mailman.unsubscribe_member(user, list)
            return HttpResponseRedirect('/member/')
        except mailman.MailmanError, e:
            error = e.msg
    except ImportError:
        if not settings.DEBUG:
            error = "You don't have mailman installed and the site is running outside of DEBUG mode."
        else:
            error = (
                "If mailman had been installed we would have added %s and removed %s"
                % (str(add), str(remove)))
    return render_to_response('memberinfo/request_error.html', {
        'name': 'Mailing Lists',
        'error': error,
    },
                              context_instance=RequestContext(
                                  request, {}, [path_processor]))