~mailman-coders/mailman.client/trunk

« back to all changes in this revision

Viewing changes to src/mailmanclient/docs/using.rst

  • Committer: Florian Fuchs
  • Date: 2015-04-16 13:38:27 UTC
  • Revision ID: flo.fuchs@gmail.com-20150416133827-0qti5ggrlwr8kcur
added subscription policy features

Show diffs side-by-side

added added

removed removed

Lines of Context:
192
192
::
193
193
 
194
194
    >>> test_two = client.get_list('test-two@example.com')
195
 
 
196
 
    >>> test_one.subscribe('anna@example.com', 'Anna')
 
195
    >>> print(test_two.settings['subscription_policy'])
 
196
    confirm
 
197
 
 
198
Email addresses need to be verified first, so if we try to subscribe a 
 
199
user, we get a response with a token:
 
200
 
 
201
    >>> data = test_one.subscribe('unverified@example.com', 'Unverified')
 
202
    >>> data['token'] is not None
 
203
    True
 
204
    >>> print(data['token_owner'])
 
205
    subscriber
 
206
 
 
207
If we know the email address to be valid, we can set the 
 
208
``pre_verified`` flag. However, the list's subscription policy is 
 
209
"confirm", so if we try to subscribe a user, we will also get a token 
 
210
back: 
 
211
 
 
212
    >>> data = test_one.subscribe('unconfirmed@example.com',
 
213
    ...                           'Unconfirmed',
 
214
    ...                            pre_verified=True)
 
215
    >>> data['token'] is not None
 
216
    True
 
217
    >>> print(data['token_owner'])
 
218
    subscriber
 
219
 
 
220
If we know the user originated the subscription (for example if she or 
 
221
he has been authenticated elsewhere), we can set the ``pre_confirmed`` 
 
222
flag.
 
223
 
 
224
The ``pre_approved`` flag is used for lists that require moderator 
 
225
approval and should only be used if the subscription is initiated by a 
 
226
moderator or admin. 
 
227
 
 
228
    >>> test_one.subscribe('anna@example.com', 'Anna',
 
229
    ...                    pre_verified=True,
 
230
    ...                    pre_confirmed=True)
197
231
    <Member "anna@example.com" on "test-one.example.com">
198
 
    >>> test_one.subscribe('bill@example.com', 'Bill')
 
232
 
 
233
    >>> test_one.subscribe('bill@example.com', 'Bill',
 
234
    ...                    pre_verified=True,
 
235
    ...                    pre_confirmed=True)
199
236
    <Member "bill@example.com" on "test-one.example.com">
200
 
    >>> test_two.subscribe('anna@example.com')
 
237
 
 
238
    >>> test_two.subscribe('anna@example.com',
 
239
    ...                    pre_verified=True,
 
240
    ...                    pre_confirmed=True)
201
241
    <Member "anna@example.com" on "test-two.example.com">
202
 
    >>> test_two.subscribe('cris@example.com', 'Cris')
 
242
 
 
243
    >>> test_two.subscribe('cris@example.com', 'Cris',
 
244
    ...                    pre_verified=True,
 
245
    ...                    pre_confirmed=True)
203
246
    <Member "cris@example.com" on "test-two.example.com">
204
247
 
205
248
We can retrieve all known memberships.  These are sorted first by mailing list
267
310
 
268
311
    >>> prefs = cris_test_two.preferences
269
312
    >>> print(prefs['delivery_mode'])
270
 
    regular
 
313
    None
271
314
    >>> print(prefs['acknowledge_posts'])
272
315
    None
273
316
    >>> print(prefs['delivery_status'])
275
318
    >>> print(prefs['hide_address'])
276
319
    None
277
320
    >>> print(prefs['preferred_language'])
278
 
    en
 
321
    None
279
322
    >>> print(prefs['receive_list_copy'])
280
323
    None
281
324
    >>> print(prefs['receive_own_postings'])
356
399
 
357
400
The list of users can also be paginated:
358
401
 
359
 
    >>> page = client.get_user_page(count=2, page=1)
 
402
    >>> page = client.get_user_page(count=4, page=1)
360
403
    >>> page.nr
361
404
    1
362
405
 
363
406
    >>> for user in page:
364
407
    ...     print(user)
 
408
    <User "Unverified" (...)>
 
409
    <User "Unconfirmed" (...)>
365
410
    <User "Anna" (...)>
366
411
    <User "Bill" (...)>
367
412
 
381
426
 
382
427
    >>> for user in page:
383
428
    ...     print(user)
 
429
    <User "Unverified" (...)>
 
430
    <User "Unconfirmed" (...)>
384
431
    <User "Anna" (...)>
385
432
    <User "Bill" (...)>
386
433
 
425
472
 
426
473
The address has not been verified:
427
474
 
428
 
    >>> print(address.verified_on is None)
 
475
    >>> print(address.verified_on is not None)
429
476
    True
430
477
 
431
478
But that can be done via the address object:
498
545
 
499
546
    >>> settings = test_one.settings
500
547
    >>> len(settings)
501
 
    50
 
548
    51
502
549
 
503
550
    >>> for attr in sorted(settings):
504
551
    ...     print(attr + ': ' + str(settings[attr]))
606
653
Members and owners/moderators are separate entries in in the general members
607
654
list:
608
655
 
609
 
    >>> test_one.subscribe('bar@example.com')
 
656
    >>> test_one.subscribe('bar@example.com', 'Bar',
 
657
    ...                    pre_verified=True,
 
658
    ...                    pre_confirmed=True)
610
659
    <Member "bar@example.com" on "test-one.example.com">
611
660
 
612
661
    >>> for member in client.members:
636
685
-----------------------
637
686
 
638
687
Subscription requests can be accessed through the list object's 
639
 
`request` property.
640
 
 
641
 
    >>> requests = test_one.requests
 
688
`request` property. So let's create a non-open list first. 
 
689
 
 
690
    >>> confirm_first = example_dot_com.create_list('confirm-first')
 
691
    >>> settings = confirm_first.settings
 
692
    >>> settings['subscription_policy'] = 'moderate'
 
693
    >>> settings.save()
 
694
 
 
695
    >>> confirm_first = client.get_list('confirm-first.example.com')
 
696
    >>> print(confirm_first.settings['subscription_policy'])
 
697
    moderate
642
698
 
643
699
Initially there are no requests:
644
700
 
645
 
    >>> requests
 
701
    >>> test_one.requests
646
702
    []
647
703
 
648
704