class MaterialEntryRepozer(ConferenceEntryRepozer,RepozerMaterial): def __init__(self, fid=None): self._fid = fid self.confId, self.sessionId, self.talkId, self.materialId = self._fid.split("|") self.ch = ConferenceHolder() conf = self.ch.getById(self.confId) self.matId, self.resId = self.materialId.split('/') if not(self.resId) or self.resId == 'not assigned': self.resId = '0' obj = None if self.talkId: # Material inside Talk if self.sessionId: # Talk inside Session s = conf.getSessionById(self.sessionId) obj = s.getContributionById(self.talkId) else: obj = conf.getContributionById(self.talkId) else: obj = conf self.mat = None if obj: self.mat = obj.getMaterialById(self.matId) self.robj = None self.ext = '' if self.mat: self.res = self.mat.getResourceById(self.resId) self.robj = RepozerMaterial(self.res) self.ext = self.robj.ext def isVisible(self, user): # Only PUBLIC documents are Indexed return True def getMaterial(self): try: return self.robj except: return None def getTitle(self): if not(self.robj): return "- NO TITLE -" else: return self.robj.getTitle() def getDescription(self): return '' def getStartDate(self, aw): return None def getEndDate(self, aw): return None def getTarget(self): return self.getMaterial() def getURL(self): suffix = '' if self.sessionId: suffix += '/session/' + self.sessionId if self.talkId: suffix += '/contribution/' + self.talkId suffix += '/material/' + self.materialId + self.ext return self.ch.getById(self.confId).getURL().replace('/e/','/event/') + suffix
def _getAnswer(self): im = indexes.IndexesHolder() ch = ConferenceHolder() calIdx = im.getIndex("calendar") evtIds = calIdx.getObjectsIn(self._sDate, self._eDate) evtsByCateg = {} for evtId in evtIds: try: evt = ch.getById(evtId) categs = evt.getOwnerList() categname = categs[0].getName() if not evtsByCateg.has_key(categname): evtsByCateg[categname] = [] evtsByCateg[categname].append( ( evt.getTitle().strip(), evt.getAdjustedStartDate().strftime("%d/%m/%Y %H:%M "), evt.getAdjustedEndDate().strftime("%d/%m/%Y %H:%M "), evt.getTimezone(), ) ) except Exception: continue return evtsByCateg
def displayList(res, startdate, enddate, repeat, displayCateg, tz): text = "" ch = ConferenceHolder() day = startdate days = {} found = {} while day <= enddate: for confId in res: c = ch.getById(confId) if day.date() >= c.getAdjustedStartDate(tz).date() and day.date( ) <= c.getAdjustedEndDate(tz).date() and (repeat == 1 or not found.has_key(c)): if not days.has_key(day): days[day] = [] days[day].append(c) found[c] = 1 day = day + datetime.timedelta(days=1) day = startdate while day <= enddate: if days.has_key(day): text += "<br><b>%s</b>" % day.strftime("%A %B %d, %Y") days[day].sort(lambda x, y: cmp( x.calculateDayStartTime(day).time(), y.calculateDayStartTime(day).time())) for c in days[day]: text += displayConf(c, displayCateg, day, tz) day = day + datetime.timedelta(days=1) return text
def displayList(res,tz): text = """ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <TITLE>Forthcoming Seminars</TITLE> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </HEAD> <BODY LINK="#0000FF" VLINK="#800080"> <H1> <A HREF="http://www.cern.ch/"><IMG SRC="http://www.cern.ch/CommonImages/Banners/CERNHeadE.gif" ALT="CERN European Laboratory for Particle Physics" NOSAVE BORDER=0 HEIGHT=20 WIDTH=411></A></H1> <H2> FORTHCOMING SEMINARS / SEMINAIRES A VENIR</H2> """ ch = ConferenceHolder() curDate = None for confId in res: c = ch.getById(confId) if curDate!=c.getAdjustedStartDate(tz): curDate = c.getAdjustedStartDate(tz) text += "<hr>%s<br>" % curDate.strftime("%A %B %d, %Y") text += displayConf(c,tz) return text
def _event_or_shorturl(confId, shorturl_namespace=False, ovw=False): from MaKaC.conference import ConferenceHolder from MaKaC.common.url import ShortURLMapper with DBMgr.getInstance().global_connection(): ch = ConferenceHolder() su = ShortURLMapper() if ch.hasKey(confId): # For obvious reasons an event id always comes first. # If it's used within the short url namespace we redirect to the event namespace, otherwise # we call the RH to display the event if shorturl_namespace: url = UHConferenceDisplay.getURL(ch.getById(confId)) func = lambda: redirect(url) else: params = request.args.to_dict() params['confId'] = confId if ovw: params['ovw'] = 'True' func = lambda: conferenceDisplay.RHConferenceDisplay(None).process(params) elif (shorturl_namespace or app.config['INDICO_COMPAT_ROUTES']) and su.hasKey(confId): if shorturl_namespace: # Correct namespace => redirect to the event url = UHConferenceDisplay.getURL(su.getById(confId)) func = lambda: redirect(url) else: # Old event namespace => 301-redirect to the new shorturl first to get Google etc. to update it url = url_for('.shorturl', confId=confId) func = lambda: redirect(url, 301) else: raise NotFound( _('The specified event with id or tag "%s" does not exist or has been deleted') % confId) return func()
def displayList(res, tz): text = """ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <TITLE>Forthcoming Seminars</TITLE> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </HEAD> <BODY LINK="#0000FF" VLINK="#800080"> <H1> <A HREF="http://www.cern.ch/"><IMG SRC="http://www.cern.ch/CommonImages/Banners/CERNHeadE.gif" ALT="CERN European Laboratory for Particle Physics" NOSAVE BORDER=0 HEIGHT=20 WIDTH=411></A></H1> <H2> FORTHCOMING SEMINARS / SEMINAIRES A VENIR</H2> """ ch = ConferenceHolder() curDate = None for confId in res: c = ch.getById(confId) if curDate != c.getAdjustedStartDate(tz): curDate = c.getAdjustedStartDate(tz) text += "<hr>%s<br>" % curDate.strftime("%A %B %d, %Y") text += displayConf(c, tz) return text
def _event_or_shorturl(confId, shorturl_namespace=False, ovw=False): from MaKaC.conference import ConferenceHolder from MaKaC.common.url import ShortURLMapper with DBMgr.getInstance().global_connection(): ch = ConferenceHolder() su = ShortURLMapper() if ch.hasKey(confId): # For obvious reasons an event id always comes first. # If it's used within the short url namespace we redirect to the event namespace, otherwise # we call the RH to display the event if shorturl_namespace: url = UHConferenceDisplay.getURL(ch.getById(confId)) func = lambda: redirect(url) else: params = request.args.to_dict() params['confId'] = confId if ovw: params['ovw'] = 'True' func = lambda: conferenceDisplay.RHConferenceDisplay(None).process(params) elif (shorturl_namespace or app.config['INDICO_COMPAT_ROUTES']) and su.hasKey(confId): if shorturl_namespace: # Correct namespace => redirect to the event url = UHConferenceDisplay.getURL(su.getById(confId)) func = lambda: redirect(url) else: # Old event namespace => 301-redirect to the new shorturl first to get Google etc. to update it url = url_for('.shorturl', confId=confId) func = lambda: redirect(url, 301) else: raise NotFound( _('The specified event with id or tag "%s" does not exist or has been deleted') % confId) return func()
def export_timetable(self, aw): ch = ConferenceHolder() d = {} for cid in self._idList: conf = ch.getById(cid) d[cid] = ScheduleToJson.process(conf.getSchedule(), self._tz.tzname(None), aw, days=None, mgmtMode=False) return d
def export_timetable(self, aw): ch = ConferenceHolder() d = {} for cid in self._idList: conf = ch.getById(cid) d[cid] = ScheduleToJson.process(conf.getSchedule(), self._tz.tzname(None), aw, days = None, mgmtMode = False) return d
def displayXMLList(res, req, tz, dc=1): ch = ConferenceHolder() xml = xmlGen.XMLGen() xml.openTag("collection") for confId in res: c = ch.getById(confId) xml = displayXMLConf(c, xml, tz, dc) xml.closeTag("collection") return xml.getXml()
def displayXMLList(res, req, tz, dc=1): ch = ConferenceHolder() xml = xmlGen.XMLGen() xml.openTag("collection") for confId in res: c = ch.getById(confId) xml = displayXMLConf(c,xml,tz,dc) xml.closeTag("collection") return xml.getXml()
def call(self): """ Warning! Before creating the conferences and the bookings, you probably want to comment the lines in collaboration.py that actually communicate with the API. This should be used to test the Indico DB performance. """ ch = ConferenceHolder() for i in xrange(1, 0 + 1): #ids of events to remove c = ch.getById(str(i)) c.delete()
def call(self): """ Warning! Before creating the conferences and the bookings, you probably want to comment the lines in collaboration.py that actually communicate with the API. This should be used to test the Indico DB performance. """ ch = ConferenceHolder() for i in xrange(1, 0+1): #ids of events to remove c = ch.getById(str(i)) c.delete()
def main(): DBMgr.getInstance().startRequest() ch = ConferenceHolder() ids = [] print "Getting conference IDs..." for conf in ch.getList(): ids.append(conf.getId()) totalNumberConfs = len(ids) DBMgr.getInstance().endRequest() print "Updating conferences..." i = 0 N_CONF = 10 cErrorList = [] while ids: if len(ids) >= N_CONF: lids = ids[:N_CONF] del ids[:N_CONF] else: lids = ids ids = None for j in range(10): conf = None try: DBMgr.getInstance().startRequest() for id in lids: conf = ch.getById(id) log("check for conference %s: %s/%s" % (conf.getId(), i, totalNumberConfs)) for cont in conf.getContributionList(): #if not isinstance(cont, AcceptedContribution): if "content" in cont.getFields().keys(): if cont.getFields()["content"]: if cont.getFields( )["content"] != cont.description: log(" contribution %s : content field no empty and diffrent from description" % cont.getId()) else: #cont.setField("content",cont.description) cont.getFields()["content"] = cont.description cont._p_changed = 1 else: #cont.setField("content",cont.description) cont.getFields()["content"] = cont.description cont._p_changed = 1 i += 1 DBMgr.getInstance().endRequest() print "wait 0.5s..." sleep(0.5) break except Exception, e: cErrorList.append(conf) i -= N_CONF log("error %s, retry %d time(s)" % (e, int(10 - j))) sleep(int(j)) DBMgr.getInstance().abort()
def main(): DBMgr.getInstance().startRequest() ch = ConferenceHolder() ids = [] print "Getting conference IDs..." for conf in ch.getList(): ids.append(conf.getId()) totalNumberConfs = len(ids) DBMgr.getInstance().endRequest() print "Updating conferences..." i = 0 N_CONF = 10 cErrorList = [] while ids: if len(ids) >= N_CONF: lids = ids[:N_CONF] del ids[:N_CONF] else: lids = ids ids = None for j in range(10): conf = None try: DBMgr.getInstance().startRequest() for id in lids: conf = ch.getById(id) log("check for conference %s: %s/%s" % (conf.getId(), i, totalNumberConfs)) for cont in conf.getContributionList(): # if not isinstance(cont, AcceptedContribution): if "content" in cont.getFields().keys(): if cont.getFields()["content"]: if cont.getFields()["content"] != cont.description: log( " contribution %s : content field no empty and diffrent from description" % cont.getId() ) else: # cont.setField("content",cont.description) cont.getFields()["content"] = cont.description cont._p_changed = 1 else: # cont.setField("content",cont.description) cont.getFields()["content"] = cont.description cont._p_changed = 1 i += 1 DBMgr.getInstance().endRequest() print "wait 0.5s..." sleep(0.5) break except Exception, e: cErrorList.append(conf) i -= N_CONF log("error %s, retry %d time(s)" % (e, int(10 - j))) sleep(int(j)) DBMgr.getInstance().abort()
def displayList(res,tz): text = "" ch = ConferenceHolder() curDate = None for confId in res: c = ch.getById(confId) if curDate!=c.getAdjustedStartDate(tz): curDate = c.getAdjustedStartDate(tz) text += "%s<br>" % curDate.strftime("%A %B %d, %Y") text += displayConf(c,tz) return text
def get_category_scores(avatar, debug=False): attendance_roles = set(['conference_participant', 'contribution_submission', 'abstract_submitter', 'registration_registrant', 'evaluation_submitter']) links = avatar_links.get_links(avatar) ch = ConferenceHolder() attended = filter(None, (ch.getById(eid, True) for eid, roles in links.iteritems() if attendance_roles & roles)) categ_events = defaultdict(list) for event in attended: categ_events[event.getOwner()].append(event) return dict((categ, _get_category_score(avatar, categ, events, debug)) for categ, events in categ_events.iteritems())
def displayList(res, tz): text = "" ch = ConferenceHolder() curDate = None for confId in res: c = ch.getById(confId) if curDate != c.getAdjustedStartDate(tz): curDate = c.getAdjustedStartDate(tz) text += "%s<br>" % curDate.strftime("%A %B %d, %Y") text += displayConf(c, tz) return text
def contribution(self, idlist): ch = ConferenceHolder() event = ch.getById(self._eventId) def _iterate_objs(objIds): for objId in objIds: obj = event.getContributionById(objId) if obj is not None: yield obj return self._process(_iterate_objs(idlist))
def contribution(self, idlist): ch = ConferenceHolder() event = ch.getById(self._eventId) def _iterate_objs(objIds): for objId in objIds: obj = event.getContributionById(objId) if obj is not None: yield obj return self._process(_iterate_objs(idlist))
def get_category_scores(user, debug=False): attendance_roles = {"contribution_submission", "abstract_submitter", "registration_registrant", "survey_submitter"} links = avatar_links.get_links(user) for event_id in get_events_with_submitted_surveys(user): links.setdefault(str(event_id), set()).add("survey_submitter") ch = ConferenceHolder() attended = filter(None, (ch.getById(eid, True) for eid, roles in links.iteritems() if attendance_roles & roles)) categ_events = defaultdict(list) for event in attended: categ_events[event.getOwner()].append(event) return dict((categ, _get_category_score(user, categ, events, debug)) for categ, events in categ_events.iteritems())
def session(self, idlist): ch = ConferenceHolder() event = ch.getById(self._eventId) def _iterate_objs(objIds): for objId in objIds: session = event.getSessionById(objId) for obj in session.getSlotList(): if obj is not None: yield obj return self._process(_iterate_objs(idlist))
def session(self, idlist): ch = ConferenceHolder() event = ch.getById(self._eventId) def _iterate_objs(objIds): for objId in objIds: session = event.getSessionById(objId) for obj in session.getSlotList(): if obj is not None: yield obj return self._process(_iterate_objs(idlist))
def export_event(self, aw): ch = ConferenceHolder() index = IndexesHolder().getIndex('conferenceTitle') try: query = ' AND '.join(map(lambda y: "*%s*" % y, filter(lambda x: len(x) > 0, self._search.split(' ')))) results = index.search(query) except parsetree.ParseError: results = [] d = [] for id, v in results: event = ch.getById(id) if event.canAccess(aw): d.append({'id': id, 'title': event.getTitle(), 'startDate': event.getStartDate(), 'hasAnyProtection': event.hasAnyProtection()}) return d
def update_event_data(avatar, categ, data): attendance_roles = set(['conference_participant', 'contribution_submission', 'abstract_submitter', 'registration_registrant', 'evaluation_submitter']) links = avatar_links.get_links(avatar) ch = ConferenceHolder() attended = filter(None, (ch.getById(eid, True) for eid, roles in links.iteritems() if attendance_roles & roles)) attended = [e for e in attended if e.getOwner() == categ] # Count common chairpersons and attendants chair_count = data.setdefault('chair_count', Counter()) participant_count = data.setdefault('participant_count', Counter()) for event in attended: for ch in event.getChairList(): chair_count[ch.getEmail()] += 1 for part in event.getParticipation().getParticipantList(): participant_count[part.getEmail()] += 1
def getResults(self, query=None): res = [] params = self.params if params.get('id', None): event = ch.getById(params['id']) res.append(event) return 1, res if not query: query = self.getQuery() if not query: return 0, [] collections = params.get('collections', 'Conference') rc = RepozeCatalog() if collections == 'Material': rc = RepozeCatalog(matCatalog) if collections == 'Contribution': rc = RepozeCatalog(contribCatalog) catalog = rc.catalog ch = ConferenceHolder() desc = params.get('desc', False) sort_field = params.get('sort_field', 'startDate') numdocs, results = catalog.query(query, sort_index=sort_field, reverse=desc, limit=params.get('limit', 5000)) results = [ catalog.document_map.address_for_docid(result) for result in results ] if params.get('onlyFids', False): return numdocs, results else: for obj in results: try: confId = str(obj).split("|")[0] event = ch.getById(confId) res.append(event) except: pass return numdocs, res
def get_category_scores(avatar, debug=False): attendance_roles = set([ 'conference_participant', 'contribution_submission', 'abstract_submitter', 'registration_registrant', 'evaluation_submitter' ]) links = avatar_links.get_links(avatar) ch = ConferenceHolder() attended = filter( None, (ch.getById(eid, True) for eid, roles in links.iteritems() if attendance_roles & roles)) categ_events = defaultdict(list) for event in attended: categ_events[event.getOwner()].append(event) return dict((categ, _get_category_score(avatar, categ, events, debug)) for categ, events in categ_events.iteritems())
def getBody(self): res = sets.Set() im = indexes.IndexesHolder() catIdx = im.getIndex('category') calIdx = im.getIndex('calendar') if self._date == None: c1 = calIdx.getObjectsEndingAfter(nowutc().astimezone( timezone(self._tz))) else: date = self._date c1 = calIdx.getObjectsInDay(date) confIds = sets.Set(catIdx.getItems(self._categ.getId())) confIds.intersection_update(c1) res.union_update(confIds) res = list(res) res.sort(sortByStartDate) rss = xmlGen.XMLGen() rss.openTag('rss version="2.0"') rss.openTag("channel") rss.writeTag( "title", "Indico RSS Feed for category %s" % self._categ.getTitle()) rss.writeTag("link", Config.getInstance().getBaseURL()) rss.writeTag( "description", "Forthcoming meetings in category %s" % self._categ.getTitle()) rss.writeTag("language", "en") rss.writeTag( "pubDate", nowutc().astimezone(timezone( self._tz)).strftime("%a, %d %b %Y %H:%M:%S %Z")) rss.writeTag("category", "") rss.writeTag("generator", "CDS Indico %s" % Config.getInstance().getVersion()) rss.writeTag( "webMaster", info.HelperMaKaCInfo.getMaKaCInfoInstance().getSupportEmail()) rss.writeTag("ttl", "1440") for confId in res: ch = ConferenceHolder() conf = ch.getById(confId) rss = ConferenceToRSS(conf, tz=self._tz).getCore(rss) rss.closeTag("channel") rss.closeTag("rss") return rss.getXml()
def getOwner( self ): """ FINAL (not intented to be overriden) Owner in terms of "parent", i.e. conference """ ####---FIXING THE USE OF IMPERSISTANT CLASS----- if isinstance(self.__owner, Impersistant): o = self.__owner.getObject() if o: self.__owner=o.getId() else: self.__owner=None ####---ENDO OF FIXING THE USE OF IMPERSISTANT CLASS----- ch = ConferenceHolder() if self.__owner and self.__owner in ch._getIdx(): return ch.getById(self.__owner) return None
def getOwner(self): """ FINAL (not intented to be overriden) Owner in terms of "parent", i.e. conference """ ####---FIXING THE USE OF IMPERSISTANT CLASS----- if isinstance(self.__owner, Impersistant): o = self.__owner.getObject() if o: self.__owner = o.getId() else: self.__owner = None ####---ENDO OF FIXING THE USE OF IMPERSISTANT CLASS----- ch = ConferenceHolder() if self.__owner and self.__owner in ch._getIdx(): return ch.getById(self.__owner) return None
def get_category_scores(user, debug=False): attendance_roles = { 'contribution_submission', 'abstract_submitter', 'registration_registrant', 'survey_submitter' } links = avatar_links.get_links(user) for event_id in get_events_with_submitted_surveys(user): links.setdefault(str(event_id), set()).add('survey_submitter') ch = ConferenceHolder() attended = filter( None, (ch.getById(eid, True) for eid, roles in links.iteritems() if attendance_roles & roles)) categ_events = defaultdict(list) for event in attended: categ_events[event.getOwner()].append(event) return dict((categ, _get_category_score(user, categ, events, debug)) for categ, events in categ_events.iteritems())
def getResults(self, query=None): res = [] params = self.params if params.get('id',None): event = ch.getById(params['id']) res.append(event) return 1, res if not query: query = self.getQuery() if not query: return 0, [] collections = params.get('collections', 'Conference') rc = RepozeCatalog() if collections == 'Material': rc = RepozeCatalog(matCatalog) if collections == 'Contribution': rc = RepozeCatalog(contribCatalog) catalog = rc.catalog ch = ConferenceHolder() desc = params.get('desc',False) sort_field = params.get('sort_field','startDate') numdocs, results = catalog.query(query, sort_index=sort_field, reverse=desc, limit=params.get('limit',5000)) results = [catalog.document_map.address_for_docid(result) for result in results] if params.get('onlyFids', False): return numdocs, results else: for obj in results: try: confId = str(obj).split("|")[0] event = ch.getById(confId) res.append(event) except: pass return numdocs, res
def update_event_data(avatar, categ, data): attendance_roles = set([ 'conference_participant', 'contribution_submission', 'abstract_submitter', 'registration_registrant', 'evaluation_submitter' ]) links = avatar_links.get_links(avatar) ch = ConferenceHolder() attended = filter( None, (ch.getById(eid, True) for eid, roles in links.iteritems() if attendance_roles & roles)) attended = [e for e in attended if e.getOwner() == categ] # Count common chairpersons and attendants chair_count = data.setdefault('chair_count', Counter()) participant_count = data.setdefault('participant_count', Counter()) for event in attended: for ch in event.getChairList(): chair_count[ch.getEmail()] += 1 for part in event.getParticipation().getParticipantList(): participant_count[part.getEmail()] += 1
def displayRSSList(res,req,tz): ch = ConferenceHolder() rss = xmlGen.XMLGen() rss.openTag('rss version="2.0"') rss.openTag("channel") rss.writeTag("title","Indico RSS Feed") rss.writeTag("link", Config.getInstance().getBaseURL()) rss.writeTag("description","Export of some events stored in Indico") rss.writeTag("language","en") rss.writeTag("pubDate", nowutc().strftime("%a, %d %b %Y %H:%M:%S %Z")) rss.writeTag("category","") rss.writeTag("generator", "CDS Indico %s" % Config.getInstance().getVersion()) rss.writeTag("webMaster", HelperMaKaCInfo.getMaKaCInfoInstance().getSupportEmail()) rss.writeTag("ttl","1440") for confId in res: c = ch.getById(confId) rss = displayRSSConf(c,rss,tz) rss.closeTag("channel") rss.closeTag("rss") return rss.getXml()
def displayICalList(res,req): filename = "Event.ics" # TODO: proper methods in the iCal interface # for serializing a sequence of events icalBase = ICALBase() data = icalBase._printHeader() ch = ConferenceHolder() for confId in res: conf = ch.getById(confId) ical = ConferenceToiCal(conf.getConference()) data += ical.getCore() data += icalBase._printFooter() req.headers_out["Content-Length"] = "%s"%len(data) cfg = Config.getInstance() mimetype = cfg.getFileTypeMimeType( "ICAL" ) req.content_type = """%s"""%(mimetype) req.headers_out["Content-Disposition"] = """inline; filename="%s\""""%filename return data
def displayRSSList(res, req, tz): ch = ConferenceHolder() rss = xmlGen.XMLGen() rss.openTag('rss version="2.0"') rss.openTag("channel") rss.writeTag("title", "Indico RSS Feed") rss.writeTag("link", Config.getInstance().getBaseURL()) rss.writeTag("description", "Export of some events stored in Indico") rss.writeTag("language", "en") rss.writeTag("pubDate", nowutc().strftime("%a, %d %b %Y %H:%M:%S %Z")) rss.writeTag("category", "") rss.writeTag("generator", "CDS Indico %s" % Config.getInstance().getVersion()) rss.writeTag("webMaster", HelperMaKaCInfo.getMaKaCInfoInstance().getSupportEmail()) rss.writeTag("ttl", "1440") for confId in res: c = ch.getById(confId) rss = displayRSSConf(c, rss, tz) rss.closeTag("channel") rss.closeTag("rss") return rss.getXml()
def displayICalList(res, req): filename = "Event.ics" # TODO: proper methods in the iCal interface # for serializing a sequence of events icalBase = ICALBase() data = icalBase._printHeader() ch = ConferenceHolder() for confId in res: conf = ch.getById(confId) ical = ConferenceToiCal(conf.getConference()) data += ical.getCore() data += icalBase._printFooter() req.headers_out["Content-Length"] = "%s" % len(data) cfg = Config.getInstance() mimetype = cfg.getFileTypeMimeType("ICAL") req.content_type = """%s""" % (mimetype) req.headers_out[ "Content-Disposition"] = """inline; filename="%s\"""" % filename return data
def run4eachConfSlowly(): DBMgr.getInstance().startRequest() ch = ConferenceHolder() ids = [] print "Getting conference IDs..." for conf in ch.getList(): ids.append(conf.getId()) totalNumberConfs = len(ids) DBMgr.getInstance().endRequest() print "Updating conferences..." i = 0 N_CONF = 10 cErrorList = [] while ids: if len(ids) >= N_CONF: lids = ids[:N_CONF] del ids[:N_CONF] else: lids = ids ids = None for j in range(10): conf = None try: DBMgr.getInstance().startRequest() for id in lids: conf = ch.getById(id) log("check for conference %s: %s/%s" % (conf.getId(), i, totalNumberConfs)) i += 1 DBMgr.getInstance().endRequest() print "wait 0.5s..." sleep(0.5) break except Exception, e: cErrorList.append(conf) i -= N_CONF log("error %s, retry %d time(s)" % (e, int(10 - j))) sleep(int(j)) DBMgr.getInstance().abort()
def run4eachConfSlowly(): DBMgr.getInstance().startRequest() ch = ConferenceHolder() ids = [] print "Getting conference IDs..." for conf in ch.getList(): ids.append(conf.getId()) totalNumberConfs = len(ids) DBMgr.getInstance().endRequest() print "Updating conferences..." i = 0 N_CONF = 10 cErrorList = [] while ids: if len(ids) >= N_CONF: lids = ids[:N_CONF] del ids[:N_CONF] else: lids = ids ids = None for j in range(10): conf = None try: DBMgr.getInstance().startRequest() for id in lids: conf = ch.getById(id) log("check for conference %s: %s/%s" % (conf.getId(), i, totalNumberConfs)) i += 1 DBMgr.getInstance().endRequest() print "wait 0.5s..." sleep(0.5) break except Exception, e: cErrorList.append(conf) i -= N_CONF log("error %s, retry %d time(s)" % (e, int(10 - j))) sleep(int(j)) DBMgr.getInstance().abort()
def _getAnswer(self): im = indexes.IndexesHolder() ch = ConferenceHolder() calIdx = im.getIndex("calendar") evtIds = calIdx.getObjectsIn(self._sDate, self._eDate) evtsByCateg = {} for evtId in evtIds: try: evt = ch.getById(evtId) categs = evt.getOwnerList() categname = categs[0].getName() if not evtsByCateg.has_key(categname): evtsByCateg[categname] = [] evtsByCateg[categname].append( (evt.getTitle().strip(), evt.getAdjustedStartDate().strftime('%d/%m/%Y %H:%M '), evt.getAdjustedEndDate().strftime('%d/%m/%Y %H:%M '), evt.getTimezone())) except Exception: continue return evtsByCateg
def displayList(res,startdate,enddate,repeat,displayCateg,tz): text = "" ch = ConferenceHolder() day = startdate days = {} found = {} while day <= enddate: for confId in res: c = ch.getById(confId) if day.date() >= c.getAdjustedStartDate(tz).date() and day.date() <= c.getAdjustedEndDate(tz).date() and (repeat==1 or not found.has_key(c)): if not days.has_key(day): days[day]=[] days[day].append(c) found[c] = 1 day = day + datetime.timedelta(days=1) day = startdate while day <= enddate: if days.has_key(day): text += "<br><b>%s</b>" % day.strftime("%A %B %d, %Y") days[day].sort(lambda x,y: cmp(x.calculateDayStartTime(day).time(),y.calculateDayStartTime(day).time())) for c in days[day]: text += displayConf(c,displayCateg,day,tz) day = day + datetime.timedelta(days=1) return text
def getBody(self): res = sets.Set() im = indexes.IndexesHolder() catIdx = im.getIndex('category') calIdx = im.getIndex('calendar') if self._date == None: c1 = calIdx.getObjectsEndingAfter(nowutc().astimezone(timezone(self._tz))) else: date = self._date c1 = calIdx.getObjectsInDay(date) confIds=sets.Set(catIdx.getItems(self._categ.getId())) confIds.intersection_update(c1) res.union_update(confIds) res = list(res) res.sort(sortByStartDate) rss = xmlGen.XMLGen() rss.openTag('rss version="2.0"') rss.openTag("channel") rss.writeTag("title","Indico RSS Feed for category %s" % self._categ.getTitle()) rss.writeTag("link", Config.getInstance().getBaseURL()) rss.writeTag("description","Forthcoming meetings in category %s" % self._categ.getTitle()) rss.writeTag("language","en") rss.writeTag("pubDate", nowutc().astimezone(timezone(self._tz)).strftime("%a, %d %b %Y %H:%M:%S %Z")) rss.writeTag("category","") rss.writeTag("generator", "CDS Indico %s" % Config.getInstance().getVersion()) rss.writeTag("webMaster", info.HelperMaKaCInfo.getMaKaCInfoInstance().getSupportEmail()) rss.writeTag("ttl","1440") for confId in res: ch = ConferenceHolder() conf = ch.getById(confId) rss = ConferenceToRSS(conf, tz=self._tz).getCore(rss) rss.closeTag("channel") rss.closeTag("rss") return rss.getXml()
def index(req, **params): """This script displays the list of meetings taking place in a given category at a given date""" global ids db.DBMgr.getInstance().startRequest() try: fid = params['fid'] date = params['date'] days = int(params['days']) - 1 event = params.get('event', "") of = params.get('of', 'text') rooms = params.get('rooms', []) tzstring = params.get( 'tz', info.HelperMaKaCInfo.getMaKaCInfoInstance().getTimezone()) if tzstring not in common_timezones: tzstring = 'UTC' tz = timezone(tzstring) protected = int(params.get('protected', 1)) # repeat the event every day of its duration repeat = int(params.get('re', 0)) # display the category tree the event belongs to displayCateg = int(params.get('dc', 1)) except: return usage() #instanciate indexes #create list of ids ids = re.split(' ', fid) event_types = re.split(' ', event) #create date object if date == "today": date = nowutc().astimezone(tz).date().isoformat() [year, month, day] = re.split('-', date) startdate = tz.localize( datetime.datetime(int(year), int(month), int(day), 0, 0, 0)) enddate = startdate + datetime.timedelta( days=days, hours=23, minutes=59, seconds=59) res = getConfList(startdate, enddate, ids) # filter with event type if event_types != ['']: finalres = [] ch = ConferenceHolder() for confId in res: conf = ch.getById(confId) type = conf.getType() if type in event_types: finalres.append(confId) else: finalres = res res = finalres # filter with room name if rooms != []: finalres = [] ch = ConferenceHolder() for confId in res: conf = ch.getById(confId) if conf.getRoom(): confroom = conf.getRoom().getName() if confroom in rooms: finalres.append(confId) else: finalres = res # filter protected events ch = ConferenceHolder() if not protected: for id in finalres: conf = ch.getById(id) if conf.isProtected(): finalres.remove(id) if of == 'xml': req.content_type = "text/xml" return displayXMLList(finalres, req, tzstring, displayCateg) elif of == 'rss': req.content_type = "application/xhtml+xml" return displayRSSList(finalres, req, tzstring) elif of == 'ical': req.content_type = "text/v-calendar" return displayICalList(finalres, req) else: req.content_type = "text/html" return displayList(finalres, startdate, enddate, repeat, displayCateg, tzstring)
def sortByStartDate(conf1, conf2): ch = ConferenceHolder() return cmp( ch.getById(conf1).getStartDate(), ch.getById(conf2).getStartDate())
class RepozeCatalog(): def __init__(self, catalogName=confCatalog): self.catalog = {} self.db = db.DBMgr.getInstance().getDBConnection() self.ch = ConferenceHolder() plugin = PluginsHolder().getPluginType('search').getPlugin("repozer") self.iConf = plugin.getOptions()["indexConference"].getValue() self.iContrib = plugin.getOptions()["indexContribution"].getValue() self.iMat = plugin.getOptions()["indexMaterial"].getValue() # init all standard catalogs for cat in [confCatalog,contribCatalog,matCatalog]: if cat not in self.db.root(): self.catalogName = cat self.init_catalog() self.catalogName = catalogName # init customized catalog if self.catalogName not in [confCatalog,contribCatalog,matCatalog] and self.catalogName not in self.db.root(): self.init_catalog() self.catalog = self.db.root()[self.catalogName] def init_catalog(self): ''' Create a repoze.catalog instance and specify indices of intereset ''' catalog = RCatalog() catalog.document_map = DocumentMap() # set up indexes catalog['title'] = CatalogTextIndex('_get_title') catalog['titleSorter'] = CatalogFieldIndex('_get_sorter') catalog['collection'] = CatalogKeywordIndex('_get_collection') # Descriptions are converted to TEXT for indexing catalog['description'] = CatalogTextIndex('_get_description') catalog['startDate'] = CatalogFieldIndex('_get_startDate') catalog['endDate'] = CatalogFieldIndex('_get_endDate') catalog['modificationDate'] = CatalogFieldIndex('_get_modificationDate') catalog['fid'] = CatalogTextIndex('_get_fid') catalog['keywords'] = CatalogKeywordIndex('_get_keywordsList') catalog['category'] = CatalogKeywordIndex('_get_categoryList') # I define as Text because I would permit searched for part of names catalog['rolesVals'] = CatalogTextIndex('_get_roles') catalog['persons'] = CatalogTextIndex('_get_persons') # ICTP SPECIFIC: index a deadline date if found. Just COMMENT this line if not interested catalog['deadlineDate'] = CatalogFieldIndex('_get_deadlineDate') self.db.root()[self.catalogName] = catalog self.catalog = self.db.root()[self.catalogName] # commit the indexes transaction.commit() def indexConference(self, obj, catalog=None): try: p = obj.hasAnyProtection() except: p = True if not(p): if not catalog: catalog = self.db.root()[confCatalog] fid = ut.getFid(obj) doc_id = catalog.document_map.new_docid() catalog.document_map.add(fid, doc_id) #obj._get_description = ut.getTextFromHtml(obj.getDescription()) txt = ut.getTextFromHtml(obj.getDescription()) obj._get_description = unicode(txt).encode('ascii', 'xmlcharrefreplace') obj._get_title = obj.getTitle().decode('utf8','ignore') obj._get_sorter = obj._get_title.lower().replace(" ", "")[:10] obj._get_collection = [ut.get_type(obj, '')] obj._get_keywordsList = [] obj._get_categoryList = ut.getCat(obj) if hasattr(obj, '_keywords') and len(obj._keywords)>0: obj._get_keywordsList = obj.getKeywords().replace('\r','').split('\n') obj._get_roles = '[]' if "getRolesVal" in dir(obj): obj._get_roles = obj.getRolesVal() obj._get_persons = '' if obj.getChairList(): obj._get_persons = ut.getTextFromAvatar(obj.getChairList()) obj._get_fid = fid obj._get_startDate = obj.getStartDate() obj._get_endDate = obj.getEndDate() obj._get_modificationDate = obj.getModificationDate() # cannot use dd = None, so I set it to 01/01/1970 dd = None if "getDeadlineDate" in dir(obj): dd = obj.getDeadlineDate() if not dd: dd = datetime.strptime('01/01/1970', '%d/%m/%Y') obj._get_deadlineDate = dd catalog.index_doc(doc_id, obj) def indexContribution(self, obj, catalog=None): if not(obj.hasAnyProtection()): if not catalog: catalog = self.db.root()[contribCatalog] doc_id = catalog.document_map.new_docid() fid = ut.getFid(obj) confId, sessionId, talkId, materialId = fid.split("|") catalog.document_map.add(fid, doc_id) localTimezone = info.HelperMaKaCInfo.getMaKaCInfoInstance().getTimezone() nd = timezone(localTimezone).localize(datetime(1970,1,1, 0, 0)) # Set 1900/1/1 as None if not obj.startDate: obj.startDate = nd if not hasattr(obj, 'endDate'): obj.endDate = nd if hasattr(obj, 'duration') and obj.duration: obj.endDate = obj.startDate + obj.duration obj._get_categoryList = ut.getCat(self.ch.getById(confId)) #obj._get_description = ut.getTextFromHtml(obj.getDescription()) txt = ut.getTextFromHtml(obj.getDescription()) obj._get_description = unicode(txt).encode('ascii', 'xmlcharrefreplace') obj._get_title = obj.getTitle().decode('utf8','ignore') obj._get_sorter = obj._get_title.lower().replace(" ", "")[:10] obj._get_collection = [ut.get_type(obj, '')] obj._get_keywordsList = [] if hasattr(obj, '_keywords') and len(obj._keywords)>0: obj._get_keywordsList = obj.getKeywords().split('\n') obj._get_roles = '[]' obj._get_persons = '' if obj.getSpeakerList(): obj._get_persons = ut.getTextFromAvatar(obj.getSpeakerList()) obj._get_fid = fid obj._get_startDate = obj.getStartDate() obj._get_endDate = obj.getEndDate() obj._get_modificationDate = obj.getModificationDate() #print "___Talk Title=",obj.getTitle() catalog.index_doc(doc_id, obj) def _indexMat(self, obj, catalog): doc_id = catalog.document_map.new_docid() robj = RepozerMaterial(obj) fid = ut.getFid(robj) confId, sessionId, talkId, materialId = fid.split("|") catalog.document_map.add(fid, doc_id) robj._get_categoryList = ut.getCat(self.ch.getById(confId)) robj._get_description = robj.getDescription() robj._get_title = robj.getTitle() robj._get_sorter = robj._get_title.lower().replace(" ", "")[:10] robj._get_collection = ['Material'] robj._get_keywordsList = [] if hasattr(obj, '_keywords') and len(obj._keywords)>0: robj._get_keywordsList = obj.getKeywords().split('\n') robj._get_roles = '[]' robj._get_person = '' robj._get_fid = fid localTimezone = info.HelperMaKaCInfo.getMaKaCInfoInstance().getTimezone() nd = timezone(localTimezone).localize(datetime(1970,1,1, 0, 0)) # Set 1900/1/1 as None robj._get_startDate = nd robj._get_endDate = nd robj._get_modificationDate = nd catalog.index_doc(doc_id, robj) return def indexMaterial(self, res, catalog=None): if not catalog: catalog = self.db.root()[matCatalog] if not(res.isProtected()): try: ftype = res.getFileType().lower() fname = res.getFileName() fpath = res.getFilePath() except: ftype = None content = '' PDFc = pdf2txt() jod = jodconverter2txt() if ftype in PDFc.av_ext: # I do not use pyPDF because most of PDF are protected #print "CONVERSIONE PDF IN CORSO...", str(datetime.now()) PDFc.convert(fpath) content = PDFc.text res._content = content #print "...CONVERSIONE PDF CONCLUSA", str(datetime.now()) #print "START INDEXING", str(datetime.now()) #print ".... indexing Material ",fpath, "___content=",content[:50] self._indexMat(res, catalog) #print "FINISHED INDEXING", str(datetime.now()) if ftype in jod.av_ext: jod.convert(fpath, ftype) content = jod.text res._content = content #print ".... indexing Material ",fpath, "___content=",content[:50] self._indexMat(res, catalog) PDFc = None jod = None return def fullIndex(self, obj): fid = ut.getFid(obj) confId, sessionId, talkId, materialId = fid.split("|") conf = self.ch.getById(confId) if self.iConf: catalog = self.db.root()[confCatalog] self.indexConference(conf, catalog) if self.iMat: for mat in conf.getAllMaterialList(): # Index Material inside Conference for res in mat.getResourceList(): self.indexMaterial(res) if self.iContrib: for talk in conf.getContributionList(): catalog = self.db.root()[contribCatalog] self.indexContribution(talk, catalog) if self.iMat: for mat in talk.getAllMaterialList(): # Index Material inside Contributions for res in mat.getResourceList(): self.indexMaterial(res) transaction.commit() def indexObject(self, obj): cname = obj.__class__.__name__ #print "__INDEXING__", obj, " __TYPE__ ", cname #print "STARTED AT", str(datetime.now()) if cname == 'Conference' and self.iConf: objExist = True try: o = self.ch.getById(obj.getId()) except: objExist = False # if obj has not been DELETED: if objExist: self.indexConference(obj) if cname == 'Contribution' and self.iContrib: self.indexContribution(obj) if cname == 'LocalFile': if self.iMat: try: self.indexMaterial(obj) except: pass else: catalog = self.db.root()[matCatalog] catalog def unindexObject(self, obj, recursive=False): fid = ut.getFid(obj) if fid == '|||': return conf = None cname = obj.__class__.__name__ useCatalog = None if cname == 'Conference' and self.iConf: useCatalog = confCatalog confId, sessionId, talkId, materialId = fid.split("|") cat = self.db.root()[confCatalog] (hits, res) = cat.query(Eq('fid',fid)) for doc_id in res: #print "__unindex fid=",fid,"__TITLE=", obj.getTitle() cat.unindex_doc(doc_id) if recursive: # also remove inner objects for cat in [self.db.root()[contribCatalog],self.db.root()[matCatalog]]: (hits, res) = cat.query(Eq('fid',confId+'|*')) for doc_id in res: cat.unindex_doc(doc_id) if cname == 'Contribution' and self.iContrib: useCatalog = contribCatalog # Remove Contrib: cat = self.db.root()[contribCatalog] (hits, res) = cat.query(Eq('fid',fid)) for doc_id in res: cat.unindex_doc(doc_id) if recursive: # also remove inner objects cat = self.db.root()[matCatalog] (hits, res) = cat.query(Eq('fid',fid+'*')) for doc_id in res: cat.unindex_doc(doc_id) if cname == 'LocalFile' and self.iMat: cat = self.db.root()[matCatalog] (hits, res) = cat.query(Eq('fid',fid)) for doc_id in res: cat.unindex_doc(doc_id) def closeConnection(self): #transaction.commit() #self.factory.db.close() #self.manager.commit() #self.manager.close() return def openConnection(self): #plugin = PluginsHolder().getPluginType('search').getPlugin("repozer") #DBpath = plugin.getOptions()["DBpath"].getValue() #self.factory = FileStorageCatalogFactory(DBpath,'repoze_catalog') #self.manager = ConnectionManager() #self.catalog = self.factory(self.manager) return
## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Indico; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. from MaKaC.common.db import DBMgr from MaKaC.conference import ConferenceHolder DBMgr.getInstance().startRequest() confId = "18714" translations = { "#FFCC00": "#FFCC66", "#6699CC": "#66CCFF", "#33CC00": "#99FF66", "#9900FF": "#CC99FF", "#FFFF00": "#FFFF99" } ch = ConferenceHolder() conf = ch.getById(confId) for ses in conf.getSessionList(): oc = ses.getColor() if translations.get(oc, "") != "": nc = translations[oc] ses.setColor(nc) DBMgr.getInstance().endRequest()
def setMaterial(mat): mat.getAccessController().setOwner(mat) for res in mat.getResourceList(): setResource(res) def setResource(res): res.getAccessController().setOwner(res) DBMgr.getInstance().startRequest() confIds = [] for conf in ConferenceHolder().getList(): confIds.append(conf.getId()) DBMgr.getInstance().endRequest() ch = ConferenceHolder() for id in confIds: for i in range(10): try: DBMgr.getInstance().startRequest() setConference(ch.getById(id)) DBMgr.getInstance().endRequest() break except Exception, e: DBMgr.getInstance().abort() print "try %d raise error: %s" % (i, e)
class TestCategoryDayIndex(unittest.TestCase): def setUp(self): DBMgr.getInstance().startRequest() self.oldIndex = IndexesHolder()._getIdx()["categoryDateLtd"] self.newIndex = IndexesHolder()._getIdx()["categoryDate"] self.startDate = datetime(2010,5,13, 10, 0, 0, tzinfo=timezone('UTC')) self.endDate = datetime(2010,5,14, 14, 0, 0, tzinfo=timezone('UTC')) self.ch = ConferenceHolder() self.categId = '0' def tearDownModule(self): DBMgr.getInstance().abort() DBMgr.getInstance().endRequest() def testGetObjectsStartingInDay(self): newRes = self.newIndex._idxCategItem[self.categId].getObjectsStartingInDay(self.startDate) oldTmp = self.oldIndex._idxCategItem[self.categId].getObjectsStartingInDay(self.startDate) oldRes = set() for res in oldTmp: oldRes.add(self.ch.getById(res)) assert(oldRes == newRes) def testGetObjectsStartingIn(self): newRes = self.newIndex.getObjectsStartingIn(self.categId, self.startDate, self.endDate) oldTmp = self.oldIndex.getObjectsStartingIn(self.categId, self.startDate, self.endDate) oldRes = set() for res in oldTmp: oldRes.add(self.ch.getById(res)) assert(oldRes == newRes) def testGetObjectsStartingAfterTest(self): newRes = self.newIndex._idxCategItem[self.categId].getObjectsStartingAfter(self.startDate) oldTmp = self.oldIndex._idxCategItem[self.categId].getObjectsStartingAfter(self.startDate) oldRes = set() for res in oldTmp: oldRes.add(self.ch.getById(res)) assert(oldRes == newRes) def testGetObjectsEndingAfterTest(self): newRes = self.newIndex._idxCategItem[self.categId].getObjectsEndingAfter(self.startDate) oldTmp = self.oldIndex._idxCategItem[self.categId].getObjectsEndingAfter(self.startDate) oldRes = set() for res in oldTmp: oldRes.add(self.ch.getById(res)) assert(oldRes == newRes) def testGetObjectsEndingInDay(self): newRes = self.newIndex._idxCategItem[self.categId].getObjectsEndingInDay(self.startDate) oldTmp = self.oldIndex._idxCategItem[self.categId].getObjectsEndingInDay(self.startDate) oldRes = set() for res in oldTmp: oldRes.add(self.ch.getById(res)) assert(oldRes == newRes) def testGetObjectsEndingIn(self): newRes = self.newIndex._idxCategItem[self.categId].getObjectsEndingIn(self.startDate,self.endDate) oldTmp = self.oldIndex._idxCategItem[self.categId].getObjectsEndingIn(self.startDate,self.endDate) oldRes = set() for res in oldTmp: oldRes.add(self.ch.getById(res)) assert(oldRes == newRes) def testGetObjectsInDay(self): newRes = self.newIndex._idxCategItem[self.categId].getObjectsInDay(self.startDate) oldTmp = self.oldIndex._idxCategItem[self.categId].getObjectsInDay(self.startDate) oldRes = set() for res in oldTmp: oldRes.add(self.ch.getById(res)) assert(oldRes == newRes) def testGetObjectsIn(self): newRes = self.newIndex._idxCategItem[self.categId].getObjectsIn(self.startDate,self.endDate) oldTmp = self.oldIndex._idxCategItem[self.categId].getObjectsIn(self.startDate,self.endDate) oldRes = set() for res in oldTmp: oldRes.add(self.ch.getById(res)) assert(oldRes == newRes)
def main(): DBMgr.getInstance().startRequest() ch = ConferenceHolder() ih = indexes.IndexesHolder() catIdx = ih.getById("category") confIdx = ih.getById("OAIConferenceModificationDate") contIdx = ih.getById("OAIContributionModificationDate") confIdxPr = ih.getById("OAIPrivateConferenceModificationDate") contIdxPr = ih.getById("OAIPrivateContributionModificationDate") confIdx.initIndex() contIdx.initIndex() confIdxPr.initIndex() contIdxPr.initIndex() DBMgr.getInstance().commit() print "Count conferences..." ids = catIdx.getItems('0') totalConf = len(ids) print "%d conferences found"%totalConf ic = 1 DBMgr.getInstance().sync() DBMgr.getInstance().endRequest() i = 0 pubConf = 0 privConf = 0 while ids: if len(ids) >= 10: lids = ids[:10] del ids[:10] else: lids = ids ids = None startic = ic startPubConf = pubConf startPrivConf = privConf for j in range(10): try: DBMgr.getInstance().startRequest() for id in lids: conf = ch.getById(id) confIdx = ih.getById("OAIConferenceModificationDate") contIdx = ih.getById("OAIContributionModificationDate") confIdxPr = ih.getById("OAIPrivateConferenceModificationDate") contIdxPr = ih.getById("OAIPrivateContributionModificationDate") print "Index conference %s: %d on %d"%(id, ic, totalConf) ic += 1 if conf.hasAnyProtection(): confIdxPr.indexConference(conf) privConf += 1 else: confIdx.indexConference(conf) pubConf += 1 for cont in conf.getContributionList(): if cont.hasAnyProtection(): contIdxPr.indexContribution(cont) else: contIdx.indexContribution(cont) for sc in cont.getSubContributionList(): if cont.isProtected(): contIdxPr.indexContribution(sc) else: contIdx.indexContribution(sc) DBMgr.getInstance().endRequest() print "wait 0.5s..." sleep(0.5) break except Exception, e: print "error %s, retry %d time(s)"%(e,int(10-j)) sleep(int(j)) ic = startic pubConf = startPubConf privConf = startPrivConf DBMgr.getInstance().abort()
def setUp(self): self.random = Random() self._loggingSetup() self._log("Start of test. Current pid is: " + str(os.getpid())) self._log("Initiating setUp of test") self._log('') try: if makeCopy: self._log("Copying " + testingDbfile + " to " + collaborationDbFile + " ...") try: os.remove(collaborationDbFile) os.remove(collaborationDbFile + '.index') os.remove(collaborationDbFile + '.tmp') except: pass shutil.copy(testingDbfile, collaborationDbFile) try: shutil.copy(testingDbfile + '.index', collaborationDbFile + '.index') except: self._log("problem copying " + testingDbfile + '.index') try: shutil.copy(testingDbfile + '.tmp', collaborationDbFile + '.tmp') except: self._log("problem copying " + testingDbfile + '.tmp') self._log("copy finished.") self._log('') self._log("Starting the ZEO server...") self.zeoServer = self.createDBServer(collaborationDbFile, zeoPort) self._log("zodb server started on pid: " + str(self.zeoServer) + " .") self._log('') self._log("Creating a CustomDBMgr on port " + str(zeoPort)) self.cdbmgr = DBMgr.getInstance(hostname="localhost", port=zeoPort) self._log("Starting a request ...") self.cdbmgr.startRequest() self._log("Request started successfully.") self._log('') if doCleanUp: self._log( 'Cleaning the DB of bookings and recreating the indexes') DeleteAllBookingsAction(FalseAction()).call() self._log('Cleanup succesfull') self._log("We start populating DB with bookings...") #ConferenceHolder()._getIdx() is an OOBTree size = lastConfId - firstConfId self._log("Populating among aproximately " + str(size) + " events, from " + str(firstConfId) + " to " + str(lastConfId) + ", with aproximately " + str(startingBookings) + " bookings") self._log("Initial size of 'all' index: " + str(IndexesHolder().getById( "Collaboration").getAllBookingsIndex().getCount())) self.validConfIds = [] self.confsWithBookings = [] populated = 0 added = 0 chance = (float(startingBookings) / float(size)) / 2.0 ch = ConferenceHolder() for confId in xrange(firstConfId, lastConfId + 1): confId = str(confId) if self.random.random() < chance: try: conf = ch.getById(confId) self.validConfIds.append(confId) except MaKaCError: continue i = 0 bookingsForThisConf = max( int(self.random.normalvariate(3, 3)), 0) added += bookingsForThisConf while i < bookingsForThisConf: Catalog.getIdx("cs_bookingmanager_conference").get( conf.getId()).createTestBooking(bookingParams={ 'startDate': self._randomDate(startDate, endDate) }) i += 1 populated += 1 self.confsWithBookings.append(confId) if populated % 100 == 0: self._log( str(populated) + ' events populated. Index size: ' + str(IndexesHolder().getById("Collaboration"). getAllBookingsIndex().getCount())) self._log("Populating finished. " + str(populated) + " events populated with " + str(added) + " bookings") self._log("Size of 'all' index is now: " + str(IndexesHolder().getById( "Collaboration").getAllBookingsIndex().getCount())) self._log("Performing commit...") self.cdbmgr.endRequest(True) #True = commmit self._log("End of request") self._log('') except Exception, e: tb = str(traceback.format_tb(sys.exc_info()[2])) self.logger.error( "There was an exception in setUp. Calling tearDown. Exception: " + str(e) + ", Traceback = " + tb) self.tearDown() self.fail("setUp failed. Cause: " + str(e) + ", Traceback = " + tb)
def index(req, **params): """This script displays the list of meetings which are planned in the coming week""" global ids try: stdate = params['stdate'] nbweeks = params['nbweeks'] except: return usage() [year,month,day] = stdate.split("-") days = int(nbweeks) * 7 ch = ConferenceHolder() previous = "" if str(year) == "2008": previous = """<a href="http://indico.cern.ch/tools/SSLPdisplay.py?stdate=2007-07-02&nbweeks=7">Previous Year Lecture Programme</a>""" elif str(year) == "2009": previous = """<a href="http://indico.cern.ch/tools/SSLPdisplay.py?stdate=2008-06-30&nbweeks=9">Previous Year Lecture Programme</a>""" elif str(year) == "2010": previous = """<a href="http://indico.cern.ch/tools/SSLPdisplay.py?stdate=2009-06-29&nbweeks=8">Previous Year Lecture Programme</a>""" elif str(year) == "2011": previous = """<a href="http://indico.cern.ch/scripts/SSLPdisplay.py?stdate=2010-07-05&nbweeks=7">Previous Year Lecture Programme</a>""" html = """ <!doctype html public "-//w3c//dtd html 4.0 transitional//en"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="Author" content="Matthias Egger"> <meta name="GENERATOR" content="Mozilla/4.75 [en] (Win95; U) [Netscape]"> <meta name="resp1" content="Matthias Egger"> <meta name="resp2" content="Tanja Peeters"> <meta name="DateCreated" content="971205"> <meta name="DateExpires" content="981201"> <meta name="DateModified" content="971205"> <meta name="Keywords" content="summer student lecture programme"> <meta name="Description" content="The Summer Student lecture programme."> <title>Summer Student Lecture Programme</title> </head> <body text="#000099" bgcolor="#FFFFCC" link="#000000" vlink="#C6600" alink="#FF9900"> <div align=right></div> <map name="cern_options_banner_2"><area shape="rect" coords="1,16,70,35" href="http://cern.web.cern.ch/CERN/Divisions/PE/HRS/Recruitment/Welcome.html"><area shape="rect" coords="72,17,146,35" href="http://cern.web.cern.ch/CERN/Divisions/PE/HRS/Recruitment/youngpeople.html"><area shape="rect" coords="146,15,181,37" href="http://cern.web.cern.ch/CERN/Divisions/PE/HRS/Recruitment/staff.html"><area shape="rect" coords="182,15,224,38" href="http://cern.web.cern.ch/CERN/Divisions/PE/HRS/Recruitment/fellows.html"><area shape="rect" coords="225,15,286,38" href="http://cern.web.cern.ch/CERN/Divisions/PE/HRS/Recruitment/associates.html"><area shape="rect" coords="286,16,337,37" href="http://cern.web.cern.ch/CERN/Divisions/PE/HRS/Recruitment/students.html"><area shape="rect" coords="338,16,389,36" href="http://cern.web.cern.ch/CERN/Divisions/PE/HRS/Recruitment/aboutus.html"><area shape="rect" coords="391,17,449,35" href="http://cern.web.cern.ch/CERN/Divisions/PE/HRS/Recruitment/contactus.html"><area shape="rect" coords="450,16,503,35" href="http://cern.web.cern.ch/CERN/Divisions/PE/HRS/Recruitment/other.html"><area shape="rect" coords="506,2,552,46" href="http://www.cern.ch"><area shape="default" nohref></map> %s <br> <br> <center> <p><a NAME="Prog"></a><b><font face="Verdana"><font color="#000080"><font size=+2>Summer Student Lecture Programme %s </font></font></font></b></center> </font></font></font> <p><b><font face="Verdana"><font color="#000080"><font size=-1>Keys:</font></font></font></b> <br><font face="Verdana"><font size=-1><font color="green">(v): videos</font></font></font> <br><font face="Verdana"><font size=-1><font color="red">(t): transparencies</font></font></font> <br><font face="Verdana"><font size=-1><font color="brown">(l): web lecture</font></font></font> <br><font face="Verdana"><font size=-1><font color="blue">(b): biography</font></font></font> <br><font face="Verdana"><font size=-1><font color="grey">(q): questionnaire</font></font></font> <br> """ % (previous,year) #create list of ids ids = [345,346,347,348] db.DBMgr.getInstance().startRequest() tz = info.HelperMaKaCInfo.getMaKaCInfoInstance().getTimezone() #create date object startdate = timezone(tz).localize(datetime.datetime(int(year),int(month),int(day))) stdatedays = startdate.toordinal() enddate = startdate + datetime.timedelta(days=int(days)) #create result set res = sets.Set() #instanciate indexes im = indexes.IndexesHolder() catIdx = im.getIndex('category') calIdx = im.getIndex('calendar') c1 = calIdx.getObjectsIn(startdate, enddate) for id in ids: confIds=sets.Set(catIdx.getItems(id)) confIds.intersection_update(c1) res.update(confIds) res = list(res) res.sort(sortByStartDate) seminars = {} stimes = [] etimes = [] for id in res: obj = ch.getById(id) agenda={} agenda['object'] = obj agenda['id'] = obj.getId() agenda['stime1'] = obj.getAdjustedStartDate(tz).time().isoformat()[0:5] agenda['atitle'] = obj.getTitle() agenda['desc'] = "" if obj.getComments() != "": agenda['desc'] = "<br>%s" % obj.getComments() if obj.getChairList() != []: agenda['chairman'] = obj.getChairList()[0].getFullName() else: agenda['chairman'] = "" agenda['stdate'] = obj.getAdjustedStartDate(tz).date() agenda['fduration'] = (obj.getAdjustedEndDate(tz)-obj.getAdjustedStartDate(tz)).seconds agenda['etime1'] = obj.getAdjustedEndDate(tz).time().isoformat()[0:5] stime = obj.getAdjustedStartDate(tz).time().isoformat()[0:5] etime = obj.getAdjustedEndDate(tz).time().isoformat()[0:5] stdate = obj.getAdjustedStartDate(tz).date() if not seminars.has_key(stdate): seminars[stdate] = {} if not seminars[stdate].has_key(stime): seminars[stdate][stime] = [] seminars[stdate][stime].append(agenda) if not stime in stimes: stimes.append(stime) etimes.append(etime) for week in range(0,int(nbweeks)): html += """<table BORDER CELLPADDING=4 WIDTH="100%" > <tr> <td VALIGN=TOP WIDTH="6%" HEIGHT="27" BGCOLOR="#FFFFFF"> <center><b><font face="Arial">Time</font></b></center> </td>""" beginweek = stdatedays+(week*7) endweek = stdatedays+(week+1)*7-2 # display day names days = beginweek while days < endweek: thisday = datetime.datetime.fromordinal(days).strftime("%A %d %b") html += """ <td VALIGN=TOP WIDTH="19%%" HEIGHT="27" BGCOLOR="#FFFFFF"> <center><b><font face="Arial">%s</font></b></center> </td>""" % thisday days+=1 html+= "</TR>" #display hour per hour agenda rowtext = "" for i in range(len(stimes)): val = stimes[i] rowtext = "" nbtalks = 0 rowtext += """ <TR><td VALIGN=TOP WIDTH="6%%" BGCOLOR="#FFFFFF"> <center><b><font face="Arial">%s</font></b> <br><b><font face="Arial">-</font></b> <br><b><font face="Arial">%s</font></b></center> </td>""" % (stimes[i],etimes[i]) days = beginweek while days < endweek: thisday = datetime.date.fromordinal(days) texttime = "" if seminars.has_key(thisday) and seminars[thisday].has_key(val): for agenda in seminars[thisday][val]: ida = agenda['id'] if agenda['stime1'] != stimes[i] or agenda['etime1'] != etimes[i]: texttime = "<BR><i>("+agenda['stime1']+" - "+agenda['etime1']+")</i>" #FILES textfiles = ""; miscitems = 0; for m in agenda['object'].getAllMaterialList(): entry = m.getTitle().lower() if entry[0:4] != "part": if entry == "video" or entry == "video in cds": entry = "<font color=green>v</font>" elif entry in ["transparencies","slides"]: entry = "<font color=red>t</font>" elif entry in ["biography"]: entry = "<font color=blue>b</font>" elif entry == "questionnaire": entry = "<font color=grey>q</font>" elif entry == "syncomat": entry = "<font color=brown>l</font>" elif entry == "lecture": entry = "<font color=brown>l</font>" elif entry == "lecture_from_2000": entry = "<font color=brown>l/2000</font>" elif entry == "video_from_2000": entry = "<font color=green>v/2000</font>" else: entry = "m" url = UHMaterialDisplay.getURL(m) textfiles += "(<A HREF=%s>%s</A>)" % (url,entry) rowtext += """<td VALIGN=TOP WIDTH="19%%"><font face="Arial"><font size=-1><a href="%s">%s</a>%s%s</font></font><p><i><font face="Arial"><font size=-1><i>%s</I>%s</font></font></i></td>\n""" % ( UHConferenceDisplay.getURL(agenda['object']),agenda['atitle'],agenda['desc'],textfiles,agenda['chairman'],texttime ) nbtalks+=1 else: rowtext += """<td VALIGN=TOP WIDTH="19%"> </td>""" days+=1 rowtext += "</TR>" if nbtalks != 0: html+=rowtext html+="</TABLE>" html+="<br> " html += """ <br> <!-- <p><a href="http://cern.web.cern.ch/CERN/Divisions/PE/HRS/Recruitment/6sumprog.html#SUMMER STUDENTS">CERN Recruitment Service</a> --> <center> <hr WIDTH="100%"> <!-- <br><font face="Verdana,Helvetica,Helvetica"><font size=-2><font color="#A00000"><a href="http://cern.web.cern.ch/CERN/Divisions/PE/HRS/Recruitment/search_HRS.html">Search</a></font><font color="#0000A0"> the pages of the Recruitment Service</font></font></font> <br><font face="Verdana,Helvetica"><font color="#000099"><font size=-2> Comments about this Web site to: <a href="mailto:[email protected]">[email protected]</a></font></font></font> <br><font face="Verdana,Helvetica"><font color="#000099"><font size=-2>Enquiries about Recruitment Programmes to: <a href="mailto:[email protected]">[email protected]</a></font></font></font> --> <br><font face="Verdana,Helvetica"><font color="#000099"><font size=-2>Copyright CERN - the European Laboratory for Particle Physics (Geneva, Switzerland)</font></font></font></center> <p><br> </body> </html>""" return html
mat.getAccessController().setOwner(mat) for res in mat.getResourceList(): setResource(res) def setResource(res): res.getAccessController().setOwner(res) DBMgr.getInstance().startRequest() confIds = [] for conf in ConferenceHolder().getList(): confIds.append(conf.getId()) DBMgr.getInstance().endRequest() ch = ConferenceHolder() for id in confIds: for i in range(10): try: DBMgr.getInstance().startRequest() setConference(ch.getById(id)) DBMgr.getInstance().endRequest() break except Exception, e: DBMgr.getInstance().abort() print "try %d raise error: %s"%(i, e)
DBMgr.getInstance().startRequest() confids = [] for conf in ch.getList(): confids.append(conf.getId()) DBMgr.getInstance().endRequest() print "indexing conferences..." i = 0 total = len(confids) for confId in confids: print "processed %d(current:%s) conferences on %d"%(i, confId, total) i += 1 DBMgr.getInstance().startRequest() conf = ch.getById(confId) conf.getCreator().linkTo(conf, "creator") for prin in conf.getChairList(): if isinstance(prin, Avatar): prin.linkTo(conf, "chair") for prin in conf.getManagerList(): if isinstance(prin, Avatar): prin.linkTo(conf, "manager") for prin in conf.getAllowedToAccessList(): if isinstance(prin, Avatar): prin.linkTo(conf, "access") for av in conf.getAbstractMgr().getAuthorizedSubmitterList():
def setUp(self): self.random = Random() self._loggingSetup() self.falseSession = FalseSession() self._log("Start of test. Current pid is: " + str(os.getpid())) self._log("Initiating setUp of test") self._log('') try: if makeCopy: self._log("Copying " + testingDbfile + " to " + collaborationDbFile + " ...") try: os.remove(collaborationDbFile) os.remove(collaborationDbFile + '.index') os.remove(collaborationDbFile + '.tmp') except: pass shutil.copy(testingDbfile, collaborationDbFile) try: shutil.copy(testingDbfile + '.index', collaborationDbFile + '.index') except: self._log("problem copying " + testingDbfile + '.index') try: shutil.copy(testingDbfile + '.tmp', collaborationDbFile + '.tmp') except: self._log("problem copying " + testingDbfile + '.tmp') self._log("copy finished.") self._log('') self._log("Starting the ZEO server...") self.zeoServer = self.createDBServer(collaborationDbFile, zeoPort) self._log("zodb server started on pid: " + str(self.zeoServer) + " .") self._log('') self._log("Creating a CustomDBMgr on port " + str(zeoPort)) self.cdbmgr = DBMgr.getInstance(hostname="localhost", port=zeoPort) self._log("Starting a request ...") self.cdbmgr.startRequest() self._log("Request started successfully.") self._log('') if doCleanUp: self._log('Cleaning the DB of bookings and recreating the indexes') DeleteAllBookingsAction(FalseAction()).call() self._log('Cleanup succesfull') self._log("We start populating DB with bookings...") #ConferenceHolder()._getIdx() is an OOBTree size = lastConfId - firstConfId self._log("Populating among aproximately " + str(size) + " events, from " + str(firstConfId) + " to " + str(lastConfId) + ", with aproximately " + str(startingBookings) + " bookings") self._log("Initial size of 'all' index: " + str(IndexesHolder().getById("Collaboration").getAllBookingsIndex().getCount())) self.validConfIds = [] self.confsWithBookings = [] populated = 0 added = 0 chance = (float(startingBookings) / float(size)) / 2.0 ch = ConferenceHolder() for confId in xrange(firstConfId, lastConfId + 1): confId = str(confId) if self.random.random() < chance: try: conf = ch.getById(confId) self.validConfIds.append(confId) except MaKaCError: continue i = 0 bookingsForThisConf = max(int(self.random.normalvariate(3, 3)),0) added += bookingsForThisConf while i < bookingsForThisConf: conf.getCSBookingManager().createTestBooking(bookingParams = {'startDate': self._randomDate(startDate, endDate)}) i += 1 populated += 1 self.confsWithBookings.append(confId) if populated % 100 == 0: self._log(str(populated) + ' events populated. Index size: ' + str (IndexesHolder().getById("Collaboration").getAllBookingsIndex().getCount())) self._log("Populating finished. " + str(populated) + " events populated with " + str(added) + " bookings") self._log("Size of 'all' index is now: " + str(IndexesHolder().getById("Collaboration").getAllBookingsIndex().getCount())) self._log("Performing commit...") self.cdbmgr.endRequest(True) #True = commmit self._log("End of request") self._log('') except Exception, e: tb = str(traceback.format_tb(sys.exc_info()[2])) self.logger.error("There was an exception in setUp. Calling tearDown. Exception: " + str(e) + ", Traceback = " + tb) self.tearDown() self.fail("setUp failed. Cause: " + str(e) + ", Traceback = " + tb)
def sortByStartDate(conf1,conf2): ch = ConferenceHolder() return cmp(ch.getById(conf1).getStartDate(),ch.getById(conf2).getStartDate())
def updateOAIIndexes(): DBMgr.getInstance().startRequest() ch = ConferenceHolder() ih = indexes.IndexesHolder() catIdx = ih.getById("category") confIdx = ih.getById("OAIConferenceModificationDate") contIdx = ih.getById("OAIContributionModificationDate") confIdxPr = ih.getById("OAIPrivateConferenceModificationDate") contIdxPr = ih.getById("OAIPrivateContributionModificationDate") confIdx.initIndex() contIdx.initIndex() confIdxPr.initIndex() contIdxPr.initIndex() DBMgr.getInstance().commit() log("Count conferences...") ids = catIdx.getItems('0') totalConf = len(ids) log("%d conferences found"%totalConf) ic = 1 DBMgr.getInstance().sync() DBMgr.getInstance().endRequest() i = 0 pubConf = 0 privConf = 0 while ids: if len(ids) >= 10: lids = ids[:10] del ids[:10] else: lids = ids ids = None startic = ic startPubConf = pubConf startPrivConf = privConf for j in range(10): try: DBMgr.getInstance().startRequest() for id in lids: conf = ch.getById(id) confIdx = ih.getById("OAIConferenceModificationDate") contIdx = ih.getById("OAIContributionModificationDate") confIdxPr = ih.getById("OAIPrivateConferenceModificationDate") contIdxPr = ih.getById("OAIPrivateContributionModificationDate") log("Index conference %s: %d on %d"%(id, ic, totalConf)) ic += 1 if conf.hasAnyProtection(): confIdxPr.indexConference(conf) privConf += 1 else: confIdx.indexConference(conf) pubConf += 1 for cont in conf.getContributionList(): if cont.hasAnyProtection(): contIdxPr.indexContribution(cont) else: contIdx.indexContribution(cont) for sc in cont.getSubContributionList(): if cont.isProtected(): contIdxPr.indexContribution(sc) else: contIdx.indexContribution(sc) DBMgr.getInstance().endRequest() log("wait 0.5s...") sleep(0.5) break except Exception, e: log("error %s, retry %d time(s)"%(e,int(10-j))) sleep(int(j)) ic = startic pubConf = startPubConf privConf = startPrivConf DBMgr.getInstance().abort()
def index(req, **params): """This script displays the list of meetings which are planned in the coming week""" global ids try: stdate = params['stdate'] nbweeks = params['nbweeks'] except: return usage() [year, month, day] = stdate.split("-") days = int(nbweeks) * 7 ch = ConferenceHolder() previous = "" if str(year) == "2008": previous = """<a href="http://indico.cern.ch/tools/SSLPdisplay.py?stdate=2007-07-02&nbweeks=7">Previous Year Lecture Programme</a>""" elif str(year) == "2009": previous = """<a href="http://indico.cern.ch/tools/SSLPdisplay.py?stdate=2008-06-30&nbweeks=9">Previous Year Lecture Programme</a>""" elif str(year) == "2010": previous = """<a href="http://indico.cern.ch/tools/SSLPdisplay.py?stdate=2009-06-29&nbweeks=8">Previous Year Lecture Programme</a>""" elif str(year) == "2011": previous = """<a href="http://indico.cern.ch/scripts/SSLPdisplay.py?stdate=2010-07-05&nbweeks=7">Previous Year Lecture Programme</a>""" html = """ <!doctype html public "-//w3c//dtd html 4.0 transitional//en"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="Author" content="Matthias Egger"> <meta name="GENERATOR" content="Mozilla/4.75 [en] (Win95; U) [Netscape]"> <meta name="resp1" content="Matthias Egger"> <meta name="resp2" content="Tanja Peeters"> <meta name="DateCreated" content="971205"> <meta name="DateExpires" content="981201"> <meta name="DateModified" content="971205"> <meta name="Keywords" content="summer student lecture programme"> <meta name="Description" content="The Summer Student lecture programme."> <title>Summer Student Lecture Programme</title> </head> <body text="#000099" bgcolor="#FFFFCC" link="#000000" vlink="#C6600" alink="#FF9900"> <div align=right></div> <map name="cern_options_banner_2"><area shape="rect" coords="1,16,70,35" href="http://cern.web.cern.ch/CERN/Divisions/PE/HRS/Recruitment/Welcome.html"><area shape="rect" coords="72,17,146,35" href="http://cern.web.cern.ch/CERN/Divisions/PE/HRS/Recruitment/youngpeople.html"><area shape="rect" coords="146,15,181,37" href="http://cern.web.cern.ch/CERN/Divisions/PE/HRS/Recruitment/staff.html"><area shape="rect" coords="182,15,224,38" href="http://cern.web.cern.ch/CERN/Divisions/PE/HRS/Recruitment/fellows.html"><area shape="rect" coords="225,15,286,38" href="http://cern.web.cern.ch/CERN/Divisions/PE/HRS/Recruitment/associates.html"><area shape="rect" coords="286,16,337,37" href="http://cern.web.cern.ch/CERN/Divisions/PE/HRS/Recruitment/students.html"><area shape="rect" coords="338,16,389,36" href="http://cern.web.cern.ch/CERN/Divisions/PE/HRS/Recruitment/aboutus.html"><area shape="rect" coords="391,17,449,35" href="http://cern.web.cern.ch/CERN/Divisions/PE/HRS/Recruitment/contactus.html"><area shape="rect" coords="450,16,503,35" href="http://cern.web.cern.ch/CERN/Divisions/PE/HRS/Recruitment/other.html"><area shape="rect" coords="506,2,552,46" href="http://www.cern.ch"><area shape="default" nohref></map> %s <br> <br> <center> <p><a NAME="Prog"></a><b><font face="Verdana"><font color="#000080"><font size=+2>Summer Student Lecture Programme %s </font></font></font></b></center> </font></font></font> <p><b><font face="Verdana"><font color="#000080"><font size=-1>Keys:</font></font></font></b> <br><font face="Verdana"><font size=-1><font color="green">(v): videos</font></font></font> <br><font face="Verdana"><font size=-1><font color="red">(t): transparencies</font></font></font> <br><font face="Verdana"><font size=-1><font color="brown">(l): web lecture</font></font></font> <br><font face="Verdana"><font size=-1><font color="blue">(b): biography</font></font></font> <br><font face="Verdana"><font size=-1><font color="grey">(q): questionnaire</font></font></font> <br> """ % (previous, year) #create list of ids ids = [345, 346, 347, 348] db.DBMgr.getInstance().startRequest() tz = info.HelperMaKaCInfo.getMaKaCInfoInstance().getTimezone() #create date object startdate = timezone(tz).localize( datetime.datetime(int(year), int(month), int(day))) stdatedays = startdate.toordinal() enddate = startdate + datetime.timedelta(days=int(days)) #create result set res = sets.Set() #instanciate indexes im = indexes.IndexesHolder() catIdx = im.getIndex('category') calIdx = im.getIndex('calendar') c1 = calIdx.getObjectsIn(startdate, enddate) for id in ids: confIds = sets.Set(catIdx.getItems(id)) confIds.intersection_update(c1) res.update(confIds) res = list(res) res.sort(sortByStartDate) seminars = {} stimes = [] etimes = [] for id in res: obj = ch.getById(id) agenda = {} agenda['object'] = obj agenda['id'] = obj.getId() agenda['stime1'] = obj.getAdjustedStartDate(tz).time().isoformat()[0:5] agenda['atitle'] = obj.getTitle() agenda['desc'] = "" if obj.getComments() != "": agenda['desc'] = "<br>%s" % obj.getComments() if obj.getChairList() != []: agenda['chairman'] = obj.getChairList()[0].getFullName() else: agenda['chairman'] = "" agenda['stdate'] = obj.getAdjustedStartDate(tz).date() agenda['fduration'] = (obj.getAdjustedEndDate(tz) - obj.getAdjustedStartDate(tz)).seconds agenda['etime1'] = obj.getAdjustedEndDate(tz).time().isoformat()[0:5] stime = obj.getAdjustedStartDate(tz).time().isoformat()[0:5] etime = obj.getAdjustedEndDate(tz).time().isoformat()[0:5] stdate = obj.getAdjustedStartDate(tz).date() if not seminars.has_key(stdate): seminars[stdate] = {} if not seminars[stdate].has_key(stime): seminars[stdate][stime] = [] seminars[stdate][stime].append(agenda) if not stime in stimes: stimes.append(stime) etimes.append(etime) for week in range(0, int(nbweeks)): html += """<table BORDER CELLPADDING=4 WIDTH="100%" > <tr> <td VALIGN=TOP WIDTH="6%" HEIGHT="27" BGCOLOR="#FFFFFF"> <center><b><font face="Arial">Time</font></b></center> </td>""" beginweek = stdatedays + (week * 7) endweek = stdatedays + (week + 1) * 7 - 2 # display day names days = beginweek while days < endweek: thisday = datetime.datetime.fromordinal(days).strftime("%A %d %b") html += """ <td VALIGN=TOP WIDTH="19%%" HEIGHT="27" BGCOLOR="#FFFFFF"> <center><b><font face="Arial">%s</font></b></center> </td>""" % thisday days += 1 html += "</TR>" #display hour per hour agenda rowtext = "" for i in range(len(stimes)): val = stimes[i] rowtext = "" nbtalks = 0 rowtext += """ <TR><td VALIGN=TOP WIDTH="6%%" BGCOLOR="#FFFFFF"> <center><b><font face="Arial">%s</font></b> <br><b><font face="Arial">-</font></b> <br><b><font face="Arial">%s</font></b></center> </td>""" % (stimes[i], etimes[i]) days = beginweek while days < endweek: thisday = datetime.date.fromordinal(days) texttime = "" if seminars.has_key(thisday) and seminars[thisday].has_key( val): for agenda in seminars[thisday][val]: ida = agenda['id'] if agenda['stime1'] != stimes[i] or agenda[ 'etime1'] != etimes[i]: texttime = "<BR><i>(" + agenda[ 'stime1'] + " - " + agenda['etime1'] + ")</i>" #FILES textfiles = "" miscitems = 0 for m in agenda['object'].getAllMaterialList(): entry = m.getTitle().lower() if entry[0:4] != "part": if entry == "video" or entry == "video in cds": entry = "<font color=green>v</font>" elif entry in ["transparencies", "slides"]: entry = "<font color=red>t</font>" elif entry in ["biography"]: entry = "<font color=blue>b</font>" elif entry == "questionnaire": entry = "<font color=grey>q</font>" elif entry == "syncomat": entry = "<font color=brown>l</font>" elif entry == "lecture": entry = "<font color=brown>l</font>" elif entry == "lecture_from_2000": entry = "<font color=brown>l/2000</font>" elif entry == "video_from_2000": entry = "<font color=green>v/2000</font>" else: entry = "m" url = UHMaterialDisplay.getURL(m) textfiles += "(<A HREF=%s>%s</A>)" % (url, entry) rowtext += """<td VALIGN=TOP WIDTH="19%%"><font face="Arial"><font size=-1><a href="%s">%s</a>%s%s</font></font><p><i><font face="Arial"><font size=-1><i>%s</I>%s</font></font></i></td>\n""" % ( UHConferenceDisplay.getURL(agenda['object']), agenda['atitle'], agenda['desc'], textfiles, agenda['chairman'], texttime) nbtalks += 1 else: rowtext += """<td VALIGN=TOP WIDTH="19%"> </td>""" days += 1 rowtext += "</TR>" if nbtalks != 0: html += rowtext html += "</TABLE>" html += "<br> " html += """ <br> <!-- <p><a href="http://cern.web.cern.ch/CERN/Divisions/PE/HRS/Recruitment/6sumprog.html#SUMMER STUDENTS">CERN Recruitment Service</a> --> <center> <hr WIDTH="100%"> <!-- <br><font face="Verdana,Helvetica,Helvetica"><font size=-2><font color="#A00000"><a href="http://cern.web.cern.ch/CERN/Divisions/PE/HRS/Recruitment/search_HRS.html">Search</a></font><font color="#0000A0"> the pages of the Recruitment Service</font></font></font> <br><font face="Verdana,Helvetica"><font color="#000099"><font size=-2> Comments about this Web site to: <a href="mailto:[email protected]">[email protected]</a></font></font></font> <br><font face="Verdana,Helvetica"><font color="#000099"><font size=-2>Enquiries about Recruitment Programmes to: <a href="mailto:[email protected]">[email protected]</a></font></font></font> --> <br><font face="Verdana,Helvetica"><font color="#000099"><font size=-2>Copyright CERN - the European Laboratory for Particle Physics (Geneva, Switzerland)</font></font></font></center> <p><br> </body> </html>""" return html
class TestCategoryDayIndex(unittest.TestCase): def setUp(self): DBMgr.getInstance().startRequest() self.oldIndex = IndexesHolder()._getIdx()["categoryDateLtd"] self.newIndex = IndexesHolder()._getIdx()["categoryDate"] self.startDate = datetime(2010, 5, 13, 10, 0, 0, tzinfo=timezone('UTC')) self.endDate = datetime(2010, 5, 14, 14, 0, 0, tzinfo=timezone('UTC')) self.ch = ConferenceHolder() self.categId = '0' def tearDownModule(self): DBMgr.getInstance().abort() DBMgr.getInstance().endRequest() def testGetObjectsStartingInDay(self): newRes = self.newIndex._idxCategItem[ self.categId].getObjectsStartingInDay(self.startDate) oldTmp = self.oldIndex._idxCategItem[ self.categId].getObjectsStartingInDay(self.startDate) oldRes = set() for res in oldTmp: oldRes.add(self.ch.getById(res)) assert (oldRes == newRes) def testGetObjectsStartingIn(self): newRes = self.newIndex.getObjectsStartingIn(self.categId, self.startDate, self.endDate) oldTmp = self.oldIndex.getObjectsStartingIn(self.categId, self.startDate, self.endDate) oldRes = set() for res in oldTmp: oldRes.add(self.ch.getById(res)) assert (oldRes == newRes) def testGetObjectsStartingAfterTest(self): newRes = self.newIndex._idxCategItem[ self.categId].getObjectsStartingAfter(self.startDate) oldTmp = self.oldIndex._idxCategItem[ self.categId].getObjectsStartingAfter(self.startDate) oldRes = set() for res in oldTmp: oldRes.add(self.ch.getById(res)) assert (oldRes == newRes) def testGetObjectsEndingAfterTest(self): newRes = self.newIndex._idxCategItem[ self.categId].getObjectsEndingAfter(self.startDate) oldTmp = self.oldIndex._idxCategItem[ self.categId].getObjectsEndingAfter(self.startDate) oldRes = set() for res in oldTmp: oldRes.add(self.ch.getById(res)) assert (oldRes == newRes) def testGetObjectsEndingInDay(self): newRes = self.newIndex._idxCategItem[ self.categId].getObjectsEndingInDay(self.startDate) oldTmp = self.oldIndex._idxCategItem[ self.categId].getObjectsEndingInDay(self.startDate) oldRes = set() for res in oldTmp: oldRes.add(self.ch.getById(res)) assert (oldRes == newRes) def testGetObjectsEndingIn(self): newRes = self.newIndex._idxCategItem[self.categId].getObjectsEndingIn( self.startDate, self.endDate) oldTmp = self.oldIndex._idxCategItem[self.categId].getObjectsEndingIn( self.startDate, self.endDate) oldRes = set() for res in oldTmp: oldRes.add(self.ch.getById(res)) assert (oldRes == newRes) def testGetObjectsInDay(self): newRes = self.newIndex._idxCategItem[self.categId].getObjectsInDay( self.startDate) oldTmp = self.oldIndex._idxCategItem[self.categId].getObjectsInDay( self.startDate) oldRes = set() for res in oldTmp: oldRes.add(self.ch.getById(res)) assert (oldRes == newRes) def testGetObjectsIn(self): newRes = self.newIndex._idxCategItem[self.categId].getObjectsIn( self.startDate, self.endDate) oldTmp = self.oldIndex._idxCategItem[self.categId].getObjectsIn( self.startDate, self.endDate) oldRes = set() for res in oldTmp: oldRes.add(self.ch.getById(res)) assert (oldRes == newRes)