Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Silva (icarito) <sebastian@sugarlabs.org>2012-12-04 06:56:27 (GMT)
committer Sebastian Silva (icarito) <sebastian@sugarlabs.org>2012-12-04 06:56:27 (GMT)
commit1a217dfc6c07ed732b77653e2c0189bdf2f05cd8 (patch)
tree48973430171078283e59e790e80eaa113732f0c4
parentbf23399b93a90715103cc0b7a75ab16626776a32 (diff)
API update alsroot
-rw-r--r--sugar_network_webui/app.py161
-rw-r--r--sugar_network_webui/client.py34
-rw-r--r--sugar_network_webui/cursor.py4
-rw-r--r--sugar_network_webui/cursors.py48
-rw-r--r--sugar_network_webui/objects.py86
-rw-r--r--sugar_network_webui/templates/_artifact-list.html4
-rw-r--r--sugar_network_webui/templates/_browser-grid.html8
-rw-r--r--sugar_network_webui/templates/_context-article-view.html2
-rw-r--r--sugar_network_webui/templates/_context-artifact-list.html2
-rw-r--r--sugar_network_webui/templates/_context-comment-list.html6
-rw-r--r--sugar_network_webui/templates/_context-resource-list.html2
-rw-r--r--sugar_network_webui/templates/_context-review-list.html5
-rw-r--r--sugar_network_webui/templates/_context-solution-list.html10
-rw-r--r--sugar_network_webui/templates/_resource-list.html4
-rw-r--r--sugar_network_webui/templates/base.html24
-rw-r--r--sugar_network_webui/templates/context-view.html17
16 files changed, 142 insertions, 275 deletions
diff --git a/sugar_network_webui/app.py b/sugar_network_webui/app.py
index d1d8040..de4f956 100644
--- a/sugar_network_webui/app.py
+++ b/sugar_network_webui/app.py
@@ -14,6 +14,7 @@
# 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 errno
import logging
import sys
import os
@@ -249,62 +250,15 @@ def gen_icon(context_guid=None):
context_cursor = g.Projects
else:
context_cursor = g.Contexts
- context = context_cursor[offset]
+ context_guid = context_cursor[offset].guid
else:
- context = g.client.Context(context_guid)
-
- def send(icon_file):
- while True:
- chunk = icon_file.read(_BUFFER_SIZE)
- if not chunk:
- break
- yield chunk
-
- def download(context):
- try:
- with context.get_blob('icon') as icon:
- while True:
- chunk = icon.read(_BUFFER_SIZE)
- if not chunk:
- break
- yield chunk
- except:
- icon = app.open_resource('static/icons/document-generic.png')
-
- while True:
- chunk = icon.read(_BUFFER_SIZE)
- if not chunk:
- break
- yield chunk
-
- header = Headers()
- header.add("Content-Type", "image/png")
- return Response(download(context), headers=header, direct_passthrough=True)
+ context_cursor = g.client.Context
+ return redirect(context_cursor.url(context_guid, 'icon'))
@app.route('/artifacts/preview/<guid>')
def gen_preview(guid):
- artifact = g.client.Artifact(guid)
-
- def download(artifact):
- with artifact.get_blob('preview') as icon:
- if icon.closed:
- icon = app.open_resource('static/icons/document-generic.png')
- else:
- if os.fstat(icon.fileno()).st_size == 0:
- icon = app.open_resource(
- 'static/icons/document-generic.png')
-
- while True:
- chunk = icon.read(_BUFFER_SIZE)
- if not chunk:
- break
- yield chunk
-
- header = Headers()
- header.add("Content-Type", "image/png")
- return Response(download(artifact), headers=header,
- direct_passthrough=True)
+ return redirect(g.client.Artifact.url(guid, 'preview'))
@app.route('/launch/<context_guid>')
@@ -326,7 +280,7 @@ def case_1(context_guid=None):
context = g.Contexts[offset]
else:
context = g.client.Context(context_guid,
- reply=['title', 'keep', 'keep_impl'])
+ reply=['title', 'favorite', 'clone'])
return render_template('resource-form.html', context=context)
@@ -340,12 +294,10 @@ def artifact_post():
if upload:
filename = secure_filename(upload.filename)
artifact['title'] = filename
- full_filename = os.path.join(app.config['UPLOAD_FOLDER'], filename)
- upload.save(full_filename)
+ artifact['type'] = 'instance'
artifact.post()
-
- if filename:
- artifact.upload_blob('data', full_filename)
+ if filename:
+ artifact.upload_blob('data', upload.read(), upload.content_type)
return redirect('/context/artifacts/' + request.form['context'])
@@ -363,8 +315,8 @@ def artifact_copy(guid):
filename = artifact['title']
blob = artifact.get_blob('data')
document_path = get_documents_path()
- from shutil import copy
- copy(blob.name, os.path.join(document_path, filename))
+ with file(os.path.join(document_path, filename), 'w') as f:
+ f.write(blob)
title = _('Artifact has been downloaded.')
body = _('Success!\n\n'
'File %s has been copied to your Documents folder.\n'
@@ -376,24 +328,7 @@ def artifact_copy(guid):
def artifact_download(guid):
if not WWW:
return redirect(url_for('artifact_copy', guid=guid))
-
- artifact = g.client.Artifact(guid, reply=['guid', 'title'])
- filename = artifact['title']
-
- def download(artifact):
- with artifact.get_blob('data') as data:
- while True:
- chunk = data.read(_BUFFER_SIZE)
- if not chunk:
- break
- yield chunk
-
- header = Headers()
- header.add("Content-Type", "application/octet-stream")
- header.add("Content-Disposition", "attachment; filename=" + filename)
-
- return Response(download(artifact), headers=header,
- direct_passthrough=True)
+ return redirect(g.client.Artifact.url(guid, 'data'))
@app.route('/favorites')
@@ -452,16 +387,15 @@ def stars(context=None):
return jsonify()
guid = context[5:] # remove "stars-" from id
- keep = request.args.get('keep')
+ favorite = request.args.get('favorite')
- context = g.client.Context(guid)
- context['keep'] = (keep == 'true')
- context.post()
+ Client.call('PUT', document='context', guid=guid, cmd='favorite',
+ content=(favorite == 'true'))
# TODO Need to reset query object until supporting notifications
g.Contexts._reset()
- return jsonify(keep=keep)
+ return jsonify(favorite=favorite)
@app.route('/_moon/<context>')
@@ -469,14 +403,13 @@ def moon(context=None):
if not context:
return jsonify()
- keep_impl = request.args.get('keep_impl', None)
+ clone = request.args.get('clone', None)
guid = context[5:] # remove "moon-" from id
- context = g.client.Context(guid)
- context['keep_impl'] = 1 if keep_impl == 'true' else 0
- context.post()
+ Client.call('PUT', document='context', guid=guid, cmd='clone',
+ content=1 if clone == 'true' else 0)
- return jsonify(keep_impl=keep_impl)
+ return jsonify(clone=clone)
def paginate(resource, full_query, _PAGE_SIZE=6, page=1, context=None):
@@ -695,12 +628,13 @@ def del_comment(resource_guid):
@app.route('/_comments/<resource_guid>')
def comments_browser(resource_guid=None):
- g.Comments.filter(parent=resource_guid)
+ document = request.args['document']
+ g.Comments.filter(**{document: resource_guid})
result = g.Comments
if not result:
result = []
return render_template('_context-comment-list.html',
- result=result, resource_guid=resource_guid)
+ result=result, resource_guid=resource_guid, document=document)
@app.route('/article/<context_guid>')
@@ -713,7 +647,7 @@ def project_browser(context_guid=None):
template = 'context-view.html'
context = g.client.Context(context_guid,
reply=['guid', 'title', 'description', 'author',
- 'summary', 'user', 'keep', 'keep_impl', 'type'])
+ 'summary', 'favorite', 'clone', 'type'])
try:
session['last_context_title'] = context['title']
except RuntimeError:
@@ -725,16 +659,16 @@ def project_browser(context_guid=None):
inner_template=inner_template)
-@app.route('/reload/<path:href>')
-def reload(href=None):
- g.Solutions._reset()
- g.Comments._reset()
- g.Contexts._reset()
- g.Questions._reset()
- g.Ideas._reset()
- g.Resources._reset()
- g.Reviews._reset()
- return redirect(href)
+#@app.route('/reload/<path:href>')
+#def reload(href=None):
+# g.Solutions._reset()
+# g.Comments._reset()
+# g.Contexts._reset()
+# g.Questions._reset()
+# g.Ideas._reset()
+# g.Resources._reset()
+# g.Reviews._reset()
+# return redirect(href)
@app.route('/context/reviews/<resource_guid>')
@@ -743,11 +677,10 @@ def reload(href=None):
@app.route('/review/<review_guid>')
def reviews_browser(resource_guid=None, review_guid=None):
if review_guid:
- r = g.client.Feedback(guid=review_guid, reply=['context'],
- type='review')
+ r = g.client.Review(guid=review_guid, reply=['context'])
resource_guid = r['context']
return redirect('/context/reviews/' + resource_guid)
- g.Reviews.filter(context=resource_guid, type='review')
+ g.Reviews.filter(context=resource_guid)
inner_template = '_context-review-list.html'
if '_pjax' in request.args:
@@ -757,7 +690,7 @@ def reviews_browser(resource_guid=None, review_guid=None):
template = 'context-view.html'
context = g.client.Context(resource_guid,
reply=['guid', 'title', 'description', 'author',
- 'summary', 'user', 'keep', 'keep_impl', 'type'])
+ 'summary', 'favorite', 'clone', 'type'])
try:
session['last_context_title'] = context['title']
except RuntimeError:
@@ -788,7 +721,7 @@ def solution_browser(resource_guid=None):
resource = resource_cursor[offset]
else:
resource = g.client.Feedback(resource_guid,
- reply=['guid', 'title', 'content', 'author', 'user', 'context',
+ reply=['guid', 'title', 'content', 'author', 'context',
'tags', 'mtime', 'type'])
g.Solutions.filter(feedback=resource['guid'])
@@ -802,7 +735,7 @@ def solution_browser(resource_guid=None):
try:
context = g.client.Context(resource['context'],
reply=['guid', 'title', 'description', 'summary', 'author',
- 'keep', 'keep_impl', 'type'])
+ 'favorite', 'clone', 'type'])
except:
return redirect(url_for('resource_list'))
@@ -863,7 +796,7 @@ def context_resource_browser(context_guid=None, query=None):
context = resource_cursor[offset]
else:
context = g.client.Context(context_guid, reply=['guid', 'title',
- 'author', 'summary', 'description', 'keep', 'keep_impl', 'type'])
+ 'author', 'summary', 'description', 'favorite', 'clone', 'type'])
try:
session['last_context'] = context['guid']
session['last_context_title'] = context['title']
@@ -907,7 +840,7 @@ def edit_resource():
resource = g.client.Feedback(resource_guid)
resource_cursor = g.Problems
elif resource_type == 'review':
- resource = g.client.Feedback(resource_guid)
+ resource = g.client.Review(resource_guid)
resource_cursor = g.Reviews
elif resource_type == 'solution':
resource = g.client.Solution(resource_guid)
@@ -989,10 +922,10 @@ def new_solution():
@app.route('/submit_review', methods=['POST'])
def new_review():
- review = g.client.Feedback()
+ review = g.client.Review()
review['content'] = request.form['review']
review['title'] = ''
- review['type'] = 'review'
+ review['rating'] = 0
context = review['context'] = request.form['resource_guid']
if review['content']:
review.post()
@@ -1002,15 +935,15 @@ def new_review():
@app.route('/submit_comment', methods=['POST'])
def new_comment():
+ document = request.form['document']
comment = g.client.Comment()
comment['message'] = request.form['comment']
- comment['parent'] = request.form['resource_guid']
- comment['parent_resource'] = request.form['resource_type']
+ comment[document] = request.form['resource_guid']
if comment['message']:
comment.post()
g.Comments._reset()
- return redirect('_comments/%s?resource_type=%s' %
- (comment['parent'], comment['parent_resource']))
+ return redirect('_comments/%s?resource_type=%s&document=%s' %
+ (comment[document], request.form['resource_type'], document))
@app.route('/_events/comment')
diff --git a/sugar_network_webui/client.py b/sugar_network_webui/client.py
index 70b4d6f..d3b4676 100644
--- a/sugar_network_webui/client.py
+++ b/sugar_network_webui/client.py
@@ -17,9 +17,9 @@ import socket
import logging
import active_document as ad
-from active_toolkit import coroutine, sockets
-from sugar_network import local
-from sugar_network.toolkit import sugar
+from sugar_network.toolkit import sugar, router
+from sugar_network.client import ipc_port
+from sugar_network import api_url
commands_processor = None
@@ -35,14 +35,15 @@ class Client(object):
@classmethod
def call(cls, method, cmd=None, content=None,
content_type='application/json', **kwargs):
- request = ad.Request(kwargs)
+ request = router.Request(**kwargs)
request.access_level = ad.ACCESS_LOCAL
request.principal = sugar.uid()
request['method'] = method
if cmd:
request['cmd'] = cmd
request.content = content
- request.content_type = content_type
+ if method != 'GET':
+ request.content_type = content_type
return commands_processor.call(request)
@classmethod
@@ -59,20 +60,6 @@ class Client(object):
commands_processor.disconnect(callback)
@classmethod
- def subscribe(cls):
- """Start subscription session.
-
- :returns:
- `SocketFile` object connected to IPC server to read events from
-
- """
- ipc.rendezvous()
- # pylint: disable-msg=E1101
- conn = sockets.SocketFile(coroutine.socket(socket.AF_UNIX))
- conn.connect(local.ensure_path('run', 'subscribe'))
- return conn
-
- @classmethod
def mounts(cls):
return cls.call('GET', 'mounts')
@@ -111,9 +98,9 @@ class Client(object):
optional list of arguments to pass to launching implementation
"""
- # TODO Make a diference in launching from "~" and "/" mounts
- self.publish('launch', mountpoint=self._mountpoint, context=context,
- command=command, object_id=object_id, uri=uri, args=args)
+ return self.call('GET', cmd='launch', mountpoint=self._mountpoint,
+ document='context', guid=context, object_id=object_id, uri=uri,
+ args=args)
def __getattr__(self, name):
"""Class-like object to access to a resource or call a method.
@@ -140,6 +127,9 @@ class _Resource(object):
self.mountpoint = mountpoint
self.document = name
+ def url(self, guid, prop):
+ return 'http://localhost:5001/%s/%s/%s?mountpoint=%s' % (self.document, guid, prop, self.mountpoint)
+
def cursor(self, query=None, order_by=None, reply=None, page_size=18,
**filters):
"""Query resource objects.
diff --git a/sugar_network_webui/cursor.py b/sugar_network_webui/cursor.py
index db9df81..c722d28 100644
--- a/sugar_network_webui/cursor.py
+++ b/sugar_network_webui/cursor.py
@@ -17,6 +17,7 @@ import logging
import collections
from active_toolkit import coroutine, util, enforce
+from sugar_network.client import ipc_port
from objects import Object
from client import Client
@@ -88,6 +89,9 @@ class Cursor(object):
self._order_by = value
self._reset()
+ def url(self, guid, prop):
+ return 'http://localhost:5001/%s/%s/%s?mountpoint=%s' % (self.document, guid, prop, self.mountpoint)
+
def read_events(self):
if self._wait_session is None:
self._wait_session = _WaitSession()
diff --git a/sugar_network_webui/cursors.py b/sugar_network_webui/cursors.py
index 0e3c066..c05aff6 100644
--- a/sugar_network_webui/cursors.py
+++ b/sugar_network_webui/cursors.py
@@ -18,73 +18,73 @@ from client import Client
class Mount:
- def __init__(self, mountpoint, keep_impl=None):
+ def __init__(self, mountpoint, clone=None):
self.mountpoint = mountpoint
self.client = Client(mountpoint)
- if not keep_impl:
+ if not clone:
self.Contexts = self.client.Context.cursor(
type=["activity", "project"],
reply=['guid', 'type', 'title', 'author', 'summary',
- 'description', 'keep', 'keep_impl', 'mtime'],
+ 'description', 'favorite', 'clone', 'mtime'],
order_by='-mtime')
self.autocomplete_Contexts = self.client.Context.cursor(
reply=['guid', 'title'], order_by='-mtime')
self.Projects = self.client.Context.cursor(type='project',
reply=['guid', 'type', 'title', 'author', 'summary',
- 'description', 'keep', 'keep_impl', 'mtime'],
+ 'description', 'favorite', 'clone', 'mtime'],
order_by='-mtime')
self.Activities = self.client.Context.cursor(type='activity',
reply=['guid', 'type', 'title', 'author', 'summary',
- 'description', 'keep', 'keep_impl', 'mtime'],
+ 'description', 'favorite', 'clone', 'mtime'],
order_by='-mtime')
else:
self.Contexts = self.client.Context.cursor(
- keep_impl=keep_impl,
+ clone=clone,
reply=['guid', 'type', 'title', 'author', 'summary',
- 'description', 'keep', 'keep_impl', 'mtime'],
+ 'description', 'favorite', 'clone', 'mtime'],
order_by='-mtime')
self.autocomplete_Contexts = self.client.Context.cursor(
- keep_impl=keep_impl,
+ clone=clone,
reply=['guid', 'title'],
order_by='-mtime')
self.Projects = self.client.Context.cursor(type='project',
- keep_impl=keep_impl,
+ clone=clone,
reply=['guid', 'type', 'title', 'author', 'summary',
- 'description', 'keep', 'keep_impl', 'mtime'],
+ 'description', 'favorite', 'clone', 'mtime'],
order_by='-mtime')
self.Activities = self.client.Context.cursor(type='activity',
- keep_impl=keep_impl,
+ clone=clone,
reply=['guid', 'type', 'title', 'author', 'summary',
- 'description', 'keep', 'keep_impl', 'mtime'],
+ 'description', 'favorite', 'clone', 'mtime'],
order_by='-mtime')
self.Questions = self.client.Feedback.cursor(type="question",
reply=['guid', 'type', 'title', 'content', 'context', 'author',
- 'user', 'tags', 'mtime'], order_by='-mtime')
+ 'tags', 'mtime'], order_by='-mtime')
self.Problems = self.client.Feedback.cursor(type="problem",
reply=['guid', 'type', 'title', 'content', 'context', 'author',
- 'user', 'tags', 'mtime'], order_by='-mtime')
+ 'tags', 'mtime'], order_by='-mtime')
self.Ideas = self.client.Feedback.cursor(type="idea",
reply=['guid', 'type', 'title', 'content', 'context', 'author',
- 'user', 'tags', 'mtime'], order_by='-mtime')
+ 'tags', 'mtime'], order_by='-mtime')
self.Solutions = self.client.Solution.cursor(
- reply=['guid', 'content', 'feedback', 'author', 'user', 'tags',
+ reply=['guid', 'content', 'feedback', 'author', 'tags',
'mtime'], order_by='-mtime')
self.Comments = self.client.Comment.cursor(
- reply=['guid', 'message', 'tags', 'author', 'user', 'parent',
- 'parent_resource', 'mtime'])
- self.Reviews = self.client.Feedback.cursor(type="review",
- reply=['guid', 'type', 'content', 'context', 'author', 'user',
+ reply=['guid', 'message', 'tags', 'author',
+ 'mtime'])
+ self.Reviews = self.client.Review.cursor(
+ reply=['guid', 'content', 'context', 'author',
'tags', 'mtime'], order_by='-mtime')
self.Resources = self.client.Feedback.cursor(
reply=['guid', 'type', 'title', 'content', 'context', 'author',
- 'user', 'tags', 'mtime'], order_by='-mtime')
+ 'tags', 'mtime'], order_by='-mtime')
self.Artifacts = self.client.Artifact.cursor(
- reply=['guid', 'title', 'description', 'context', 'filesize',
- 'user', 'author', 'tags', 'mtime', 'traits', 'preview'],
+ reply=['guid', 'title', 'description', 'context',
+ 'author', 'tags', 'mtime'],
order_by='-mtime')
network_mount = Mount('/')
-home_mount = Mount('~', keep_impl=2)
+home_mount = Mount('~', clone=2)
diff --git a/sugar_network_webui/objects.py b/sugar_network_webui/objects.py
index c190563..4791398 100644
--- a/sugar_network_webui/objects.py
+++ b/sugar_network_webui/objects.py
@@ -17,12 +17,13 @@ import logging
from cStringIO import StringIO
from os.path import isdir, abspath
-from sugar_network.toolkit import sugar
from active_toolkit import enforce
from client import Client
+from sugar_network import sugar
_logger = logging.getLogger('sugar_network.objects')
+_uid = sugar.uid()
class Object(object):
@@ -34,7 +35,6 @@ class Object(object):
self._reply = reply or []
self._guid = guid
self._props = props or {}
- self._blobs = {}
self._dirty = set()
self.offset = offset
@@ -45,6 +45,10 @@ class Object(object):
def guid(self):
return self._guid
+ @property
+ def is_author(self):
+ return _uid in [i.get('guid') for i in self['author']]
+
def get(self, prop):
if prop == 'guid':
return self._guid
@@ -85,7 +89,6 @@ class Object(object):
document=self.document, guid=self._guid, content=props,
content_type='application/json')
else:
- props['user'] = [sugar.uid()]
self._guid = Client.call('POST', mountpoint=self.mountpoint,
document=self.document, content=props,
content_type='application/json')
@@ -93,39 +96,15 @@ class Object(object):
self._dirty.clear()
return self._guid
- def get_blob_path(self, prop):
- blob, is_path = self._get_blob(prop)
- if is_path:
- return blob['path'], blob['mime_type']
- else:
- return None, None
-
def get_blob(self, prop):
- blob, is_path = self._get_blob(prop)
- if is_path:
- path = blob['path']
- if path is None:
- return _empty_blob
- enforce(not isdir(path), 'Requested BLOB is a dictionary')
- return _Blob(path, blob['mime_type'])
- elif blob is not None:
- return _StringIO(blob.encode('utf8'))
- else:
- return _empty_blob
+ return Client.call('GET', mountpoint=self.mountpoint,
+ document=self.document, guid=self._guid, prop=prop)
- def upload_blob(self, prop, path, pass_ownership=False):
+ def upload_blob(self, prop, content, content_type):
enforce(self._guid, 'Object needs to be posted first')
- Client.call('PUT', 'upload_blob', mountpoint=self.mountpoint,
+ Client.call('PUT', mountpoint=self.mountpoint,
document=self.document, guid=self._guid, prop=prop,
- path=abspath(path), pass_ownership=pass_ownership)
-
- def _get_blob(self, prop):
- blob = self._blobs.get(prop)
- if blob is None:
- blob = Client.call('GET', 'get_blob', mountpoint=self.mountpoint,
- document=self.document, guid=self._guid, prop=prop)
- self._blobs[prop] = blob
- return blob, isinstance(blob, dict) and 'path' in blob
+ content=content, content_type=content_type)
def __getitem__(self, prop):
result = self.get(prop)
@@ -146,46 +125,3 @@ class Object(object):
def __exit__(self, exc_type, exc_value, traceback):
self.post()
-
-
-class _Blob(file):
-
- def __init__(self, path, mime_type):
- file.__init__(self, path)
- self.mime_type = mime_type
-
-
-class _EmptyBlob(object):
-
- closed = True
- mime_type = 'application/octet-stream'
-
- def read(self, size=None):
- return ''
-
- def close(self):
- pass
-
- def __enter__(self):
- return self
-
- def __exit__(self, exc_type, exc_value, traceback):
- pass
-
-
-class _StringIO(object):
-
- def __init__(self, *args, **kwargs):
- self._stream = StringIO(*args, **kwargs)
-
- def __getattr__(self, name):
- return getattr(self._stream, name)
-
- def __enter__(self):
- return self
-
- def __exit__(self, exc_type, exc_value, traceback):
- self.close()
-
-
-_empty_blob = _EmptyBlob()
diff --git a/sugar_network_webui/templates/_artifact-list.html b/sugar_network_webui/templates/_artifact-list.html
index 7e2a93d..5237f35 100644
--- a/sugar_network_webui/templates/_artifact-list.html
+++ b/sugar_network_webui/templates/_artifact-list.html
@@ -28,7 +28,7 @@
{{item['description']}}</a>
</div>
<div class="resource-meta">
- {{_('by %(author)s on %(date)s', author=item['author'][0], date=item['mtime']|timedelta)}}
+ {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}}
{%- for tag in item['tags'] %}
<span class="tag">{{tag}}</span>
{%- endfor %}
@@ -36,7 +36,7 @@
</div>
<!--
<div class="icon-column">
- %- if item['keep'] %
+ %- if item['favorite'] %
<img class="star" src="/static/icons/emblem-favorite.png"/>
%- else %
<img class="star" src="/static/icons/add-link.png"/>
diff --git a/sugar_network_webui/templates/_browser-grid.html b/sugar_network_webui/templates/_browser-grid.html
index 2d78fd2..987f156 100644
--- a/sugar_network_webui/templates/_browser-grid.html
+++ b/sugar_network_webui/templates/_browser-grid.html
@@ -33,16 +33,16 @@
<div class="context-label">
<span class="context-controls">
<img title="{{_('available offline')}}" id="moon-{{context['guid']}}"
- {% if context['keep_impl'] %}
+ {% if context['clone'] %}
style="background-color:{{fill}}; border: 1px solid {{stroke}};"
- data-keep_impl="true"
+ data-clone="true"
{% endif %}
class="moon-emblem has_tooltip" src="/static/icons/moon.png"/>
<img title="{{_('favorite')}}" id="star-{{context['guid']}}"
- {% if context['keep'] %}
+ {% if context['favorite'] %}
style="background-color:{{fill}}; border: 1px solid {{stroke}};"
- data-keep="true"
+ data-favorite="true"
{% endif %}
class="star-emblem has_tooltip" src="/static/icons/add-link-small.png"/>
</span>
diff --git a/sugar_network_webui/templates/_context-article-view.html b/sugar_network_webui/templates/_context-article-view.html
index 8afdd24..2cee695 100644
--- a/sugar_network_webui/templates/_context-article-view.html
+++ b/sugar_network_webui/templates/_context-article-view.html
@@ -21,7 +21,7 @@
<pre>{{context['description']|safe}}</pre>
</div>
<div>
- {%- if userid in context['user'] -%}
+ {%- if context.is_author -%}
<a href="{{url_for('ProjectView:edit',
context=context['guid'],
title=context['title'],
diff --git a/sugar_network_webui/templates/_context-artifact-list.html b/sugar_network_webui/templates/_context-artifact-list.html
index 9fa896a..1d42359 100644
--- a/sugar_network_webui/templates/_context-artifact-list.html
+++ b/sugar_network_webui/templates/_context-artifact-list.html
@@ -36,7 +36,7 @@
</a>
</div>
<div class="mtime">
- {{_('by %(author)s on %(date)s', author=item['author'][0], date=item['mtime']|timedelta)}}
+ {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}}
</div>
<div class="resource-meta">
{%- for tag in item['tags'] %}
diff --git a/sugar_network_webui/templates/_context-comment-list.html b/sugar_network_webui/templates/_context-comment-list.html
index 18f485d..36175ce 100644
--- a/sugar_network_webui/templates/_context-comment-list.html
+++ b/sugar_network_webui/templates/_context-comment-list.html
@@ -6,8 +6,8 @@
<img class="comment-icon" src="/static/icons/comments.png" />
<div class="comment-content">{{item['message']}}</div>
</div>
- <div class='mtime mtime-comment'>{{_('by %(author)s on %(date)s', author=item['author'][0], date=item['mtime']|timedelta)}}
- {%- if userid in item['user'] -%}
+ <div class='mtime mtime-comment'>{{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}}
+ {%- if item.is_author -%}
<span class="delete-comment-button has_tooltip" title="{{_('delete')}}" data-guid="{{item['guid']}}"><img class="action-button" src="/static/icons/edit-delete.png"></img></span>
{%- endif -%}
</div>
@@ -21,7 +21,7 @@
{%- endfor %}
</ul>
<img class="resource-throbber" id="comment_throbber_{{resource_guid}}" src="/static/images/throbber4.gif" />
- <form id="comment_form_{{resource_guid}}" class="comment-form" data-guid="{{resource_guid}}" method="POST" action="/submit_comment">
+ <form id="comment_form_{{resource_guid}}" class="comment-form" data-document="{{document}}" data-guid="{{resource_guid}}" method="POST" action="/submit_comment">
<input type="hidden" name="resource_guid" value="{{resource_guid}}" />
<input type="hidden" name="resource_type" value="solution" />
{%- if (session['connected'] or False) -%}
diff --git a/sugar_network_webui/templates/_context-resource-list.html b/sugar_network_webui/templates/_context-resource-list.html
index 1137517..08a9b1b 100644
--- a/sugar_network_webui/templates/_context-resource-list.html
+++ b/sugar_network_webui/templates/_context-resource-list.html
@@ -36,7 +36,7 @@
</a>
</div>
<div class="mtime">
- {{_('by %(author)s on %(date)s', author=item['author'][0], date=item['mtime']|timedelta)}}
+ {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}}
</div>
<div class="resource-meta">
{%- for tag in item['tags'] %}
diff --git a/sugar_network_webui/templates/_context-review-list.html b/sugar_network_webui/templates/_context-review-list.html
index a1ea8d5..2e20efe 100644
--- a/sugar_network_webui/templates/_context-review-list.html
+++ b/sugar_network_webui/templates/_context-review-list.html
@@ -31,14 +31,14 @@
{{item['content']}}
</div>
<div class='mtime'>
- {{_('by %(author)s on %(date)s', author=item['author'][0], date=item['mtime']|timedelta)}}
+ {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}}
</div>
<div class="resource-meta">
{%- for tag in item['tags'] %}
<span class="tag">{{tag}}</span>
{%- endfor %}
</div>
- {%- if userid in item['user'] -%}
+ {%- if item.is_author -%}
<span class="comments-button has_tooltip"
title="{{_('edit')}}"
onclick='edit_resource("review",
@@ -52,6 +52,7 @@
<span class="comments-button has_tooltip"
title="{{_('comment')}}"
id="comments-button-{{item['guid']}}"
+ data-document="review"
data-guid="{{item['guid']}}">
<img src="/static/icons/comments.png" />
</span>
diff --git a/sugar_network_webui/templates/_context-solution-list.html b/sugar_network_webui/templates/_context-solution-list.html
index 45214a0..4177222 100644
--- a/sugar_network_webui/templates/_context-solution-list.html
+++ b/sugar_network_webui/templates/_context-solution-list.html
@@ -11,14 +11,14 @@
<div class="resource-content">
<pre>{{resource['content']|safe}}</pre>
</div>
- <div class='mtime'>{{_('by %(author)s on %(date)s', author=resource['author'][0], date=resource['mtime']|timedelta)}}
+ <div class='mtime'>{{_('by %(author)s on %(date)s', author=resource['author'][0]['name'], date=resource['mtime']|timedelta)}}
</div>
<div class="resource-meta">
{%- for tag in resource['tags'] %}
<span class="tag">{{tag}}</span>
{%- endfor %}
</div>
- {%- if userid in resource['user'] -%}
+ {%- if resource.is_author -%}
<!--span class="edit-button"
onclick="edit_resource( {{resource_type|tojson}},
{{resource["guid"]|tojson}},
@@ -39,6 +39,7 @@
<span class="comments-button has_tooltip"
title="{{_('comment')}}"
id="comments-button-{{resource['guid']}}"
+ data-document="feedback"
data-guid="{{resource['guid']}}">
<img src="/static/icons/comments.png" />
</span>
@@ -60,14 +61,14 @@
{{item['content']|safe}}
</div>
<div class='mtime'>
- {{_('by %(author)s on %(date)s', author=item['author'][0], date=item['mtime']|timedelta)}}
+ {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}}
</div>
<div class="resource-meta">
{%- for tag in item['tags'] %}
<span class="tag">{{tag}}</span>
{%- endfor %}
</div>
- {%- if userid in item['user'] -%}
+ {%- if item.is_author -%}
<span class="comments-button has_tooltip"
title="{{_('edit')}}"
onclick="edit_resource('solution',
@@ -81,6 +82,7 @@
<span class="comments-button has_tooltip"
title="{{_('comment')}}"
id="comments-button-{{item['guid']}}"
+ data-document="solution"
data-guid="{{item['guid']}}">
<img src="/static/icons/comments.png" />
</span>
diff --git a/sugar_network_webui/templates/_resource-list.html b/sugar_network_webui/templates/_resource-list.html
index c963a6a..f9402b9 100644
--- a/sugar_network_webui/templates/_resource-list.html
+++ b/sugar_network_webui/templates/_resource-list.html
@@ -28,7 +28,7 @@
{{item['content']}}</a>
</div>
<div class="resource-meta">
- {{_('by %(author)s on %(date)s', author=item['author'][0], date=item['mtime']|timedelta)}}
+ {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}}
{%- for tag in item['tags'] %}
<span class="tag">{{tag}}</span>
{%- endfor %}
@@ -36,7 +36,7 @@
</div>
<!--
<div class="icon-column">
- %- if item['keep'] %
+ %- if item['favorite'] %
<img class="star" src="/static/icons/emblem-favorite.png"/>
%- else %
<img class="star" src="/static/icons/add-link.png"/>
diff --git a/sugar_network_webui/templates/base.html b/sugar_network_webui/templates/base.html
index 0e1256c..1ce2ef4 100644
--- a/sugar_network_webui/templates/base.html
+++ b/sugar_network_webui/templates/base.html
@@ -368,34 +368,34 @@
$('.button_selected').unbind('mouseenter mouseleave');
//
$('.star-emblem').click( function() {
- if ( $(this).data('keep') == true) {
+ if ( $(this).data('favorite') == true) {
$(this).css('background-color', '#fff');
$(this).css('border','1px solid #fff');
- $(this).data('keep', false);
+ $(this).data('favorite', false);
}
else {
$(this).css('background-color','{{fill}}');
$(this).css('border','1px solid {{stroke}}');
- $(this).data('keep', true);
+ $(this).data('favorite', true);
}
- $.get('/_stars/' + $(this).attr("id") + '?keep=' +
- $(this).data('keep'),
- function (data) {/* alert (data.keep) */} );
+ $.get('/_stars/' + $(this).attr("id") + '?favorite=' +
+ $(this).data('favorite'),
+ function (data) {/* alert (data.favorite) */} );
});
$('.moon-emblem').click( function() {
- if ( $(this).data('keep_impl') == true) {
+ if ( $(this).data('clone') == true) {
$(this).css('background-color', '#fff');
$(this).css('border','1px solid #fff');
- $(this).data('keep_impl', false);
+ $(this).data('clone', false);
}
else {
$(this).css('background-color','{{fill}}');
$(this).css('border','1px solid {{stroke}}');
- $(this).data('keep_impl', true);
+ $(this).data('clone', true);
}
- $.get('/_moon/' + $(this).attr("id") + '?keep_impl=' +
- $(this).data('keep_impl'),
- function (data) {/* alert (data.keep) */} );
+ $.get('/_moon/' + $(this).attr("id") + '?clone=' +
+ $(this).data('clone'),
+ function (data) {/* alert (data.favorite) */} );
});
};
/* For deleting elements from tag palette */
diff --git a/sugar_network_webui/templates/context-view.html b/sugar_network_webui/templates/context-view.html
index 7bda912..4d90479 100644
--- a/sugar_network_webui/templates/context-view.html
+++ b/sugar_network_webui/templates/context-view.html
@@ -52,16 +52,16 @@
<span class="context-controls">
<img id="moon-{{context['guid']}}"
title="{{_('available offline')}}"
- {% if context['keep_impl'] %}
+ {% if context['clone'] %}
style="background-color:{{fill}}; border: 1px solid {{stroke}};"
- data-keep_impl="true"
+ data-clone="true"
{% endif %}
class="moon-emblem has_tooltip" src="/static/icons/moon.png"/>
<img id="star-{{context['guid']}}"
title="{{_('favorite')}}"
- {% if context['keep'] %}
+ {% if context['favorite'] %}
style="background-color:{{fill}}; border: 1px solid {{stroke}};"
- data-keep="true"
+ data-favorite="true"
{% endif %}
class="star-emblem has_tooltip" src="/static/icons/add-link-small.png"/>
</span>
@@ -75,7 +75,7 @@
{%- for author in context['author'] -%}
<div id="sugar-man">
<img class="grid-icon-regular" src="/static/icons/sugar-xo.png" />
- {{author}}
+ {{author['name']}}
</div>
{%- endfor -%}
</div>
@@ -98,7 +98,7 @@
$('#throbber_'+guid).slideDown();
$('#comments-button-'+guid).slideUp( function () {
});
- $.get('/_comments/'+guid, { resource_type:'{{resource_type}}' }, function ( data ) {
+ $.get('/_comments/'+guid, { document: $(this).data('document'), resource_type:'{{resource_type}}' }, function ( data ) {
$('#comments-'+guid).empty().append( data );
$('#throbber_'+guid).slideUp(
function() {
@@ -129,14 +129,15 @@
function onSubmit_Comment (e) {
e.preventDefault();
var guid = $(this).data('guid');
+ var document = $(this).data('document');
$('#comment_form_'+guid).slideUp();
$('#comment_button_'+guid).slideUp();
$('#comment_throbber_'+guid).slideDown();
$.post( '/submit_comment',
- $(this).serialize(),
+ $(this).serialize() + '&document=' + $(this).data('document'),
function(response) {
$.get('/_comments/'+guid,
- { resource_type:'{{resource_type}}' }, function ( data ) {
+ { document: document, resource_type:'{{resource_type}}' }, function ( data ) {
$('#comment_throbber_'+guid).slideUp();
$('#comments-'+guid).empty().append( data );
$('#comment_form_'+guid).submit(onSubmit_Comment);