------------------------------------------------------------
revno: 41
committer: Florian Fuchs <[email protected]>
branch nick: mailman.client
timestamp: Tue 2013-03-19 14:18:04 -0700
message:
  * new User properties:
    - subscriptions (returns Member instances)
    - subscription_list_ids (returns the list id of every of the user's Member 
instances)
modified:
  src/mailmanclient/_client.py
  src/mailmanclient/docs/using.txt


--
lp:mailman.client
https://code.launchpad.net/~mailman-coders/mailman.client/trunk

Your team Mailman Coders is subscribed to branch lp:mailman.client.
To unsubscribe from this branch go to 
https://code.launchpad.net/~mailman-coders/mailman.client/trunk/+edit-subscription
=== modified file 'src/mailmanclient/_client.py'
--- src/mailmanclient/_client.py	2013-03-19 17:27:11 +0000
+++ src/mailmanclient/_client.py	2013-03-19 21:18:04 +0000
@@ -591,6 +591,8 @@
         self._url = url
         self._info = None
         self._addresses = None
+        self._subscriptions = None
+        self._subscription_list_ids = None
         self._preferences = None
         self._cleartext_password = None
 
@@ -641,6 +643,31 @@
         return self._info['self_link']
 
     @property
+    def subscriptions(self):
+        if self._subscriptions is None:
+            subscriptions = []
+            for address in self.addresses:
+                response, content = self._connection.call('members/find',
+                    data={'subscriber': address})
+                try:
+                    for entry in content['entries']:
+                        subscriptions.append(_Member(self._connection,
+                            entry['self_link']))
+                except KeyError:
+                    pass
+            self._subscriptions = subscriptions
+        return self._subscriptions
+
+    @property
+    def subscription_list_ids(self):
+        if self._subscription_list_ids is None:
+            list_ids = []
+            for sub in self.subscriptions:
+                list_ids.append(sub.list_id)
+            self._subscription_list_ids = list_ids
+        return self._subscription_list_ids
+
+    @property
     def preferences(self):
         if self._preferences is None:
             path = 'users/{0}/preferences'.format(self.user_id)

=== modified file 'src/mailmanclient/docs/using.txt'
--- src/mailmanclient/docs/using.txt	2013-03-19 17:27:11 +0000
+++ src/mailmanclient/docs/using.txt	2013-03-19 21:18:04 +0000
@@ -342,6 +342,23 @@
     False
 
 
+User Subscriptions
+------------------
+
+A Users subscriptions can be access through their ``subscriptions`` property.
+
+    >>> bill = client.get_user('[email protected]')
+    >>> for subscription in bill.subscriptions:
+    ...     print subscription
+    <Member "[email protected]" on "test-one.example.com">
+
+If all you need are the list ids of all mailing lists a user is subscribed to, you can use the ``subscription_list_ids`` property.
+
+    >>> for list_id in bill.subscription_list_ids:
+    ...     print list_id
+    test-one.example.com
+
+
 List Settings
 =============
 

_______________________________________________
Mailman-coders mailing list
[email protected]
http://mail.python.org/mailman/listinfo/mailman-coders

Reply via email to