Denis Merigoux пре 9 година
родитељ
комит
da151f8c04
4 измењених фајлова са 38 додато и 15 уклоњено
  1. 29 0
      counter/rss.py
  2. 2 2
      counter/templates/baseTemplate.html
  3. 5 3
      counter/urls.py
  4. 2 10
      counter/views.py

+ 29 - 0
counter/rss.py

@@ -0,0 +1,29 @@
1
+from django.contrib.syndication.views import Feed
2
+from counter.models import Counter, Reset
3
+from django.core.urlresolvers import reverse
4
+from babel.dates import format_datetime
5
+from django.utils import timezone
6
+from datetime import timedelta
7
+
8
+
9
+class SeumFeed(Feed):
10
+    title = "Flil du seum"
11
+    link = "/rss"
12
+    description = "Notifications seumesques"
13
+
14
+    def items(self):
15
+        return Reset.objects.filter(timestamp__gte=timezone.now() -
16
+                                    timedelta(days=7)).order_by('-timestamp')
17
+
18
+    def item_title(self, item):
19
+        return (item.counter.trigramme + ' (' + item.counter.name +
20
+                ') a eu le seum')
21
+
22
+    def item_description(self, item):
23
+        return (format_datetime(item.timestamp, locale='fr',
24
+                                format="dd/MM/Y 'à' HH:mm") +
25
+                ' : ' + item.reason)
26
+
27
+    # item_link is only needed if NewsItem has no get_absolute_url method.
28
+    def item_link(self, item):
29
+        return reverse('counter', args=[item.counter.id])

+ 2 - 2
counter/templates/baseTemplate.html

@@ -5,8 +5,8 @@
5 5
 	<meta charset="UTF-8" />
6 6
 	<meta name="author" content="Seum Man" />
7 7
 	<meta name="keywords" content="seum compteur" />
8
-	<meta name="description" content="Compteurs de seum" />
9
-	<meta name="viewport" content="width=device-width">
8
+	<meta name="description" content="Ça fout le seum" />
9
+	<meta name="viewport" content="width=device-width, initial-scale=1.0">
10 10
 	<link rel="shortcut icon" type="image/png" href="{{STATIC_URL}}/favicon.ico"/>
11 11
 	<title>SeumBook™ – {% block title %}{% endblock %}</title>
12 12
 

+ 5 - 3
counter/urls.py

@@ -1,11 +1,13 @@
1 1
 from django.conf.urls import url
2
+from counter.rss import SeumFeed
2 3
 
3 4
 from . import views
4 5
 
5 6
 urlpatterns = [
6 7
     url(r'^$', views.home,name="home"),
7
-    url(r'^reset-counter/',views.resetCounter,name="reset-counter"),
8
+    url(r'^reset-counter',views.resetCounter,name="reset-counter"),
8 9
     url(r'^counter/(?P<id_counter>\d+)$', views.counter, name="counter"),
9
-    url(r'^set-my-counter/',views.setMyCounter,name="set-my-counter"),
10
-    url(r'^reset-my-counter/',views.resetMyCounter,name="reset-my-counter"),
10
+    url(r'^set-my-counter',views.setMyCounter,name="set-my-counter"),
11
+    url(r'^reset-my-counter',views.resetMyCounter,name="reset-my-counter"),
12
+    url(r'^rss',SeumFeed())
11 13
 ]

+ 2 - 10
counter/views.py

@@ -14,14 +14,6 @@ import math
14 14
 import copy
15 15
 from django.utils import timezone
16 16
 
17
-
18
-class resetCounterForm(forms.ModelForm):
19
-
20
-    class Meta:
21
-        model = Reset
22
-        fields = ['reason', 'counter']
23
-
24
-
25 17
 def home(request):
26 18
     # JSS above this limit will not be displayed on the col graph
27 19
     JSS_limit = 7
@@ -237,7 +229,7 @@ def resetCounter(request):
237 229
         emails = [u[0] for u in Counter.objects.all().values_list('email')
238 230
                   if u[0] != 'null@localhost']
239 231
         # Now send emails to everyone
240
-        email_to_send = EmailMessage(counter.name + ' a le seum',
232
+        email_to_send = EmailMessage('[SeumBook] '+counter.name + ' a le seum',
241 233
                                      data['reason'][0] + '''
242 234
 
243 235
 --
@@ -279,7 +271,7 @@ def counter(request, id_counter):
279 271
     for reset in resets:
280 272
         reset.date = format_datetime(
281 273
             reset.timestamp, locale='fr',
282
-            format="EEEE dd MMMM Y 'à' HH:mm:ss").capitalize()
274
+            format="EEEE dd MMMM Y 'à' HH:mm").capitalize()
283 275
     # Timeline graph
284 276
     # Data pre-processing
285 277
     resets_graph = resets