コード例 #1
0
 def unsubscribe_mailing(self, mailing):
     # Unsubscribe user from a mailing list
     try:
         mm = MailMan()
         mm.unsubscribe(mailing, self.email)
     except Exception, e:
         print 'Failed to unsubscribe %s from %s : %s' % (self.username,
                                                          mailing, str(e))
         return False
コード例 #2
0
 def subscribe_mailing(self, mailing, email=None):
     # Subscribe user to a mailing list
     try:
         mm = MailMan()
         mm.subscribe(mailing, email or self.email,
                      '%s %s' % (self.first_name, self.last_name))
     except Exception, e:
         print 'Failed to subscribe %s to %s : %s' % (self.username,
                                                      mailing, str(e))
         return False
コード例 #3
0
ファイル: models.py プロジェクト: paulrsilva/coach
    def delete_mailing_list(self):
        '''
    Delete a mailing list for the club group
    '''
        if not self.mailing_list:
            raise Exception('Missing a mailing list')

        try:
            mm = MailMan()
            mm.delete_list(self.mailing_list)
        except Exception, e:
            print 'Failed to delete mailing list %s : %s' % (self.mailing_list,
                                                             str(e))
            return False
コード例 #4
0
ファイル: models.py プロジェクト: paulrsilva/coach
    def create_mailing_list(self):
        '''
    Create a mailing list for the club group
    '''
        if self.mailing_list:
            raise Exception('Already a registered mailing list')

        # Create on mailman
        name = self.slug.lower()
        try:
            mm = MailMan()
            mm.create_list(name, self.name)
        except Exception, e:
            print 'Failed to create mailing list %s : %s' % (name, str(e))
            return False
コード例 #5
0
    def handle(self, *args, **kwargs):
        self.mm = MailMan()

        # Global mailing
        global_ml = 'all'
        extra = {
            'default_member_action': 'discard',  # members can't send messages
            'default_nonmember_action':
            'discard',  # non-members can't send messages
        }
        self.mm.create_list(global_ml,
                            'Membres RunReport',
                            extra_settings=extra)
        for u in Athlete.objects.filter(is_active=True):
            u.subscribe_mailing(global_ml)
            print '[%s] %s' % (global_ml, u)

        # Sync all clubs
        for club in Club.objects.order_by('name'):
            print 'Club %s' % club

            # Create mailing list
            if not club.mailing_list:
                club.create_mailing_list()
                print ' > Created mailing'

            # Sync the club
            emails = club.clubmembership_set.exclude(role__in=('prospect',
                                                               'archive'))
            emails = emails.values_list('user__email', flat=True)
            self.sync_mailing(club.mailing_list, emails)

            # Sync all club groups
            for g in club.groups.all():
                print 'ClubGroup %s' % g

                # Create mailing list
                if not g.mailing_list:
                    g.create_mailing_list()
                    print ' > Created mailing'

                # Sync the group
                emails = g.members.values_list('user__email', flat=True)
                self.sync_mailing(g.mailing_list, emails)