コード例 #1
0
ファイル: models.py プロジェクト: esteluk/uwcs-website
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
コード例 #2
0
ファイル: models.py プロジェクト: esteluk/uwcs-website
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
コード例 #3
0
ファイル: models.py プロジェクト: esteluk/uwcs-website
 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