1 # This file is part of Indico.
2 # Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
4 # Indico is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3 of the
7 # License, or (at your option) any later version.
9 # Indico is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Indico; if not, see <http://www.gnu.org/licenses/>.
18 from datetime
import datetime
21 from MaKaC
import conference
22 from MaKaC
.common
import timezoneUtils
23 from MaKaC
.common
.Counter
import Counter
24 from MaKaC
.webinterface
.pages
.main
import WPMainBase
25 from MaKaC
.webinterface
import urlHandlers
26 from MaKaC
.webinterface
import wcomponents
28 from indico
.core
.config
import Config
29 from indico
.util
.i18n
import _
, get_current_locale
30 from indico
.util
.date_time
import format_date
33 class WPCalendarBase( WPMainBase
):
35 def __init__( self
, rh
, calendar
, categ
=None ):
36 WPMainBase
.__init
__( self
, rh
)
39 self
._locTZ
= timezoneUtils
.DisplayTZ(self
._getAW
(),None,useServerTZ
=1).getDisplayTZ()
42 return WPMainBase
._getTitle
(self
) + " - " + _("Calendar Overview")
46 _colorList
= ["#f4dabe", "#bcdff2", "#f7f4c0", "#CCFF99", "#e0baef", "#ecf409", "#FFFFCC" ]
48 def __init__( self
, categList
):
51 for categ
in categList
:
52 self
._colorDict
[categ
.getId()] = self
.getNewColor()
54 def getNewColor( self
):
55 if self
._colorIdx
>= len( self
._colorList
):
56 r
= random
.randint(130,255)
57 g
= random
.randint(130,255)
58 b
= random
.randint(130,255)
59 return "#%X%X%X"%(r
,g
,b
)
62 color
= self
._colorList
[self
._colorIdx
]
66 def getColor( self
, categ
):
67 if not self
._colorDict
.has_key( categ
.getId() ):
69 return self
._colorDict
[ categ
.getId() ]
72 class WCalendarMonthItem
:
74 def __init__( self
, month
, multipleColor
, categColors
, cal
):
77 self
._multipleColor
= multipleColor
78 self
._categColors
= categColors
80 def _getDiv( self
, day
):
81 fulldate
= "%s%02d%02d" % (self
._month
.getYear(),self
._month
.getMonthNumber(),day
.getDayNumber())
83 <div id="d%s" class="calendarList">
84 <table cellSpacing=0 cellPadding=1 bgcolor="#A0A0A0" border=0>
87 <table cellSpacing=0 cellPadding=4 bgcolor="#FFFFFF" border=0>"""%fulldate
]
88 for conf
in day
.getConferences():
89 categs
= self
._cal
.getConferenceCategories( conf
)
92 <table cellspacing="0" cellpadding="0" border="0" align="left">
95 colors
.append("""<td bgcolor="%s"> </td>"""%self
._categColors
.getColor( categ
))
99 maincolor
= self
._multipleColor
102 maincolor
= self
._categColors
.getColor( categs
[0] )
103 title
= conf
.getTitle()
105 <tr bgcolor="#ECECEC" %s>
106 <td valign=top>%s<a href="%s">%s</a></td>
107 </tr>""" % (maincolor
, "\n".join(colors
), urlHandlers
.UHConferenceDisplay
.getURL(conf
), title
))
115 <script type="text/javascript">
117 menudivs["d%s"] = new Object();
118 menudivs["d%s"].id = "d%s";
119 menudivs["d%s"].anchorId = "a%s";
120 menudivs["d%s"].spanId = "s%s";
121 menudivs["d%s"].menuOn = false;
122 menudivs["d%s"].onAnchor = false;
125 """%(fulldate
,fulldate
,fulldate
,fulldate
,fulldate
,fulldate
,fulldate
,fulldate
,fulldate
))
126 return "\n".join(res
)
133 for day
in self
._month
.getDayList():
134 fulldate
= "%s%02d%02d" % (self
._month
.getYear(),self
._month
.getMonthNumber(),day
.getDayNumber())
135 if day
.getDayNumber() == 1:
136 for i
in range(day
.getWeekDay()):
137 res
.append("<td></td>")
138 categs
= day
.getCategories()
141 <table cellspacing="0" cellpadding="0" border="0" align="left">
144 colors
.append("""<td bgcolor="%s"> </td>"""%self
._categColors
.getColor( categ
))
148 res
.append( """<td align="right" bgcolor="%s" onMouseOver="setOnAnchor('d%s')" onMouseOut="clearOnAnchor('d%s')">%s<span style="cursor: default;" id="a%s">%s</span></td>"""%( self
._multipleColor
, fulldate
, fulldate
, "\n".join(colors
), fulldate
, day
.getDayNumber() ) )
149 divs
.append(self
._getDiv
(day
))
150 elif len(categs
) == 1:
151 res
.append( """<td align="right" bgcolor="%s" onMouseOver="setOnAnchor('d%s')" onMouseOut="clearOnAnchor('d%s')"><span style="cursor: default;" id="a%s">%s</span></td>"""%( self
._categColors
.getColor( categs
[0] ), fulldate
, fulldate
, fulldate
, day
.getDayNumber() ) )
152 divs
.append(self
._getDiv
(day
))
154 res
.append( """<td align="right">%s</td>"""%day
.getDayNumber() )
155 if day
.getWeekDay() == 6:
160 <table cellspacing="1" cellpadding="5">
162 <td colspan="7" align="center" style="font-size: 1.2em;">%s</b></td>
172 """ % (format_date(self
._month
._date
, 'MMM YYYY'),
173 ''.join(list('<td align="right" bgcolor="#CCCCCC">{}</td>'.format(
174 get_current_locale().weekday(wd
)[:2]) for wd
in xrange(0, 7))),
175 "\n".join(res
), "\n".join(divs
))
179 class WCalendar(wcomponents
.WTemplated
):
180 _multipleColor
= "#DDDDDD"
182 def __init__( self
, aw
, cal
):
186 def _getLegendItem( self
, color
, caption
):
187 str = """<div style="font-size: 15px; margin-bottom: 5px;">
188 <div style="border: 1px solid #AAAAAA; float: left; width: 15px; height: 15px; background-color: %s"></div>
189 <span style="padding-left: 10px">%s</span>
191 """%( color
, caption
)
194 def _getLegend( self
, categDisplayURLGen
):
195 cl
= CategColorList( self
._cal
.getCategoryList() )
197 for categ
in self
._cal
.getCategoryList():
198 url
= categDisplayURLGen( categ
)
199 caption
= """<a href="%s">%s</a>"""%( url
, categ
.getName() )
200 l
.append( """%s"""%self
._getLegendItem
(cl
.getColor(categ
), caption
) )
201 l
.append( """%s"""%self
._getLegendItem
( self
._multipleColor
, _("Multiple") ) )
203 return """%s """%("".join(l
))
205 def _getCalendar( self
):
206 cl
= CategColorList( self
._cal
.getCategoryList() )
209 for month
in self
._cal
.getMonthList():
210 if idx
== self
._cal
.getNrColumns():
211 res
.append("</tr>\n<tr>")
213 m
= WCalendarMonthItem( month
, self
._multipleColor
, cl
, self
._cal
)
214 res
.append(""" <td valign="top">%s</td>"""%m
.getHTML() )
217 return "".join( res
)
220 vars = wcomponents
.WTemplated
.getVars( self
)
221 locNM
= self
._cal
.getLocator()
223 vars["locatorNoMonth"]= locNM
.getWebForm()
224 vars["locator"]= self
._cal
.getLocator().getWebForm()
225 for i
in range(6, 13):
226 if self
._cal
.getNrMonths() == i
:
227 vars["def%s"%i] = "selected"
230 vars["legend"] = self
._getLegend
( urlHandlers
.UHCategoryDisplay
.getURL
)
231 vars["calendar"] = self
._getCalendar
()
232 vars["selectedmonths"] = int(self
._cal
.getNrMonths())
233 vars["selectedcolumns"] = int(self
._cal
.getNrColumns())
234 vars["selectedmonth"] = int(self
._cal
.getStartDate().strftime("%m"))
235 vars["selectedyear"] = int(self
._cal
.getStartDate().strftime("%Y"))
239 class WPCalendar(WPCalendarBase
):
241 def _getBody(self
, params
):
242 wc
= WCalendar(self
._getAW
(), self
._cal
)
244 catman
= conference
.CategoryManager()
246 for cat
in self
._cal
.getCategoryList():
247 while cat
.getId() != "0":
249 catList
.append(cat
.getId())
250 params
= {"changeMonthsURL": urlHandlers
.UHCalendar
.getURL(),
251 "categDisplayURL": urlHandlers
.UHCategoryDisplay
.getURL(self
._categ
),
252 "selCategsURL": str(urlHandlers
.UHCalendarSelectCategories
.getURL()),
253 "categoryTitle": self
._categ
.getTitle(),
254 "currentYear": datetime
.now().year
,
256 params
["selCategsURL"] += "?xs=" + catman
.getRoot().getId()
258 params
["selCategsURL"] += "&xs=" + id
259 return wc
.getHTML(params
)
261 def _getNavigationDrawer(self
):
262 #link = [{"url": urlHandlers.UHCalendar.getURL([self._categ]), "title": _("Calendar overview")}]
263 pars
= {"target": self
._categ
, "isModif": False}
264 return wcomponents
.WNavigationDrawer( pars
, type = "Calendar" )
267 class MulSelectCategTree
:
269 def __init__( self
, aw
):
271 self
._number
= Counter()
272 def _getItem( self
, categ
, level
=0 ):
273 if not categ
.canView( self
._aw
):
276 number
=self
._number
.newCount()
277 for i
in range(level
):
278 html
= "%s "%html
279 cfg
= Config
.getInstance()
282 if categ
in self
._selCategs
:
284 title
= """<input type="checkbox" name="selCateg" id="%s" onClick="alerta(%s);" value="%s" %s> %s"""%\
285 (number
,number
,categ
.getId(), checked
, categ
.getName() )
286 if categ
in self
._expandedCategs
:
287 temp
= copy( self
._expandedCategs
)
289 html
= """%s<a href="%s"><img src="%s" border="0" alt="fold"></a> %s"""%\
291 self
._expandURLGen
( temp
), \
292 cfg
.getSystemIconURL("exploded.png"), \
294 for subcat
in categ
.getSubCategoryList():
295 html
= "%s<br>%s"%(html
, self
._getItem
(subcat
, level
+1) )
297 html
= """%s<a href="%s"><img src="%s" border="0" alt="unfold"></a> %s"""%\
299 self
._expandURLGen
( self
._expandedCategs
+[categ
] ), \
300 cfg
.getSystemIconURL("collapsd.png"), \
305 def getHTML( self
, selected
, expanded
, expandURLGen
):
306 self
._selCategs
= selected
307 self
._expandedCategs
= expanded
308 self
._expandURLGen
= expandURLGen
309 r
= conference
.CategoryManager().getRoot()
310 return self
._getItem
( r
)
313 class WCalendarSelectCategs( wcomponents
.WTemplated
):
315 def __init__( self
, aw
, cal
):
319 def getHTML( self
, expanded
, expandURLGen
, calendarURL
):
321 self
._expURLGen
= expandURLGen
322 self
._calURL
= calendarURL
323 return wcomponents
.WTemplated
.getHTML( self
, {} )
326 vars = wcomponents
.WTemplated
.getVars( self
)
327 l
= self
._cal
.getLocator()
328 vars["locator"] = l
.getWebForm()
330 vars["locatorNoCategs"] = l
.getWebForm()
331 vars["categs"] = MulSelectCategTree( self
._aw
).getHTML( \
332 self
._cal
.getCategoryList(), \
333 self
._exp
, self
._expURLGen
)
334 vars["calendarURL"] = self
._calURL
338 class WPCalendarSelectCategories( WPCalendarBase
):
340 def _getExpandedCategURL( self
, exList
):
341 url
= urlHandlers
.UHCalendarSelectCategories
.getURL( self
._cal
)
344 ex
.append( categ
.getId() )
345 url
.addParam( "xs", ex
)
348 def _getBody( self
, params
):
349 wc
= WCalendarSelectCategs( self
._getAW
(), self
._cal
)
350 return wc
.getHTML( params
["expanded"], \
351 self
._getExpandedCategURL
, \
352 urlHandlers
.UHCalendar
.getURL() )