# -*- coding: utf-8 # $Id$ # import zipfile import xml.dom.minidom import xml.sax from xml.dom.minidom import Document import string from xml.sax import saxutils from xml.dom.ext.reader import Sax2 from ImportExport import Counter, DataTable, Exporter, Dump from common import FakeRequest, FakeUpload, to_utf8, to_unicode, get_text, get_attr from xml.dom import implementation from xml.dom import EMPTY_NAMESPACE, XML_NAMESPACE from xml.dom.ext import PrettyPrint #from Products.ZWiki.ZWikiPage import ZWikiPage from types import UnicodeType from input_checks import strip_non_xml from StringIO import StringIO import OFS.Image import types, time import re, time __version__ = "$Revision$"[11:-2] class User_export: def __init__(self): self.binarydata = DataTable() self.sisegrupid = [] doctype = implementation.createDocumentType("enterprise", "http://www.htk.tlu.ee/%7Evahur/ims_epv1p1.dtd", "http://www.htk.tlu.ee/%7Evahur/ims_epv1p1.dtd") self.user = implementation.createDocument(EMPTY_NAMESPACE, "enterprise", doctype) self.userelem = self.user.documentElement prop = self.user.createElement('properties') self.userelem.appendChild(prop) source = self.user.createElement('datasource') source_data = self.user.createTextNode('IVA') source.appendChild(source_data) prop.appendChild(source) datetime = self.user.createElement('datetime') datetime_data = self.user.createTextNode('kuupaev') datetime.appendChild(datetime_data) prop.appendChild(datetime) def kirjutaKasutaja(self,kasutaja,kursus=''): person = self.user.createElement('person') self.userelem.appendChild(person) sourcedid = self.user.createElement('sourcedid') person.appendChild(sourcedid) source = self.user.createElement('source') source_data = self.user.createTextNode('IVA') source.appendChild(source_data) sourcedid.appendChild(source) id = self.user.createElement('id') id_data = self.user.createTextNode(kasutaja.get_uname()) id.appendChild(id_data) sourcedid.appendChild(id) userid = self.user.createElement('userid') try: userid.setAttribute('password',kasutaja.getPassword()) except: userid.setAttribute('password','nipitiri') userid_name = self.user.createTextNode(kasutaja.get_uname()) userid.appendChild(userid_name) person.appendChild(userid) name = self.user.createElement('name') person.appendChild(name) fn = self.user.createElement('fn') fn_data = self.user.createTextNode(kasutaja.get_first_name()+' '+kasutaja.get_last_name()) fn.appendChild(fn_data) name.appendChild(fn) n = self.user.createElement('n') name.appendChild(n) family = self.user.createElement('family') family_data = self.user.createTextNode(kasutaja.get_last_name()) family.appendChild(family_data) n.appendChild(family) given = self.user.createElement('given') given_data = self.user.createTextNode(kasutaja.get_first_name()) given.appendChild(given_data) n.appendChild(given) partname = self.user.createElement('partname') partname.setAttribute('partnametype','First') partname.setAttribute('lang',kasutaja.get_language()) partname_data = self.user.createTextNode(kasutaja.get_first_name()) partname.appendChild(partname_data) n.appendChild(partname) demogr = self.user.createElement('demographics') email = self.user.createElement('email') email_data = self.user.createTextNode(kasutaja.get_email()) email.appendChild(email_data) person.appendChild(email) url = self.user.createElement('url') url_data = self.user.createTextNode(kasutaja.get_homepage()) url.appendChild(url_data) person.appendChild(url) tel_t = self.user.createElement('tel') tel_t.setAttribute('teltype','Voice') tel_t_data = self.user.createTextNode(kasutaja.get_phone()) tel_t.appendChild(tel_t_data) person.appendChild(tel_t) tel_gsm = self.user.createElement('tel') tel_gsm.setAttribute('teltype','Mobile') tel_gsm_data = self.user.createTextNode(kasutaja.get_gsm()) tel_gsm.appendChild(tel_gsm_data) person.appendChild(tel_gsm) adr = self.user.createElement('adr') person.appendChild(adr) extadd = self.user.createElement('extadd') extadd_data = self.user.createTextNode(kasutaja.get_address2()) extadd.appendChild(extadd_data) adr.appendChild(extadd) street = self.user.createElement('street') street_data = self.user.createTextNode(kasutaja.get_address1()) street.appendChild(street_data) adr.appendChild(street) locality = self.user.createElement('locality') locality_data = self.user.createTextNode(kasutaja.get_city()) locality.appendChild(locality_data) adr.appendChild(locality) country = self.user.createElement('country') country_data = self.user.createTextNode(kasutaja.get_country()) country.appendChild(country_data) adr.appendChild(country) try: if kasutaja.has_photo(): photo = self.user.createElement('photo') real_photo = kasutaja.get_photo_obj() #XXX: image type #photo.setAttribute('imgtype',kasutaja.get_photo_type()) photo.setAttribute('imgtype', real_photo.getContentType()) extref = self.user.createElement('extref') #XXX: data - needs testing! photo_name = self.binarydata.storeData(real_photo.data,'user') extref_data = self.user.createTextNode(photo_name) extref.appendChild(extref_data) photo.appendChild(extref) person.appendChild(photo) except: pass systemrole = self.user.createElement('systemrole') kas_admin = kasutaja.getRoles() if 'Manager' in kas_admin: systemrole.setAttribute('systemroletype','SysAdmin') else: systemrole.setAttribute('systemroletype','User') person.appendChild(systemrole) try: instrole = self.user.createElement('institutionrole') instrole.setAttribute('primaryrole','No') instrole.setAttribute('institutionroletype','Learner') for abc in kursus.get_local_roles(): if abc[0]==kasutaja.get_uname() and 'Teacher' in abc[1]: instrole.setAttribute('institutionroletype','Instructor') person.appendChild(instrole) except: pass extension = self.user.createElement('extension') person.appendChild(extension) org = self.user.createElement('org') extension.appendChild(org) orgname = self.user.createElement('orgname') orgname_data = self.user.createTextNode(kasutaja.get_organization()) orgname.appendChild(orgname_data) org.appendChild(orgname) comment = self.user.createElement('comments') comment_data = self.user.createTextNode(kasutaja.get_background()) comment.appendChild(comment_data) extension.appendChild(comment) desc = self.user.createElement('description') extension.appendChild(desc) short = self.user.createElement('short') short_data = self.user.createTextNode(kasutaja.get_personal_interests()) short.appendChild(short_data) desc.appendChild(short) long = self.user.createElement('long') long_data = self.user.createTextNode(kasutaja.get_professional_interests()) long.appendChild(long_data) desc.appendChild(long) label = self.user.createElement('label') label_data = self.user.createTextNode(kasutaja.get_quote()) label.appendChild(label_data) extension.appendChild(label) return "valmis" def pakiFaili(self,kursusega,failinimi="userexport.zip"): "Pakitakse kasutajad faili" if kursusega=="/": kursusega = '' if zipfile.is_zipfile(failinimi): zip = zipfile.ZipFile(failinimi,"a",zipfile.ZIP_DEFLATED) else: zip = zipfile.ZipFile(failinimi,"w",zipfile.ZIP_DEFLATED) dump = Dump() PrettyPrint(self.user,stream=dump) zip.writestr(zipfile.ZipInfo(kursusega+"users.xml"),dump.getdata()) for name in self.binarydata.names: zip.writestr( zipfile.ZipInfo(kursusega+name), str(self.binarydata.getData(name))) zip.close() def kirjutaKursusGrupina(self,kursus): # Kirjutab grupi mis omab kursuse funktsiooni. Kõik kes selles grupis on # student või teacher krupp = self.user.createElement('group') krupp_s = self.user.createElement('sourcedid') krupp_source = self.user.createElement('source') krupp_source_data = self.user.createTextNode('IVA') krupp_source.appendChild(krupp_source_data) krupp_s.appendChild(krupp_source) krupp_id = self.user.createElement('id') krupp_id_data = self.user.createTextNode(kursus.get_name()) krupp_id.appendChild(krupp_id_data) krupp_s.appendChild(krupp_id) krupp.appendChild(krupp_s) krupp_type = self.user.createElement('grouptype') type_value = self.user.createElement('typevalue') type_value.setAttribute('level','1') krupp_type.appendChild(type_value) krupp.appendChild(krupp_type) description = self.user.createElement('description') desc_short = self.user.createElement('short') desc_short_data = self.user.createTextNode(kursus.getQuote()) desc_short.appendChild(desc_short_data) description.appendChild(desc_short) desc_long = self.user.createElement('long') desc_long_data = self.user.createTextNode(kursus.get_methods()) desc_long.appendChild(desc_long_data) description.appendChild(desc_long) desc_full = self.user.createElement('full') desc_full_data = self.user.createTextNode(kursus.get_description()) desc_full.appendChild(desc_long_data) description.appendChild(desc_full) krupp.appendChild(description) org = self.user.createElement('org') orgname = self.user.createElement('orgname') orgname_data = self.user.createTextNode(kursus.get_name()) orgname.appendChild(orgname_data) org.appendChild(orgname) orgunit = self.user.createElement('orgunit') orgunit_data = self.user.createTextNode(kursus.get_organisation()) orgunit.appendChild(orgunit_data) org.appendChild(orgunit) krupp.appendChild(org) enrollcontrol = self.user.createElement('enrollcontrol') enroll_accept = self.user.createElement('enrollaccept') enroll_allowed = self.user.createElement('enrollallowed') try: if str(kursus.getStatus()) == str('0') or int(kursus.getStatus())>1: enroll_accept_data = self.user.createTextNode('0') else: enroll_accept_data = self.user.createTextNode('1') except: enroll_accept_data = self.user.createTextNode('0') enroll_allowed_data = self.user.createTextNode('1') enroll_accept.appendChild(enroll_accept_data) enroll_allowed.appendChild(enroll_allowed_data) enrollcontrol.appendChild(enroll_accept) enrollcontrol.appendChild(enroll_allowed) krupp.appendChild(enrollcontrol) self.userelem.appendChild(krupp) def kirjutaSisegrupid(self,kursus,sisegrupp): krupp = self.user.createElement('group') sourcedid = self.user.createElement('sourcedid') source = self.user.createElement('source') source_data = self.user.createTextNode('IVA') source.appendChild(source_data) sourcedid.appendChild(source) id = self.user.createElement('id') # id_data = self.user.createTextNode(str(kursus.get_id())+":"+str(sisegrupp.id)) id_data = self.user.createTextNode(str(sisegrupp.id)) id.appendChild(id_data) sourcedid.appendChild(id) krupp.appendChild(sourcedid) description = self.user.createElement('description') short = self.user.createElement('short') short_data = self.user.createTextNode(sisegrupp.title) short.appendChild(short_data) description.appendChild(short) krupp.appendChild(description) #relationship relationship = self.user.createElement('relationship') relationship.setAttribute('relation','2') sourcedid = self.user.createElement('sourcedid') source = self.user.createElement('source') source_data = self.user.createTextNode('IVA') source.appendChild(source_data) sourcedid.appendChild(source) id = self.user.createElement('id') id_data = self.user.createTextNode(kursus.get_name()) id.appendChild(id_data) sourcedid.appendChild(id) relationship.appendChild(sourcedid) label = self.user.createElement('label') label_data = self.user.createTextNode('Course sub-group') label.appendChild(label_data) relationship.appendChild(label) krupp.appendChild(relationship) self.userelem.appendChild(krupp) return def kirjutaMembership(self,kogum,tyyp='kursus', users=''): # write tag if tyyp == 'kursus': sortsu_id = kogum.get_name() kasutajad = kogum.get_all_users() comment_data = self.user.createTextNode('KURSUS') else: sortsu_id = kogum.id #kasutajad = kogum.kasutajad_sisegrupis(sortsu_id,objektina=1) kasutajad = kogum.subgroup_members(as_object=True) comment_data = self.user.createTextNode('SISEGRUPP') if users: kasutajad = users membership = self.user.createElement('membership') comment = self.user.createElement('comments') comment.appendChild(comment_data) membership.appendChild(comment) sourcedid = self.user.createElement('sourcedid') source = self.user.createElement('source') source_data = self.user.createTextNode('IVA') source.appendChild(source_data) sourcedid.appendChild(source) id = self.user.createElement('id') id_data = self.user.createTextNode(str(sortsu_id)) id.appendChild(id_data) sourcedid.appendChild(id) membership.appendChild(sourcedid) for juuser in kasutajad: member = self.user.createElement('member') sourcedid = self.user.createElement('sourcedid') source = self.user.createElement('source') source_data = self.user.createTextNode('IVA') source.appendChild(source_data) sourcedid.appendChild(source) id = self.user.createElement('id') id_data = self.user.createTextNode(juuser.get_uname()) id.appendChild(id_data) sourcedid.appendChild(id) member.appendChild(sourcedid) idtype = self.user.createElement('idtype') idtype_data = self.user.createTextNode('1') idtype.appendChild(idtype_data) member.appendChild(idtype) role = self.user.createElement('role') role.setAttribute('roletype','Learner') for abc in kogum.get_local_roles(): if abc[0]==juuser.get_uname() and 'Teacher' in abc[1]: role.setAttribute('roletype','Instructor') status = self.user.createElement('status') status_data = self.user.createTextNode('1') status.appendChild(status_data) role.appendChild(status) if tyyp == 'kursus': self.kirjutaHinded(role,kogum,juuser) member.appendChild(role) membership.appendChild(member) # self.userelem.appendChild(membership) self.sisegrupid.append(membership) return def kirjutaHinded(self,base_elem,kogum,kasutaja): # kirjutab kasutaja hinded #XXX: teacher comment, total points comment, total grade & comment, are not exported! uname = kasutaja.get_uname() for abc in kogum.kodutood.listAssignments(): punktid = -1 komm = "" punktid = abc.getGrades(uname, 'points') komm = abc.getGrades(uname, 'comment') abc.getGrades(uname, 'teacherComment') # if abc.tyyp == 0: # if hasattr(kc, 'testivastused'): # try: # vk = getattr(kc.testivastused, abc.testiID) # komm = vk.objectValues()[0].annaKoguKommentaar() # except: # pass self.kirjutaInter(base_elem, abc, punktid, komm) koondHinne = kogum.kodutood.getOverallDetails(uname, 'TotPoints') koondKomm = kogum.kodutood.getOverallDetails(uname, 'overallComment') self.kirjutaInter(base_elem, 'abc', koondHinne, koondKomm,'finalresult') return def kirjutaInter(self,base_elem, too, punktid, komm, mida='interimresult'): if punktid == -1: punktid = 0 interim = self.user.createElement(mida) if mida == 'interimresult': interim.setAttribute('resulttype',too.id) mode = self.user.createElement('mode') if mida == 'interimresult': mode_data = self.user.createTextNode('Letter Grade') else: mode_data = self.user.createTextNode('protsent') mode.appendChild(mode_data) interim.appendChild(mode) values = self.user.createElement('values') values.setAttribute('valuetype','1') val_min = self.user.createElement('min') val_min_data = self.user.createTextNode('0') val_min.appendChild(val_min_data) values.appendChild(val_min) val_max = self.user.createElement('max') try: pp = str(too.getPoints()) except: pp = '9999' val_max_data = self.user.createTextNode(pp) val_max.appendChild(val_max_data) values.appendChild(val_max) interim.appendChild(values) result = self.user.createElement('result') result_data = self.user.createTextNode(str(punktid)) result.appendChild(result_data) interim.appendChild(result) comments = self.user.createElement('comments') comments_data = self.user.createTextNode(str(komm)) comments.appendChild(comments_data) interim.appendChild(comments) base_elem.appendChild(interim) return def lisaMembership(self): for abc in self.sisegrupid: self.userelem.appendChild(abc) return class kirjutaYldM: def __init__(self, userArchive=0): self.mainmani = Document() self.root_element = self.mainmani.createElement("manifest") self.root_element.setAttribute('identifier','IVA') self.root_element.setAttribute('version','1') self.root_element.setAttribute('xmlns','http://www.imsproject.org/xsd/ims_cp_rootv1p1') self.root_element.setAttribute('xmlns:imsmd','http://www.imsproject.org/xsd/ims_md_rootv1p1.xsd') self.root_element.setAttribute('xmlns:xsi','http://www.w3.org/2000/10/XMLSchema-instance') self.root_element.setAttribute('xsi:schemaLocation','http://www.imsproject.org/xsd/ims_cp_rootv1p1 http://www.imsproject.org/xsd/ims_cp_rootv1p1.xsd http://www.imsproject.org/xsd/ims_md_rootv1p1 http://www.imsproject.org/xsd/ims_md_rootv1p1.xsd') self.mainmani.appendChild(self.root_element) md=self.mainmani.createElement("metadata") self.root_element.appendChild(md) if userArchive: userArchive = self.mainmani.createElement("userArchive") userArchive.setAttribute('archive', '1') userArchive.appendChild(self.mainmani.createTextNode('1')) md.appendChild(userArchive) mds=self.mainmani.createElement('schema') md.appendChild(mds) text = self.mainmani.createTextNode('IMS Content') mds.appendChild(text) mdv=self.mainmani.createElement('schemaversion') md.appendChild(mdv) mdv.appendChild(self.mainmani.createTextNode('1.1')) rek = self.mainmani.createElement('imsmd:record') md.appendChild(rek) gen = self.mainmani.createElement('imsmd:general') rek.appendChild(gen) tit = self.mainmani.createElement('imsmd:title') gen.appendChild(tit) lang = self.mainmani.createElement('imsmd:langstring') lang.setAttribute('xml:lang','en-US') lang.appendChild(self.mainmani.createTextNode('Data exported from IVA. See http://www.htk.tlu.ee/iva')) tit.appendChild(lang) self.organizations = self.mainmani.createElement("organizations") self.root_element.appendChild(self.organizations) self.organization = self.mainmani.createElement("organization") self.organization.setAttribute('identifier','courses') self.organizations.appendChild(self.organization) self.ress = self.mainmani.createElement("resources") self.root_element.appendChild(self.ress) def kirjutaYldmanifest(self, kursusenr=0, kirjeldus='kirjeldus',tyyp='imscp_xmlv1p1p3',base='course/',href='imsmanifest.xml', uniq_id=''): m = self.mainmani.createElement("item") m.setAttribute('identifier','item_'+str(kursusenr)) m.setAttribute('identifierref','resource_'+str(kursusenr)) # m.setAttribute('identifier','course'+str(kursusenr)) self.organization.appendChild(m) title = self.mainmani.createElement("title") title.appendChild(self.mainmani.createTextNode(kirjeldus)) m.appendChild(title) item = self.mainmani.createElement("resource") item.setAttribute('identifier','resource_'+str(kursusenr)) item.setAttribute('type',tyyp) if base != "": item.setAttribute('xml:base',base) item.setAttribute('href',href) item_title = self.mainmani.createElement('file') item_title.setAttribute('href',href) item.appendChild(item_title) if uniq_id: item.setAttribute('uniq_id', uniq_id) self.ress.appendChild(item) return m def lisaFaili(self, failinimi="ivaarhiiv.zip"): "Lisatakse yldmanifest zip'i" if zipfile.is_zipfile(failinimi): zip = zipfile.ZipFile(failinimi,"a",zipfile.ZIP_DEFLATED) else: zip = zipfile.ZipFile(failinimi,"w",zipfile.ZIP_DEFLATED) dump = Dump() self.mainmani.writexml(dump) zip.writestr(zipfile.ZipInfo("imsmanifest.xml"),dump.getdata()) zip.close() class Kirjutus: import string def __init__(self, ivajuur, kursusenr): """ Uue eksportkirjutaja loomine. Parameetrina eksporditava iva juurobjekt """ self.generateID() # just in case self.iva = ivajuur if kursusenr != None and kursusenr != 0: self.kursus = getattr(ivajuur.courses, str(kursusenr)) self.kursusenr = kursusenr else: self.kursusenr = 0 self.kursus = None return def looKursuseFail(self,metadata=1): # kursuse faili loomine # must be called before other functions self.binarydata = DataTable() self.idmap = {} self.dom=Document() self.loendur=Counter() # valmistame ette dokumendi self.root=self.dom.createElement("manifest") self.dom.appendChild(self.root) self.root.setAttribute('identifier','IVA') self.root.setAttribute('version','1') self.root.setAttribute('xmlns','http://www.imsproject.org/xsd/ims_cp_rootv1p1') self.root.setAttribute('xmlns:imsmd','http://www.imsproject.org/xsd/ims_md_rootv1p1.xsd') self.root.setAttribute('xmlns:xsi','http://www.w3.org/2000/10/XMLSchema-instance') self.root.setAttribute('xmlns:ivamd','http://www.htk.tlu.ee/%7Evahur/ivaplus.xsd') self.root.setAttribute('xsi:schemaLocation','http://www.imsproject.org/xsd/ims_cp_rootv1p1 http://www.imsproject.org/xsd/ims_cp_rootv1p1.xsd http://www.imsproject.org/xsd/ims_md_rootv1p1 http://www.imsproject.org/xsd/ims_md_rootv1p1.xsd http://www.htk.tlu.ee/%7Evahur/ivaplus http://www.htk.tlu.ee/%7Evahur/ivaplus.xsd') if metadata: metadata = self.dom.createElement("metadata") schema = self.dom.createElement("schema") schema_data = self.dom.createTextNode("IMS Content") schema.appendChild(schema_data) schema_ver = self.dom.createElement("schemaversion") schema_ver_data = self.dom.createTextNode("1.1") schema_ver.appendChild(schema_ver_data) metadata.appendChild(schema) metadata.appendChild(schema_ver) md_methods = self.dom.createElement('ivamd:methods') md_methods_data = self.dom.createTextNode(self.kursus.get_methods()) md_methods.appendChild(md_methods_data) metadata.appendChild(md_methods) md_organisation = self.dom.createElement('ivamd:organisation') md_organisation_data = self.dom.createTextNode(self.kursus.get_organisation()) md_organisation.appendChild(md_organisation_data) metadata.appendChild(md_organisation) md_quote = self.dom.createElement('ivamd:quote') md_quote_data = self.dom.createTextNode(self.kursus.getQuote()) md_quote.appendChild(md_quote_data) metadata.appendChild(md_quote) #XXX this needs to be corrected. get if self.kursus.hasLogo(): md_picture = self.dom.createElement('ivamd:picture') name = self.binarydata.storeData(self.kursus.getLogoTag().data) md_picture.setAttribute('href',name) metadata.appendChild(md_picture) md_status = self.dom.createElement('ivamd:status') try: md_status_data = self.dom.createTextNode(str(self.kursus.staatus)) except: md_status_data = self.dom.createTextNode(str(0)) md_status.appendChild(md_status_data) metadata.appendChild(md_status) record = self.dom.createElement('imsmd:record') general = self.dom.createElement('imsmd:general') record.appendChild(general) title = self.dom.createElement('imsmd:title') general.appendChild(title) lang = self.dom.createElement('imsmd:langstring') lang.setAttribute('xml:lang','en-US') lang_data = self.dom.createTextNode(self.kursus.get_name()) lang.appendChild(lang_data) title.appendChild(lang) descr = self.dom.createElement('imsmd:description') descrlang = self.dom.createElement('imsmd:langstring') descrlang.setAttribute('xml:lang','en-US') descrlang_data = self.dom.createTextNode(self.kursus.get_description()) descrlang.appendChild(descrlang_data) descr.appendChild(descrlang) general.appendChild(descr) metadata.appendChild(record) org = self.dom.createElement('organization_sec') org_data = self.dom.createTextNode(str(self.kursus.getCourseCategory())) org.appendChild(org_data) metadata.appendChild(org) score = self.dom.createElement('score') score_data = self.dom.createTextNode(self.kursus.get_credits()) score.appendChild(score_data) metadata.appendChild(score) code = self.dom.createElement('code') code_data = self.dom.createTextNode(self.kursus.get_courseID()) code.appendChild(code_data) metadata.appendChild(code) start = self.dom.createElement('start_time') start_data = self.dom.createTextNode(str(self.kursus.get_start_date())) start.appendChild(start_data) metadata.appendChild(start) end = self.dom.createElement('end_time') end_data = self.dom.createTextNode(str(self.kursus.get_end_date())) end.appendChild(end_data) metadata.appendChild(end) uniq_id = self.dom.createElement('uniqID') uniq_id_data = self.dom.createTextNode(str(self.kursus.getUniqId())) uniq_id.appendChild(uniq_id_data) metadata.appendChild(uniq_id) self.root.appendChild(metadata) self.organizations = self.dom.createElement('organizations') self.organization = self.dom.createElement('organization') self.organization.setAttribute('identifier','IVA_CONTENT'+str(self.idnumber)) self.organizations.appendChild(self.organization) self.resources = self.dom.createElement('resources') self.root.appendChild(self.organizations) self.root.appendChild(self.resources) def generateID(self): # generates idnumber. used as identifer and identifierref # used as 'ITEM'+str(self.idnumber) and 'TARGET'+str(self.idnumber) import random self.idnumber = str(random.randint(1,9999))+"_"+str(random.randint(1,9999)) return self.idnumber def lisaMetadata(self,vanem,objekt,technical='',annotations=''): metadata = self.dom.createElement('metadata') try: metadata.setAttribute('creationtime',str(objekt.get_timestamp())) except AttributeError: pass if technical: technical = self.dom.createElement('imsmd:technical') format = self.dom.createElement('imsmd:format') try: format_data = self.dom.createTextNode(str(objekt.content_type)) except: format_data = self.dom.createTextNode('text/plain') format.appendChild(format_data) technical.appendChild(format) perm = self.dom.createElement('permission') technical.appendChild(perm) status = self.dom.createElement('status') status.appendChild(self.dom.createTextNode(str(objekt.getObjPermission()))) perm.appendChild(status) order = self.dom.createElement('position') order.appendChild(self.dom.createTextNode(str(objekt.weight))) perm.appendChild(order) docStatus = self.dom.createElement('docstatus') docStatus.appendChild(self.dom.createTextNode(str(objekt.getDocStatus()))) perm.appendChild(docStatus) #userRating!? uca = self.dom.createElement('commentable') uca.setAttribute('view',str(objekt.isCommentsVisible())) uca.appendChild(self.dom.createTextNode(str(objekt.isCommentable()))) perm.appendChild(uca) ura = self.dom.createElement('rateable') ura.setAttribute('view',str(objekt.isRatingVisible())) ura.appendChild(self.dom.createTextNode(str(objekt.isRateable()))) perm.appendChild(ura) time = self.dom.createElement('timelimits') time.setAttribute('start',str(objekt.getStartTime())) time.setAttribute('end',str(objekt.getEndTime())) time.appendChild(self.dom.createTextNode(str(objekt.getTimeFunc()))) perm.appendChild(time) for up in objekt.listLocalUserRoles('Items'): granted = self.dom.createElement('granted') granted.appendChild(self.dom.createTextNode(str(up))) perm.appendChild(granted) metadata.appendChild(technical) if annotations: for x in objekt.getComments(): an = self.dom.createElement('annotation') an.setAttribute('parameters','comment') metadata.appendChild(an) person = self.dom.createElement('person') person.appendChild(self.dom.createTextNode(str(x[0]))) an.appendChild(person) date = self.dom.createElement('date') date.appendChild(self.dom.createTextNode(str(x[2]))) an.appendChild(date) desc = self.dom.createElement('description') desc.appendChild(self.dom.createTextNode(str(x[4]))) an.appendChild(desc) #XXX:not compilant stat = self.dom.createElement('status') stat.appendChild(self.dom.createTextNode(str(x[1]))) an.appendChild(stat) value = self.dom.createElement('value') value.appendChild(self.dom.createTextNode(str(x[3]))) an.appendChild(value) vanem.appendChild(metadata) return metadata def kirjutaItem(self,vanem,isvisible='',parameters='',tiitel='',no_ref=0,originalID='',originalOwner='',realObject=None, realname=''): # writes an item tag and appends to vanem item = self.dom.createElement('item') item.setAttribute('identifier','ITEM'+str(self.idnumber)) #if realObject is not None and realObject.kasEsitluskaust(): # item.setAttribute('presentation',str(realObject.kasEsitluskaust())) if not no_ref: item.setAttribute('identifierref','TARGET'+str(self.idnumber)) if realObject: md = self.dom.createElement('metadata') try: md.setAttribute('creationtime',str(realObject.get_timestamp())) except AttributeError: pass item.appendChild(md) if hasattr(realObject.aq_self, 'kylastused'): for x in realObject.aq_self.kylastused.keys(): an = self.dom.createElement('annotation') an.setAttribute('parameters','visit') md.appendChild(an) ps = self.dom.createElement('person') ps.appendChild(self.dom.createTextNode(str(x))) an.appendChild(ps) dt = self.dom.createElement('date') dt.appendChild(self.dom.createTextNode(str(realObject.aq_self.kylastused[x]))) an.appendChild(dt) perm = self.dom.createElement('permission') md.appendChild(perm) status = self.dom.createElement('status') status.appendChild(self.dom.createTextNode(str(realObject.getObjPermission()))) perm.appendChild(status) order = self.dom.createElement('position') order.appendChild(self.dom.createTextNode(str(realObject.weight))) perm.appendChild(order) time = self.dom.createElement('timelimits') time.setAttribute('start',str(realObject.getStartTime())) time.setAttribute('end',str(realObject.getEndTime())) time.appendChild(self.dom.createTextNode(str(realObject.getTimeFunc()))) perm.appendChild(time) for up in realObject.listLocalUserRoles('Items'): granted = self.dom.createElement('granted') granted.appendChild(self.dom.createTextNode(str(up))) perm.appendChild(granted) if isvisible != '': item.setAttribute('isvisible',isvisible) if parameters != '': item.setAttribute('parameters',parameters) if tiitel != '': self.kirjutaTitle(item,tiitel,originalID=originalID,originalOwner=originalOwner, realname=realname) vanem.appendChild(item) return item def kirjutaResource(self,vanem,tyyp='webcontent',fail='', href='',base=''): # writes resource tag and appends to vanem resource = self.dom.createElement('resource') resource.setAttribute('identifier','TARGET'+str(self.idnumber)) resource.setAttribute('type',tyyp) if base != '': resource.setAttribute('xml:base',base) if href != '': resource.setAttribute('href',str(href)) if fail != '': self.kirjutaFile(resource,fail) vanem.appendChild(resource) return resource def kirjutaTitle(self,vanem,tiitel,namespace='',originalID='',originalOwner='', realname=''): title = self.dom.createElement(namespace+'title') if originalID: #XXX: THIS IS NOT IMS VALID! title.setAttribute('originalID',originalID) if originalOwner: #XXX: THIS IS NOT IMS VALID! title.setAttribute('originalOwner',originalOwner) if realname: title.setAttribute('realname', realname) title_data = self.dom.createTextNode(tiitel) title.appendChild(title_data) vanem.appendChild(title) return title def kirjutaFile(self,vanem,fail): fail_elem = self.dom.createElement('file') fail_elem.setAttribute('href',fail) vanem.appendChild(fail_elem) return fail_elem def kirjutaDependency(self,vanem,targetid): dep = self.dom.createElement('dependency') dep.setAttribute('identifierref','TARGET'+str(targetid)) vanem.appendChild(dep) return dep def kirjutaManifest(self,base=''): # creates sub-manifest, returns 3 elements: metadata, organizations and resources manifest = self.dom.createElement('manifest') manifest.setAttribute('identifier','TARGET'+str(self.idnumber)) if base != '': manifest.setAttribute('xml:base',base) metadata = self.dom.createElement('metadata') manifest.appendChild(metadata) organizations = self.dom.createElement('organizations') manifest.appendChild(organizations) resources = self.dom.createElement('resources') manifest.appendChild(resources) self.root.appendChild(manifest) return metadata,organizations,resources def otsiWebtopItemid(self,folder,itemid,resource,start=0): targetid = self.generateID() prms = '' if folder.kasWikiKaust(): prms = 'wikifolder' if not start: item = self.kirjutaItem(itemid,parameters=prms,no_ref=1,realObject=folder) self.kirjutaTitle(item,folder.get_name(),originalID=folder.getId(),originalOwner=folder.getOwnerTuple()[1]) else: item = itemid for obj in folder.list_contents(criteria='weight'): print obj.absolute_url() targetid = self.generateID() if obj.meta_type != 'WebtopFolder': ii = self.kirjutaItem(item) self.kirjutaTitle(ii, obj.get_name(),originalID=obj.getId(),originalOwner=obj.getOwnerTuple()[1]) if obj.meta_type == 'WebtopFile': res = self.kirjutaResource(resource,tyyp='file') fnimi = self.binarydata.storeData(obj.data,'file') fail = self.kirjutaFile(res,fnimi) metadata = self.lisaMetadata(fail,obj, technical=1,annotations=1) self.kirjutaTitle(metadata,obj.get_name(),'imsmd:',originalID=obj.getId(),originalOwner=obj.getOwnerTuple()[1], realname=obj.get_realname()) if obj.meta_type == 'WebtopLink': res = self.kirjutaResource(resource,tyyp='URL') fail = self.kirjutaFile(res,obj.get_url()) metadata = self.lisaMetadata(fail,obj,technical=1,annotations=1) self.kirjutaTitle(fail,obj.get_name(),'imsmd:',originalID=obj.getId(),originalOwner=obj.getOwnerTuple()[1]) if obj.meta_type == 'WebtopMemo': res = self.kirjutaResource(resource,tyyp='memo') mnimi = self.binarydata.storeData(obj.get_body(),'memo') file = self.kirjutaFile(res,mnimi) metadata = self.lisaMetadata(file,obj,technical=1,annotations=1) self.kirjutaTitle(file,obj.get_name(),'imsmd:',originalID=obj.getId(),originalOwner=obj.getOwnerTuple()[1]) if obj.meta_type == 'WebtopFolder' or obj.meta_type == 'Portfolio' or obj.meta_type == 'AssignmentProxy': targetid = self.generateID() if obj.kasWikiKaust(): self.kirjutaWiki(obj, 'ident',obj.aq_inner.get_name(),obj.wikiKaustEsimeneLeht(),item) else: self.otsiWebtopItemid(obj,item,resource) # for fol in folder.objectValues('WebtopFolder'): #if fol.kasWikiKaust(): # XXX wiki kirjutamine!? # self.kirjutaWiki(fol, 'ident', fol.get_name(),fol.wikiKaustEsimeneLeht(),item) #else: # self.otsiWebtopItemid(fol,item,resource) return def kirjutaWebtop(self,point,misc='ident',tiitel='SISEGRUPP'): # exports webtop style components self.generateID() self.kirjutaItem(self.organization,tiitel=tiitel, parameters=tiitel) e_metadata,e_organizations,e_resources = self.kirjutaManifest() organization = self.dom.createElement('organization') # organization.setAttribute('identifier',misc+str(self.idnumber)) organization.setAttribute('identifier',misc) e_organizations.appendChild(organization) self.otsiWebtopItemid(point,organization,e_resources,start=1) return def kirjutaKasutajaWebtop(self,kasutajad): self.generateID() self.kirjutaItem(self.organization,tiitel='KASUTAJATE WEBTOPID',parameters='KASUTAJATE WEBTOPID') w_metadata,w_organizations,w_resources = self.kirjutaManifest() # self.generateID() # self.kirjutaItem(self.organization,tiitel='KASUTAJATE SAHTLID',parameters='KASUTAJATE SAHTLID') # s_metadata,s_organizations,s_resources = self.kirjutaManifest() for user in kasutajad: uname = user.get_uname() try: pp = getattr(self.iva.fle_users, uname) point = getattr(pp.webtop, 'c'+self.kursusenr) webtop_ation = self.dom.createElement('organization') webtop_ation.setAttribute('identifier','user_'+str(uname)+'_webtop') w_organizations.appendChild(webtop_ation) self.otsiWebtopItemid(point,webtop_ation,w_resources,start=1) except: pass return def generateExportRSS(self, point): blogdoc = Document() root = blogdoc.createElement('rss') blogdoc.appendChild(root) root.setAttribute('version', '2.0') channel = blogdoc.createElement('channel') root.appendChild(channel) title = blogdoc.createElement('title') title.appendChild(blogdoc.createTextNode('Blog')) channel.appendChild(title) link = blogdoc.createElement('link') link.appendChild(blogdoc.createTextNode(point.absolute_url())) channel.appendChild(link) pubDate = blogdoc.createElement('pubDate') pubDate.appendChild(blogdoc.createTextNode('last entry date')) channel.appendChild(pubDate) generator = blogdoc.createElement('generator') generator.appendChild(blogdoc.createTextNode('IVA')) channel.appendChild(generator) for entry in point.getEntries(): item = blogdoc.createElement('item') channel.appendChild(item) title = blogdoc.createElement('title') title.appendChild(blogdoc.createTextNode(entry.getTitle())) item.appendChild(title) link = blogdoc.createElement('link') link.appendChild(blogdoc.createTextNode(entry.absolute_url())) item.appendChild(link) pubDate = blogdoc.createElement('pubDate') pubDate.appendChild(blogdoc.createTextNode(str(entry.time))) item.appendChild(pubDate) creator = blogdoc.createElement('creator') # was dc:creator creator.appendChild(blogdoc.createTextNode(entry.getAuthor())) item.appendChild(creator) cat = blogdoc.createElement('category') cat.appendChild(blogdoc.createTextNode(self.kursus.getUniqId())) item.appendChild(cat) guid = blogdoc.createElement('guid') guid.appendChild(blogdoc.createTextNode(entry.absolute_url())) item.appendChild(guid) desc = blogdoc.createElement('description') desc.appendChild(blogdoc.createTextNode(entry.getIntro())) item.appendChild(desc) content = blogdoc.createElement('content') content.appendChild(blogdoc.createTextNode(entry.getContent())) item.appendChild(content) comments = blogdoc.createElement('comments') item.appendChild(comments) for com in entry.getAllComments(): comment = blogdoc.createElement('comment') comments.appendChild(comment) cAuthor = blogdoc.createElement('cAuthor') try: cAuthor.setAttribute('uniqId', self.iva.fle_users.get_user_info(com.getAuthor()).getUniqId()) except: pass cAuthor.appendChild(blogdoc.createTextNode(com.getAuthor())) comment.appendChild(cAuthor) cTitle = blogdoc.createElement('cTitle') cTitle.appendChild(blogdoc.createTextNode(com.getTitle())) comment.appendChild(cTitle) cContent = blogdoc.createElement('cContent') cContent.appendChild(blogdoc.createTextNode(com.getContent())) comment.appendChild(cContent) cTime = blogdoc.createElement('cTime') cTime.appendChild(blogdoc.createTextNode(str(com.getTime()))) comment.appendChild(cTime) return blogdoc.toprettyxml() def kirjutaBlog(self, point, itemid, resource, tiitel='KURSUS BLOG', parameters='KURSUS BLOG'): targetid = self.generateID() res = self.kirjutaResource(resource, tyyp='blog') data = '' data = self.generateExportRSS(point) fnimi = self.binarydata.storeData(data, 'blog') fail = self.kirjutaFile(res, fnimi) i = self.kirjutaItem(itemid, tiitel=tiitel, parameters=parameters) def kirjutaKasutajaBlog(self, kasutajad, point=None): self.generateID() self.kirjutaItem(self.organization, tiitel='KASUTAJATE BLOGID', parameters='KASUTAJATE BLOGID') w_metadata,w_organizations,w_resources = self.kirjutaManifest() for user in kasutajad: uname = user.get_uname() print "blog... processing user", uname try: pp = getattr(self.iva.fle_users, uname) if point is None: point = getattr(pp.webtop, 'c'+self.kursusenr).portfolio webtop_ation = self.dom.createElement('organization') webtop_ation.setAttribute('identifier','user_'+str(uname)+'_blog') w_organizations.appendChild(webtop_ation) self.kirjutaBlog(point, webtop_ation, w_resources, tiitel='KASUTAJA BLOG', parameters='KASUTAJA BLOG') except AttributeError: #raise 'F***1' pass self.generateID() return def pakiKursusFaili(self,failinimi,path='ABCDE'): import string if path == 'ABCDE': path = str(self.kursusenr) if path != '': path += '/' if zipfile.is_zipfile(failinimi): zip = zipfile.ZipFile(failinimi,"a",zipfile.ZIP_DEFLATED) else: zip = zipfile.ZipFile(failinimi,"w",zipfile.ZIP_DEFLATED) dump = Dump() self.dom.writexml(dump) zip.writestr(zipfile.ZipInfo(path+"imsmanifest.xml"),dump.getdata()) for name in self.binarydata.names: zip.writestr( zipfile.ZipInfo(path+name), str(self.binarydata.getData(name))) zip.close() def otsiWikiLapsed(self,point,resources,organization,start='WikiStart',sygavus=99999): #puudub koht muutjate jaoks for wiki in self.wikid: wiki_vanemad = wiki[1] if start in wiki_vanemad: self.generateID() wikileht = getattr(point, wiki[0]) item = self.kirjutaItem(organization,parameters='ZWiki',tiitel=wikileht.name()) wname = self.binarydata.storeData(wikileht,'wiki') self.kirjutaResource(resources,'wikipage',wname) if not self.wikilevel == sygavus: self.wikilevel = self.wikilevel+1 self.otsiWikiLapsed(point, resources, item, wikileht.name(),sygavus) self.wikilevel = self.wikilevel-1 for wiki in self.wiki_pildid: self.generateID() wiki_pilt = getattr(point, wiki) if wiki_pilt.meta_type == 'Image': tyyp = 'wikiimage' if wiki_pilt.meta_type == 'File': tyyp = 'wikifile' item = self.kirjutaItem(organization, parameters='ZWiki',tiitel=wiki_pilt.id()) wname = self.binarydata.storeData(wiki_pilt.data,tyyp) res = self.kirjutaResource(resources,tyyp=tyyp) fail = self.kirjutaFile(res,wname) metadata = self.lisaMetadata(fail,wiki_pilt, technical=1) #print wiki_pilt.getContentType() self.wiki_pildid = [] return def indekseeriWikid(self,point): self.wikid = [] self.wiki_pildid = [] temp = [] #for wiki in point.objectValues('ZWiki Page'): for wiki in point.objectValues(): if wiki.meta_type == 'ZWiki Page': try: temp.append(wiki.name()) temp.append(wiki.parents) self.wikid.append(temp) temp = [] except: pass if wiki.meta_type == 'Image' or wiki.meta_type == 'File': self.wiki_pildid.append(wiki.id()) #print wiki.__name__+" "+wiki.meta_type return def kirjutaWiki(self,point,misc='ident',tiitel='ZWIKI',start='WikiStart',toc='',palju=''): self.generateID() if toc: self.kirjutaItem(toc,parameters='wikifolder',tiitel=tiitel,originalID=point.getId(),originalOwner=point.getOwnerTuple()[1],realObject=point) else: self.kirjutaItem(self.organization,tiitel=tiitel,parameters='wikifolder') w_metadata,w_organizations,w_resources = self.kirjutaManifest() organization = self.dom.createElement('organization') organization.setAttribute('identifier',misc+str(self.idnumber)) w_organizations.appendChild(organization) #kirjutame esieme wiki-lehe self.generateID() try: item = self.kirjutaItem(organization,parameters='ZWiki',tiitel=getattr(point,start).name()) except: start = 'WikiAvaLeht' item = self.kirjutaItem(organization,parameters='ZWiki',tiitel=getattr(point,'WikiAvaLeht').name()) wnimi = self.binarydata.storeData(getattr(point, start),'wiki') self.kirjutaResource(w_resources,'wikipage', wnimi) self.indekseeriWikid(point) self.wikilevel = 1 if palju: self.otsiWikiLapsed(point,w_resources,item,start,palju) else: self.otsiWikiLapsed(point,w_resources,item,start) return def kirjutaKasutajaWiki(self,kasutajad,start='WikiStart'): self.generateID() self.kirjutaItem(self.organization,tiitel='KASUTAJA WIKI') w_metadata,w_organizations,w_resources = self.kirjutaManifest() self.generateID() for kasutaja in kasutajad: uname = kasutaja.get_uname() try: pp = getattr(self.iva.fle_users, uname) point = getattr(pp.webtop, 'c'+self.kursusenr) wiki_organization = self.dom.createElement('organization') wiki_organization.setAttribute('identifier','user_'+str(uname)+'_wiki') self.generateID() try: item = self.kirjutaItem(wiki_organization,tiitel=getattr(point,start).name()) except: start = 'WikiAvaLeht' try: item = self.kirjutaItem(wiki_organization,tiitel=getattr(point,start).name()) except: continue w_organizations.appendChild(wiki_organization) wnimi = self.binarydata.storeData(getattr(point, start),'wiki') self.kirjutaResource(w_resources,'wikipage', wnimi) self.indekseeriWikid(point) self.otsiWikiLapsed(point,w_resources,item,start) except: pass return def vCalTime(self, aeg): vaeg = time.localtime(aeg) v_aeg = "" v_aeg += str(vaeg[0]) if len(str(vaeg[1])) == 1: v_aeg += "0" +str(vaeg[1]) else: v_aeg += str(vaeg[1]) if len(str(vaeg[2])) == 1: v_aeg += "0" +str(vaeg[2]) else: v_aeg += str(vaeg[2]) v_aeg += "T" if len(str(vaeg[3])) == 1: v_aeg += "0"+str(vaeg[3]) else: v_aeg += str(vaeg[3]) if len(str(vaeg[4])) == 1: v_aeg += "0"+str(vaeg[4]) else: v_aeg += str(vaeg[4]) if len(str(vaeg[5])) == 1: v_aeg += "0"+str(vaeg[5]) else: v_aeg += str(vaeg[5]) return v_aeg def format(self,sisend): temp = re.sub('\r\n',' ',sisend) pikkus = len(temp) tulem = "" if pikkus>60: abc = "" for taht in temp: abc += taht if len(abc)>59: tulem += abc tulem += "\r\n" tulem += " " abc = "" tulem += abc #tulem += "\r\n" else: tulem = temp return tulem def kirjutaEvent(self,point,omanik='mina',kat='kursus'): tulem = "" for syndmus in point.objectValues(): tulem += "BEGIN:VEVENT\r\n" tulem += "DTSTART:"+self.vCalTime(syndmus.algus)+"\r\n" tulem += "DTEND:"+self.vCalTime(syndmus.lopp)+"\r\n" tulem += "N:"+omanik+"\r\n" tulem += "DESCRIPTION:"+self.format(syndmus.getContent())+"\r\n" #tulem += "SUMMARY:"+self.format(syndmus.lyhi)+"\r\n" tulem += "STATUS:"+str(syndmus.olek)+"\r\n" tulem += "CUTYPE:"+kat+"\r\n" tulem += "URL:"+syndmus.viide+"\r\n" tulem += "X-PROPERTY;VALUE=NAME:"+self.format(syndmus.nimi)+"\r\n" # tulem += "X-COMPONENT;VALUE=NAME:"+self.format(oma)+"\r\n" tulem += "RESOURCES:"+self.format(syndmus.siseviide)+"\r\n" tulem += "END:VEVENT\r\n" return tulem def has_events(self,point): for syndmus in point.objectValues(): return 1 return 0 def kirjutavCal(self,point,omanik,kat,organiz='', resour=''): if organiz == '': organiz = self.organization if resour == '': resour = self.resources if self.has_events(point): vCal = "BEGIN:VCALENDAR\r\n" vCal += "METHOD:PUBLISH\r\n" vCal += "VERSION:2.0\r\n" vCal += "PRODID:IVA\r\n" vCal += self.kirjutaEvent(point,omanik,kat) vCal += "END:VCALENDAR\r\n" nimi = self.binarydata.storeData(vCal,'vcal','.ics') self.generateID() self.kirjutaItem(organiz,tiitel='iCalendar - '+omanik+' - syndmused',parameters='iCalendar - '+omanik+' - syndmused') # self.kirjutaItem(self.organization,tiitel='iCalendar - '+omanik+' syndmused') self.kirjutaResource(resour,'iCalendar',nimi) # self.kirjutaResource(self.resources,'iCalendar',nimi) return def kirjutaKasutajaSyndmus(self,kasutajad): self.generateID() self.kirjutaItem(self.organization, tiitel="KASUTAJATE SYNDMUSED",parameters="KASUTAJATE SYNDMUSED") s_metadata,s_organizations,s_resources = self.kirjutaManifest() for user in kasutajad: try: uname = user.get_uname() point = getattr(self.iva.fle_users, uname) if self.has_events(point.syndmused): syndmus_organization = self.dom.createElement('organization') syndmus_organization.setAttribute('identifier','user_'+str(uname)+'_events') s_organizations.appendChild(syndmus_organization) self.kirjutavCal(point.syndmused, uname, 'INDIVIDUAL',syndmus_organization,s_resources) except: pass return def exportMail(self,failinimi,palju=''): mmdoc = Document() mm = mmdoc.createElement('MailMessages') mmdoc.appendChild(mm) users = [] if not palju: users = self.iva.fle_users.get_users() else: users = eval(palju) for x in users: if not hasattr(x, 'kirjad'): continue point = getattr(x, 'kirjad') cat = mmdoc.createElement('catalog') cat.setAttribute('owner', x.get_uname()) mm.appendChild(cat) for kiri in point.objectValues(): mess = mmdoc.createElement('message') mess.setAttribute('read',str(kiri.kasLoetud())) if kiri.kasOmaKoopia(): mess.setAttribute('owncopy','1') cat.appendChild(mess) title = mmdoc.createElement('title') tekst = kiri.kysiPealkiri() tekst = re.sub(']]>',']] >',tekst) # decode and then encode try: tekst = tekst.decode('utf-8') except UnicodeDecodeError: tekst = tekst.decode('iso-8859-15') tekst = tekst.encode('utf-8') title.appendChild(mmdoc.createCDATASection(strip_non_xml(tekst))) mess.appendChild(title) body = mmdoc.createElement('body') tekst = kiri.kysiSisu() tekst = re.sub(']]>',']] >',tekst) try: tekst = tekst.decode('utf-8') except UnicodeDecodeError: tekst = tekst.decode('iso-8859-13') tekst = tekst.encode('utf-8') body.appendChild(mmdoc.createCDATASection(strip_non_xml(tekst))) mess.appendChild(body) sender = mmdoc.createElement('sender') sender.appendChild(mmdoc.createTextNode(str(kiri.kysiSaatja()))) mess.appendChild(sender) receiver = mmdoc.createElement('receiver') receiver.appendChild(mmdoc.createTextNode(str(kiri.saaja))) mess.appendChild(receiver) date = mmdoc.createElement('date') date.appendChild(mmdoc.createTextNode(str(kiri.kysiAeg()))) mess.appendChild(date) if zipfile.is_zipfile(failinimi): zip = zipfile.ZipFile(failinimi,"a",zipfile.ZIP_DEFLATED) else: zip = zipfile.ZipFile(failinimi,"w",zipfile.ZIP_DEFLATED) # mmdoc.dump = Dump() # mmdoc.writexml(mmdoc.dump) # zip.writestr(zipfile.ZipInfo("messages.xml"),mmdoc.dump.getdata()) zip.writestr(zipfile.ZipInfo("messages.xml"),mmdoc.toprettyxml()) zip.close() return def exportCourseCategories(self, failinimi): """ export course categories """ cm = self.iva.courses mmdoc = Document() mm = mmdoc.createElement('CourseCats') mmdoc.appendChild(mm) course_cat = cm.cCategories c = mmdoc.createElement('categories') c_data = mmdoc.createTextNode(str(course_cat)) c.appendChild(c_data) mm.appendChild(c) if zipfile.is_zipfile(failinimi): zip = zipfile.ZipFile(failinimi,"a",zipfile.ZIP_DEFLATED) else: zip = zipfile.ZipFile(failinimi,"w",zipfile.ZIP_DEFLATED) zip.writestr(zipfile.ZipInfo("course_cat.xml"),mmdoc.toprettyxml()) zip.close() return def exportAffiliations(self, failinimi): """ export affiliation codes """ mmdoc = Document() mm = mmdoc.createElement('Affiliations') mmdoc.appendChild(mm) e = self.iva.fle_users.getAffiliations() for x in e: aff = mmdoc.createElement('affiliation') aff_data = mmdoc.createTextNode(x) aff.appendChild(aff_data) mm.appendChild(aff) if zipfile.is_zipfile(failinimi): zip = zipfile.ZipFile(failinimi,"a",zipfile.ZIP_DEFLATED) else: zip = zipfile.ZipFile(failinimi,"w",zipfile.ZIP_DEFLATED) zip.writestr(zipfile.ZipInfo("affiliations.xml"),mmdoc.toprettyxml()) zip.close() return def exportServerSettings(self, failinimi): """ export iva settings """ mmdoc = Document() mm = mmdoc.createElement('Settings') mmdoc.appendChild(mm) # allow user registration auto = mmdoc.createElement('auto_register') auto_data = mmdoc.createTextNode(str(self.iva.get_allow_autoregister())) auto.appendChild(auto_data) mm.appendChild(auto) # quota quota = mmdoc.createElement('quota') quota_data = mmdoc.createTextNode(str(self.iva.webtop_quota)) quota.appendChild(quota_data) mm.appendChild(quota) # quota amount quota_amount = mmdoc.createElement('quota_amount') quota_amount_data = mmdoc.createTextNode(str(self.iva.webtop_quota_amount)) quota_amount.appendChild(quota_amount_data) mm.appendChild(quota_amount) # mail from mail_from = mmdoc.createElement('mail_from') mail_from_data = mmdoc.createTextNode(str(self.iva.MFROM)) mail_from.appendChild(mail_from_data) mm.appendChild(mail_from) # default language def_lang = mmdoc.createElement('default_language') def_lang_data = mmdoc.createTextNode(str(self.iva.get_default_language())) def_lang.appendChild(def_lang_data) mm.appendChild(def_lang) # must change password def_change = mmdoc.createElement('force_change') def_change_data = mmdoc.createTextNode(str(self.iva.def_passwd)) def_change.appendChild(def_change_data) mm.appendChild(def_change) # cannot change affiliation def_aff = mmdoc.createElement('deny_affiliation_change') def_aff_data = mmdoc.createTextNode(str(self.iva.def_not_aff)) def_aff.appendChild(def_aff_data) mm.appendChild(def_aff) # cannot change password def_password = mmdoc.createElement('deny_password_change') def_password_data = mmdoc.createTextNode(str(self.iva.def_not_change)) def_password.appendChild(def_password_data) mm.appendChild(def_password) if zipfile.is_zipfile(failinimi): zip = zipfile.ZipFile(failinimi,"a",zipfile.ZIP_DEFLATED) else: zip = zipfile.ZipFile(failinimi,"w",zipfile.ZIP_DEFLATED) zip.writestr(zipfile.ZipInfo("settings.xml"),mmdoc.toprettyxml()) zip.close() return def exportKodutood(self, point,failinimi,path): # expordime kodutööd kt_doc = Document() kt = kt_doc.createElement('Assignments') kt_doc.appendChild(kt) kt.setAttribute('identifier','IVA') kt.setAttribute('version','1') for kodu in point.listAssignments(): too = kt_doc.createElement('Assignment') too.setAttribute('originalID',kodu.get_id()) kt.appendChild(too) tyyp = kt_doc.createElement('type') tyyp_data = kt_doc.createTextNode(str(kodu.tyyp)) tyyp.appendChild(tyyp_data) too.appendChild(tyyp) pkiri = kt_doc.createElement('title') pkiri_data = kt_doc.createTextNode(str(kodu.getTitle())) pkiri.appendChild(pkiri_data) too.appendChild(pkiri) kirjeldus = kt_doc.createElement('description') kirjeldus_data = kt_doc.createTextNode(str(kodu.kirjeldus)) kirjeldus.appendChild(kirjeldus_data) too.appendChild(kirjeldus) punkt = kt_doc.createElement('points') punkt_data = kt_doc.createTextNode(str(kodu.getPoints())) punkt.appendChild(punkt_data) too.appendChild(punkt) try: resour = kt_doc.createElement('resource') resour_data = kt_doc.createTextNode(str(kodu.juhend)) resour.appendChild(resour_data) too.appendChild(resour) except: pass try: aeg = kt_doc.createElement('end') aeg_data = kt_doc.createTextNode(str(kodu.loppaeg)) aeg.appendChild(aeg_data) too.appendChild(aeg) except: pass try: grupp = kt_doc.createElement('groups') for abc in kodu.getGroups(): gr = kt_doc.createElement('group') grupp_data = kt_doc.createTextNode(str(abc)) gr.appendChild(grupp_data) grupp.appendChild(gr) too.appendChild(grupp) except: pass try: test = kt_doc.createElement('test') test_data = kt_doc.createTextNode(str(kodu.testiID)) test.appendChild(test_data) too.appendChild(test) except: pass self.generateID() self.kirjutaItem(self.organization,tiitel='Assignments',parameters='Assignments') self.kirjutaResource(self.resources,'assignments','assignments.xml','assignments.xml') if zipfile.is_zipfile(failinimi): zip = zipfile.ZipFile(failinimi,"a",zipfile.ZIP_DEFLATED) else: zip = zipfile.ZipFile(failinimi,"w",zipfile.ZIP_DEFLATED) kt_doc.dump = Dump() kt_doc.writexml(kt_doc.dump) zip.writestr(zipfile.ZipInfo(path+"assignments.xml"),kt_doc.dump.getdata()) zip.close() return def exportPajad(self,failinimi,path,startonly=0): self.generateID() TP = Document() MP = Document() kala = Exporter(self.iva) tp_elem = TP.createElement('KnowledgeBuilding') for ctx in self.kursus.get_children("CourseContext"): tp_elem.appendChild(kala.exportContext(ctx,startonly)) TP.appendChild(tp_elem) mp_elem = MP.createElement('Jamming') try: #for c in courses.get_children('Course'): for js in self.kursus.get_child('jamming').get_children('JamSession'): mp_elem.appendChild(kala.exportJamSession(self.kursus, js,startonly)) except: pass MP.appendChild(mp_elem) self.kirjutaItem(self.organization,tiitel='TEADMUSPAJA',parameters='TEADMUSPAJA') self.kirjutaResource(self.resources,'teadmuspaja','teadmuspaja.xml','teadmuspaja.xml') self.generateID() self.kirjutaItem(self.organization,tiitel='MEEDIAPAJA',parameters='MEEDIAPAJA') self.kirjutaResource(self.resources,'meediapaja','meediapaja.xml','meediapaja.xml') if zipfile.is_zipfile(failinimi): zip = zipfile.ZipFile(failinimi,"a",zipfile.ZIP_DEFLATED) else: zip = zipfile.ZipFile(failinimi,"w",zipfile.ZIP_DEFLATED) TP.dump = Dump() MP.dump = Dump() TP.writexml(TP.dump) MP.writexml(MP.dump) zip.writestr(zipfile.ZipInfo(path+"teadmuspaja.xml"),TP.dump.getdata()) zip.writestr(zipfile.ZipInfo(path+"meediapaja.xml"),MP.dump.getdata()) for name in kala.binarydata.names: zip.writestr( zipfile.ZipInfo(path+name), str(kala.binarydata.getData(name))) zip.close() return def exportQTI(self,failinimi,path,teacherExporting=0): # function for going all necessary to export tests self.generateID() self.kirjutaItem(self.organization,tiitel='QTI',parameters='QTI') self.kirjutaResource(self.resources,'imsqti_xmlv1p1','qti.xml','qti.xml') element = self.looTestiFail() self.kirjutaTestid(element,teacherExporting=teacherExporting) self.kirjutaTestidZipi(failinimi,path) def looTestiFail(self): self.generateID() self.qti = Document() self.qtibin = DataTable() self.qtiroot = self.qti.createElement("questestinterop") self.qtiroot.setAttribute('xmlns','http://www.imsglobal.org/xsd/ims_qtiasiv1p2') self.qtiroot.setAttribute('xmlns:xsi','http://www.w3.org/2000/10/XMLSchema-instance') self.qtiroot.setAttribute('xsi:schemaLocation','http://www.imsglobal.org/xsd/ims_qtiasiv1p2 http://www.imsglobal.org/xsd/ims_qtiasiv1p2.xsd') self.qti.appendChild(self.qtiroot) return self.qtiroot def kirjutaTestidZipi(self,failinimi,path=''): if zipfile.is_zipfile(failinimi): zip = zipfile.ZipFile(failinimi,"a",zipfile.ZIP_DEFLATED) else: zip = zipfile.ZipFile(failinimi,"w",zipfile.ZIP_DEFLATED) self.qti.dump = Dump() self.qti.writexml(self.qti.dump) zip.writestr(zipfile.ZipInfo(path+"qti.xml"),self.qti.dump.getdata()) for name in self.qtibin.names: zip.writestr( zipfile.ZipInfo(path+name), str(self.qtibin.getData(name))) zip.close() return def testiPilt(self,vanem, varamu): #print "Otsin pilti:", vanem, varamu, varamu.kirjeldavTekst images = [] pattern = re.compile('src=".*?"') qtimg = varamu.qtimages iter = pattern.finditer(varamu.kirjeldavTekst) for i in iter: url = i.group()[5:-1] if not 'qtimages' in url: continue # its somewhere else and we don't want it path = url.split('/') imgname = path[path.index('qtimages')+1:] try: images.append(qtimg.unrestrictedTraverse('/'.join(imgname))) except KeyError: pass for img in images: mat_pilt = self.qti.createElement('matimage') name = self.qtibin.storeData(img.data,'qti') mat_pilt.setAttribute('uri',name) mat_pilt.setAttribute('id',img.getId()) mat_pilt.setAttribute('title',img.title) vanem.appendChild(mat_pilt) return vanem def testiViide(self,vanem, varamu): if varamu.viiteURL != '': matem = self.qti.createElement('matemtext') matem.setAttribute('uri',varamu.viiteURL) matem.appendChild(self.qti.createTextNode(varamu.viiteTekst)) vanem.appendChild(matem) return vanem def testiKirjeldavTekst(self,vanem,varamu): if varamu.kirjeldavTekst != '': komm = self.qti.createElement('qticomment') komm.appendChild(self.qti.createTextNode(varamu.kirjeldavTekst)) vanem.appendChild(komm) return vanem def testiItem(self,vanem,varamu): elem = self.qti.createElement('item') elem.setAttribute('ident',varamu.get_id()) elem.setAttribute('title',varamu.meta_type) vanem.appendChild(elem) return elem def exportUserResponses(self,vanem,hoidla,users=''): if not users: users = self.kursus.get_all_users() else: users = eval(users) for x in users: try: tmpx = getattr(self.iva.fle_users, x.get_uname()).webtop tmpy = getattr(tmpx, 'c'+self.kursus.get_id()).testivastused z = getattr(tmpy.aq_self, hoidla.get_id()) except AttributeError: continue elem = self.qti.createElement('response') elem.setAttribute('owner',x.get_uname()) for i in z.aq_self.objectValues(): ver = self.qti.createElement('version') ver.setAttribute('id',str(i.get_id())) try: ver.setAttribute('comment',str(i.annaKoguKommentaar())) except AttributeError: pass elem.appendChild(ver) for j in i.objectValues(): yl = self.qti.createElement('yl') yl.setAttribute('id',j.get_id()) try: if j.annaOpetajaPunktid() is not None: yl.setAttribute('score',str(j.annaOpetajaPunktid())) except AttributeError: pass try: yl.setAttribute('comment',str(j.annaOpetajaKommentaar())) except AttributeError: pass try: if type(j.pakutud())==types.ListType: yl.setAttribute('type','List') yl.appendChild(self.qti.createTextNode(str(j.pakutud()))) except AttributeError: pass ver.appendChild(yl) vanem.appendChild(elem) return def kirjutaTestid(self,vanem,testinimi='',users='',teacherExporting=0): if testinimi != '': ainult_yks_test = 1 else: ainult_yks_test = 0 qticomment = self.qti.createElement("qticomment") qticomment_data = self.qti.createTextNode('Here is a set of questions and tests from IVA') qticomment.appendChild(qticomment_data) vanem.appendChild(qticomment) # export all tests and questions within course for hoidla in self.kursus.testid.getQuizzes(): if hoidla.get_id() == testinimi or not ainult_yks_test: sektion = self.qti.createElement('section') sektion.setAttribute('title',str(hoidla.pealkiri)) sektion.setAttribute('ident',str(hoidla.get_id())) sektion.setAttribute('type',str(hoidla.kysiTyyp())) sektion.setAttribute('randomize',str(hoidla.kasKysimusteJuhuslikJarjekord())) sektion.setAttribute('answers',str(hoidla.kysiVastusteNahtavus())) sektion.setAttribute('open',str(hoidla.avatudTaitmiseks)) md = self.qti.createElement('metadata') sektion.appendChild(md) tl = self.qti.createElement('timelimit') tl.setAttribute('repeat',str(hoidla.koigiLuba.kordadeArv)) tl.setAttribute('start',str(hoidla.koigiLuba.algusAeg)) tl.setAttribute('end',str(hoidla.koigiLuba.loppAeg)) md.appendChild(tl) grs = self.qti.createElement('groups') md.appendChild(grs) for x in hoidla.grupiLoad.objectValues(): gr = self.qti.createElement('group') gr.setAttribute('repeat',str(x.kordadeArv)) gr.setAttribute('start',str(x.algusAeg)) gr.setAttribute('end',str(x.loppAeg)) gr.setAttribute('name',str(x.id)) grs.appendChild(gr) prs = self.qti.createElement('persons') md.appendChild(prs) for x in hoidla.isikuLoad.objectValues(): pr = self.qti.createElement('person') pr.setAttribute('repeat',str(x.kordadeArv)) pr.setAttribute('start',str(x.algusAeg)) pr.setAttribute('end',str(x.loppAeg)) pr.setAttribute('name',str(x.id)) prs.appendChild(pr) desc = self.qti.createElement('description') desc.appendChild(self.qti.createTextNode(str(hoidla.annaKirjeldus()))) md.appendChild(desc) uresp = self.qti.createElement('userresponses') sektion.appendChild(uresp) if not teacherExporting: self.exportUserResponses(uresp,hoidla,users) #print hoidla.get_id() for yled in hoidla.objectValues(): #print "->>"+yled.get_id() #print yled.get_id()+" - "+ yled.meta_type tyyp = yled.meta_type if tyyp=='ValikYlesanne': elem = self.testiItem(sektion,yled) self.testiKirjeldavTekst(elem,yled) present = self.qti.createElement('presentation') elem.appendChild(present) flo = self.qti.createElement('flow') present.appendChild(flo) mat = self.qti.createElement('material') flo.appendChild(mat) mattext = self.qti.createElement('mattext') mattext.appendChild(self.qti.createTextNode(yled.kysimus)) mat.appendChild(mattext) self.testiViide(mat,yled) self.testiPilt(mat,yled) resp_lid = self.qti.createElement('response_lid') resp_lid.setAttribute('ident',yled.get_id()) resp_lid.setAttribute('rcardinality',"Single") flo.appendChild(resp_lid) render = self.qti.createElement('render_choice') resp_lid.appendChild(render) flow_l = self.qti.createElement('flow_label') render.appendChild(flow_l) resp_lab = self.qti.createElement('response_label') resp_lab.setAttribute('ident','T') flow_l.appendChild(resp_lab) mat2 = self.qti.createElement('material') resp_lab.appendChild(mat2) mattext2 = self.qti.createElement('mattext') mattext2.appendChild(self.qti.createTextNode('True')) mat2.appendChild(mattext2) resp_lab = self.qti.createElement('response_label') resp_lab.setAttribute('ident','F') flow_l.appendChild(resp_lab) mat2 = self.qti.createElement('material') resp_lab.appendChild(mat2) mattext2 = self.qti.createElement('mattext') mattext2.appendChild(self.qti.createTextNode('False')) mat2.appendChild(mattext2) resproc = self.qti.createElement('resprocessing') elem.appendChild(resproc) out = self.qti.createElement('outcomes') resproc.appendChild(out) muut = self.qti.createElement('decvar') muut.setAttribute('vartype','Integer') muut.setAttribute('maxvalue',str(yled.normPunktid)) out.appendChild(muut) kond = self.qti.createElement('respcondition') kond.setAttribute('title','Correct') resproc.appendChild(kond) kond_var = self.qti.createElement('conditionvar') kond.appendChild(kond_var) varequal = self.qti.createElement('varequal') varequal.setAttribute('respident',yled.get_id()) if yled.vastus: varequal.appendChild(self.qti.createTextNode('T')) else: varequal.appendChild(self.qti.createTextNode('F')) kond_var.appendChild(varequal) setvar = self.qti.createElement('setvar') setvar.setAttribute('action','Add') setvar.appendChild(self.qti.createTextNode(str(yled.normPunktid))) kond.appendChild(setvar) pass if tyyp=='OigeTekstivastusegaYlesanne': elem = self.testiItem(sektion,yled) self.testiKirjeldavTekst(elem,yled) present = self.qti.createElement('presentation') elem.appendChild(present) flo = self.qti.createElement('flow') present.appendChild(flo) mat = self.qti.createElement('material') flo.appendChild(mat) mattext = self.qti.createElement('mattext') mattext.appendChild(self.qti.createTextNode(yled.kysimus)) mat.appendChild(mattext) self.testiViide(mat,yled) self.testiPilt(mat,yled) resp_lid = self.qti.createElement('response_str') resp_lid.setAttribute('ident',yled.get_id()) resp_lid.setAttribute('rcardinality',"Single") flo.appendChild(resp_lid) render = self.qti.createElement('render_fib') render.setAttribute('fibtype','String') render.setAttribute('encoding','UTF_8') resp_lid.appendChild(render) resp_lab = self.qti.createElement('response_label') resp_lab.setAttribute('ident','A') render.appendChild(resp_lab) resproc = self.qti.createElement('resprocessing') elem.appendChild(resproc) out = self.qti.createElement('outcomes') resproc.appendChild(out) muut = self.qti.createElement('decvar') muut.setAttribute('vartype','Integer') muut.setAttribute('maxvalue',str(yled.normPunktid)) out.appendChild(muut) kond = self.qti.createElement('respcondition') kond.setAttribute('title','Correct') resproc.appendChild(kond) kond_var = self.qti.createElement('conditionvar') kond.appendChild(kond_var) for abc in yled.variandid: varequal = self.qti.createElement('varequal') varequal.setAttribute('respident',yled.get_id()) varequal.appendChild(self.qti.createTextNode(str(abc))) kond_var.appendChild(varequal) setvar = self.qti.createElement('setvar') setvar.setAttribute('action','Add') setvar.appendChild(self.qti.createTextNode(str(yled.normPunktid))) kond.appendChild(setvar) pass if tyyp=='YksikvalikYlesanne': elem = self.testiItem(sektion,yled) self.testiKirjeldavTekst(elem,yled) present = self.qti.createElement('presentation') elem.appendChild(present) flo = self.qti.createElement('flow') present.appendChild(flo) mat = self.qti.createElement('material') flo.appendChild(mat) mattext = self.qti.createElement('mattext') mattext.appendChild(self.qti.createTextNode(yled.kysimus)) mat.appendChild(mattext) self.testiViide(mat,yled) self.testiPilt(mat,yled) resp_lid = self.qti.createElement('response_lid') resp_lid.setAttribute('ident',yled.get_id()) resp_lid.setAttribute('rcardinality',"Single") flo.appendChild(resp_lid) render = self.qti.createElement('render_choice') render.setAttribute('shuffle','Yes') resp_lid.appendChild(render) i=0 for abc in yled.valikud: resp_lab = self.qti.createElement('response_label') resp_lab.setAttribute('ident',str(i)) render.appendChild(resp_lab) flow_mat = self.qti.createElement('flow_mat') resp_lab.appendChild(flow_mat) mat2 = self.qti.createElement('material') flow_mat.appendChild(mat2) mattext2 = self.qti.createElement('mattext') mattext2.appendChild(self.qti.createTextNode(abc)) mat2.appendChild(mattext2) i=i+1 resproc = self.qti.createElement('resprocessing') elem.appendChild(resproc) out = self.qti.createElement('outcomes') resproc.appendChild(out) muut = self.qti.createElement('decvar') muut.setAttribute('vartype','Integer') muut.setAttribute('maxvalue',str(yled.normPunktid)) out.appendChild(muut) kond = self.qti.createElement('respcondition') kond.setAttribute('title','Correct') resproc.appendChild(kond) kond_var = self.qti.createElement('conditionvar') kond.appendChild(kond_var) varequal = self.qti.createElement('varequal') varequal.setAttribute('respident',yled.get_id()) varequal.appendChild(self.qti.createTextNode(str(yled.oigeValik))) kond_var.appendChild(varequal) setvar = self.qti.createElement('setvar') setvar.setAttribute('action','Add') setvar.appendChild(self.qti.createTextNode(str(yled.normPunktid))) kond.appendChild(setvar) i=0 if not hasattr(yled,'selgitused'): selgitused = [] for abc in yled.selgitused: itemfeed = self.qti.createElement('itemfeedback') itemfeed.setAttribute('ident',str(i)) elem.appendChild(itemfeed) flow_m = self.qti.createElement('flow_mat') itemfeed.appendChild(flow_m) mat = self.qti.createElement('material') flow_m.appendChild(mat) mattext = self.qti.createElement('mattext') mattext.appendChild(self.qti.createTextNode(abc)) mat.appendChild(mattext) i=i+1 pass if tyyp=='TekstivastusegaYlesanne': elem = self.testiItem(sektion,yled) self.testiKirjeldavTekst(elem,yled) present = self.qti.createElement('presentation') elem.appendChild(present) flo = self.qti.createElement('flow') present.appendChild(flo) mat = self.qti.createElement('material') flo.appendChild(mat) mattext = self.qti.createElement('mattext') mattext.appendChild(self.qti.createTextNode(yled.kysimus)) mat.appendChild(mattext) self.testiViide(mat,yled) self.testiPilt(mat,yled) resp_lid = self.qti.createElement('response_str') resp_lid.setAttribute('ident',yled.get_id()) resp_lid.setAttribute('rcardinality',"Ordered") flo.appendChild(resp_lid) render = self.qti.createElement('render_fib') render.setAttribute('fibtype','String') render.setAttribute('enconding','UTF_8') render.setAttribute('prompt','Box') resp_lid.appendChild(render) resp_lab = self.qti.createElement('response_label') resp_lab.setAttribute('ident','A') render.appendChild(resp_lab) pass if tyyp=='MitmikvalikYlesanne': elem = self.testiItem(sektion,yled) self.testiKirjeldavTekst(elem,yled) present = self.qti.createElement('presentation') elem.appendChild(present) flo = self.qti.createElement('flow') present.appendChild(flo) mat = self.qti.createElement('material') flo.appendChild(mat) mattext = self.qti.createElement('mattext') mattext.appendChild(self.qti.createTextNode(yled.kysimus)) mat.appendChild(mattext) self.testiViide(mat,yled) self.testiPilt(mat,yled) resp_lid = self.qti.createElement('response_lid') resp_lid.setAttribute('ident',yled.get_id()) resp_lid.setAttribute('rcardinality',"Multiple") flo.appendChild(resp_lid) render = self.qti.createElement('render_choice') render.setAttribute('shuffle','Yes') resp_lid.appendChild(render) i=0 for abc in yled.valikud: resp_lab = self.qti.createElement('response_label') resp_lab.setAttribute('ident',str(i)) render.appendChild(resp_lab) flow_mat = self.qti.createElement('flow_mat') resp_lab.appendChild(flow_mat) mat2 = self.qti.createElement('material') flow_mat.appendChild(mat2) mattext2 = self.qti.createElement('mattext') mattext2.appendChild(self.qti.createTextNode(abc)) mat2.appendChild(mattext2) i=i+1 resproc = self.qti.createElement('resprocessing') elem.appendChild(resproc) out = self.qti.createElement('outcomes') resproc.appendChild(out) muut = self.qti.createElement('decvar') muut.setAttribute('vartype','Integer') muut.setAttribute('maxvalue',str(yled.normPunktid)) out.appendChild(muut) kond = self.qti.createElement('respcondition') kond.setAttribute('title','Correct') resproc.appendChild(kond) kond_var = self.qti.createElement('conditionvar') kond.appendChild(kond_var) for abc in yled.oigedValikud: varequal = self.qti.createElement('varequal') varequal.setAttribute('respident',yled.get_id()) varequal.appendChild(self.qti.createTextNode(str(abc))) kond_var.appendChild(varequal) setvar = self.qti.createElement('setvar') setvar.setAttribute('action','Add') setvar.appendChild(self.qti.createTextNode(str(yled.normPunktid))) kond.appendChild(setvar) i=0 for abc in yled.selgitused: itemfeed = self.qti.createElement('itemfeedback') itemfeed.setAttribute('ident',str(i)) elem.appendChild(itemfeed) flow_m = self.qti.createElement('flow_mat') itemfeed.appendChild(flow_m) mat = self.qti.createElement('material') flow_m.appendChild(mat) mattext = self.qti.createElement('mattext') mattext.appendChild(self.qti.createTextNode(abc)) mat.appendChild(mattext) i=i+1 pass if tyyp=='ArvuvahemikuliseVastusegaYlesanne': elem = self.testiItem(sektion,yled) self.testiKirjeldavTekst(elem,yled) present = self.qti.createElement('presentation') elem.appendChild(present) flo = self.qti.createElement('flow') present.appendChild(flo) mat = self.qti.createElement('material') flo.appendChild(mat) mattext = self.qti.createElement('mattext') mattext.appendChild(self.qti.createTextNode(yled.kysimus)) mat.appendChild(mattext) self.testiViide(mat,yled) self.testiPilt(mat,yled) resp_lid = self.qti.createElement('response_num') resp_lid.setAttribute('ident',yled.get_id()) resp_lid.setAttribute('rcardinality',"Single") resp_lid.setAttribute('numtype','Decimal') flo.appendChild(resp_lid) render = self.qti.createElement('render_fib') render.setAttribute('fibtype','Decimal') render.setAttribute('prompt','Box') resp_lid.appendChild(render) resp_lab = self.qti.createElement('response_label') resp_lab.setAttribute('ident','A') render.appendChild(resp_lab) resproc = self.qti.createElement('resprocessing') elem.appendChild(resproc) out = self.qti.createElement('outcomes') resproc.appendChild(out) komm = self.qti.createElement('qticomment') komm.appendChild(self.qti.createTextNode(str(yled.arvutusTyyp))) out.appendChild(komm) muut = self.qti.createElement('decvar') muut.setAttribute('vartype','Integer') muut.setAttribute('maxvalue',str(yled.normPunktid)) out.appendChild(muut) kond = self.qti.createElement('respcondition') kond.setAttribute('title','Correct') resproc.appendChild(kond) kond_var = self.qti.createElement('conditionvar') kond.appendChild(kond_var) varless = self.qti.createElement('vargte') varless.setAttribute('respident',yled.get_id()) varless.appendChild(self.qti.createTextNode(str(yled.alamPiir))) kond_var.appendChild(varless) varequal = self.qti.createElement('varequal') varequal.setAttribute('respident',yled.get_id()) varequal.appendChild(self.qti.createTextNode(str(yled.oigeVastus))) kond_var.appendChild(varequal) varover = self.qti.createElement('varlte') varover.setAttribute('respident',yled.get_id()) varover.appendChild(self.qti.createTextNode(str(yled.ylemPiir))) kond_var.appendChild(varover) setvar = self.qti.createElement('setvar') setvar.setAttribute('action','Add') setvar.appendChild(self.qti.createTextNode(str(yled.normPunktid))) kond.appendChild(setvar) pass if tyyp=='ProtsentYlesanne': elem = self.testiItem(sektion,yled) self.testiKirjeldavTekst(elem,yled) present = self.qti.createElement('presentation') elem.appendChild(present) flo = self.qti.createElement('flow') present.appendChild(flo) mat = self.qti.createElement('material') flo.appendChild(mat) mattext = self.qti.createElement('mattext') mattext.appendChild(self.qti.createTextNode(yled.kysimus)) mat.appendChild(mattext) self.testiViide(mat,yled) self.testiPilt(mat,yled) points = self.qti.createElement('points') points_data = self.qti.createTextNode(str(yled.normPunktid)) points.appendChild(points_data) elem.appendChild(points) searching = self.qti.createElement('searching') searching.appendChild(self.qti.createTextNode(str(yled.kysitav))) elem.appendChild(searching) solvent = self.qti.createElement('solvent') #lahus min = self.qti.createElement('min') min.appendChild(self.qti.createTextNode(str(yled.lahustiAlamPiir))) max = self.qti.createElement('max') max.appendChild(self.qti.createTextNode(str(yled.lahustiYlemPiir))) names = self.qti.createElement('names') names.appendChild(self.qti.createTextNode(str(yled.lahustiTekst))) stype = self.qti.createElement('type') stype.appendChild(self.qti.createTextNode(str(yled.lahustiYhik))) solvent.appendChild(min) solvent.appendChild(max) solvent.appendChild(names) solvent.appendChild(stype) elem.appendChild(solvent) soluble = self.qti.createElement('soluble') #aine min = self.qti.createElement('min') min.appendChild(self.qti.createTextNode(str(yled.aineAlamPiir))) max = self.qti.createElement('max') max.appendChild(self.qti.createTextNode(str(yled.aineYlemPiir))) names = self.qti.createElement('names') names.appendChild(self.qti.createTextNode(str(yled.aineTekst))) stype = self.qti.createElement('type') stype.appendChild(self.qti.createTextNode(str(yled.aineYhik))) soluble.appendChild(min) soluble.appendChild(max) soluble.appendChild(names) soluble.appendChild(stype) elem.appendChild(soluble) accuracy = self.qti.createElement('accuracy') accuracy.appendChild(self.qti.createTextNode(str(yled.vastuseTapsusProtsent))) elem.appendChild(accuracy) scoring = self.qti.createElement('scoring') scoring.appendChild(self.qti.createTextNode(str(yled.arvutusTyyp))) elem.appendChild(scoring) if tyyp=='VastavusYlesanne': elem = self.testiItem(sektion,yled) self.testiKirjeldavTekst(elem,yled) present = self.qti.createElement('presentation') elem.appendChild(present) flo = self.qti.createElement('flow') present.appendChild(flo) mat = self.qti.createElement('material') flo.appendChild(mat) mattext = self.qti.createElement('mattext') mattext.appendChild(self.qti.createTextNode(yled.kysimus)) mat.appendChild(mattext) self.testiViide(mat,yled) self.testiPilt(mat,yled) resp_grp = self.qti.createElement('response_grp') resp_grp.setAttribute('ident',yled.get_id()) resp_grp.setAttribute('rcardinality',"Multiple") flo.appendChild(resp_grp) render = self.qti.createElement('render_choice') render.setAttribute('shuffle','Yes') resp_grp.appendChild(render) i=0 krupp = '' for abc in yled.vastused: resp_lab = self.qti.createElement('response_label') ident = 'p'+str(i) if krupp != '': krupp = krupp+',' krupp = krupp + ident resp_lab.setAttribute('ident',ident) resp_lab.setAttribute('rshuffle','Yes') resp_lab.setAttribute('rrange','Exact') render.appendChild(resp_lab) rmat = self.qti.createElement('material') resp_lab.appendChild(rmat) rmattext = self.qti.createElement('mattext') rmattext.setAttribute('texttype','text/plain') rmattext.appendChild(self.qti.createTextNode(abc)) rmat.appendChild(rmattext) i=i+1 i=0 for abc in yled.kysimused: resp_lab = self.qti.createElement('response_label') resp_lab.setAttribute('ident','v'+str(i)) resp_lab.setAttribute('match_max','1') resp_lab.setAttribute('match_group',krupp) resp_lab.setAttribute('rshuffle','Yes') resp_lab.setAttribute('rrange','Exact') render.appendChild(resp_lab) rmat = self.qti.createElement('material') resp_lab.appendChild(rmat) rmattext = self.qti.createElement('mattext') rmattext.setAttribute('texttype','text/plain') rmattext.appendChild(self.qti.createTextNode(abc)) rmat.appendChild(rmattext) i=i+1 resproc = self.qti.createElement('resprocessing') elem.appendChild(resproc) out = self.qti.createElement('outcomes') resproc.appendChild(out) muut = self.qti.createElement('decvar') muut.setAttribute('vartype','Integer') muut.setAttribute('maxvalue',str(yled.normPunktid)) out.appendChild(muut) kond = self.qti.createElement('respcondition') kond.setAttribute('title','Correct') resproc.appendChild(kond) kond_var = self.qti.createElement('conditionvar') kond.appendChild(kond_var) jah = self.qti.createElement('and') kond_var.appendChild(jah) i=0 for abc in yled.vastused: varsub = self.qti.createElement('varsubset') varsub.setAttribute('respident',yled.get_id()) varsub.setAttribute('setmatch','Exact') varsub.appendChild(self.qti.createTextNode('v'+str(i)+','+'p'+str(i))) jah.appendChild(varsub) i=i+1 setvar = self.qti.createElement('setvar') setvar.setAttribute('action','Add') setvar.appendChild(self.qti.createTextNode(str(yled.normPunktid))) kond.appendChild(setvar) pass vanem.appendChild(sektion) return