diff options
author | Sebastian Silva <sebastian@somosazucar.org> | 2013-10-24 05:44:42 (GMT) |
---|---|---|
committer | Sebastian Silva <sebastian@somosazucar.org> | 2013-10-24 05:54:46 (GMT) |
commit | c2a53079a8b66ecef738aa0b1721ff6424c1ff30 (patch) | |
tree | eb16029d1454e535e9433d8c75b15da997dd85ef | |
parent | 3905ebf1e56d73fc03bf9881762fa09ec6b94fdf (diff) |
initial implementation of atom feeds for contexts and feedback
-rw-r--r-- | sugar_network_webui/app.py | 12 | ||||
-rw-r--r-- | sugar_network_webui/cursors.py | 14 | ||||
-rw-r--r-- | sugar_network_webui/feeds.py | 72 |
3 files changed, 95 insertions, 3 deletions
diff --git a/sugar_network_webui/app.py b/sugar_network_webui/app.py index 16e47f3..6a8f617 100644 --- a/sugar_network_webui/app.py +++ b/sugar_network_webui/app.py @@ -51,6 +51,8 @@ app.config['BABEL_DEFAULT_LOCALE'] = 'en' app.config['BABEL_DEFAULT_TIMEZONE'] = 'America/Lima' app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER +from feeds import * + from cursors import * from dialogs import * @@ -164,6 +166,7 @@ def before_request(): g.Artifacts = home_mount.Artifacts g.Projects = home_mount.Projects g.autocomplete_Contexts = home_mount.autocomplete_Contexts + g.feed_Contexts = home_mount.feed_Contexts g.Questions = home_mount.Questions g.Ideas = home_mount.Ideas g.Problems = home_mount.Problems @@ -171,6 +174,7 @@ def before_request(): g.Comments = home_mount.Comments g.Reviews = home_mount.Reviews g.Resources = home_mount.Resources + g.feed_Resources = home_mount.feed_Resources else: g.client = network_mount.client g.Contexts = network_mount.Contexts @@ -178,6 +182,7 @@ def before_request(): g.Artifacts = network_mount.Artifacts g.Projects = network_mount.Projects g.autocomplete_Contexts = network_mount.autocomplete_Contexts + g.feed_Contexts = network_mount.feed_Contexts g.Questions = network_mount.Questions g.Ideas = network_mount.Ideas g.Problems = network_mount.Problems @@ -185,6 +190,7 @@ def before_request(): g.Comments = network_mount.Comments g.Reviews = network_mount.Reviews g.Resources = network_mount.Resources + g.feed_Resources = home_mount.feed_Resources def incoming(event): @@ -722,9 +728,9 @@ def solution_browser(resource_guid=None): @app.route('/context/view/<context_guid>/<query>') @app.route('/context/view/<context_guid>') -@app.route('/context/questions/<context_guid>') -@app.route('/context/ideas/<context_guid>') -@app.route('/context/problems/<context_guid>') +@app.route('/context/questions/<context_guid>', endpoint='context_question_browser') +@app.route('/context/ideas/<context_guid>', endpoint='context_idea_browser') +@app.route('/context/problems/<context_guid>', endpoint='context_problem_browser') @app.route('/context/artifacts/<context_guid>') @app.route('/context/gallery/<context_guid>') @app.route('/context/all/<context_guid>') diff --git a/sugar_network_webui/cursors.py b/sugar_network_webui/cursors.py index f129188..9e4bc8b 100644 --- a/sugar_network_webui/cursors.py +++ b/sugar_network_webui/cursors.py @@ -29,6 +29,11 @@ class Mount: order_by='-mtime') self.autocomplete_Contexts = self.client.Context.cursor( reply=['guid', 'title'], order_by='-mtime') + + self.feed_Contexts = self.client.Context.cursor( page_size=15, + reply=['guid', 'title', 'description', 'author', 'ctime', 'mtime'], + order_by='-mtime') + self.Projects = self.client.Context.cursor(type='project', reply=['guid', 'type', 'title', 'author', 'summary', 'description', 'layer', 'mtime'], @@ -47,6 +52,12 @@ class Mount: layer='clone', reply=['guid', 'title'], order_by='-mtime') + + self.feed_Contexts = self.client.Context.cursor( page_size=15, + layer='clone', + reply=['guid', 'title', 'description', 'author', 'ctime', 'mtime'], + order_by='-mtime') + self.Projects = self.client.Context.cursor(type='project', reply=['guid', 'type', 'title', 'author', 'summary', 'description', 'layer', 'mtime'], @@ -78,6 +89,9 @@ class Mount: self.Resources = self.client.Feedback.cursor( reply=['guid', 'type', 'title', 'content', 'context', 'author', 'tags', 'mtime'], order_by='-mtime') + self.feed_Resources = self.client.Feedback.cursor( + reply=['guid', 'type', 'title', 'content', 'context', 'author', + 'tags', 'mtime', 'ctime'], order_by='-mtime') self.Artifacts = self.client.Artifact.cursor( reply=['guid', 'title', 'description', 'context', 'author', 'tags', 'mtime'], diff --git a/sugar_network_webui/feeds.py b/sugar_network_webui/feeds.py new file mode 100644 index 0000000..2d71d79 --- /dev/null +++ b/sugar_network_webui/feeds.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2012, Sebastian Silva +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +from flask import g,request,url_for +from flaskext.babel import gettext as _ +import logging +from werkzeug.contrib.atom import AtomFeed + +import datetime +from app import app + +def timedelta(mtime): + return datetime.datetime.fromtimestamp(mtime) + +@app.route('/context.atom') +def context_feed(): + + feed = AtomFeed(_('Recent Contexts'), + feed_url=request.url, url=request.url_root) + + g.feed_Contexts._reset() + g.feed_Contexts.offset = -1 + i = 0 + for context in g.feed_Contexts: + if i==15: + break + feed.add(context['title'], unicode(context.get('description')), + content_type='text', + author=context['author'], + url=url_for('project_browser', context_guid=context['guid']), + updated=timedelta(context['mtime']), + published=timedelta(context['ctime'])) + i = i+1 + + return feed.get_response() + +@app.route('/feedback.atom') +def feedback_feed(): + + feed = AtomFeed(_('Recent Feedback'), + feed_url=request.url, url=request.url_root) + + g.feed_Resources._reset() + g.feed_Resources.offset = -1 + i = 0 + for resource in g.feed_Resources: + if i==15: + break + feed.add(resource['title'], unicode(resource.get('content')), + content_type='text', + author=resource['author'], + url=url_for('solution_browser', + resource_guid=resource['guid']), + categories=[{'term':resource['type'].pop()}], + updated=timedelta(resource['mtime']), + published=timedelta(resource['ctime'])) + i = i+1 + + return feed.get_response() |