Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/model.py
diff options
context:
space:
mode:
authorSimon Schampijer <simon@schampijer.de>2007-09-01 14:52:05 (GMT)
committer Simon Schampijer <simon@schampijer.de>2007-09-01 14:52:05 (GMT)
commit08e96f508c5d099059bb098433c30b504ac96b83 (patch)
treef637ff479cb64ba1299069a7ae695e78bfb521ca /model.py
parent15758583c51de734d49f2af241ca87e53ca7e2e6 (diff)
Finalized the work to move to json
We now use json for storing the history and the shared link information to the journal.
Diffstat (limited to 'model.py')
-rw-r--r--model.py30
1 files changed, 14 insertions, 16 deletions
diff --git a/model.py b/model.py
index 4fdb708..1ee85f8 100644
--- a/model.py
+++ b/model.py
@@ -17,16 +17,14 @@
#
import os
-import logging
import json
import sha
import gobject
-
-_logger = logging.getLogger('model')
+import base64
class Model(gobject.GObject):
- ''' The model of the activity which uses json to serialize its data
- to a file and deserelize from it.
+ ''' The model of web-activity which uses json to serialize its data
+ to a file and deserealize from it.
'''
__gsignals__ = {
'add_link': (gobject.SIGNAL_RUN_FIRST,
@@ -35,31 +33,31 @@ class Model(gobject.GObject):
def __init__(self):
gobject.GObject.__init__(self)
-
self.data = {}
- self._links = []
- self.data['shared_links'] = self._links
+ self.data['shared_links'] = []
def add_link(self, url, title, thumb, owner, color):
- self.links.append( {'hash':sha.new(url).hexdigest(), 'url':url, 'title':title, 'thumb':thumb,
- 'owner':owner, 'color':color, 'deleted':0} )
- self.emit('add_link', len(self.links)-1)
+ self.data['shared_links'].append( {'hash':sha.new(str(url)).hexdigest(),
+ 'url':str(url), 'title':str(title),
+ 'thumb':base64.b64encode(thumb),
+ 'owner':str(owner),
+ 'color':str(color), 'deleted':0} )
+ self.emit('add_link', len(self.data['shared_links'])-1)
def mark_link_deleted(self, index):
- self._links[index]['deleted'] = 1
- self._links[index]['thumb'] = ''
+ self.data['shared_links'][index]['deleted'] = 1
+ self.data['shared_links'][index]['thumb'] = ''
def serialize(self):
- self.get_session()
+ print self.data
return json.write(self.data)
def deserialize(self, data):
self.data = json.read(data)
- self.links = self.data
def get_links_ids(self):
ids = []
- for link in self._links:
+ for link in self.data['shared_links']:
ids.append(link['hash'])
ids.append('')
return ids