equal
deleted
inserted
replaced
1 # copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
1 # copyright 2003-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # |
3 # |
4 # This file is part of CubicWeb. |
4 # This file is part of CubicWeb. |
5 # |
5 # |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
37 from cubicweb.web.http_headers import generateDateTime |
37 from cubicweb.web.http_headers import generateDateTime |
38 from cubicweb.web.controller import Controller |
38 from cubicweb.web.controller import Controller |
39 from cubicweb.web.views.urlrewrite import URLRewriter |
39 from cubicweb.web.views.urlrewrite import URLRewriter |
40 |
40 |
41 |
41 |
42 |
|
43 class StaticFileController(Controller): |
42 class StaticFileController(Controller): |
44 """an abtract class to serve static file |
43 """an abtract class to serve static file |
45 |
44 |
46 Make sure to add your subclass to the STATIC_CONTROLLERS list""" |
45 Make sure to add your subclass to the STATIC_CONTROLLERS list""" |
47 __abstract__ = True |
46 __abstract__ = True |
48 directory_listing_allowed = False |
47 directory_listing_allowed = False |
49 |
48 |
50 def max_age(self, path): |
49 def max_age(self, path): |
51 """max cache TTL""" |
50 """max cache TTL""" |
52 return 60*60*24*7 |
51 return 60 * 60 * 24 * 7 |
53 |
52 |
54 def static_file(self, path): |
53 def static_file(self, path): |
55 """Return full content of a static file. |
54 """Return full content of a static file. |
56 |
55 |
57 XXX iterable content would be better |
56 XXX iterable content would be better |
246 def publish(self, rset=None): |
245 def publish(self, rset=None): |
247 staticdir = self._cw.vreg.config.static_directory |
246 staticdir = self._cw.vreg.config.static_directory |
248 relpath = self.relpath[len(self.__regid__) + 1:] |
247 relpath = self.relpath[len(self.__regid__) + 1:] |
249 return self.static_file(osp.join(staticdir, relpath)) |
248 return self.static_file(osp.join(staticdir, relpath)) |
250 |
249 |
|
250 |
251 STATIC_CONTROLLERS = [DataController, FCKEditorController, |
251 STATIC_CONTROLLERS = [DataController, FCKEditorController, |
252 StaticDirectoryController] |
252 StaticDirectoryController] |
|
253 |
253 |
254 |
254 class StaticControlerRewriter(URLRewriter): |
255 class StaticControlerRewriter(URLRewriter): |
255 """a quick and dirty rewritter in charge of server static file. |
256 """a quick and dirty rewritter in charge of server static file. |
256 |
257 |
257 This is a work around the flatness of url handling in cubicweb.""" |
258 This is a work around the flatness of url handling in cubicweb.""" |
265 if uri.startswith('/%s/' % ctrl.__regid__): |
266 if uri.startswith('/%s/' % ctrl.__regid__): |
266 break |
267 break |
267 else: |
268 else: |
268 self.debug("not a static file uri: %s", uri) |
269 self.debug("not a static file uri: %s", uri) |
269 raise KeyError(uri) |
270 raise KeyError(uri) |
270 relpath = self._cw.relative_path(includeparams=False) |
|
271 self._cw.form['static_relative_path'] = self._cw.relative_path(includeparams=True) |
271 self._cw.form['static_relative_path'] = self._cw.relative_path(includeparams=True) |
272 return ctrl.__regid__, None |
272 return ctrl.__regid__, None |