Browse Source

Add feeds on member dashboard. 1 feed for the provide, 1 feed of FFDN. Ajaxy loaded. Use feedparser.

Fabs 10 years ago
parent
commit
bb43699afb

+ 29 - 0
coin/members/templates/members/index.html

@@ -16,6 +16,35 @@
         <h3>Stats</h3>
         <div class="panel">Use MOAR bandwidth !</div>
     </div>
+    <div class="large-6 columns">
+        <h3>News de nous</h3>
+        <div class="panel" id="feed_provider"><i class="fa fa-spinner fa-spin"></i>
+ Chargement en cours</div>
+    </div>
+    <div class="large-6 columns">
+        <h3>News de FFDN</h3>
+        <div class="panel" id="feed_ffdn"><i class="fa fa-spinner fa-spin"></i>
+ Chargement en cours</div>
+    </div>
 </div>
 
 {% endblock %}
+
+
+{% block js %}
+    {{ block.super }}
+    <script>
+    $(function() {
+        $.ajax({
+            url: "{% url 'feed_provider' %}",
+        }).done(function(html) {
+            $('#feed_provider').html(html);
+        });
+        $.ajax({
+            url: "{% url 'feed_ffdn' %}",
+        }).done(function(html) {
+            $('#feed_ffdn').html(html);
+        });
+    });
+    </script>
+{% endblock js %}

+ 1 - 1
coin/members/urls.py

@@ -50,5 +50,5 @@ urlpatterns = patterns(
     # url(r'^subscription/(?P<id>\d+)', views.subscriptions, name = 'subscription'),
 
     url(r'^invoices/', views.invoices, name='invoices'),
-    url(r'^contact/', views.contact, name='contact')
+    url(r'^contact/', views.contact, name='contact'),
 )

+ 6 - 0
coin/settings.py

@@ -249,6 +249,12 @@ MEMBER_DEFAULT_COTISATION = 20
 # Reset session if cookie older than 2h.
 SESSION_COOKIE_AGE = 7200
 
+# RSS/Atom feeds to display on dashboard
+FEED_PROVIDER_URL = 'http://www.illyse.net/feed/'
+FEED_PROVIDER_MAX_ENTRIES = 3
+FEED_FFDN_URL = 'http://www.ffdn.org/fr/rss.xml'
+FEED_FFDN_MAC_ENTRIES = FEED_PROVIDER_MAX_ENTRIES
+
 # Surcharge les paramètres en utilisant le fichier settings_local.py
 try:
     from settings_local import *

+ 15 - 0
coin/static/css/illyse.css

@@ -267,3 +267,18 @@ tr.inactive {
 	background-color: #FFFFFF;
 	border: 2px solid #C0C0C0;
 }
+
+/* Feeds */
+.feed {
+    font-size:80%;
+}
+
+.feed .entry {
+    margin-bottom:1em;
+
+}
+
+.feed .entry .date {
+    color:gray;
+    font-size:80%;
+}

+ 3 - 3
coin/templates/base.html

@@ -65,9 +65,9 @@
     <script src="{% static "js/vendor/jquery.js" %}"></script>
     <script src="{% static "js/foundation.min.js" %}"></script>
     <script src="{% static "js/foundation/foundation.offcanvas.js" %}"></script>
+    <script> $(document).foundation(); </script>
+
+    {% block js %}{% endblock js %}
 
-    <script>
-      $(document).foundation();
-    </script>
   </body>
 </html>

+ 11 - 0
coin/templates/fragments/feed.html

@@ -0,0 +1,11 @@
+<div class="feed">
+{% for entry in feed_entries %}
+    <div class="entry">
+        <div class="date">{{ entry.published_parsed.tm_mday }}/{{ entry.published_parsed.tm_mon }}/{{ entry.published_parsed.tm_year }}</div>
+        <h5><a href="{{ entry.link }}" target="_blank">{{ entry.title }}</a></h5>
+        <div class="intro">
+            {{ entry.summary|striptags|slice:":255" }}
+        </div>
+    </div>
+{% endfor %}
+</div>

+ 6 - 0
coin/urls.py

@@ -6,6 +6,9 @@ from django.conf.urls import patterns, include, url
 from django.conf.urls.static import static
 from django.contrib.staticfiles.urls import staticfiles_urlpatterns
 
+from coin import views
+
+
 import autocomplete_light
 autocomplete_light.autodiscover()
 
@@ -25,6 +28,9 @@ urlpatterns = patterns(
 
     # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
     
+    url(r'^feed_provider/', views.feed_provider, name='feed_provider'),
+    url(r'^feed_ffdn/', views.feed_ffdn, name='feed_ffdn'),
+
     url(r'^autocomplete/', include('autocomplete_light.urls')),
 
 )

+ 49 - 0
coin/views.py

@@ -0,0 +1,49 @@
+import feedparser
+
+from django.template import RequestContext
+from django.shortcuts import render_to_response
+from django.http import HttpResponse
+from django.conf import settings
+
+
+def feed_provider(request):
+    feed_url = ''
+    limit = 3
+    try:
+        if settings.FEED_PROVIDER_URL:
+            feed_url = settings.FEED_PROVIDER_URL
+        if settings.FEED_PROVIDER_MAX_ENTRIES:
+            limit = settings.FEED_PROVIDER_MAX_ENTRIES
+    except:
+        pass
+
+    return feed(request, feed_url, limit)
+
+
+def feed_ffdn(request):
+    feed_url = ''
+    limit = 3
+    try:
+        if settings.FEED_FFDN_URL:
+            feed_url = settings.FEED_FFDN_URL
+        if settings.FEED_FFDN_MAX_ENTRIES:
+            limit = settings.FEED_FFDN_MAX_ENTRIES
+    except:
+        pass
+
+    return feed(request, feed_url, limit)
+
+
+def feed(request, feed_url, limit):
+    try:
+        if feed_url:
+            feed = feedparser.parse(feed_url)
+            entries = feed.entries[:limit]
+
+            return render_to_response('fragments/feed.html',
+                                      {'feed_entries': entries},
+                                      context_instance=RequestContext(request))
+    except:
+        pass
+
+    return HttpResponse('')

+ 1 - 0
requirements.txt

@@ -12,3 +12,4 @@ django-sendfile==0.3.6
 -e git+https://code.ffdn.org/zorun/django-postgresql-netfields.git#egg=django-netfields
 -e git+https://github.com/chrisglass/xhtml2pdf@a5d37ffd0ccb0603bdf668198de0f21766816104#egg=xhtml2pdf-master
 -e git+https://github.com/jlaine/django-ldapdb@1c4f9f29e52176f4367a1dffec2ecd2e123e2e7a#egg=django-ldapdb
+feedparser