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/>.
17 from persistent
import Persistent
18 from MaKaC
.common
.Counter
import Counter
19 from MaKaC
.common
.info
import HelperMaKaCInfo
20 from indico
.core
.config
import Config
22 from indico
.modules
import Module
24 class CssTplsModule(Module
):
26 This module holds all the templates that can be used by a conference
27 in order to display all the information.
32 self
._cssTpls
= {"template0.css": CSSItem("template0.css"), \
33 "right_menu.css": CSSItem("right_menu.css"),
34 "orange.css": CSSItem("orange.css"),
35 "brown.css": CSSItem("brown.css"),
37 "template_indico.css": CSSItem("template_indico.css")}
39 self
._cssCounter
= Counter()
41 def getCssTplsList(self
):
42 return self
._cssTpls
.values()
44 def getCssTplById(self
, id):
45 if self
._cssTpls
.has_key(id):
46 return self
._cssTpls
[id]
49 def addTemplate(self
, tplId
):
51 tplId must be the name of the css file
53 self
._cssTpls
[tplId
] = CSSItem(tplId
)
55 def addLocalFile(self
, lf
):
56 lf
.setId(self
._cssCounter
.newCount())
57 # TODO: add owner and repository
58 self
._cssTpls
[lf
.getId()] = CSSItem(lf
)
62 class CSSItem(Persistent
):
64 This class will handle a CSS template that can be applied
65 to a conference display. CSS file can be an upload file or a
66 template we already have. The upload file is an object of the class
67 LocalFile and the template is just a string with the id (name) of the
69 The class encapsulates the CSS so the user does not care about if it is
70 a template or a local file.
73 def __init__(self
, css
):
75 A CSS item can be a local file or a template, but not both things at the same time.
76 We keep to variables to make it readable, even if it would be possible to do the same
79 _id is the same as _templateId when using a template and not a local file.
82 self
._localFile
= None
83 self
._templateId
= None
84 if isinstance(css
, str): # if css is not an object but a string, then we assume it is a template id.
85 self
._templateId
= self
._id
= css
91 return self
._localFile
.getId()
93 return self
._templateId
98 def isLocalFile(self
):
99 return self
._localfile
is not None
101 def getLocalfile(self
):
102 return self
._localFile
104 def getLocator(self
):
106 loc
["cssId"] = self
.getId()
111 # TODO: return a correct URL when possible to have files as templates
112 #from MaKaC.webinterface.urlHandlers import UHConferenceCSS
113 #return UHConferenceCSS.getURL(self._localFile)
116 return "%s/%s"%(Config
.getInstance().getCssConfTemplateBaseURL(),self
._templateId
)
118 def getFileName(self
, extension
=True):
120 fn
=self
._localFile
.getFileName()
122 fn
= self
._templateId
124 fn
= fn
.lower().replace(".css","")
129 return self
._localFile
.getSize()
131 # so size for direct templates
136 self
._localFile
.delete()
138 self
._templateId
=None