# -*- coding: utf-8 # -*- Mode: Python; py-indent-offset: 4 -*- # $Id$ # # Copyright (c) 2006, Vahur Rebas, HTK, TLU # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ Container for Questions """ __version__ = "$Revision:33$"[11:-2] import re import Globals from Globals import Acquisition, Persistent from Acquisition import aq_base, aq_inner, aq_parent, Explicit from AccessControl import ClassSecurityInfo from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2 from zope.interface import implements from common import commons from BaseQuestion import BaseQuestion from types import Choice from types import Choice_multiple from types import Order from types import associate from types import Match from types import Gap_match from types import Text_entry from types import Inline_choice from types import Extended_text from types import Hottext from types import Slider from types import Hotspot import Images import Videos from Permissions import * from interfaces import IQuestions, IQuestionAuthoring class Questions(BTreeFolder2, Persistent, Explicit, commons): """ container class for questions """ meta_type = 'Questions' security = ClassSecurityInfo() security.declareObjectPublic() implements(IQuestions, IQuestionAuthoring) manage_options = BTreeFolder2.manage_options id = 'questions' def __init__(self): BTreeFolder2.__init__(self, self.id) def index_html(self): """ index """ return self.restrictedTraverse('questions.html')() def getKeywordsFrequencies(self, user): """ returns most used keywords frequencies {'keyword1': 3, 'keyword2': 5, ..} """ raw_tags = {} query = {'getErased': 0, 'getStatus': ['public', 'draft']} query2 = {'getErased': 0, 'getUser': str(user), 'getStatus': 'private'} results = self.cat_ques(query) + self.cat_ques(query2) for res in results: keys = res.getKeywordsTuple for k in keys: if k.strip() != '': if raw_tags.has_key(k): raw_tags[k] = raw_tags[k] + 1 else: raw_tags[k] = 1 # return only 100 most popular keywords limit = 100 # sort tagdict by count #print "raw_tags_before: ", raw_tags #raw_tags.sort(lambda x, y: cmp(x[1], y[1])) #print "raw_tags_after: ", raw_tags[:5] return raw_tags def makeTagCloud(self, user, all=True): """ generate a tagcloud """ raw_tags = [] if all == False: user = str(user) userfolder = getattr(self.users, user, None) if userfolder is not None: raw_tags = userfolder.getUserKeywordsFrequencies() if all == True: raw_tags = self.getKeywordsFrequencies(user) taglist = [] for ts in raw_tags: try: ts_name = ts.decode('utf-8') taglist.append((ts_name, raw_tags[ts])) except UnicodeDecodeError: pass # sort tagdict by count taglist.sort(lambda x, y: cmp(x[1], y[1])) if all == True: # limit with 100 taglist.reverse() taglist = taglist[:100] taglist.reverse() if taglist != []: # find max and min frequency ranges = self.getRanges(taglist) # write out results to output, tags are written out alphabetically # with size indicating the relative frequency of their occurence return self.writeCloud(taglist, ranges, all) return "" def getRanges(self,taglist): mincount = taglist[0][1] maxcount = taglist[len(taglist) - 1][1] distrib = (maxcount - mincount) / 4; if (distrib == 0): distrib = 1 index = mincount ranges = [] while (index < maxcount): index = index + distrib if index > maxcount - distrib: index = maxcount + 1 ranges.append(index) return ranges def writeCloud(self, taglist, ranges, all): html = "" rangeStyle = ["smallestTag", "smallTag", "mediumTag", "largeTag", "largestTag"] # resort the tags alphabetically taglist.sort(lambda x, y: cmp(x[0], y[0])) from bisect import bisect for tag in taglist: t = tag[0] tagcount = tag[1] if all == True: url = self.absolute_url()+"?search_button=&keyword="+t else: url = self.absolute_url()+"?keyword="+t try: style = rangeStyle[bisect(ranges, tag[1])] except IndexError: style = 'largestTag' try: html += "" + t + "" except UnicodeDecodeError: html += "" + t.decode('utf-8') + "" html += " " return html def getQuestions(self, REQUEST, exclude=[]): """ """ from AccessControl import getSecurityManager # if REQUEST.has_key('my_ques') == 'on' or not REQUEST.has_key('search_button'): # user = str(REQUEST.AUTHENTICATED_USER) authenticated_user = getSecurityManager().getUser() role = self.checkRoles(self, authenticated_user, 'Manager') #1-manager 0-somebody else if REQUEST.get('my_ques', '') == 'on' or not REQUEST.has_key('search_button'): user = str(REQUEST.AUTHENTICATED_USER) licence = REQUEST.get('licence', '') status = ['draft', 'public', 'private'] else: user = '' licence = REQUEST.get('licence', '') if role == 0: if licence == '': licence = ['copyleft', 'cc1', 'cc2', 'cc3', 'copyright'] status = ['draft', 'public'] elif role == 1: status = ['draft', 'public', 'private'] previous = REQUEST.get('previous_sort', ''); sort = REQUEST.get('sort_by', 'getLastChange'); fulltext = REQUEST.get('searchword', '') if fulltext == 'search' or fulltext == 'otsi': fulltext = '' order = 'ascending' if previous == sort: order = 'descending' if sort == 'getLastChange': order='ascending' else: order = 'ascending' if sort == 'getLastChange': order='descending' query = { 'getUser': user, 'fulltext': fulltext, 'getLicence': licence, 'getDifficulty': REQUEST.get('difficulty', ''), 'getLanguage': REQUEST.get('language', ''), 'getKeywordsTuple': REQUEST.get('keyword', ''), 'getErased': 0, 'getStatus':status, 'sort_on': sort, 'sort_order': order } results = self.cat_ques(query) # also get authenticated user private questions if REQUEST.get('my_ques', '') != 'on' and REQUEST.has_key('search_button') and role == 0: user = str(REQUEST.AUTHENTICATED_USER) status = 'private' query2 = { 'getUser': user, 'fulltext': fulltext, 'getLicence': licence, 'getDifficulty': REQUEST.get('difficulty', ''), 'getLanguage': REQUEST.get('language', ''), 'getKeywordsTuple': REQUEST.get('keyword', ''), 'getErased': 0, 'getStatus': status, 'sort_on': sort, 'sort_order': order } results += self.cat_ques(query2) if not exclude: return results res = [] for x in results: if x.getId in exclude: continue res.append(x) return res def actions(self, REQUEST, remove='', delete_nupp='', zip_nupp=''): """ """ if delete_nupp and not remove: return REQUEST.RESPONSE.redirect('questions.html?message=Choose questions to delete!') if isinstance(remove, type('')): remove = [remove,] if delete_nupp: user = str(REQUEST.get('AUTHENTICATED_USER')) for ques in remove: q = self.getQuestionById(ques) creator = q.getUser() if str(user) == creator: q._setErased() if (q.getWaramuUid() != ""): q._deleteFromWaramu(); q.reindex_object() if zip_nupp: if remove == ['']: return REQUEST.RESPONSE.redirect('questions.html?message=Choose questions to export!') export_data = self._makeZip(remove) REQUEST.RESPONSE.setHeader('content-type', 'application/zip') REQUEST.RESPONSE.setHeader('Content-disposition','attachment; filename=questions.zip') return export_data return REQUEST.RESPONSE.redirect('questions.html') def getLargestNumber(self, suva): highest=0 for x in suva: number=x.replace('v', '') number=int(number.replace('coords', '')) if number>highest: highest=number return highest def getQuestionTypes(self): return self.configuration.getTypesList() def getQuesName(self, qtype): return self.configuration.getName(qtype) def getEditTemplateName(self, REQUEST): return self.configuration.getEdit(REQUEST.get('type')) def getViewTemplateName(self, REQUEST, qtype=''): qt = '' if qtype: qt = qtype else: qt = REQUEST.get('type') return self.configuration.getView(qt) def getTypeFactor(self, REQUEST): return self.configuration.getFactor(REQUEST.get('type')) def getQuestion(self, REQUEST): """ """ REQUEST.RESPONSE.setHeader('Content-Type', 'text/html; charset=UTF-8') return "" def batch_previous(self, batch): """ generate links to next and previous pages """ result = [] while batch.previous: batch = batch.previous result.append(batch.start-1) result.reverse() return result def batch_next(self, batch): """ generate links to next and previous pages """ result = [] while batch.next: batch = batch.next result.append(batch.start-1) return result def getHelpText(self, qtype): """ get question helptext """ helptext = self.configuration.getHelptext(qtype) if helptext: return self.utranslate(qtype+'_helptext', helptext) def getQuesStat(self, ques_id): """ """ query = {'getQuesId': ques_id,} results = self.cat_answers(query) correctans = self.cat_answers({'getQuesId': ques_id, 'isCorrect': True}) wrongans = self.cat_answers({'getQuesId':ques_id, 'isCorrect': False}) return [len(results), len(correctans), len(wrongans)] def getQuesinTestsCount(self, ques_id): """ in how many tests is question """ query = {'getQuestions':ques_id, 'getErased':0} results = self.cat_tests(query) users = [] for res in results: author = res.getUser if author not in users: users.append(author) return [len(users), len(results)] def fixQuestions(self): """ fix description, keywords """ ques_objs = self.objectValues() for ques in ques_objs: lang = ques.getLanguage() desc = ques.getDescription() desc_dict = {} desc_dict[lang] = desc ques.setDescription(desc_dict) keywords = ques.getKeywords() keys_dict = {} keys_dict[lang] = keywords ques.setKeywords(keys_dict) security.declareProtected('QTAuthor: Create question', 'add_new_choice') def add_new_choice(self, REQUEST, imported=False): """ """ id=self.random_generator() obj=Choice.ChoiceType(id) user = str(REQUEST.get('AUTHENTICATED_USER')) obj.setUser(user) self._setObject(id, obj) obj = getattr(self, id) obj._setHtmlUid() obj.setCreatingDay() if not imported: obj.changeQuestion(REQUEST, add=1) if imported: return obj security.declareProtected('QTAuthor: Create question', 'add_new_choice') def add_new_multiple(self, REQUEST, imported=False): """ """ id=self.random_generator() obj=Choice_multiple.ChoiceMultiple(id) user = str(REQUEST.get('AUTHENTICATED_USER')) obj.setUser(user) self._setObject(id, obj) obj = getattr(self, id) obj._setHtmlUid() obj.setCreatingDay() if not imported: obj.changeQuestion(REQUEST, add=1) if imported: return obj security.declareProtected('QTAuthor: Create question', 'add_new_order') def add_new_order(self, REQUEST, imported=False): """ """ id=self.random_generator() obj=Order.OrderType(id) user = str(REQUEST.get('AUTHENTICATED_USER')) obj.setUser(user) self._setObject(id, obj) obj = getattr(self, id) obj._setHtmlUid() obj.setCreatingDay() if not imported: obj.changeQuestion(REQUEST, add=1) if imported: return obj security.declareProtected('QTAuthor: Create question', 'add_new_associate') def add_new_associate(self, REQUEST, imported=False): """ """ id=self.random_generator() obj=associate.AssociateType(id) user = str(REQUEST.get('AUTHENTICATED_USER')) obj.setUser(user) self._setObject(id, obj) obj = getattr(self, id) obj._setHtmlUid() obj.setCreatingDay() if not imported: obj.changeQuestion(REQUEST, add=1) if imported: return obj security.declareProtected('QTAuthor: Create question', 'add_new_match') def add_new_match(self, REQUEST, imported=False): """ """ id=self.random_generator() obj=Match.MatchType(id) user = str(REQUEST.get('AUTHENTICATED_USER')) obj.setUser(user) self._setObject(id, obj) obj = getattr(self, id) obj._setHtmlUid() obj.setCreatingDay() if imported: return obj obj.changeQuestion(REQUEST, add=1) security.declareProtected('QTAuthor: Create question', 'add_new_gap_match') def add_new_gap_match(self, REQUEST, imported=False): """ """ id=self.random_generator() obj=Gap_match.GapMatchType(id) user = str(REQUEST.get('AUTHENTICATED_USER')) obj.setUser(user) self._setObject(id, obj) obj = getattr(self, id) obj._setHtmlUid() obj.setCreatingDay() if imported: return obj obj.changeQuestion(REQUEST) security.declareProtected('QTAuthor: Create question', 'add_new_inline_choice') def add_new_inline_choice(self, REQUEST, imported=False): """ """ id=self.random_generator() obj=Inline_choice.InlineChoiceType(id) user = str(REQUEST.get('AUTHENTICATED_USER')) obj.setUser(user) self._setObject(id, obj) obj = getattr(self, id) obj._setHtmlUid() obj.setCreatingDay() if imported: return obj obj.changeQuestion(REQUEST) security.declareProtected('QTAuthor: Create question', 'add_new_text_entry') def add_new_text_entry(self, REQUEST, imported=False): """ """ id=self.random_generator() obj=Text_entry.TextEntryType(id) user = str(REQUEST.get('AUTHENTICATED_USER')) obj.setUser(user) self._setObject(id, obj) obj = getattr(self, id) obj._setHtmlUid() obj.setCreatingDay() if imported: return obj obj.changeQuestion(REQUEST) security.declareProtected('QTAuthor: Create question', 'add_new_extended_text') def add_new_extended_text(self, REQUEST, imported=False): """ """ id=self.random_generator() obj=Extended_text.ExtendedTextType(id) user = str(REQUEST.get('AUTHENTICATED_USER')) obj.setUser(user) self._setObject(id, obj) obj = getattr(self, id) obj._setHtmlUid() obj.setCreatingDay() if imported: return obj obj.changeQuestion(REQUEST, add=1) security.declareProtected('QTAuthor: Create question', 'add_new_hottext') def add_new_hottext(self, REQUEST, imported=False): """ """ id=self.random_generator() obj=Hottext.HotTextType(id) user = str(REQUEST.get('AUTHENTICATED_USER')) obj.setUser(user) self._setObject(id, obj) obj = getattr(self, id) obj._setHtmlUid() obj.setCreatingDay() if imported: return obj obj.changeQuestion(REQUEST) security.declareProtected('QTAuthor: Create question', 'add_new_slider') def add_new_slider(self, REQUEST, imported=False): """ """ id=self.random_generator() obj=Slider.SliderType(id) user = str(REQUEST.get('AUTHENTICATED_USER')) obj.setUser(user) self._setObject(id, obj) obj = getattr(self, id) obj._setHtmlUid() obj.setCreatingDay() if imported: return obj obj.changeQuestion(REQUEST, add=1) security.declareProtected('QTAuthor: Create question', 'add_new_hotspot') def add_new_hotspot(self, REQUEST): """ """ hotspotpic = 0 id = self.random_generator() chosenPicture = REQUEST.get('picture', '') if chosenPicture == '': hotspotpic = 1 if hotspotpic == 1: return REQUEST.RESPONSE.redirect('questions/hotspot_type.html') picture = getattr(self.images, chosenPicture) picHeight = picture.height + 15 return REQUEST.RESPONSE.redirect('edit?type=hotspot_type&pic='+chosenPicture+'&height='+str(picHeight)) security.declareProtected(perm_create_question, 'create_new_hotspot_obj') def create_new_hotspot_obj(self, REQUEST, imported=False): """ """ id = self.random_generator() obj = Hotspot.HotSpotType(id) user = str(REQUEST.get('AUTHENTICATED_USER')) obj.setUser(user) obj.setCreatingDay() self._setObject(id, obj) obj = getattr(self, id) obj._setHtmlUid() if imported: return obj obj.setPicture(REQUEST.get('chosenPicture', '')) obj.changeQuestion(REQUEST, add=1) def getHotspotPicture(self, id): """ """ try: picture = getattr(self.images, id) except AttributeError: return "" x = str(picture) suva = x.split('/>') pic = suva[0] + ' onmousedown="showCoords(event);"/>' return pic #security.declareProtected('QTAuthor: Create question', 'add_new_video') def add_new_video(self, title, video, REQUEST): """ """ self.videos.add_new_video(title, video, REQUEST) def hasPermissionToView(self, context, user): return True def importQuestions(self, quesfile, REQUEST): """ """ ques_filename = quesfile.filename ques_filetype = ques_filename.split(".") if (ques_filetype[1] == "jqz"): self.importJQuizQuestions(quesfile, REQUEST) elif (ques_filetype[1] == "jcl"): self.importJClozeQuestions(quesfile, REQUEST) elif (ques_filetype[1] == 'zip'): self.importQTIQuestions(quesfile, REQUEST) else: pass def html_to_text(self, html): """ Simple parse, change

