source: indico/indico/MaKaC/webinterface/pages/base.py @ 216b1e

burotelhello-world-walkthroughipv6v0.98-seriesv0.98.2v0.98.3v0.98b1v0.98b2v0.99v1.0v1.1
Last change on this file since 216b1e was 216b1e, checked in by Pedro Ferreira <jose.pedro.ferreira@…>, 2 years ago

[FIX] Collaboration CSS

  • Property mode set to 100644
File size: 8.5 KB
Line 
1# -*- coding: utf-8 -*-
2##
3##
4## This file is part of CDS Indico.
5## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 CERN.
6##
7## CDS 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 2 of the
10## License, or (at your option) any later version.
11##
12## CDS 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.
16##
17## You should have received a copy of the GNU General Public License
18## along with CDS Indico; if not, write to the Free Software Foundation, Inc.,
19## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
20
21import MaKaC.webinterface.wcomponents as wcomponents
22import MaKaC.webinterface.urlHandlers as urlHandlers
23from MaKaC.common.Configuration import Config
24from MaKaC.common.info import HelperMaKaCInfo
25from MaKaC.i18n import _
26
27class WPBase:
28    """
29    """
30    _title = "Indico"
31
32    # required user-specific "data packages"
33    _userData = []
34
35    def __init__( self, rh ):
36        self._rh = rh
37        self._locTZ = ""
38
39        #store page specific CSS and JS
40        self._extraCSS = []
41        self._extraJS = []
42
43    def _includeJSPackage(self, packageName, module = 'indico', path=None):
44        info = HelperMaKaCInfo().getMaKaCInfoInstance()
45
46        if info.isDebugActive():
47            return ['js/%s/%s/Loader.js' % (module, packageName)]
48        else:
49            return ['js/%s/pack/%s.pack.js' % (module, packageName)]
50
51    def _includeJSFile(self, path, filename):
52        info = HelperMaKaCInfo().getMaKaCInfoInstance()
53
54        if info.isDebugActive():
55            return ['%s/%s.js' % (path, filename)]
56        else:
57            return ['%s/%s.pack.js' % (path, filename)]
58
59    def _includePresentationFiles(self):
60        info = HelperMaKaCInfo().getMaKaCInfoInstance()
61
62        if info.isDebugActive():
63            return ['js/presentation/Loader.js']
64        else:
65            return ['js/presentation/pack/Presentation.pack.js']
66
67    def _getBaseURL( self ):
68        return Config.getInstance().getBaseURL()
69
70    def _getTitle( self ):
71        return self._title
72
73    def _setTitle( self, newTitle ):
74        self._title = newTitle.strip()
75
76    def getCSSFiles(self):
77        return []
78
79    def getJSFiles(self):
80        return self._includePresentationFiles() + \
81               self._includeJSPackage('Core') + \
82               self._includeJSPackage('Legacy') + \
83               self._includeJSPackage('Common')
84
85    def _getJavaScriptInclude(self, scriptPath):
86        return '<script src="'+ scriptPath +'" type="text/javascript"></script>\n'
87
88    def _getJavaScriptUserData(self):
89        """
90        Returns structured data that should be passed on to the client side
91        but depends on user data (can't be in vars.js.tpl)
92        """
93
94        user = self._getAW().getUser();
95
96        from MaKaC.webinterface.asyndico import UserDataFactory
97
98        userData = dict((packageName,
99                         UserDataFactory(user).build(packageName))
100                        for packageName in self._userData)
101
102        return userData
103
104    def _getHeadContent( self ):
105        """
106        Returns _additional_ content between <head></head> tags.
107        Please note that <title>, <meta> and standard CSS are always included.
108
109        Override this method to add your own, page-specific loading of
110        JavaScript, CSS and other legal content for HTML <head> tag.
111        """
112        return ""
113
114    def _getWarningMessage(self):
115        return ""
116
117    def _getHTMLHeader( self ):
118        from MaKaC.webinterface.pages.conferences import WPConfSignIn
119        from MaKaC.webinterface.pages.signIn import WPSignIn
120        from MaKaC.webinterface.pages.registrationForm import WPRegistrationFormSignIn
121        from MaKaC.webinterface.rh.base import RHModificationBaseProtected
122        from MaKaC.webinterface.rh.admins import RHAdminBase
123
124        baseurl = self._getBaseURL()
125        if ((isinstance(self, WPSignIn) or isinstance(self, WPConfSignIn) or isinstance(self, WPRegistrationFormSignIn)) and \
126                Config.getInstance().getLoginURL().startswith("https")) or \
127                self._rh._req.is_https() and self._rh._tohttps:
128            baseurl = baseurl.replace("http://","https://")
129            baseurl = urlHandlers.setSSLPort( baseurl )
130
131        area=""
132        if isinstance(self._rh, RHModificationBaseProtected):
133            area=_(""" - _("Management area")""")
134        elif isinstance(self._rh, RHAdminBase):
135            area=_(""" - _("Administrator area")""")
136
137        websession = self._getAW().getSession()
138        if websession:
139            language = websession.getLang()
140        else:
141            info = HelperMaKaCInfo().getMaKaCInfoInstance()
142            language = info.getLang()
143
144        return wcomponents.WHTMLHeader().getHTML({
145                            "area": area,
146                            "baseurl": baseurl,
147                            "conf": Config.getInstance(),
148                            "page": self,
149                            "extraCSS": self.getCSSFiles(),
150                            "extraJSFiles": self.getJSFiles(),
151                            "extraJS": self._extraJS,
152                            "language": language
153                            })
154
155    def _getHTMLFooter( self ):
156        return """
157    </body>
158</html>
159               """
160
161    def _display( self, params ):
162        """
163        """
164        return _("no content")
165
166    def _getAW( self ):
167        return self._rh.getAW()
168
169    def display( self, **params ):
170        """
171        """
172        return "%s%s%s"%( self._getHTMLHeader(), \
173                            self._display( params ), \
174                            self._getHTMLFooter() )
175
176
177    def addExtraJSFile(self, filename):
178        self._extraJSFiles.append(filename)
179
180    def addExtraJS(self, jsCode):
181        self._extraJS.append(jsCode)
182
183    # auxiliar functions
184    def _escapeChars(self, text):
185        return text.replace('%','%%')
186
187
188class WPDecorated( WPBase ):
189
190    def _getSiteArea(self):
191        return "DisplayArea"
192
193    def getLoginURL( self ):
194        return urlHandlers.UHSignIn.getURL("%s"%self._rh.getCurrentURL())
195
196    def getLogoutURL( self ):
197        return urlHandlers.UHSignOut.getURL("%s"%self._rh.getCurrentURL())
198
199    def getLoginAsURL( self ):
200        return urlHandlers.UHLogMeAs.getURL("%s"%self._rh.getCurrentURL())
201
202
203    def _getHeader( self ):
204        """
205        """
206        wc = wcomponents.WHeader( self._getAW(), isFrontPage=self._isFrontPage(), currentCategory=self._currentCategory(), locTZ=self._locTZ )
207        return wc.getHTML( { "subArea": self._getSiteArea(), \
208                             "loginURL": self._escapeChars(str(self.getLoginURL())),\
209                             "logoutURL": self._escapeChars(str(self.getLogoutURL())),\
210                             "loginAsURL": self.getLoginAsURL() } )
211
212    def _getTabControl(self):
213        return None
214
215    def _getFooter( self):
216        """
217        """
218        wc = wcomponents.WFooter(isFrontPage=self._isFrontPage())
219        return wc.getHTML({ "subArea": self._getSiteArea() })
220
221    def _applyDecoration( self, body ):
222        """
223        """
224        return "<div class=\"wrapper\">%s%s<div class=\"emptyFooter\"></div></div>%s"%( self._getHeader(), body, self._getFooter() )
225
226    def _display( self, params ):
227
228        return self._applyDecoration( self._getBody( params ) )
229
230    def _getBody( self, params ):
231        """
232        """
233        pass
234
235    def _getNavigationDrawer(self):
236        return None
237
238    def _isFrontPage(self):
239        """
240            Welcome page class overloads this, so that additional info (news, policy)
241            is shown.
242        """
243        return False
244
245    def _isRoomBooking(self):
246        return False
247
248    def _currentCategory(self):
249        """
250            Whenever in category display mode this is overloaded with the current category
251        """
252        return None
253
254    def _getSideMenu(self):
255        """
256            Overload and return side menu whenever there is one
257        """
258        return None
259
260class WPNotDecorated( WPBase ):
261
262    def getLoginURL( self ):
263        return urlHandlers.UHSignIn.getURL("%s"%self._rh.getCurrentURL())
264
265    def getLogoutURL( self ):
266        return urlHandlers.UHSignOut.getURL("%s"%self._rh.getCurrentURL())
267
268    def _display( self, params ):
269        return self._getBody( params )
270
271    def _getBody( self, params ):
272        """
273        """
274        pass
275
276    def _getNavigationDrawer(self):
277        return None
278
279
280
Note: See TracBrowser for help on using the repository browser.