From b343dc73e5ea4aaf1314b6b277c3806f15ac0635 Mon Sep 17 00:00:00 2001 From: François Schmidts Date: Wed, 8 Apr 2015 12:33:40 +0200 Subject: moving feed views related code in views.feed and massive use of url_for --- pyaggr3g470r/controllers/abstract.py | 9 +- pyaggr3g470r/templates/about.html | 2 +- pyaggr3g470r/templates/admin/user.html | 6 +- pyaggr3g470r/templates/feed.html | 4 +- pyaggr3g470r/templates/feeds.html | 8 +- pyaggr3g470r/templates/home.html | 18 ++-- pyaggr3g470r/templates/layout.html | 4 +- pyaggr3g470r/templates/management.html | 2 +- pyaggr3g470r/templates/unread.html | 4 +- pyaggr3g470r/views/feed.py | 149 ++++++++++++++++++++++++++++++--- pyaggr3g470r/views/views.py | 80 +----------------- 11 files changed, 171 insertions(+), 115 deletions(-) (limited to 'pyaggr3g470r') diff --git a/pyaggr3g470r/controllers/abstract.py b/pyaggr3g470r/controllers/abstract.py index f1173817..8f0a8e3f 100644 --- a/pyaggr3g470r/controllers/abstract.py +++ b/pyaggr3g470r/controllers/abstract.py @@ -56,8 +56,8 @@ class AbstractController(object): if not obj: raise NotFound({'message': 'No %r (%r)' % (self._db_cls.__class__.__name__, filters)}) - if self.user_id is not None \ - and getattr(obj, self._user_id_key) != self.user_id: + + if not self._has_right_on(obj): raise Forbidden({'message': 'No authorized to access %r (%r)' % (self._db_cls.__class__.__name__, filters)}) return obj @@ -84,3 +84,8 @@ class AbstractController(object): db.session.delete(obj) db.session.commit() return obj + + def _has_right_on(self, obj): + # user_id == None is like being admin + return self.user_id is None \ + or getattr(obj, self._user_id_key, None) == self.user_id diff --git a/pyaggr3g470r/templates/about.html b/pyaggr3g470r/templates/about.html index 08b80fbb..901b3b35 100644 --- a/pyaggr3g470r/templates/about.html +++ b/pyaggr3g470r/templates/about.html @@ -17,7 +17,7 @@

{{ _('Help') }}

{{ _('If you have any problem, contact the administrator.') }}

{{ _('The documentation of the RESTful API is here.') }}

-

{{ _('You can subscribe to new feeds with a bookmarklet. Drag this link to your browser bookmarks.', bookmarklet='javascript:window.location="https://pyaggr3g470r.herokuapp.com/bookmarklet?url="+encodeURIComponent(document.location)') }}

+

{{ _('You can subscribe to new feeds with a bookmarklet. Drag this link to your browser bookmarks.', bookmarklet='javascript:window.location="%s?url="+encodeURIComponent(document.location)' % url_for('feed.bookmarklet', _external=True)) }}

{{ _('Donation') }}

diff --git a/pyaggr3g470r/templates/admin/user.html b/pyaggr3g470r/templates/admin/user.html index f20d53dd..317fef49 100644 --- a/pyaggr3g470r/templates/admin/user.html +++ b/pyaggr3g470r/templates/admin/user.html @@ -39,9 +39,9 @@ {{ feed.site_link }} {{ feed.articles.all()|count }} - - - + + + {% endfor %} diff --git a/pyaggr3g470r/templates/feed.html b/pyaggr3g470r/templates/feed.html index 268cbf7d..c0c92279 100644 --- a/pyaggr3g470r/templates/feed.html +++ b/pyaggr3g470r/templates/feed.html @@ -4,8 +4,8 @@

{{ feed.title }}

{% if feed.description %}

{{ feed.description }}

{% endif %} - - + +

diff --git a/pyaggr3g470r/templates/feeds.html b/pyaggr3g470r/templates/feeds.html index 460ae4a2..9c57bf42 100644 --- a/pyaggr3g470r/templates/feeds.html +++ b/pyaggr3g470r/templates/feeds.html @@ -1,7 +1,7 @@ {% extends "layout.html" %} {% block content %}

-

{{ _('You are subscribed to') }} {{ feeds.count() }} {{ _('feeds') }} · {{ _('Add a') }} {{ _('feed') }}

+

{{ _('You are subscribed to') }} {{ feeds.count() }} {{ _('feeds') }} · {{ _('Add a') }} {{ _('feed') }}

@@ -25,14 +25,14 @@ {% endif %} - + {% endfor %} diff --git a/pyaggr3g470r/templates/home.html b/pyaggr3g470r/templates/home.html index c20cacfa..390ac5f6 100644 --- a/pyaggr3g470r/templates/home.html +++ b/pyaggr3g470r/templates/home.html @@ -3,7 +3,7 @@ {% if feeds|count == 0 %}

{{ _("You don't have any feeds.") }}

-

{{ _('Add some') }}, {{ _('or') }} {{ _('upload an OPML file.') }}

+

{{ _('Add some') }}, {{ _('or') }} {{ _('upload an OPML file.') }}

{% else %}
{{ feed.title }}{{ feed.title }} {{ feed.site_link }} {{ feed.articles.count() }} - + - +