New widget to display current features to sponsor.

WIP
This commit is contained in:
Antoine Nguyen
2017-03-09 14:52:56 +01:00
parent 14fc64a88a
commit a0d8f26277
2 changed files with 36 additions and 1 deletions
@@ -0,0 +1,19 @@
{% load i18n %}
<!-- Current features to sponsor -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">{% trans "Features looking for sponsoring" %}</h3>
</div>
<div class="panel-body">
{% for feature in features %}
<h4>{{ feature.name }}</h4>
<span class="label label-info">{% trans "Current:" %} {{ feature.current }}</span>
<span class="label label-success">{% trans "Goal:" %} {{ feature.goal }}</span>
<p>{{ feature.description }}</p>
<a href="{{ feature.full_url }}" class="btn btn-primary">{% trans "More" %}</a>
{% empty %}
<div class="alert alert-info">{% trans "FIXME" %}</div>
{% endfor %}
</div>
</div>
+17 -1
View File
@@ -2,6 +2,7 @@
from dateutil import parser
import feedparser
import requests
from django.views import generic
@@ -9,6 +10,8 @@ from django.contrib.auth import mixins as auth_mixins
from .. import signals
MODOBOA_WEBSITE_URL = "https://modoboa.org/"
class DashboardView(auth_mixins.AccessMixin, generic.TemplateView):
"""Dashboard view."""
@@ -32,14 +35,26 @@ class DashboardView(auth_mixins.AccessMixin, generic.TemplateView):
lang = "fr"
else:
lang = "en"
context.update({"selection": "dashboard"})
posts = feedparser.parse(
"https://modoboa.org/{}/weblog/feeds/".format(lang))
"{}{}/weblog/feeds/".format(MODOBOA_WEBSITE_URL, lang))
entries = []
for entry in posts["entries"][:5]:
entry["published"] = parser.parse(entry["published"])
entries.append(entry)
context["widgets"]["left"].append("core/_latest_news_widget.html")
context.update({"news": entries})
url = "{}{}/projects/?featured=true".format(
MODOBOA_WEBSITE_URL, lang)
response = requests.get(url)
features = []
if response.status_code == 200:
features = response.json()
context["widgets"]["left"].append("core/_current_features.html")
context.update({"features": features})
# Extra widgets
result = signals.extra_admin_dashboard_widgets.send(
sender=self.__class__, user=self.request.user)
@@ -49,4 +64,5 @@ class DashboardView(auth_mixins.AccessMixin, generic.TemplateView):
widget["template"])
# FIXME: can raise conflicts...
context.update(widget["context"])
return context