[FIX] Meta tag for compatibility mode must be right after title
[cds-indico.git] / indico / htdocs / scripts / Forthcoming.py
blob4a820f1e1f0a6b62f913b21f39824e9620e2b954
1 # -*- coding: utf-8 -*-
2 ##
3 ##
4 ## This file is part of Indico.
5 ## Copyright (C) 2002 - 2013 European Organization for Nuclear Research (CERN).
6 ##
7 ## Indico is free software; you can redistribute it and/or
8 ## modify it under the terms of the GNU General Public License as
9 ## published by the Free Software Foundation; either version 3 of the
10 ## License, or (at your option) any later version.
12 ## Indico is distributed in the hope that it will be useful, but
13 ## WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ## General Public License for more details.
17 ## You should have received a copy of the GNU General Public License
18 ## along with Indico;if not, see <http://www.gnu.org/licenses/>.
20 import sys,re
22 from MaKaC.common.general import *
23 from MaKaC.common import db
24 from MaKaC.conference import ConferenceHolder,CategoryManager
25 from MaKaC.common import indexes
26 from MaKaC.common.timezoneUtils import nowutc
27 import MaKaC.common.info as info
28 from pytz import timezone
30 def index(req, **params):
31 """This script displays the list of meetings which are planned in the coming
32 week"""
33 global ids
34 db.DBMgr.getInstance().startRequest()
36 #create list of ids
37 ids = ['1l7']
38 tz = info.HelperMaKaCInfo.getMaKaCInfoInstance().getTimezone()
39 #create date object
40 startdate = nowutc()
41 #create result set
42 res = getConfList(startdate,ids)
43 req.content_type="text/html"
44 return displayList(res,tz)
46 def displayList(res,tz):
47 text = """
48 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
49 <HTML>
50 <HEAD>
51 <TITLE>Forthcoming Seminars</TITLE>
52 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
53 </HEAD>
54 <BODY LINK="#0000FF" VLINK="#800080">
56 <H1>
57 <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>
59 <H2>
60 FORTHCOMING SEMINARS / SEMINAIRES A VENIR</H2>
61 """
62 ch = ConferenceHolder()
63 curDate = None
64 for confId in res:
65 c = ch.getById(confId)
66 if curDate!=c.getAdjustedStartDate(tz):
67 curDate = c.getAdjustedStartDate(tz)
68 text += "<hr>%s<br>" % curDate.strftime("%A %B %d, %Y")
69 text += displayConf(c,tz)
70 return text
72 def displayConf(conf,tz):
73 if conf.getRoom() != None:
74 room = conf.getRoom().getName()
75 else:
76 room = ""
77 t = "<b>%s</b>&nbsp;/&nbsp;%s&nbsp;/&nbsp;<a href=\"http://indico.cern.ch/conferenceDisplay.py?confId=%s\">%s</a>/%s" % (conf.getAdjustedStartDate(tz).time().isoformat()[0:5],conf.getOwnerList()[0].getName(),conf.getId(),conf.getTitle(),room)
78 return t
81 def sortByStartDate(conf1,conf2):
82 ch = ConferenceHolder()
83 return cmp(ch.getById(conf1).getStartDate(),ch.getById(conf2).getStartDate())
85 def getConfList(startdate,ids):
86 #create result set
87 res = set()
88 #instanciate indexes
89 im = indexes.IndexesHolder()
90 catIdx = im.getIndex('category')
91 calIdx = im.getIndex('calendar')
92 c1 = calIdx.getObjectsStartingAfter(startdate)
93 for id in ids:
94 confIds=set(catIdx.getItems(id))
95 confIds.intersection_update(c1)
96 res.update(confIds)
97 res = list(res)
98 res.sort(sortByStartDate)
99 return res