# -*- coding: utf-8 # -*- Mode: Python; py-indent-offset: 4 -*- # $Id$ # # Copyright (c) 2006, Vahur Rebas # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ Storage for packages. zip files be automatically unzipped and examined. """ __version__ = "$Revision$"[11:-2] seen = [] import Globals from Globals import Acquisition, Persistent from Acquisition import aq_base, aq_inner, aq_parent, Implicit, Explicit from AccessControl import ClassSecurityInfo from OFS.SimpleItem import SimpleItem, getSecurityManager from OFS.PropertyManager import PropertyManager from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2 from ZODB.PersistentMapping import PersistentMapping from OFS.Traversable import Traversable import re from utils import generateId, get_text, getChildNode, gen_key import logging logger = logging.getLogger('Caldoz') class commonGround: security = ClassSecurityInfo() security.declareObjectPublic() security.declareProtected('View', 'getChapters') def getChapters(self): """ get subchapters """ chaps = self.objectValues('Chapter') tmp = [] res = [] [ tmp.append([x.orderId, x]) for x in chaps ] tmp.sort() [ res.append(x[1]) for x in tmp ] return res class chapter(Persistent, BTreeFolder2, Implicit, commonGround): """ class to store 's and programmatically there is no difference between and first level chapter will represent anything else is an """ security = ClassSecurityInfo() security.declareObjectPublic() meta_type = 'Chapter' def __init__(self, title='(untitled)', orderId=0, isvisible=1): self.title = title self.orderId = orderId self.isvisible = isvisible BTreeFolder2.__init__(self, self.id) self.id = self.generateId(prefix='chapter_') self.pagename = '' self.identifier = '' self.identifierref = '' self.adlcp_scormType = '' self.parameters = '' self.xml_base = '' self.options = { 'hideLMSUI': [], 'controlMode': '' } security.declareProtected('View', 'getTitle') def getTitle(self): return self.title security.declareProtected('View', 'index_html') def index_html(self, REQUEST): """ redirect browser to right page """ #print "CALDOZ: CHAPTER: index_html", self.getRelativeURL(self), self.xml_base if self.getTargetFile(): return REQUEST.RESPONSE.redirect(self.packageUrl()+'/'+self.xml_base+self.getTargetFile()+self.parameters) else: chaps = self.getChapters() chap = chaps[0] if not chap.getTargetFile(): if chap.getChapters(): chap = chap.getChapters()[0] return REQUEST.RESPONSE.redirect(self.packageUrl()+'/'+chap.getTargetFile()) security.declareProtected('View', 'getTargetFile') def getTargetFile(self): """ returns pagename what associated with this chapter """ return self.pagename def isChapter(self): return True class packagefile(Persistent, SimpleItem, Explicit): meta_type = 'packagefile' security = ClassSecurityInfo() security.declareObjectPublic() def __init__(self, id, rawdata, filename, size): self.id = id # do some replacing here. # # step 1. modify html to use generated links/ids # step 2. create a mapping between generated links/ids and packagefile # #