# -*- coding: utf-8 # $Id: SCORMTool.py 135 2007-04-21 17:37:53Z vahur $ # # Copyright 2006 by IVA Team and contributors # # This file is part of IVA. # # IVA 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 2 of the License, or # (at your option) any later version. # # IVA 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 IVA; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Feedmoot client for IVA""" __version__ = "$Revision: 135 $"[11:-2] import Globals from Globals import Persistent from OFS import Folder from AccessControl import ClassSecurityInfo from Products.iva.Cruft import Cruft import urllib2 class FeedmootClient(Folder.Folder, Persistent, Cruft): """ Feedmoot client for IVA """ meta_type = 'FeedmootClient' id = 'feedmoot' security = ClassSecurityInfo() security.declareObjectPublic() def getFeedmootLocation(self): """ return feedmoot service location """ return "http://birdy:8888/feedmoot/" return "http://www.htk.tlu.ee/feedmoot/" def getSpace(self, context): """ get space key """ # TODO: check for valid context here! from Products.iva.UserInfo import UserInfo from AccessControl import getSecurityManager print "context:", context, isinstance(context, UserInfo) #do not support feedmoot clients somewhere else logged_in = getSecurityManager().getUser().getUserName() if isinstance(context, UserInfo): # my feedmoot or someone else's if context.get_uname() != logged_in: return "" else: # go to your UserInfo context context = self.fle_users.get_user_info(logged_in) print "context2:", context if hasattr(context.aq_base, 'feedmoot_key'): print "key 1:", context.aq_base.feedmoot_key return context.aq_base.feedmoot_key else: import json resp = self.wrapper({'QUERY_STRING':'makeContract'}) print resp k = json.read(json.read(resp)) print k space_key = k.get('resp').get('key') context.feedmoot_key = space_key return space_key def _getFeedmootKey(self, context): """ return feedmoot key """ try: return context.aq_base.feedmoot_key except AttributeError: return "" def _delFeedmootKey(self, context): """ delete feedmoot key """ print "... deleting feedmoot key" del context.feedmoot_key def xhtml(self): """ empty """ return "Hello there!
Your feedmoot page is empty.
Click \"edit\"!" def listPages(self, context): """ list pages """ import json empty = ['Feedmoot', self.absolute_url()] init_resp = self.wrapper({'QUERY_STRING': 'initSession?token='+self._getFeedmootKey(context)}) init = json.read(init_resp) print init_resp if json.read(init_resp).get('errno') == 3: if self._getFeedmootKey(context): self._delFeedmootKey(context) return [empty] session_key = init.get('resp').get('session_key') list_resp = self.wrapper({'QUERY_STRING': 'listPages?session_key='+session_key}) pagelist_raw = json.read(list_resp) pagelist = pagelist_raw.get('resp').get('pages') print self.wrapper({'QUERY_STRING': 'closeSession?session_key='+session_key}) res = [] for x in pagelist: res.append([x.get('title'), x.get('url')]) if not res: res.append(empty) return res def getContent(self, url): """ """ print "trying to open url:"+url opener = urllib2.urlopen(url+'/xhtml') return opener.read() def wrapper(self, REQUEST): """ wrapper """ url = self.getFeedmootLocation() opener = urllib2.urlopen(url+REQUEST.get('QUERY_STRING')) return opener.read() Globals.InitializeClass(FeedmootClient)