diff options
-rw-r--r-- | sugar_network_webui/app.py | 20 | ||||
-rw-r--r-- | sugar_network_webui/cursors.py | 14 | ||||
-rw-r--r-- | sugar_network_webui/dialogs.py | 16 | ||||
-rw-r--r-- | sugar_network_webui/feeds.py | 72 |
4 files changed, 115 insertions, 7 deletions
diff --git a/sugar_network_webui/app.py b/sugar_network_webui/app.py index 16e47f3..6d46394 100644 --- a/sugar_network_webui/app.py +++ b/sugar_network_webui/app.py @@ -34,7 +34,7 @@ from werkzeug import secure_filename import simplejson import tempfile -from sugar_network.toolkit.http import NotFound +from sugar_network.toolkit.http import NotFound from client import Client _BUFFER_SIZE = 1024 * 10 @@ -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 * @@ -112,7 +114,7 @@ def get_user(): try: import gconf except ImportError: - return 'demo' + return 'demo' conf = gconf.client_get_default() return conf.get_string('/desktop/sugar/user/nick') @@ -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,15 +190,16 @@ 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): global _pull_events _pull_events.append(event) #if event['event']=='inline' and event.get('state')=='offline': - # session['connected'] = False + # session['connected'] = False #if event['event']=='inline' and event.get('state')=='online': - # session['connected'] = True + # session['connected'] = True return None _pull_listener = Client.connect(incoming) @@ -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..32621b6 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/dialogs.py b/sugar_network_webui/dialogs.py index fcc5fe6..b4abdba 100644 --- a/sugar_network_webui/dialogs.py +++ b/sugar_network_webui/dialogs.py @@ -1,3 +1,19 @@ +# -*- 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/>. + import flask from flask_classy import FlaskView from flaskext.babel import gettext as _ diff --git a/sugar_network_webui/feeds.py b/sugar_network_webui/feeds.py new file mode 100644 index 0000000..9022664 --- /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() |