to \n\n and
to \n and remove all other html-tags """ user = str(REQUEST.get('AUTHENTICATED_USER')) html_strip=re.compile(r""" (?P<\s*?/p\s*?>\n?) # closing paragraph tag,

< /p >,

|(?P<\s?br[\s/]*?>\n?) #
-tag or
or < br/>... |(?P<.*?>\s*?) """, re.IGNORECASE | re.VERBOSE | re.MULTILINE | re.DOTALL) def replacements(match): # if match.group('paragraph'): # return '\n\n' if match.group('linebreak'): return ' ' elif match.group('lonetag'): return '' # else: return '' return '' return html_strip.sub(replacements, html) def importJQuizQuestions(self, quesfile, REQUEST): """ import hot potatoes questions made with jquiz """ file = quesfile.read() from xml.sax.saxutils import unescape file = unescape(file) import xml.dom.minidom dom = xml.dom.minidom.parseString(file.encode('utf-8')) questions = dom.getElementsByTagName("question-record") for ques in questions: questiontype = ques.getElementsByTagName("question-type")[0].childNodes[0].data questiontext = ques.getElementsByTagName("question")[0].childNodes[0].data #print "questext before: ", questiontext.encode('utf-8') qtext = self.html_to_text(questiontext) #print "questext after: ", qtext.encode('utf-8') answers = ques.getElementsByTagName("answer") correct_answers = 0 # if jquiz question type is multiple choice, hybrid or multiple correct if (int(questiontype) != 3): # calculate how many correct answers (is it choice type or choice_multiple) for answer in answers: correct = answer.getElementsByTagName("correct")[0].childNodes[0].data # 1-correct 0-false #answertext = answer.getElementsByTagName("text")[0].childNodes[0].data.encode('utf-8') if (int(correct) == 1): correct_answers += 1 # if choice type (only one correct answer) if (correct_answers == 1): obj = self.add_new_choice(REQUEST, True) variants = {} rightanswers = {} feedbacks = {} counter = 0 for answer in answers: if (answer.getElementsByTagName("text")[0].childNodes): answertext = answer.getElementsByTagName("text")[0].childNodes[0].data answertext = self.html_to_text(answertext) correct_ans = answer.getElementsByTagName("correct")[0].childNodes[0].data counter += 1 if (answer.getElementsByTagName("feedback")[0].childNodes): feedback = answer.getElementsByTagName("feedback")[0].childNodes[0].data else: feedback = '' if (int(correct_ans) == 1): rightanswers['val'] = 'v'+str(counter) variants['v'+str(counter)] = answertext feedbacks['v'+str(counter)] = feedback obj.setQuestion(questiontext) obj.setAnswers(variants, rightanswers, len(answers)+1, feedbacks, '', '') obj.setAuthor(str(REQUEST.get('AUTHENTICATED_USER'))) obj.reindex_object() else: obj = self.add_new_multiple(REQUEST, True) variants = {} rightanswers = {} points = {} counter = 0 for answer in answers: if (answer.getElementsByTagName("text")[0].childNodes): answertext = answer.getElementsByTagName("text")[0].childNodes[0].data answertext = self.html_to_text(answertext) correct_ans = answer.getElementsByTagName("correct")[0].childNodes[0].data counter += 1 if (int(correct_ans) == 1): rightanswers['v'+str(counter)] = 'v'+str(counter) points['v'+str(counter)] = 1 else: points['v'+str(counter)] = 0 variants['v'+str(counter)] = answertext obj.setQuestion(questiontext) obj.setAnswers(variants, rightanswers, counter) obj.setPoints(points) obj.setAuthor(str(REQUEST.get('AUTHENTICATED_USER'))) obj.reindex_object() # if jquiz question type is text, then create text_entry type question #elif (int(questiontype) == 3): # obj = self.add_new_text_entry(REQUEST, True) # ques = questext + "
" # for answer in answers: def importJClozeQuestions(self, quesfile, REQUEST): """ import hot potatoes questions made with JCloze """ file = quesfile.read() from xml.sax.saxutils import unescape file = unescape(file) import xml.dom.minidom dom = xml.dom.minidom.parseString(file.encode('utf-8')) gap_fill_tag = dom.getElementsByTagName("gap-fill")[0] #print "gap_fill_tag_childnodes: ", gap_fill_tag.childNodes #questiontext = gap_fill_tag.childNodes[0].data questiontext = "" for child in gap_fill_tag.childNodes: if child.nodeType == child.TEXT_NODE: questiontext += self.html_to_text(child.data) else: # get correct answers answers = child.getElementsByTagName("answer") gap_answers = "" for answer in answers: answertext = answer.getElementsByTagName("text")[0].childNodes[0].data gap_answers += "{"+answertext+"}" questiontext += gap_answers #print "questiontext: ", questiontext.encode('utf-8') def importQTIQuestions(self, quesfile, REQUEST): """ """ import zipfile z = zipfile.ZipFile(quesfile, "r") for filename in z.namelist(): print 'filename:', filename filetype = filename.split(".") print ("filenamelen: "+str(len(filetype))) if (len(filetype) == 1): continue filetype = filetype[1] if filetype != 'xml': pass #im = z.read(filename) #print im #self.images.add_new(image=im, imported=True) else: #data = z.read(filename).encode('utf-8', 'ignore') data = z.read(filename) import xml.dom.minidom dom = xml.dom.minidom.parseString(data) if dom.getElementsByTagName("assessmentItem"): item = dom.getElementsByTagName("assessmentItem") title = item[0].getAttribute("title") if dom.getElementsByTagName("choiceInteraction"): res = dom.getElementsByTagName("responseDeclaration") cardinality = res[0].getAttribute("cardinality") if cardinality == 'single': #tee uus choice objekt obj = self.add_new_choice(REQUEST, True) if cardinality == 'multiple': #tee uus choice_multiple objekt obj = self.add_new_multiple(REQUEST, True) if dom.getElementsByTagName("orderInteraction"): obj = self.add_new_order(REQUEST, True) if dom.getElementsByTagName("associateInteraction"): obj = self.add_new_associate(REQUEST, True) if dom.getElementsByTagName("matchInteraction"): obj = self.add_new_match(REQUEST, True) if dom.getElementsByTagName("gapMatchInteraction"): obj = self.add_new_gap_match(REQUEST, True) if dom.getElementsByTagName("inlineChoiceInteraction"): obj = self.add_new_inline_choice(REQUEST, True) if dom.getElementsByTagName("textEntryInteraction"): obj = self.add_new_text_entry(REQUEST, True) if dom.getElementsByTagName("extendedTextInteraction"): obj = self.add_new_extended_text(REQUEST, True) if dom.getElementsByTagName("hottextInteraction"): obj = self.add_new_hottext(REQUEST, True) if dom.getElementsByTagName("sliderInteraction"): obj = self.add_new_slider(REQUEST, True) if dom.getElementsByTagName("hotspotInteraction"): continue obj = self.create_new_hotspot_object(REQUEST, True) obj.setTitle(title.encode('utf-8')) additional = obj.importQuestion(data, dom) for a in additional: im = z.read(a) #print 'fnimi:',im.filename new_img_id = additional.get(a) user = str(REQUEST.get('AUTHENTICATED_USER')) self.images.add_new(id=new_img_id, image=im, user=user) #if dom.getElementsByTagName("manifest"): manifest = z.read('imsmanifest.xml') dom = xml.dom.minidom.parseString(manifest) resources = dom.getElementsByTagName("resource") for res in resources: res_file = res.getAttribute("href") if filename == res_file: if res.getElementsByTagName("imsmd:general"): general = res.getElementsByTagName("imsmd:general") title = general[0].getElementsByTagName("imsmd:title") lang = title[0].getElementsByTagName("imsmd:langstring") lang = lang[0].getAttribute("xml:lang") obj.setLanguage(lang.encode('utf-8')) desc = general[0].getElementsByTagName("imsmd:description") desc_dict = {} desc_dict[lang] = desc # try: # description = desc[0].childNodes[0].data # obj.setDescription(description.encode('utf-8')) # except: pass keywords = general[0].getElementsByTagName("imsmd:keyword") keys = '' keys_dict = {} for key in keywords: i = keywords.index(key) keyword = key.getElementsByTagName("imsmd:langstring") if keyword[0].childNodes: keyword = keyword[0].childNodes[0].data keys += keyword.encode('utf-8') if i+1 != len(keywords): keys += ', ' keys_dict[lang] = keys obj.setKeywords(keys_dict) user = str(REQUEST.get('AUTHENTICATED_USER')) #obj.setKeywords2(obj.getKeywordsTuple(), user) #print 'keywords::', keys diff = general[0].getElementsByTagName("imsmd:difficulty") diff = diff[0].getElementsByTagName("imsmd:langstring") diff = diff[0].childNodes[0].data #print 'difficulty::', diff obj.setDifficulty(diff.encode('utf-8')) rights = res.getElementsByTagName("imsmd:rights") rights_desc = rights[0].getElementsByTagName("imsmd:description") rights_desc = rights_desc[0].getElementsByTagName("imsmd:langstring") licence = rights_desc[0].childNodes[0].data obj.setLicence(licence.encode('utf-8')) obj.reindex_object() Globals.InitializeClass(Questions) # EOF