Merge pull request #1071 from modoboa/feature/crowdfunding_widget

Feature/crowdfunding widget
This commit is contained in:
Antoine Nguyen
2017-03-10 10:08:51 +01:00
committed by GitHub
5 changed files with 59 additions and 3 deletions
+1 -1
View File
@@ -320,7 +320,7 @@ def add_widgets_to_admin_dashboard(sender, user, **kwargs):
"domains": models.Domain.objects.get_for_admin(user)}
template = "admin/_per_domain_statistics_widget.html"
return [{
"column": "right",
"column": "left",
"template": template,
"context": context
}]
@@ -0,0 +1,26 @@
{% load core_tags 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 }}
<span class="pull-right">
<span class="label label-success">
{{ feature.current|currencyfmt }} / {{ feature.goal|currencyfmt }}</span>
</span>
</h4>
<p class="slogan">{{ feature.slogan|safe }}</p>
<div class="text-center">
<a href="{{ feature.full_url }}" class="btn btn-primary" target="_blank">
{% trans "More" %}</a>
</div>
{% if not forloop.last %}<hr>{% endif %}
{% empty %}
<div class="alert alert-info">{% trans "Nothing to sponsor yet." %}</div>
{% endfor %}
</div>
</div>
+11 -1
View File
@@ -1,3 +1,4 @@
# coding: utf-8
"""Custom tags for Core application."""
import os
@@ -10,7 +11,7 @@ from django.core.urlresolvers import reverse
from django.template.loader import render_to_string
from django.utils import timezone
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext as _
from django.utils.translation import get_language, ugettext as _
from django.contrib.sessions.models import Session
@@ -255,3 +256,12 @@ def display_messages(msgs):
});
</script>
""" % (level, text, timeout))
@register.filter
def currencyfmt(amount):
"""Simple temp. filter to replace babel."""
lang = get_language()
if lang == "fr":
return u"{} €".format(amount)
return u"€{}".format(amount)
+16 -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,25 @@ 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 = "{}{}/api/projects/?featured=true".format(
MODOBOA_WEBSITE_URL, lang)
response = requests.get(url)
if response.status_code == 200:
features = response.json()
context["widgets"]["right"].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 +63,5 @@ class DashboardView(auth_mixins.AccessMixin, generic.TemplateView):
widget["template"])
# FIXME: can raise conflicts...
context.update(widget["context"])
return context
+5
View File
@@ -284,4 +284,9 @@ html body div.navbar div.container-fluid div#navigate-navbar-collapse.collapse u
/* Wizard */
#wizard .carousel-inner {
overflow: visible;
}
/* Dashboard */
.slogan {
padding-top: 15px;
}