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

Commits:
5688fc46 by Abhilash Raj at 2018-04-28T17:58:05Z
Add description attribute to IStyle, expose it in REST.

- - - - -
c0fd6dc6 by Abhilash Raj at 2018-04-28T17:58:05Z
Merge branch 'J08nY/mailman-list-style-descriptions' into 
'master'

Add description attribute to IStyle, expose it in REST.

See merge request mailman/mailman!371
- - - - -


9 changed files:

- src/mailman/docs/NEWS.rst
- src/mailman/interfaces/styles.py
- src/mailman/rest/docs/lists.rst
- src/mailman/rest/lists.py
- src/mailman/rest/tests/test_lists.py
- src/mailman/runners/tests/test_bounce.py
- src/mailman/styles/default.py
- src/mailman/styles/docs/styles.rst
- src/mailman/styles/tests/test_styles.py


Changes:

=====================================
src/mailman/docs/NEWS.rst
=====================================
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -129,6 +129,9 @@ REST
   ``DELETE`` on the list's ``config/acceptable_aliases`` resource.
   (Closes #394)
 * Allow setting ``max_message_size`` for a mailing list. (Closes #417)
+* Added new attribute in ``lists/styles`` resource ``styles`` that contains the
+  list of all the styles in Core along with their description. ``style_names``
+  attribute is now deprecated and will be removed in future versions.
 
 
 3.1.0 -- "Between The Wheels"


=====================================
src/mailman/interfaces/styles.py
=====================================
--- a/src/mailman/interfaces/styles.py
+++ b/src/mailman/interfaces/styles.py
@@ -34,6 +34,9 @@ class IStyle(Interface):
     name = Attribute(
         """The name of this style.  Must be unique.""")
 
+    description = Attribute(
+        """A short description of this list style.""")
+
     def apply(mailing_list):
         """Apply the style to the mailing list.
 


=====================================
src/mailman/rest/docs/lists.rst
=====================================
--- a/src/mailman/rest/docs/lists.rst
+++ b/src/mailman/rest/docs/lists.rst
@@ -191,10 +191,13 @@ Apply a style at list creation time
 of a particular type, e.g. discussion lists.  We can see which styles are
 available, and which is the default style.
 
-    >>> dump_json('http://localhost:9001/3.0/lists/styles')
-    default: legacy-default
-    http_etag: "..."
-    style_names: ['legacy-announce', 'legacy-default']
+    >>> json = call_http('http://localhost:9001/3.0/lists/styles')
+    >>> json['default']
+    'legacy-default'
+    >>> for style in json['styles']:
+    ...     print('{}: {}'.format(style['name'], style['description']))
+    legacy-announce: Announce only mailing list style.
+    legacy-default: Ordinary discussion mailing list style.
 
 When creating a list, if we don't specify a style to apply, the default style
 is used.  However, we can provide a style name in the POST data to choose a


=====================================
src/mailman/rest/lists.py
=====================================
--- a/src/mailman/rest/lists.py
+++ b/src/mailman/rest/lists.py
@@ -414,9 +414,14 @@ class Styles:
 
     def __init__(self):
         manager = getUtility(IStyleManager)
+        styles = [dict(name=style.name, description=style.description)
+                  for style in manager.styles]
         style_names = sorted(style.name for style in manager.styles)
         self._resource = dict(
+            # TODO (maxking): style_name is meant for backwards compatibility
+            # and should be removed in 3.3 release.
             style_names=style_names,
+            styles=styles,
             default=config.styles.default)
 
     def on_get(self, request, response):


=====================================
src/mailman/rest/tests/test_lists.py
=====================================
--- a/src/mailman/rest/tests/test_lists.py
+++ b/src/mailman/rest/tests/test_lists.py
@@ -347,6 +347,28 @@ class TestLists(unittest.TestCase):
         self.assertEqual(cm.exception.reason, 'Missing parameters: emails')
 
 
+class TestListStyles(unittest.TestCase):
+    """Test /lists/styles."""
+
+    layer = RESTLayer
+
+    def test_styles(self):
+        json, response = call_api('http://localhost:9001/3.0/lists/styles')
+        self.assertEqual(response.status_code, 200)
+        # Remove the variable data.
+        json.pop('http_etag')
+        self.assertEqual(json, {
+            'style_names': ['legacy-announce', 'legacy-default'],
+            'styles': [
+                {'name': 'legacy-announce',
+                 'description': 'Announce only mailing list style.'},
+                {'name': 'legacy-default',
+                 'description': 'Ordinary discussion mailing list style.'}
+                    ],
+            'default': 'legacy-default'
+            })
+
+
 class TestListArchivers(unittest.TestCase):
     """Test corner cases for list archivers."""
 


=====================================
src/mailman/runners/tests/test_bounce.py
=====================================
--- a/src/mailman/runners/tests/test_bounce.py
+++ b/src/mailman/runners/tests/test_bounce.py
@@ -227,6 +227,7 @@ class TestStyle:
     """See `IStyle`."""
 
     name = 'test'
+    description = 'A test style.'
 
     def apply(self, mailing_list):
         """See `IStyle`."""


=====================================
src/mailman/styles/default.py
=====================================
--- a/src/mailman/styles/default.py
+++ b/src/mailman/styles/default.py
@@ -17,6 +17,7 @@
 
 """Application of list styles to new and existing lists."""
 
+from mailman.core.i18n import _
 from mailman.interfaces.styles import IStyle
 from mailman.styles.base import (
     Announcement, BasicOperation, Bounces, Discussion, Identity, Moderation,
@@ -33,6 +34,7 @@ class LegacyDefaultStyle(
     """The legacy default style."""
 
     name = 'legacy-default'
+    description = _('Ordinary discussion mailing list style.')
 
     def apply(self, mailing_list):
         """See `IStyle`."""
@@ -52,6 +54,7 @@ class LegacyAnnounceOnly(
     """Similar to the legacy-default style, but for announce-only lists."""
 
     name = 'legacy-announce'
+    description = _('Announce only mailing list style.')
 
     def apply(self, mailing_list):
         """See `IStyle`."""


=====================================
src/mailman/styles/docs/styles.rst
=====================================
--- a/src/mailman/styles/docs/styles.rst
+++ b/src/mailman/styles/docs/styles.rst
@@ -49,6 +49,7 @@ New styles must implement the ``IStyle`` interface.
     >>> @implementer(IStyle)
     ... class TestStyle:
     ...     name = 'a-test-style'
+    ...     description = 'Testing mailing list style.'
     ...     def apply(self, mailing_list):
     ...         # Just does something very simple.
     ...         mailing_list.display_name = 'TEST STYLE LIST'
@@ -115,6 +116,7 @@ If no style name is provided when creating the list, the 
system default style
     >>> @implementer(IStyle)
     ... class AnotherStyle:
     ...     name = 'another-style'
+    ...     description = 'Another testing mailing list style.'
     ...     def apply(self, mailing_list):
     ...         # Just does something very simple.
     ...         mailing_list.display_name = 'ANOTHER STYLE LIST'


=====================================
src/mailman/styles/tests/test_styles.py
=====================================
--- a/src/mailman/styles/tests/test_styles.py
+++ b/src/mailman/styles/tests/test_styles.py
@@ -31,14 +31,11 @@ from zope.interface.exceptions import DoesNotImplement
 class DummyStyle:
 
     name = 'dummy'
-    priority = 1
+    description = 'A dummy style.'
 
     def apply(self, mlist):
         pass
 
-    def match(self, mlist, styles):
-        styles.append(self)
-
 
 class TestStyle(unittest.TestCase):
     """Test styles."""



View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/565b2771985c6b1a470884eb65bd49457b0c452e...c0fd6dc6e628ee3b58b6b54f0f743f6c3fe0bb98

---
View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/565b2771985c6b1a470884eb65bd49457b0c452e...c0fd6dc6e628ee3b58b6b54f0f743f6c3fe0bb98
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