Abhilash Raj pushed to branch master at GNU Mailman / Mailman Core

Commits:
92d84b81 by Abhilash Raj at 2019-02-26T16:52:41Z
Expose preferred_language of a MailingList through API.

- - - - -
dbaef5f6 by Abhilash Raj at 2019-02-26T16:52:41Z
Merge branch 'language' into 'master'

Expose preferred_language of a MailingList through API.

See merge request mailman/mailman!461
- - - - -


4 changed files:

- src/mailman/docs/NEWS.rst
- src/mailman/rest/docs/listconf.rst
- src/mailman/rest/listconf.py
- src/mailman/rest/tests/test_listconf.py


Changes:

=====================================
src/mailman/docs/NEWS.rst
=====================================
@@ -20,6 +20,7 @@ REST
 ----
 * Failed validation to new Mailing List creation and Domain creation no longer
   returns 500 errors.
+* Expose ``preferred_language`` for MailingList through REST API.
 
 
 3.2.1


=====================================
src/mailman/rest/docs/listconf.rst
=====================================
@@ -72,6 +72,7 @@ All readable attributes for a list are available on a 
sub-resource.
     post_id: 1
     posting_address: a...@example.com
     posting_pipeline: default-posting-pipeline
+    preferred_language: en
     reply_goes_to_list: no_munging
     reply_to_address:
     request_address: ant-requ...@example.com
@@ -123,6 +124,7 @@ When using ``PUT``, all writable attributes must be 
included.
     ...             dmarc_mitigate_unconditionally=False,
     ...             dmarc_moderation_notice='Some moderation notice',
     ...             dmarc_wrapped_message_text='some message text',
+    ...             preferred_language='ja',
     ...             posting_pipeline='virgin',
     ...             filter_content=True,
     ...             first_strip_reply_to=True,
@@ -195,6 +197,7 @@ These values are changed permanently.
     moderator_password: {plaintext}password
     ...
     posting_pipeline: virgin
+    preferred_language: ja
     reply_goes_to_list: point_to_list
     reply_to_address: b...@example.com
     ...


=====================================
src/mailman/rest/listconf.py
=====================================
@@ -33,7 +33,7 @@ from mailman.rest.helpers import (
 from mailman.rest.validator import (
     PatchValidator, ReadOnlyPATCHRequestError, UnknownPATCHRequestError,
     Validator, enum_validator, integer_ge_zero_validator,
-    list_of_strings_validator
+    language_validator, list_of_strings_validator
     )
 from public import public
 from zope.component import getUtility
@@ -64,6 +64,24 @@ class AcceptableAliases(GetterSetter):
             alias_set.add(alias)
 
 
+class LanguageGetterSetter(GetterSetter):
+
+    def get(self, mlist, attribute):
+        """Return the language code of the preferred language."""
+        assert attribute == 'preferred_language', (
+            'Unexpected attribute: {}'.format(attribute))   # pragma: nocover
+        return mlist.preferred_language.code
+
+    def put(self, mlist, attribute, value):
+        """Set the preferred language of the MailingList."""
+        assert attribute == 'preferred_language', (
+            'Unexpected attribute: {}'.format(attribute))   # pragma: nocover
+
+        # We can just set the language code as value since the setter takes
+        # cares of converting the language code to Language model.
+        mlist.preferred_language = value
+
+
 TEMPLATE_ATTRIBUTES = dict(
     digest_footer_uri='list:digest:footer',
     digest_header_uri='list:digest:header',
@@ -179,6 +197,7 @@ ATTRIBUTES = dict(
     post_id=GetterSetter(None),
     posting_address=GetterSetter(None),
     posting_pipeline=GetterSetter(pipeline_validator),
+    preferred_language=LanguageGetterSetter(language_validator),
     reply_goes_to_list=GetterSetter(enum_validator(ReplyToMunging)),
     reply_to_address=GetterSetter(str),
     request_address=GetterSetter(None),


=====================================
src/mailman/rest/tests/test_listconf.py
=====================================
@@ -74,6 +74,7 @@ RESOURCE = dict(
     moderator_password='password',
     max_message_size='150',
     posting_pipeline='virgin',
+    preferred_language='en',
     reply_goes_to_list='point_to_list',
     reply_to_address='b...@example.com',
     require_explicit_destination=True,



View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/cc313c14fdaf883b9a89a8b95c93fb32f9c225b2...dbaef5f673477c26684f448093193326614c468a

-- 
View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/cc313c14fdaf883b9a89a8b95c93fb32f9c225b2...dbaef5f673477c26684f448093193326614c468a
You're receiving this email because of your account on gitlab.com.
_______________________________________________
Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: 
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to