Custom news for resellers and domain admins.

see #1047
This commit is contained in:
Antoine Nguyen
2017-03-10 11:39:58 +01:00
parent 92493a1127
commit c3f8e6400e
3 changed files with 29 additions and 2 deletions
+10
View File
@@ -215,6 +215,16 @@ class GeneralParametersForm(param_forms.AdminParametersForm):
required=False
)
dash_sep = SeparatorField(label=ugettext_lazy("Dashboard"))
news_url = forms.URLField(
label=ugettext_lazy("Custom news url"),
required=False,
help_text=ugettext_lazy(
"Display custom news for resellers and domain administrators"
)
)
notif_sep = SeparatorField(label=ugettext_lazy("Notifications"))
sender_address = lib_fields.UTF8EmailField(
+12
View File
@@ -62,6 +62,18 @@ class DashboardTestCase(ModoTestCase):
response = self.client.get(url)
self.assertEqual(response.status_code, 302)
def test_custom_news(self):
"""Check that custom news are displayed."""
url = reverse("core:dashboard")
response = self.client.get(url)
self.assertContains(response, "https://modoboa.org")
self.set_global_parameter(
"news_url", "https://www.djangoproject.com/rss/weblog/")
self.client.force_login(self.dadmin)
response = self.client.get(url)
self.assertContains(response, "djangoproject")
def test_root_dispatch(self):
"""Check root dispatching."""
url = reverse("core:root")
+7 -2
View File
@@ -37,8 +37,13 @@ class DashboardView(auth_mixins.AccessMixin, generic.TemplateView):
lang = "en"
context.update({"selection": "dashboard"})
posts = feedparser.parse(
"{}{}/weblog/feeds/".format(MODOBOA_WEBSITE_URL, lang))
feed_url = "{}{}/weblog/feeds/".format(MODOBOA_WEBSITE_URL, lang)
if self.request.user.role != "SuperAdmins":
custom_feed_url = (
self.request.localconfig.parameters.get_value("news_url"))
if custom_feed_url:
feed_url = custom_feed_url
posts = feedparser.parse(feed_url)
entries = []
for entry in posts["entries"][:5]:
entry["published"] = parser.parse(entry["published"])