Remove old materials from categories
[cds-indico.git] / indico / MaKaC / webinterface / pages / material.py
blob256d2f70134dd584e1cba372e4fab7fbeffe9ee2
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 xml.sax.saxutils import escape, quoteattr
19 import MaKaC.webinterface.wcomponents as wcomponents
20 import MaKaC.webinterface.urlHandlers as urlHandlers
21 import MaKaC.webinterface.navigation as navigation
22 from MaKaC.webinterface.pages.conferences import WPConferenceModifBase,WPConferenceBase,WPConferenceDefaultDisplayBase, WConfDisplayFrame
23 import MaKaC.conference as conference
24 from MaKaC.webinterface.general import strfFileSize
25 from MaKaC.webinterface.materialFactories import ConfMFRegistry,SessionMFRegistry,ContribMFRegistry
26 from indico.core.config import Config
27 from MaKaC.webinterface.pages.category import WPCategoryBase,WPCategoryDisplayBase,WPCategoryDisplay
28 import MaKaC.webinterface.pages.category
29 import MaKaC.webinterface.displayMgr as displayMgr
30 from MaKaC.i18n import _
31 from indico.util.i18n import i18nformat
33 class WPMaterialBase( WPConferenceModifBase, WPCategoryBase ):
35 def __init__( self, rh, material ):
36 self._material = self._target = material
37 if self._material.getConference()!=None:
38 WPConferenceModifBase.__init__( self, rh, self._material.getConference() )
39 else:
40 WPCategoryBase.__init__(self,rh,self._material.getCategory())
42 def _getFooter( self ):
43 """
44 """
46 wc = wcomponents.WFooter()
48 if self._conf != None:
49 p = {"modificationDate":self._conf.getModificationDate().strftime("%d %B %Y %H:%M"),
50 "subArea": self._getSiteArea() }
51 return wc.getHTML(p)
52 else:
53 return wc.getHTML()
56 class WPMaterialDisplayBase( WPConferenceDefaultDisplayBase ):
58 def __init__(self, rh, material):
59 self._material = self._target =material
60 WPConferenceDefaultDisplayBase.__init__( self, rh, self._material.getConference() )
61 self._navigationTarget = self._material
63 def getJSFiles(self):
64 return WPConferenceDefaultDisplayBase.getJSFiles(self) + \
65 self._includeJSPackage('MaterialEditor')
67 def _applyDecoration( self, body ):
68 return WPConferenceDefaultDisplayBase._applyDecoration( self, body )
70 def _getBody( self, params ):
72 wc = WMaterialDisplay( self._getAW(), self._material )
73 pars = { "fileAccessURLGen": urlHandlers.UHFileAccess.getURL }
74 return wc.getHTML( pars )
77 class WPMaterialCatDisplayBase(WPCategoryDisplayBase, WPMaterialDisplayBase ):
78 def __init__(self, rh, material):
79 self._material = self._target =material
82 WPCategoryDisplayBase.__init__(self,rh,self._material.getCategory())
83 self._navigationTarget = self._material
85 def _applyDecoration( self, body ):
87 return WPCategoryDisplayBase._applyDecoration( self, body )
89 def _getBody( self, params ):
91 wc = WMaterialDisplay( self._getAW(), self._material )
92 return wc.getHTML( )
95 class WPMaterialConfDisplayBase(WPMaterialDisplayBase, WPConferenceDefaultDisplayBase ):
97 def __init__(self,rh,material):
98 self._material = self._target =material
100 WPConferenceDefaultDisplayBase.__init__(self,rh,self._material.getConference())
102 self._navigationTarget = self._material
104 def _applyDecoration( self, body ):
106 return WPConferenceDefaultDisplayBase._applyDecoration( self, body )
109 class WMaterialDisplay(wcomponents.WTemplated):
111 def __init__(self, aw, material):
112 self._material=material
113 self._aw=aw
115 def _canSubmitResource(self, material):
116 if isinstance(material.getOwner(), conference.Contribution):
117 contrib=material.getOwner()
118 status=contrib.getCurrentStatus()
119 if not isinstance(status,conference.ContribStatusWithdrawn) and \
120 contrib.canUserSubmit(self._aw.getUser()):
121 return True
122 return False
124 def _getURL(self, resource):
125 url = resource.getURL()
126 if url.find(".wmv") != -1:
127 url = urlHandlers.UHVideoWmvAccess().getURL(resource)
128 elif url.find(".flv") != -1 or url.find(".f4v") != -1 or url.find("rtmp://") != -1:
129 url = urlHandlers.UHVideoFlashAccess().getURL(resource)
130 return url
132 def getVars( self ):
133 vars = wcomponents.WTemplated.getVars( self )
135 vars["canSubmitResource"] = self._canSubmitResource(self._material)
136 vars["material"] = self._material
137 vars["accessWrapper"] = self._aw
138 vars["getURL"] = lambda resource : self._getURL(resource)
139 vars["fileAccessURLGen"] = urlHandlers.UHFileAccess.getURL
140 if self._material.getSubContribution():
141 vars["uploadAction"] = 'Indico.Urls.UploadAction.subcontribution'
142 elif self._material.getContribution():
143 vars["uploadAction"] = 'Indico.Urls.UploadAction.contribution'
144 elif self._material.getSession():
145 vars["uploadAction"] = 'Indico.Urls.UploadAction.session'
146 elif self._material.getConference():
147 vars["uploadAction"] = 'Indico.Urls.UploadAction.conference'
149 return vars