def createIndicoLink(IndicoID, CDSID): """Create a link in Indico to the CDS record.""" # Logger.get('RecMan').debug("in createIndicoLink()") # From IndicoID, get info try: talkInfo = parseIndicoID(IndicoID) except NoReportError: return False obj = talkInfo["object"] # Only one link per talk allowed. if doesExistIndicoLink(obj): return True # consider it a success anyway else: # Logger.get('RecMan').info("creating a new link in Indico for talk %s, CDS record %s" % (IndicoID, CDSID)) # material object holds link object. # First create a material object with title "Video in CDS" or whatever the current text is. material = conference.Material() material.setTitle( CollaborationTools.getOptionValue("RecordingManager", "videoLinkName")) videoLink = Link() videoLink.setOwner(material) # I don't think this stuff is necessary: # videoLink.setName("Name goes here") # videoLink.setDescription("Description goes here") videoLink.setURL( CollaborationTools.getOptionValue("RecordingManager", "CDSBaseURL") % str(CDSID)) material.addResource(videoLink) material.setMainResource(videoLink) obj.addMaterial(material) return True
def create(contrib, matFactory, matData): if matFactory: m = matFactory.create(contrib) else: m = conference.Material() contrib.addMaterial(m) m.setValues(matData) return m
def __addMaterials(self, subcontrib): if self._materials: for material in self._materials.keys(): newMaterial = conference.Material() newMaterial.setTitle(material) for resource in self._materials[material]: newLink = conference.Link() newLink.setURL(resource) newLink.setName(resource) newMaterial.addResource(newLink) subcontrib.addMaterial(newMaterial)
def setUp(self): super(TestProtection, self).setUp() self._startDBReq() # Create a user ah = AvatarHolder() self._avatar = Avatar() self._avatar.setName("fake") self._avatar.setSurName("fake") self._avatar.setOrganisation("fake") self._avatar.setLang("en_GB") self._avatar.setEmail("*****@*****.**") self._avatar.setId("fake") ah.add(self._avatar) # Create a conference category = conference.CategoryManager().getById('0') self._conf = category.newConference(self._avatar) self._conf.setTimezone('UTC') sd = datetime(2011, 11, 1, 10, 0, tzinfo=timezone('UTC')) ed = datetime(2011, 11, 1, 18, 0, tzinfo=timezone('UTC')) self._conf.setDates(sd, ed) ch = ConferenceHolder() ch.add(self._conf) self._contrib1 = conference.Contribution() self._conf.addContribution(self._contrib1) self._session1 = conference.Session() self._conf.addSession(self._session1) self._session2 = conference.Session() self._conf.addSession(self._session2) self._contrib2 = conference.Contribution() self._session1.addContribution(self._contrib2) #Now we create the material (id=0) and attach it to the contrib self._material = conference.Material() self._contrib1.addMaterial(self._material) #Now we create a dummy file and attach it to the material filePath = os.path.join(os.getcwd(), "test.txt") fh = open(filePath, "w") fh.write("hola") fh.close() self._resource = conference.LocalFile() self._resource.setFilePath(filePath) self._resource.setFileName("test.txt") self._material.addResource(self._resource) self._stopDBReq()
def _process(self): params = self._getRequestParams() if params["title"] == "": params["title"] = "No Title" # change number of dates (lecture) if self._confirm == True: if self._event_type != "simple_event": c = self._createEvent(self._params) self.alertCreation([c]) # lectures else: lectures = [] for i in range(1, int(self._params["nbDates"]) + 1): self._params["sDay"] = self._params.get("sDay_%s" % i, "") self._params["sMonth"] = self._params.get( "sMonth_%s" % i, "") self._params["sYear"] = self._params.get( "sYear_%s" % i, "") self._params["sHour"] = self._params.get( "sHour_%s" % i, "") self._params["sMinute"] = self._params.get( "sMinute_%s" % i, "") self._params["duration"] = int( self._params.get("dur_%s" % i, 60)) lectures.append(self._createEvent(self._params)) self.alertCreation(lectures) lectures.sort(sortByStartDate) # create links for i in range(0, len(lectures)): lecture = lectures[i] if len(lectures) > 1: lecture.setTitle( "%s (%s/%s)" % (lecture.getTitle(), i + 1, len(lectures))) for j in range(0, len(lectures)): if j != i: mat = conference.Material() mat.setTitle("part%s" % (j + 1)) url = str( urlHandlers.UHConferenceDisplay.getURL( lectures[j])) link = conference.Link() link.setURL(url) link.setName(url) mat.addResource(link) lecture.addMaterial(mat) c = lectures[0] self._redirect(urlHandlers.UHConferenceModification.getURL(c)) else: url = urlHandlers.UHCategoryDisplay.getURL(self._target) self._redirect(url)
def _process(self): try: try: m = self._target.getMaterialById(self._title) except: m = None if m == None: m = conference.Material() self._target.addMaterial(m) params = {"title": self._title} m.setValues(params) l = conference.Link() l.setURL(self._value) m.addResource(l) m.setMainResource(l) except MaKaCError, e: return self._createResponse("ERROR", e.getMsg())
def _getAnswer(self): """ Creates the material class, and sets its properties """ mats = self._target.getMaterialList() for m in mats: if m.getTitle() == self._matName: raise ServiceError( "ERR-M1", _("A material with this same name already exists")) mat = conference.Material() mat.setTitle(self._matName) mat.setDescription(self._matDescription) self._target.addMaterial(mat) return DictPickler.pickle(mat)
def setUp(self): super(TestProtection, self).setUp() with self._context("database"): # Create a conference category = conference.CategoryManager().getById('0') self._conf = category.newConference(self._dummy) self._conf.setTimezone('UTC') sd = datetime(2011, 11, 1, 10, 0, tzinfo=timezone('UTC')) ed = datetime(2011, 11, 1, 18, 0, tzinfo=timezone('UTC')) self._conf.setDates(sd, ed) ch = ConferenceHolder() ch.add(self._conf) self._contrib1 = conference.Contribution() self._conf.addContribution(self._contrib1) self._session1 = conference.Session() self._conf.addSession(self._session1) self._session2 = conference.Session() self._conf.addSession(self._session2) self._contrib2 = conference.Contribution() self._session1.addContribution(self._contrib2) #Now we create the material (id=0) and attach it to the contrib self._material = conference.Material() self._contrib1.addMaterial( self._material ) #Now we create a dummy file and attach it to the material filePath = os.path.join( os.getcwd(), "test.txt" ) fh = open(filePath, "w") fh.write("hola") fh.close() self._resource = conference.LocalFile() self._resource.setFilePath( filePath ) self._resource.setFileName( "test.txt" ) self._material.addResource( self._resource )
def create(self, target): m = conference.Material() m.setTitle(self.name) target.addMaterial(m) return m
def getSubTalks(t, talk): #method for mapping subtalks. #Program logic is correct so just needs changed to fit the way subtalks are implemented cst = agenda.cursor() #creates cursor and gets all the subtalks cst.execute("select * from SUBTALK where fidt = \'" + t[2] + "\' and ida = \'" + t[0] + "\' order by stime") st = cst.fetchone() #gets the first subtalk on the list #st[0]-ida, st[1]-ids, st[2]-idt, st[3]-ttitle, st[4]-tspeaker, st[5]-tday, st[6]-tcomment, st[7]-type #st[8]-cd, st[9]-md, st[10]-stime, st[11]-repno, st[12]-affiliation, st[13]-duration, st[14]-fidt, st[15]-email while st != None: #while there are subtalk sub = talk.newSubContribution() #add new subtalk to the contribution sub.setTitle(st[3]) #sets the details sub.setDescription(st[6]) #sub.setStartDate(st[6].year, st[6].month, st[6].day, st[11].seconds/3600, st[11].seconds % 3600) / 60) #get_transaction().commit() #sub.setEndTime(end.hour, end.minute) #sub.setDuration(st[13][0:2],st[13][3:5])X sub.setDuration(st[13].seconds / 3600, (st[13].seconds % 3600) / 60) #SPEAKERS if st[4] == None: username = '' else: username = st[4] usernames = username.split(";") if st[15] == None: uemail = '' else: uemail = st[15].replace(" ", "") if username == '' or uemail == '' or username.count( " " ) >= max_white_space_in_names: #if not full user details exist if username != '' or uemail != '': if username != '': speakertext = username else: speakertext = uemail if uemail != '': speakertext = "<a href=\"mailto:%s\">%s</a>" % ( uemail, speakertext) sub.setSpeakerText(speakertext) else: for name in usernames: pw = genPW() #generates random passwor speaker = getUser(name, uemail, st[12], pw) #creates a user representing the speaker sub.addSpeaker(speaker) #and adds the user to the list #FILES cf.execute( "select * from FILE, FILE_EVENT where FILE.id = fileID and eventID = \'" + st[0] + st[1] + st[2] + "\'") f = cf.fetchone() while f != None: type = f[2] if type == "minutes": mi = sub.getMinutes() if not mi: mi = sub.createMinutes() if f[5] == t[0] + t[1] + t[2] + ".txt": getMinutes(mi, f) else: getFiles(mi, f) else: list = sub.getMaterialList() found = 0 #if type in list get existing material for i in list: if i.getTitle() == type: found = 1 mat = i if found: getFiles(mat, f) #add resources to material else: #if not then create new material with name 'type' mat = conference.Material() mat.setTitle(type) sub.addMaterial(mat) getFiles(mat, f) #add resources to material f = cf.fetchone() #get next file/resource st = cst.fetchone()
def addTalksToSession(s, ses, slot): ct = agenda.cursor( ) #creates a cursor and gets all the Talks associated with this session ct.execute("select * from TALK where ids = \'" + s[1] + "\' and ida = \'" + s[0] + "\'") t = ct.fetchone() #selects the first talk from the list #t[0]-ida, t[1]-ids, t[2]-idt, t[3]-ttitle, t[4]-tspeaker, t[5]-tday, t[6]-tcomment, t[7]-location #t[8]-bld, t[9]-floor, t[10]-room, t[11]-broadcasturl, t[12]-type, t[13]-cd, t[14]-md, t[15]-category #t[16]-stime, t[17]-repno, t[18]-affiliation, t[19]-duration, t[20]-email while t != None: #if there is another talk if t[5] != None: if t[12] == 2: #if talk is of type break br = schedule.BreakTimeSchEntry() br.setTitle(t[3]) #sets the break details br.setDescription(t[6]) br.setColor("#90C0F0") br.setStartDate( datetime(t[5].year, t[5].month, t[5].day, int(t[16].seconds / 3600), int((t[16].seconds % 3600) / 60), 2)) try: br.setDuration(int(t[19].seconds / 3600), int((t[19].seconds % 3600) / 60)) except Exception, e: log("error setting break end time %s-%s-%s: %s" % (t[0], t[1], t[2], e)) #get_transaction().abort() slot.getSchedule().addEntry(br, 2) #create a new break slot.getSchedule().reSchedule() else: talk = ses.newContribution( id="%s%s" % (t[1], t[2])) #adds a contribution to the session if t[15] != '': title = "<b>%s</b><br>%s" % (t[15], t[3]) else: title = t[3] talk.setTitle(title) #sets the contribution details talk.setDescription(t[6]) #talk.setCategory(t[15]) #sets category header for talks. Mainly used in seminars for the week of. Not in MaKaC if t[7] != "0--": loc = conference.CustomLocation() loc.setName(t[7]) #get_transaction().commit() pw = genPW() #generates random password if t[4] == None: username = '' else: username = t[4] if t[20] == None: uemail = '' else: uemail = t[20] if t[18]: aff = t[18] else: aff = '' if username == '' or uemail == '' or username.count( " " ) >= max_white_space_in_names: #if not full user details exist if username != '' or uemail != '': if username != '': speakertext = username else: speakertext = uemail if uemail != '': speakertext = "<a href=\"mailto:%s\">%s</a>" % ( uemail, speakertext) if aff != '': speakertext = "%s (%s)" % (speakertext, aff) talk.setSpeakerText(speakertext) else: speaker = getUser( username, uemail, aff, pw) #creates a user representing the speaker part = conference.ContributionParticipation() part.setDataFromAvatar(speaker) talk.addPrimaryAuthor(part) talk.addSpeaker(part) #and adds the user to the list if t[10] != "0--": talk.setLocation(loc) loc = conference.CustomRoom() loc.setName(t[10]) talk.setRoom(loc) if t[5] != None: talk.setStartDate( datetime(t[5].year, t[5].month, t[5].day, int(t[16].seconds / 3600), int((t[16].seconds % 3600) / 60)), 2) talk.setDuration(t[19].seconds / 3600, (t[19].seconds % 3600) / 60) #gets the files associated with this talk cf.execute( "select * from FILE, FILE_EVENT where FILE.id = fileID and eventID = \'" + t[0] + t[1] + t[2] + "\'") f = cf.fetchone() while f != None: type = f[2] if type == "minutes": mi = talk.getMinutes() if not mi: mi = talk.createMinutes() if f[5] == t[0] + t[1] + t[2] + ".txt": getMinutes(mi, f) else: getFiles(mi, f) else: list = talk.getMaterialList() found = 0 #if type in list get existing material for i in list: if i.getTitle() == type: found = 1 mat = i if found: getFiles(mat, f) #add resources to material else: #if not then create new material with name 'type' mat = conference.Material() mat.setTitle(type) talk.addMaterial(mat) getFiles(mat, f) #add resources to material f = cf.fetchone() #get next file/resource getSubTalks( t, talk) #call to the function which would map the subtalks sch = slot.getSchedule() try: sch.addEntry(talk.getSchEntry(), 2) except Exception, e: log("%s-%s-%s: %s" % (t[0], t[1], t[2], e))
def getSessions(c, conf): cs = agenda.cursor( ) #craetes a cursor and selects all the seesion data for that conference cs.execute("select * from SESSION where ida = \'" + c[1] + "\'") s = cs.fetchone() #s[0]-ida, s[1]-ids, s[2]-schairman, s[3]-speriod1, s[4]-stime, s[5]-eperiod1, s[6]-etime, s[7]-stitle #s[8]-snbtalks, s[9]-slocation, s[10]-scem, s[11]-sstatus, s[12]-bld, s[13]-floor #s[14]-room, s[15]-broadcasturl, s[16]-cd, s[17]-md, s[18]-scomment while s != None: #while there are more session if c[12] == "nosession" and c[5] == 1: ses = conf else: ses = conference.Session() #add a new seesion to the conference slot = conference.SessionSlot(ses) if (s[3] == s[5]) and ( s[4] == s[6] ): #if session has length of 0 set length to 1min so as not to raise exception. Results in sessions of 1min being created during mapping min = (s[6].seconds % 3600) / 60 sd = datetime(s[3].year, s[3].month, s[3].day, s[4].seconds / 3600, (s[4].seconds % 3600) / 60) ed = datetime(s[5].year, s[5].month, s[5].day, s[6].seconds / 3600, min) ses.setStartDate(sd, 2) #set the session properties ses.setEndDate(ed, 2) slot.setDates(sd, ed, 2) else: try: sd = datetime(s[3].year, s[3].month, s[3].day, int(s[4].seconds / 3600), int((s[4].seconds % 3600) / 60)) ses.setStartDate(sd, 2) #set the session properties if (s[5] != None) and (s[6] != None): ed = datetime(s[5].year, s[5].month, s[5].day, int(s[6].seconds / 3600), int((s[6].seconds % 3600) / 60)) else: ed = datetime(s[3].year, s[3].month, s[3].day, int(s[4].seconds / 3600), int((s[4].seconds % 3600) / 60)) ses.setEndDate(ed, 2) slot.setDates(sd, ed, 2) except (Exception, AttributeError, MaKaCError), e: log("error adding session %s:%s, start or end date note found:%s" % (s[0], s[1], e)) conf.removeSession(ses) ses = None return ses.addSlot(slot) ses.setTitle(s[7]) #get_transaction().commit() if s[2] == None: username = '' else: username = s[2] if s[10] == None: uemail = '' else: uemail = s[10] if username == '' or uemail == '' or username.count( " " ) >= max_white_space_in_names: #if not full user details exist if username != '' or uemail != '': if username != '': convenertext = username else: convenertext = uemail if uemail != '': convenertext = "<a href=\"mailto:%s\">%s</a>" % ( uemail, convenertext) ses.setConvenerText(convenertext) else: pw = genPW() #generates random password convener = getUser( username, uemail, '', pw) #creates a user representing the convener part = conference.SessionChair() part.setDataFromAvatar(convener) ses.addConvener(part) #and adds the user to the list if s[11] == "close": ses.setClosed(True) if s[9] != "0--": loc = conference.CustomLocation() loc.setName(s[9]) ses.setLocation(loc) if s[14] != "0--": loc = conference.CustomRoom() loc.setName(s[14]) ses.setRoom(loc) if s[18]: ses.setDescription(s[18]) conf.addSession(ses, 2) #gets the files associated with this session cf.execute( "select * from FILE, FILE_EVENT where FILE.id = fileID and eventID = \'" + s[0] + s[1] + "\'") f = cf.fetchone() while f != None: type = f[2] if type == "minutes" and not isinstance(ses, conference.Conference): mi = ses.getMinutes() if not mi: mi = ses.createMinutes() if f[5] == s[0] + s[1] + ".txt": getMinutes(mi, f) else: getFiles(mi, f) else: list = ses.getMaterialList() found = 0 #if type in list get existing material for i in list: if i.getTitle() == type: found = 1 mat = i if found: getFiles(mat, f) #add resources to material else: #if not then create new material with name 'type' mat = conference.Material() mat.setTitle(type) ses.addMaterial(mat) getFiles(mat, f) #add resources to material f = cf.fetchone() #get next file/resource addTalksToSession(s, ses, slot) #gets the talks associated with the session s = cs.fetchone() #gets the next session
def getAgenda(): print "migrating..." log("start getAgenda") cc = agenda.cursor() #creates a new cursor to the database listcat = getAllSubCategories("171") strlistcat = "','".join(listcat) #cc.execute("select * from AGENDA where id='a052023'") #cc.execute("select * from AGENDA where fid in ('%s') and YEAR(cd)=2004 order by id"%strlistcat)#gets the AGENDAS #cc.execute("select * from AGENDA where fid in ('%s') and id>='' order by id"%strlistcat)#gets the AGENDAS #cc.execute("select * from AGENDA where fid = '296'")#gets the AGENDAS cc.execute( "select * from AGENDA where id > 'a015' and id < 'a02' order by id" ) #gets the AGENDAS #cc.execute("select * from AGENDA where id like 'a00%' and cd > '2000-12-01' ")#gets the AGENDAS #cc.execute("select * from AGENDA where id like 'a02%' and id >'a021094' order by id") #cc.execute("select * from AGENDA where id>='a045146' order by id") c = cc.fetchone() #gets the next AGENDA cate = agenda.cursor() #creates a cursor to get the LEVEL informaion #c[0]-title, c[1]-id, c[2]-stdate, c[3]-endate, c[4]-location, c[5]-nbsession, c[6]-chairman, c[7]-cem #c[8]-status, c[9]-an, c[10]-cd, c[11]-md, c[12]-stylesheet, c[13]-format, c[14]-confidentiality #c[15]-apassword, c[16]-repno, c[17]-fid, c[18]-acomments, c[19]-keywords, c[20]-visibility #c[21]-bld, c[22]-floor, c[23]-room, c[24]-stime, c[25]-etime #get CERN domain dh = domain.DomainHolder() CDom = None for dom in dh.getList(): if dom.getName().upper() == "CERN": CDom = dom if not CDom: CDom = domain.Domain() CDom.setName("CERN") CDom.setDescription("CERN domain") CDom.addFiltersFromStr("128.141;128.142;137.138;192.91;194.12;192.16") dh.add(CDom) db.DBMgr.getInstance().commit() error = False ch = conference.ConferenceHolder() while c != None: #db.DBMgr.getInstance().startRequest() try: log("add conference : %s" % c[1]) cate.execute( "select * from LEVEL where uid = \'" + c[17] + "\'") #gets the name of the Category the conf belongs in catWanted = conference.Category( ) #creates Category that the AGENDA should belong to level = cate.fetchone() #sets the category properties catWanted.setName(level[3]) catWanted.setDescription(level[6]) catWanted.setOrder(level[12]) catWanted.setVisibility(level[9]) catWanted.setId(level[0]) category = getCat( catWanted, level[1], level[7] ) #checks to see if this category already exists - if not creates it if category == None: #Conference is in a category to delete: don't add log("Conference %s not added, it's inside a 'to delete' category" % c[1]) db.DBMgr.getInstance().abort() c = cc.fetchone() continue user = getUser('CDS Agenda', '*****@*****.**', '', '') #creates a user representing creator try: cd = datetime(c[10].year, c[10].month, c[10].day) except: cd = datetime(1999, 1, 1) try: md = datetime(c[11].year, c[11].month, c[11].day) except: md = datetime(1999, 1, 1) try: conf = ch.getById(c[1]) except: pass conf = category.newConference( user, c[1], cd, md) #creates new Conference to map onto # update counter #year = c[1][1:3] #count = c[1][3:] #if count == "": # count = 0 #counterName = "CONFERENCE%s" % year #idxs = ch._getTree("counters") #if not idxs.has_key(counterName): # idxs[counterName] = Counter() #idxs[counterName].sync(int(count)) if c[8] == "close": conf.setClosed(True) conf.setTitle(c[0]) conf.setDescription(c[18]) if str(c[20]) == '0' or str(c[20]) == '': visibility = 999 else: visibility = int(c[20]) conf.setVisibility(visibility) startDate = datetime(c[2].year, c[2].month, c[2].day, int(c[24].seconds / 3600), int((c[24].seconds % 3600) / 60)) endDate = None if c[3] != None: endDate = datetime(c[3].year, c[3].month, c[3].day, int(c[25].seconds / 3600), int((c[25].seconds % 3600) / 60)) if not endDate or endDate <= startDate: endDate = datetime(c[2].year, c[2].month, c[2].day, int(c[24].seconds / 3600), int((c[24].seconds % 3600) / 60)) conf.setDates(startDate, endDate) if c[4] != "0--": loc = conference.CustomLocation() loc.setName(c[4]) conf.setLocation(loc) except (MaKaCError, AttributeError), e: log("Error : %s : conference not added" % e) c = cc.fetchone() #gets the next conference error = True if not error: pw = genPW() #generates random password if c[6] == None or c[6] == '\xa0': username = '' else: username = c[6] if c[7] == None: uemail = '' else: uemail = c[7] if uemail == '' or username.count( " " ) >= max_white_space_in_names: #if not full user details exist if username != '' or uemail != '': if username != '': chairtext = username else: chairtext = uemail if uemail != '': chairtext = "<a href=\"mailto:%s\">%s</a>" % ( uemail, chairtext) conf.setChairmanText(chairtext) else: chair = getUser(username, uemail, '', pw) #creates the chairman user conf.addChair(chair) setType(c[12], conf.getId()) #sets the format of the agenda if c[13] == 'olist': #facility to cope with this not in MaKaC pass #set the format of talks to ordered list (A,B,C etc) rather than times if c[23] != "0--": loc = conference.CustomRoom() loc.setName(c[23]) conf.setRoom(loc) cf = agenda.cursor() #gets the files associated with this conference cf.execute( "select * from FILE, FILE_EVENT where FILE.id = fileID and eventID = \'" + c[1] + "\'") f = cf.fetchone() #gets the first file form the list while f != None: list = conf.getMaterialList() type = f[2] found = 0 #if type in list get existing material for i in list: if i.getTitle() == type: found = 1 mat = i if found: getFiles(mat, f) #add resources to material else: #if not then create new material with name 'type' mat = conference.Material() mat.setTitle(type) conf.addMaterial(mat) getFiles(mat, f) #add resources to material f = cf.fetchone() #get next file/resource if c[12] == "nosession": #if there are no sessions look for contributions that go directly onto conference addToConf(c, conf) else: getSessions( c, conf) #gets the sessions belonging to this conference confId = conf.getId() # ACCESS CONTROL if c[14] == 'password': #if conference is password protected creates and access user conf.setAccessKey(c[15]) #set the access password conf.setProtection(1) #makes the conference restricted access #conf.grantAccess(colin)#grants access rights to me (for testing reasons) elif c[14] == 'cern-only': conf.requireDomain(CDom) log("added CERN domain") # MODIFICATION RIGHTS conf.setModifKey(c[9]) #add modification key log("Conference added : MaKaC ID : %s" % confId) # DEFAULT STYLE if c[12] in styles.keys(): displayMgr.ConfDisplayMgrRegistery().getDisplayMgr( conf).setDefaultStyle(styles[c[12]]) else: displayMgr.ConfDisplayMgrRegistery().getDisplayMgr( conf).setDefaultStyle("standard") c = cc.fetchone() #gets the next conference else: error = False db.DBMgr.getInstance().commit()