Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2013-05-08 12:21:06 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2013-05-08 13:07:09 (GMT)
commit4c728c57c8a8c4dec95636b029646501c2fe3810 (patch)
tree683573b21671b8a682d2db1360837ebb26a1a00d
parent71aeb426148dabc39dd910cdb473f908ab4e63aa (diff)
Add information about who shared the object
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
-rw-r--r--activity.py16
-rw-r--r--utils.py18
-rw-r--r--web/index.html10
3 files changed, 40 insertions, 4 deletions
diff --git a/activity.py b/activity.py
index 69ea814..e40ead8 100644
--- a/activity.py
+++ b/activity.py
@@ -169,8 +169,13 @@ class JournalShare(activity.Activity):
logging.debug('ObjectChooser: %r',
chooser.get_selected_object())
jobject = chooser.get_selected_object()
+ # add the information about the sharer
+ jobject.metadata['shared_by'] = json.dumps(
+ utils.get_user_data())
+
if jobject and jobject.file_path:
if self._master:
+ datastore.write(jobject)
self._jm.append_to_shared_items(jobject.object_id)
else:
tmp_path = os.path.join(self._activity_root,
@@ -454,6 +459,8 @@ class JournalManager(GObject.GObject):
title = ''
desc = ''
comment = []
+ shared_by = {}
+ downloaded_by = []
object_id = dsobj.object_id
if hasattr(dsobj, 'metadata'):
if 'title' in dsobj.metadata:
@@ -465,12 +472,19 @@ class JournalManager(GObject.GObject):
comment = json.loads(dsobj.metadata['comments'])
except:
comment = []
+ if 'shared_by' in dsobj.metadata:
+ shared_by = json.loads(dsobj.metadata['shared_by'])
+ if 'downloaded_by' in dsobj.metadata:
+ downloaded_by = json.loads(
+ dsobj.metadata['downloaded_by'])
else:
logging.debug('dsobj has no metadata')
utils.package_ds_object(dsobj, self._instance_path)
results.append({'title': str(title), 'desc': str(desc),
- 'comment': comment, 'id': str(object_id)})
+ 'comment': comment, 'id': str(object_id),
+ 'shared_by': shared_by,
+ 'downloaded-by': downloaded_by})
logging.error(results)
return json.dumps(results)
diff --git a/utils.py b/utils.py
index 65fa98f..637d411 100644
--- a/utils.py
+++ b/utils.py
@@ -26,6 +26,8 @@ import logging
import websocket
import tempfile
+from sugar3 import profile
+
CHUNK_SIZE = 2048
@@ -76,6 +78,21 @@ class Uploader(GObject.GObject):
GObject.idle_add(self.emit, 'uploaded')
+def get_user_data():
+ """
+ Create this structure:
+ {"from": "Walter Bender", "icon": ["#FFC169", "#FF2B34"]}
+ used to identify the owner of a shared object
+ is compatible with how the comments are saved in
+ http://wiki.sugarlabs.org/go/Features/Comment_box_in_journal_detail_view
+ """
+ xo_color = profile.get_color()
+ data = {}
+ data['from'] = profile.get_nick_name()
+ data['icon'] = [xo_color.get_stroke_color(), xo_color.get_fill_color()]
+ return data
+
+
def package_ds_object(dsobj, destination_path):
"""
Creates a zipped file with the file associated to a journal object,
@@ -110,6 +127,7 @@ def package_ds_object(dsobj, destination_path):
for key in dsobj.metadata.keys():
if key not in ('object_id', 'preview', 'progress'):
metadata[key] = dsobj.metadata[key]
+
metadata_file.write(json.dumps(metadata))
metadata_file.close()
diff --git a/web/index.html b/web/index.html
index a2f133c..66f58cf 100644
--- a/web/index.html
+++ b/web/index.html
@@ -8,12 +8,14 @@
local = (window.location.hostname == '0.0.0.0');
- function add_tr(id, title, desc) {
+ function add_tr(id, title, desc, shared_by) {
$('#journaltable').append("<tr id=" + id + ">" +
"<td><img src='/datastore/preview_id_" + id + "?v=x'></td>"+
"<td class='desc_td'>"+
"<table class='desc_table'>"+
"<tr><td class='title'>" + title + "</td></tr>"+
+ (shared_by.from != '' ? "<tr><td>Shared by " + shared_by.from +
+ "</td></tr>" : "") +
"<tr><td>" + desc + "</td></tr>"+
(!local ? "<tr><td>"+
"<a class='download_link' href='/datastore/id_" + id +".journal'>"+
@@ -34,7 +36,8 @@
$.getJSON("/datastore/selected.json", function(selected) {
for (var i = 0; i < selected.length; i++) {
id = selected[i].id;
- add_tr(id, selected[i].title, selected[i].desc);
+ add_tr(id, selected[i].title, selected[i].desc,
+ selected[i].shared_by);
}
if (selected.length == 0) {
@@ -59,7 +62,8 @@
for (var i = 0; i < new_list.length; i++) {
id = new_list[i].id;
if ($('#' + id).length == 0) {
- add_tr(id, new_list[i].title, new_list[i].desc);
+ add_tr(id, new_list[i].title, new_list[i].desc,
+ new_list[i].shared_by);
}
}
};