# # Copyright 2001, 2002 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 import AccessControl import OFS, Globals from OFS import SimpleItem import types import time import math from TraversableWrapper import Traversable from Globals import Persistent from AccessControl import ClassSecurityInfo from Cruft import Cruft from common import translate, perm_edit, perm_view, get_roles class MapWord( OFS.SimpleItem.Item, Persistent, AccessControl.Role.RoleManager, Traversable, Cruft ): "Word in concept map" security = AccessControl.ClassSecurityInfo() security.declareObjectPublic() def __init__(self, title, description="", creator="", modifier="", backgroundcolorindex=0): "Initialize word" self.meta_type="MapWord" self.title=title self.pilt=None self.latexcode="" self.description=description self.creator=creator self.modifier=modifier self.backgroundcolorindex=backgroundcolorindex self.psize=150 self.hyperlinkurl="" self.hyperlinktitle="" self.attachmentfiledata=None self.attachmentfilename=None def makeCopy(self): "Copy of word" nw=MapWord(self.title, self.description) nw.pilt=self.pilt nw.latexcode=self.latexcode nw.backgroundcolorindex=self.backgroundcolorindex nw.hyperlinkurl=self.hyperlinkurl nw.hyperlinktitle=self.hyperlinktitle nw.attachmentfiledata=self.attachmentfiledata nw.attachmentfilename=self.attachmentfilename return nw def getPictureByteSize(self): "Picture size in bytes" if not self.pilt: return None return len(self.pilt) security.declareProtected(perm_view, 'getTitle') def getTitle(self): "Title" return self.title security.declareProtected(perm_view, 'getDescription') def getDescription(self): "Description" return self.description security.declareProtected(perm_view, 'getWordBackgroundColorIndex') def getWordBackgroundColorIndex(self): "Background color index" return self.backgroundcolorindex def hasPicture(self): "Is picture in word" if hasattr(self, 'pilt'): if self.pilt: return 1 return 0 def getPicture(self): "Gives picture if exists" if self.hasPicture(): return self.pilt return "Pole" def getPictureSize(self): "Picture displayable size" return self.psize def canEdit(self, REQUEST): "Can user edit whole wordmap" return self.aq_parent.canEdit(REQUEST) security.declareProtected(perm_view, 'getAttachmentFileData') def getAttachmentFileData(self, REQUEST): "Get binary data" REQUEST.RESPONSE.setHeader('Content-disposition', 'attachment; filename='+self.getAttachmentFileName()) REQUEST.RESPONSE.setHeader('Content-type', 'application/unknown') return self.attachmentfiledata security.declareProtected(perm_view, 'getAttachmentFileName') def getAttachmentFileName(self): "Get binary data" return self.attachmentfilename security.declareProtected(perm_view, 'getHyperlinkURL') def getHyperlinkURL(self): "getter" return self.hyperlinkurl security.declareProtected(perm_view, 'getHyperlinkTitle') def getHyperlinkTitle(self): "getter" return self.hyperlinktitle class MapEdge( OFS.SimpleItem.Item, Persistent, AccessControl.Role.RoleManager, Traversable, Cruft ): "Edge in concept map" security = AccessControl.ClassSecurityInfo() security.declareObjectPublic() security.declareProtected(perm_view, '__init__') def __init__(self, startword, endword, creator="", modifier=""): "Initialize edge" self.meta_type="MapEdge" self.startword=startword self.endword=endword self.creator=creator self.modifier=modifier self.pilt=None self.latexcode="" self.psize=150 self.types=[ "Connected", "Contains", "Uses", "Test", "Other" ] self.title=startword+"-"+endword self.startarrow=0 self.endarrow=0 self.text_in_line="" self.description="" self.type=0 self.weight=1.0 self.globalweights={} #for global map def makeCopy(self): "Copy of egde" ne=MapEdge(self.startword, self.endword) ne.types=self.types ne.title=self.title ne.startarrow=self.startarrow ne.text_in_line=self.text_in_line ne.description=self.description ne.type=self.type ne.weight=self.weight ne.pilt=self.pilt ne.latexcode=self.latexcode return ne security.declareProtected(perm_view, 'reverse') def reverse(self): "Changes edge direction" temp=self.startword self.startword=self.endword self.endword=temp security.declareProtected(perm_view, 'getTypes') def getTypes(self): "Get available connection types" return self.types security.declareProtected(perm_view, 'getType') def getType(self): "Get current connection type" return self.type security.declareProtected(perm_view, 'getStartWordTitle') def getStartWordTitle(self): "starting word title" return getattr(self.aq_parent, self.startword).title security.declareProtected(perm_view, 'getEndWordTitle') def getEndWordTitle(self): "ending word title" return getattr(self.aq_parent, self.endword).title security.declareProtected(perm_view, 'getTitle') def getTitle(self): "Title of edge" return self.getStartWordTitle()+' - '+self.getEndWordTitle() security.declareProtected(perm_view, 'getTextInLine') def getTextInLine(self): "Returns text visible in arrow line" return self.text_in_line security.declareProtected(perm_view, 'getDescription') def getDescription(self): "Returns the description of the edge" return self.description security.declareProtected(perm_view, 'getWeight') def getWeight(self): "Returns weight of the edge" return self.weight security.declareProtected(perm_view, 'getStartArrow') def getStartArrow(self): "Is start arrow for edge" return self.startarrow security.declareProtected(perm_view, 'getEndArrow') def getEndArrow(self): "Returns weight of the edge" return self.endarrow def hasPicture(self): "Is picture in word" if hasattr(self, 'pilt'): if self.pilt: return 1 return 0 def getPicture(self): "Gives picture if exists" if self.hasPicture(): return self.pilt return None def getPictureSize(self): "Picture displayable size" return self.psize class WordmapFolder( OFS.Folder.Folder, Persistent, AccessControl.Role.RoleManager, Traversable, Cruft ): "Holding set of wordmaps" security = AccessControl.ClassSecurityInfo() security.declareObjectPublic() def __init__(self): "Constructor" self.wordmapnr=0 security.declarePrivate('manage_afterAdd') def manage_afterAdd(self, item, container): "manage rights" self.manage_permission(perm_edit,('IVAAdmin','Manager','Teacher', 'Owner'),0) security.declareProtected(perm_view, 'getNewWordMapNr') def getNewWordMapNr(self): "Return growing number" self.wordmapnr+=1 return self.wordmapnr security.declareProtected(perm_edit, 'addNewWordMap') def addNewWordMap(self): "Makes new course level wordmap" nr=self.getNewWordMapNr() import WordMap m=WordMap.WordMap() m.id='map'+str(nr) self._setObject(m.id, m) return m security.declareProtected(perm_view, 'getWordMaps') def getWordMaps(self): "Wordmaps in this course" return self.objectValues('WordMap') security.declareProtected(perm_edit, 'addWordMap_handler') def addWordMap_handler(self, REQUEST): "Adds new wordmap and redirects to index page" self.addNewWordMap() REQUEST.RESPONSE.redirect(self.absolute_url()+'/wordmaps_index_html') security.declareProtected(perm_edit, 'wordmaps_index_html_handler') def wordmaps_index_html_handler(self, REQUEST, wm=None, delete=None, assessment=None, settings=None): "Main page handler" if not wm: REQUEST.RESPONSE.redirect('wordmaps_index_html?userLocation='+REQUEST.get('userLocation', '')+"&hwid="+REQUEST.get('hwid', '')) return if delete: return self.wordmaps_delete_confirm(REQUEST, wm) if assessment: REQUEST.RESPONSE.redirect(self.absolute_url()+"/"+wm+"/wordmaps_weight_page") if settings: REQUEST.RESPONSE.redirect(self.absolute_url()+"/"+wm+"/wordmaps_managing_page?userLocation="+REQUEST.get('userLocation', '')+"&hwid="+REQUEST.get('hwid', '')) security.declareProtected(perm_edit,'wordmaps_delete_confirm') def wordmaps_delete_confirm(self, REQUEST, wm=()): "Confirm deleting selected wordmaps" if not wm: REQUEST.RESPONSE.redirect('wordmaps_index_html') return return self.message_dialog2(self,REQUEST, title="Confirmation", message="Are you sure you want to delete wordmap?", option1_name="cancel", option1_value="Cancel", option2_value="Delete", option2_name="confirmation", extra_value_name=('delete', 'hwid'), extra_values = ('yes',), item_name='wm', item_value=wm, item2_name='hwid', item2_value=REQUEST.get('hwid', ''), handler="wordmaps_delete_handler" ) security.declareProtected(perm_edit,'wordmaps_delete_handler') def wordmaps_delete_handler(self, REQUEST, wm=(), cancel=None, hwid=''): "Deleting selected wordmaps" if not cancel: if type(wm) is types.StringType: wm=(wm,) for w in wm: self.wordmaps._delObject(w) if not REQUEST.get('userLocation', ''): REQUEST.RESPONSE.redirect(self.absolute_url()+'/wordmaps_index_html') else: REQUEST.RESPONSE.redirect(getattr(self.fle_root().courses, self.jooksva_kursuse_nr(REQUEST)).kodutood.absolute_url()+"/"+REQUEST.get('hwid', '')+"/manage_changeAssignment") def getWordmapTreeNode(self, map, REQUEST): "HTML for one node" #Kuluks nuputada miski PT analoog st="
  • "+map.getBreadCrumbInfo()+"" st+=" *
    " st+="" st+="
  • " if map.getChildMaps(): st+="" return st security.declareProtected(perm_view, 'getWordmapTree') def getWordmapTree(self, REQUEST): "Maps with child maps HTML" st="" return st security.declareProtected(perm_view, 'wmPuuSisu') def wmPuuSisu(self,folder,level,t,res,url, REQUEST): #puu sisu teisest tasemest alates level = level + 1 t_tmp = 1 psizes=[] for w in folder.getChildMaps(): if not w.check_permission(REQUEST, 'View'): continue path = str(t)+"-"+str(t_tmp) itf = w.wmPuuSisu(w,level,path,'',url, REQUEST) res += "" res += ""+w.getTitle()+"" for mw in w.getMapWords(): if mw.hasPicture(): if mw.getPictureByteSize() not in psizes: res+="
    "+mw.getTitle()+" " psizes.append(mw.getPictureByteSize()) res += "" res += "" res += itf+"\n" itf = "" t_tmp = t_tmp + 1 return res security.declareProtected(perm_view, 'wmTeePuu') def wmTeePuu(self, REQUEST): "puu looja" # prints a nice tree of codes with relationships import re res = "
    " level = 1 t = 1 psizes=[] # res+="" for w in self.objectValues('WordMap'): if not w.check_permission(REQUEST, 'View'): continue itf = w.wmPuuSisu(w,level,t,'',REQUEST.URL0, REQUEST) # itf = self.wmPuuSisu(self,level,t,'',REQUEST.URL0, REQUEST) res += "" res += "" res += itf t = t + 1 res += "
    " res += "
    " res += ""+name+"" for mw in w.getMapWords(): if mw.hasPicture(): if mw.getPictureByteSize() not in psizes: res+="
    "+mw.getTitle()+" " psizes.append(mw.getPictureByteSize()) res += "
    " res += "
    " return res def getChildMaps(self): "Maps in folder" return self.objectValues('WordMap') def XTMNewImportWWW(self, REQUEST, datafile, importfile=None): "New wordmap via importing" redirurl="wordmaps_index_html" if REQUEST.get('userLocation', ''): redirurl=getattr(self.fle_root().courses, self.jooksva_kursuse_nr(REQUEST)).kodutood.absolute_url()+"/"+REQUEST.get('hwid')+"/manage_changeAssignment" if not importfile: REQUEST.RESPONSE.redirect(redirurl) return if len(datafile.filename)>0: m=self.addNewWordMap() m.XTMImport(datafile.read()) REQUEST.RESPONSE.redirect(redirurl) return else: return self.message_dialog_error( self, REQUEST, title='No data', message='No XML data submitted', action=redirurl ) security.declareProtected(perm_edit, 'add_new_wordmap') def add_new_wordmap(self): "we're adding new wordmap. In class WordMap returns 0" return 1 security.declareProtected(perm_view, 'getFontNames') def getFontNames(self): "Names used in wordmap settings" return ["small", "medium", "large"] security.declareProtected(perm_view, 'getMenuTypes') def getMenuTypes(self): "Names used in wordmap settings" return ["No menu", "Simple", "Extended"] def getWordBackgroundColors(self): "Background colors used for words" return ( "#DB002B", "#3E6090", "#FFC600", "#666666", "#000000" ) security.declareProtected(perm_edit, 'wordmaps_adding_page_handler') def wordmaps_adding_page_handler(self, REQUEST): "Adding new wordmap" from input_checks import is_valid_title if not is_valid_title(REQUEST.title): return self.message_dialog( message='Invalid title', action='wordmaps_managing_page?'+REQUEST.QUERY_STRING ) m=self.addNewWordMap() m.wordmaps_management_page_handler(REQUEST, title=REQUEST.get('title', 'untitled'), description=REQUEST.get('description',''), font=REQUEST.get('font',0), colorindex=REQUEST.get('colorindex',0), wordcolortype=REQUEST.get('wordcolortype',0), menuowner=REQUEST.get('menuowner',0), maxwords=REQUEST.get('maxwords', 0), maxedgecount=REQUEST.get('maxedgecount', 0), maxedgetypes=REQUEST.get('maxedgetypes', 0), declaredwords=REQUEST.get('declaredwords', ''), declarededges=REQUEST.get('declarededges', ''), allowedsubmaps=REQUEST.get('allowedsubmaps',0), wordgraphicalpropertiesallowed=REQUEST.get('wordgraphicalpropertiesallowed', 0), equationsallowed=REQUEST.get('equationsallowed', 0), mappropertiesallowed=REQUEST.get('mappropertiesallowed', 0), visibletoothers=REQUEST.get('visibletoothers', 0), otherscanedit=REQUEST.get('otherscanedit', 0), userLocation=REQUEST.get('userLocation', 0), hwid=REQUEST.get('hwid', 0), redirect=0) if REQUEST.get('userLocation', 0)!="Management": REQUEST.RESPONSE.redirect('wordmaps_index_html') else: REQUEST.RESPONSE.redirect(getattr(self.fle_root().courses, self.jooksva_kursuse_nr(REQUEST)).kodutood.absolute_url()+"/"+REQUEST.get('hwid')+"/manage_changeAssignment") security.declareProtected(perm_view, 'hasWordmaps') def hasWordmaps(self): """ Do we have wordmaps """ return len(self.getWordMaps())>0 security.declareProtected(perm_view, 'index_html') def index_html(self, REQUEST): "index page" return self.wordmaps_index_html()