예제 #1
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
예제 #2
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
예제 #3
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
예제 #4
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
예제 #5
0
파일: models.py 프로젝트: La0/coach
 def subscribe_mailing(self, mailing, email=None):
     # Subscribe user to a mailing list
     try:
         if not email:
             email = self.email
         email = email.lower()
         mm = MailMan()
         mm.subscribe(mailing, 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
예제 #6
0
파일: models.py 프로젝트: La0/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
예제 #7
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
예제 #8
0
파일: models.py 프로젝트: La0/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
예제 #9
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
예제 #10
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)
예제 #11
0
파일: sync_mailings.py 프로젝트: La0/coach
  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)
예제 #12
0
class Command(BaseCommand):
    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)

    def sync_mailing(self, list_name, emails_db):
        '''
    Sync a mailing list for a Club or ClubGroup
    '''
        emails_db = map(lambda x: x.lower(), emails_db)

        # Retrieve list
        l = self.mm.get_list(list_name)
        emails_ml = [m.email.lower() for m in l.members]

        # Add missing active members
        for m in emails_db:
            if m in emails_ml:
                continue
            u = Athlete.objects.get(email=m)
            u.subscribe_mailing(l.list_name)
            print ' > Add member %s' % m

        # Remove useless users
        emails_ml = set([m.email.lower() for m in l.members])
        diff = emails_ml.difference(emails_db)
        for m in diff:
            self.mm.unsubscribe(l.list_name, m)
            print ' > Remove %s' % m
예제 #13
0
파일: sync_mailings.py 프로젝트: La0/coach
class Command(BaseCommand):

  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)

  def sync_mailing(self, list_name, emails_db):
    '''
    Sync a mailing list for a Club or ClubGroup
    '''
    emails_db = map(lambda x:x.lower(), emails_db)

    # Retrieve list
    l = self.mm.get_list(list_name)
    emails_ml = [m.email.lower() for m in  l.members]

    # Add missing active members
    for m in emails_db:
      if m in emails_ml:
        continue
      u = Athlete.objects.get(email=m)
      u.subscribe_mailing(l.list_name)
      print ' > Add member %s' % m

    # Remove useless users
    emails_ml = set([m.email.lower() for m in  l.members])
    diff = emails_ml.difference(emails_db)
    for m in diff:
      self.mm.unsubscribe(l.list_name, m)
      print ' > Remove %s' % m