VC: Fix error on clone page for legacy-ID events
[cds-indico.git] / indico / modules / cssTpls.py
blobc7c9fcea332c65fcd06b32de250c8b0d48c7742d
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):
25 """
26 This module holds all the templates that can be used by a conference
27 in order to display all the information.
28 """
29 id = "cssTpls"
31 def __init__(self):
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")}
38 self._p_changed = 1
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]
47 return None
49 def addTemplate(self, tplId):
50 """
51 tplId must be the name of the css file
52 """
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):
63 """
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
68 template.
69 The class encapsulates the CSS so the user does not care about if it is
70 a template or a local file.
71 """
73 def __init__(self, css):
74 """
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
77 thing with just one.
79 _id is the same as _templateId when using a template and not a local file.
80 """
81 self._id = None
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
86 else:
87 self._localFile = css
89 def getId(self):
90 if self._localFile:
91 return self._localFile.getId()
92 else:
93 return self._templateId
95 def setId(self, i):
96 self._id = i
98 def isLocalFile(self):
99 return self._localfile is not None
101 def getLocalfile(self):
102 return self._localFile
104 def getLocator(self):
105 loc = {}
106 loc["cssId"] = self.getId()
107 return loc
109 def getURL(self):
110 if self._localFile:
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)
114 pass
115 else:
116 return "%s/%s"%(Config.getInstance().getCssConfTemplateBaseURL(),self._templateId)
118 def getFileName(self, extension=True):
119 if self._localFile:
120 fn =self._localFile.getFileName()
121 else:
122 fn = self._templateId
123 if not extension:
124 fn = fn.lower().replace(".css","")
125 return fn
127 def getSize(self):
128 if self._localFile:
129 return self._localFile.getSize()
130 else:
131 # so size for direct templates
132 return None
134 def delete(self):
135 if self._localFile:
136 self._localFile.delete()
137 self._localFile=None
138 self._templateId=None