separate templates from static files
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 20 Sep 2013 14:40:52 +0000 (16:40 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 20 Sep 2013 14:40:52 +0000 (16:40 +0200)
we're now rather consistent with django mainstream's default layout
even if it's not always very convenient (use symlinks in your workdir)

55 files changed:
.gitignore
Makefile
README
auth/static/css/login.css [moved from auth/css/login.css with 100% similarity]
auth/static/css/logout.css [moved from auth/css/logout.css with 100% similarity]
auth/static/img/form_input_password.png [moved from auth/img/form_input_password.png with 100% similarity]
auth/static/js/logout.js [moved from auth/js/logout.js with 100% similarity]
devel/server-loop.sh
manifold/static/css/manifold.css [moved from manifold/css/manifold.css with 100% similarity]
manifold/static/js/class.js [moved from manifold/js/class.js with 100% similarity]
manifold/static/js/manifold-query.js [moved from manifold/js/manifold-query.js with 100% similarity]
manifold/static/js/manifold.js [moved from manifold/js/manifold.js with 100% similarity]
manifold/static/js/metadata.js [moved from manifold/js/metadata.js with 100% similarity]
manifold/static/js/plugin-sample.html [moved from manifold/js/plugin-sample.html with 100% similarity]
manifold/static/js/plugin.js [moved from manifold/js/plugin.js with 100% similarity]
myslice/settings.py
plugins/active_filters/templates/active_filters.html [moved from plugins/active_filters/static/active_filters.html with 100% similarity]
plugins/code_editor/templates/code_editor.html [moved from plugins/code_editor/static/code_editor.html with 100% similarity]
plugins/debug_platform/templates/debug_platform.html [moved from plugins/debug_platform/static/debug_platform.html with 100% similarity]
plugins/form/templates/form.html [moved from plugins/form/static/form.html with 100% similarity]
plugins/googlemap/templates/googlemap.html [moved from plugins/googlemap/static/googlemap.html with 100% similarity]
plugins/hazelnut/templates/hazelnut.html [moved from plugins/hazelnut/static/hazelnut.html with 100% similarity]
plugins/lists/templates/simplelist.html [moved from plugins/lists/static/simplelist.html with 100% similarity]
plugins/lists/templates/staticlist.html [moved from plugins/lists/static/staticlist.html with 100% similarity]
plugins/messages/templates/messages.html [moved from plugins/messages/static/messages.html with 100% similarity]
plugins/myplugin/templates/myplugin.html [moved from plugins/myplugin/static/myplugin.html with 100% similarity]
plugins/pres_view/templates/pres_view.html [moved from plugins/pres_view/static/pres_view.html with 100% similarity]
plugins/query_editor/templates/filter_input_integer.html [moved from plugins/query_editor/static/filter_input_integer.html with 100% similarity]
plugins/query_editor/templates/filter_input_others.html [moved from plugins/query_editor/static/filter_input_others.html with 100% similarity]
plugins/query_editor/templates/filter_input_string.html [moved from plugins/query_editor/static/filter_input_string.html with 100% similarity]
plugins/query_editor/templates/filter_input_string_values.html [moved from plugins/query_editor/static/filter_input_string_values.html with 100% similarity]
plugins/query_editor/templates/query_editor.html [moved from plugins/query_editor/static/query_editor.html with 100% similarity]
plugins/querycode/templates/querycode.html [moved from plugins/querycode/static/querycode.html with 100% similarity]
plugins/quickfilter/templates/quickfilter.html [moved from plugins/quickfilter/static/quickfilter.html with 100% similarity]
plugins/resources_selected/templates/resources_selected.html [moved from plugins/resources_selected/static/resources_selected.html with 100% similarity]
plugins/senslabmap/templates/senslabmap.html [moved from plugins/senslabmap/static/senslabmap.html with 100% similarity]
plugins/stack/templates/stack.html [moved from plugins/stack/static/stack.html with 100% similarity]
plugins/tabs/templates/tabs.html [moved from plugins/tabs/static/tabs.html with 100% similarity]
plugins/updater/templates/updater.html [moved from plugins/updater/static/updater.html with 100% similarity]
plugins/wizard/templates/test.html [moved from plugins/wizard/static/test.html with 100% similarity]
plugins/wizard/templates/wizard.html [moved from plugins/wizard/static/wizard.html with 100% similarity]
setup.py
trash/static/css/dashboard.css [moved from trash/css/dashboard.css with 100% similarity]
trash/static/css/sample.css [moved from trash/css/sample.css with 100% similarity]
unfold/collectstatic.py
unfold/static/css/plugin.css [moved from unfold/css/plugin.css with 100% similarity]
unfold/static/js/messages-runtime.js [moved from unfold/js/messages-runtime.js with 100% similarity]
unfold/static/js/plugin_helper.js [moved from unfold/js/plugin_helper.js with 100% similarity]
unfold/static/js/spin.presets.js [moved from unfold/js/spin.presets.js with 100% similarity]
unfold/static/js/unfold-helper.js [moved from unfold/js/unfold-helper.js with 100% similarity]
views/static/css/layout-unfold2.css [moved from views/css/layout-unfold2.css with 100% similarity]
views/static/css/topmenu.css [moved from views/css/topmenu.css with 100% similarity]
views/static/img/favicon.ico [moved from views/img/favicon.ico with 100% similarity]
views/static/img/myslice-logo.png [moved from views/img/myslice-logo.png with 100% similarity]
views/static/img/onelab-logo.png [moved from views/img/onelab-logo.png with 100% similarity]

index 62df77b..2f9285b 100644 (file)
@@ -7,10 +7,11 @@ TAGS
 *.pyc
 *~
 # these essentially are copies/links from other places
-static/
-all-templates/
+/static/
+/templates/
 # various working files
 play/
 *.leftovers
 *.hide
 entrypoints.ongoing/
+build/
index bb7da6d..4993548 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,19 +2,22 @@ SHELL = /bin/bash
 
 MAKE-SILENT = $(MAKE) --no-print-directory
 
-### first purpose, build and install from the specfile
+### first purpose, build and install from setup.py
 all: build
 
 force:
 
+# clean up and recompute
+redo: redo-static redo-templates
+
 DESTDIR := /
 datadir := /usr/share
 bindir := /usr/bin
 
 PWD := $(shell pwd)
 
-# as of sept. 2013, we collect static files using manage.py
-build: templates
+# 
+build: static templates force
        python setup.py build
 
 install: 
@@ -23,6 +26,10 @@ install:
            --install-scripts=$(DESTDIR)/$(datadir)/unfold \
            --install-data=$(DESTDIR)/$(datadir)/unfold
 
+redo-static static: force
+       rm -rf static/
+       ./manage.py collectstatic --noinput
+
 ####################
 # general stuff
 DATE=$(shell date -u +"%a, %d %b %Y %T")
@@ -141,14 +148,14 @@ list-templates: plugins-templates local-templates
 ### all-static: clean-static run-static
 
 #################### manage templates for the plugin area
-templates run-templates templates-run: force
-       mkdir -p all-templates
-       ln -sf $(foreach x,$(shell $(MAKE-SILENT) list-templates),../$(x)) ./all-templates
+templates: force
+       mkdir -p templates
+       ln -sf $(foreach x,$(shell $(MAKE-SILENT) list-templates),../$(x)) ./templates
 
 clean-templates templates-clean: force
-       rm -rf ./all-templates
+       rm -rf ./templates
 
-all-templates: clean-templates run-templates
+redo-templates: clean-templates templates
 
 ####################
 ### list-all list-resources: list-templates list-js list-css list-img
@@ -173,7 +180,7 @@ SSHCOMMAND:=ssh root@$(MYSLICEBOX)
 ### rsync options
 # the config file should probably not be overridden ??
 # --exclude settings.py 
-LOCAL_RSYNC_EXCLUDES   := --exclude '*.pyc' --exclude config.py --exclude all-static --exclude all-templates --exclude '*.sqlite3'  --exclude play/ 
+LOCAL_RSYNC_EXCLUDES   := --exclude '*.pyc' --exclude config.py --exclude static --exclude templates --exclude '*.sqlite3'  --exclude play/ 
 # usual excludes
 RSYNC_EXCLUDES         := --exclude .git --exclude '*~' --exclude TAGS --exclude .DS_Store $(LOCAL_RSYNC_EXCLUDES) 
 # make -n will propagate as rsync -n 
diff --git a/README b/README
index 2b129de..1266c96 100644 (file)
--- a/README
+++ b/README
@@ -21,13 +21,15 @@ $ ./manage.py syncdb
 $ ./manage.py migrate
 
 * gather static files
-$ ./manage.py collectstatic (formerly, we used make static, which is deprecated)
+$ ./manage.py collectstatic 
 -- or --
 $ ./manage.py collectstatic --noinput
+-- or --
+$ make static (which is a shorthand for cleaning up and run manage collectstatic --noinput)
 
 * gather templates files 
   for now we still seem to rely on a make-based templates-collection process
-  that creates all-templates/ 
+  that creates templates/ 
 $ make templates
 
 * run a local server:
@@ -138,7 +140,7 @@ package is published)
 * static/: (generated by collectstatic, see above, do not source-control)
   $ manage.py [ --noinput ] collectstatic
 
-* all-templates/
+* templates/
 
 * myslice.sqlite3
   this is where django stores its own stuff, as per settings.py
@@ -151,65 +153,68 @@ package is published)
 
 . second, when you do use it for developement purposes, please be aware that:
 
-.. the recommended layout for the various files and pieces (py, html, js and css) with django is
-   IMHO really painful; we *SHOULD* use e.g. 
-      plugins/quickfilter/quickfilter.py, 
-      plugins/quickfilter/templates/quickfilter.html,
-      plugins/quickfilter/static/js/quickfilter.js 
-      plugins/quickfilter/static/css/quickfilter.css
-   which I have tried doing for a while but I found myself just hopping around in the file tree all
-   day long, wasting cycles big time
-
-.. as that does not make sense IMHO, I've rewritten the tool for gathering these pieces (this is in
-   the Makefile). Bottom line is we can essentially store this wherever we want.
-   The only restriction being that if you have a template that is *not* html, then it *has to* sit
-   in a templates/ directory, otherwise it gets shipped as a static file.  
-
-.. as a result, we can now store all the files building a plugin in a single (git) directory; like e.g.
-      plugins/quickfilter/quickfilter.py
-      plugins/quickfilter/quickfilter.html
-      plugins/quickfilter/quickfilter.js
-      plugins/quickfilter/quickfilter.css
-
-   Of course it's a completely different matter once the service is packaged and installed, these
-   files of course get properly separated.
-
-.. as a result it is a little bit less convenient to use the development server when you change the
-   layout of your static and template files, you might need to re-run 'make static', so it is
-   recommended to use devel/server-loop.sh instead
-
-
-All this being said, here are our current conventions for storing templates and static files
-
-* templates:
-  we store this under templates/ within the corresponding app, e.g.
-     auth/templates/login.html
-  for now this is mostly about html, but the engine can be used for rendering anything 
-  including js(on) or whatever (in which case, as stated above, this *must* have /templates/ in its path.
-
-* static files:
-  we chose to have all static files (images, but also javascript and stylesheets) in the various
-  proj or app where they belong, with a layout like:
-  where-it-belongs/
-      img/
-      css/
-      js/
-  Honestly it's not yet very clear sometimes what 'where-it-belongs' should be sometimes, and it
-  does not matter too much anyway, given that the code doesn't need to change when we move things
-  around. So in particular it's fuzzy between myslice/ (where the logo could fit e.g.) views/ and
-  even trash/
-
-Makefile has a few convenience targets to list all kinds of stuff; the 2 major targets are 
-
-$ make static templates
-
-that would reset all-static/ and all-templates/ for you from the other contents
-
-* third-party
-  please note that the set of files that actually get exposed in all-static from third-party is
-  hand-coded in Makefile because we tried to preserve the original codebase layout from mainstream,
-  and there's only so much in common between 2 differents js libraries at this point.
-
+NOTE. this whole business is being changed
+basically we come back to the way django has it by default...
+
+==changing== .. the recommended layout for the various files and pieces (py, html, js and css) with django is
+==changing==    IMHO really painful; we *SHOULD* use e.g. 
+==changing==       plugins/quickfilter/quickfilter.py, 
+==changing==       plugins/quickfilter/templates/quickfilter.html,
+==changing==       plugins/quickfilter/static/js/quickfilter.js 
+==changing==       plugins/quickfilter/static/css/quickfilter.css
+==changing==    which I have tried doing for a while but I found myself just hopping around in the file tree all
+==changing==    day long, wasting cycles big time
+==changing== 
+==changing== .. as that does not make sense IMHO, I've rewritten the tool for gathering these pieces (this is in
+==changing==    the Makefile). Bottom line is we can essentially store this wherever we want.
+==changing==    The only restriction being that if you have a template that is *not* html, then it *has to* sit
+==changing==    in a templates/ directory, otherwise it gets shipped as a static file.  
+==changing== 
+==changing== .. as a result, we can now store all the files building a plugin in a single (git) directory; like e.g.
+==changing==       plugins/quickfilter/quickfilter.py
+==changing==       plugins/quickfilter/quickfilter.html
+==changing==       plugins/quickfilter/quickfilter.js
+==changing==       plugins/quickfilter/quickfilter.css
+==changing== 
+==changing==    Of course it's a completely different matter once the service is packaged and installed, these
+==changing==    files of course get properly separated.
+==changing== 
+==changing== .. as a result it is a little bit less convenient to use the development server when you change the
+==changing==    layout of your static and template files, you might need to re-run 'make static', so it is
+==changing==    recommended to use devel/server-loop.sh instead
+==changing== 
+==changing== 
+==changing== All this being said, here are our current conventions for storing templates and static files
+==changing== 
+==changing== * templates:
+==changing==   we store this under templates/ within the corresponding app, e.g.
+==changing==      auth/templates/login.html
+==changing==   for now this is mostly about html, but the engine can be used for rendering anything 
+==changing==   including js(on) or whatever (in which case, as stated above, this *must* have /templates/ in its path.
+==changing== 
+==changing== * static files:
+==changing==   we chose to have all static files (images, but also javascript and stylesheets) in the various
+==changing==   proj or app where they belong, with a layout like:
+==changing==   where-it-belongs/
+==changing==       img/
+==changing==       css/
+==changing==       js/
+==changing==   Honestly it's not yet very clear sometimes what 'where-it-belongs' should be sometimes, and it
+==changing==   does not matter too much anyway, given that the code doesn't need to change when we move things
+==changing==   around. So in particular it's fuzzy between myslice/ (where the logo could fit e.g.) views/ and
+==changing==   even trash/
+==changing== 
+==changing== Makefile has a few convenience targets to list all kinds of stuff; the 2 major targets are 
+==changing== 
+==changing== $ make static templates
+==changing== 
+==changing== that would reset static/ and templates/ for you from the other contents
+==changing== 
+==changing== * third-party
+==changing==   please note that the set of files that actually get exposed in all-static from third-party is
+==changing==   hand-coded in Makefile because we tried to preserve the original codebase layout from mainstream,
+==changing==   and there's only so much in common between 2 differents js libraries at this point.
+==changing== 
 
 
 ======== update django database to reflect changes in existing models without any migration system (e.g., south) =========
similarity index 100%
rename from auth/css/login.css
rename to auth/static/css/login.css
similarity index 100%
rename from auth/js/logout.js
rename to auth/static/js/logout.js
index 06a56ee..1ac43e4 100755 (executable)
@@ -7,8 +7,9 @@ hostname | grep -q '^z' && port=8080 || port=80
 [[ -n "$@" ]] && port=$1
 
 while true; do 
-    ./manage.py collectstatic --noinput
-    make all-templates
+    # we use make for convenience
+    # but what the static target really does is to invoke manage.py collectstatic 
+    make static templates
     ./manage.py runserver 0.0.0.0:$port
        sleep 1
 done
index f02b10f..3a39ab9 100644 (file)
@@ -95,15 +95,8 @@ STATICFILES_DIRS = (
     # Put strings here, like "/home/html/static" or "C:/www/django/static".
     # Always use forward slashes, even on Windows.
     # Don't forget to use absolute paths, not relative paths.
-    ('js', os.path.join(ROOT,'manifold/js')),
-    ('css', os.path.join(ROOT,'manifold/css')),
-    ('js', os.path.join(ROOT,'unfold/js')),
-    ('css', os.path.join(ROOT,'unfold/css')),
-    ('js', os.path.join(ROOT,'auth/js')),
-    ('css', os.path.join(ROOT,'auth/css')),
-    ('img', os.path.join(ROOT,'auth/img')),
-    ('css', os.path.join(ROOT,'views/css')),
-    ('img', os.path.join(ROOT,'views/img')),
+    # Thierry : we do not need to detail the contents 
+    # of our 'apps' since they're mentioned in INSTALLED_APPS
 )
 
 # Needed by PluginFinder
@@ -114,7 +107,8 @@ THIRDPARTY_DIR = os.path.join(ROOT, 'third-party')
 # List of finder classes that know how to find static files in
 # various locations.
 STATICFILES_FINDERS = (
-    'django.contrib.staticfiles.finders.FileSystemFinder',
+# Thierry : no need for this one    
+#    'django.contrib.staticfiles.finders.FileSystemFinder',
     'django.contrib.staticfiles.finders.AppDirectoriesFinder',
     'unfold.collectstatic.PluginFinder',
     'unfold.collectstatic.ThirdPartyFinder',
@@ -160,7 +154,7 @@ TEMPLATE_DIRS = (
     # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
     # Always use forward slashes, even on Windows.
     # Don't forget to use absolute paths, not relative paths.
-    os.path.join(ROOT,"all-templates"),
+    os.path.join(ROOT,"templates"),
 )
 
 INSTALLED_APPS = (
@@ -181,8 +175,10 @@ INSTALLED_APPS = (
     'plugins',
     # views - more or less stable 
     'views',
+    # temporary
     'trash',
-    'south', # managing database migrations
+    # managing database migrations
+    'south', 
     # Uncomment the next line to enable the admin:
     # 'django.contrib.admin',
     # Uncomment the next line to enable admin documentation:
@@ -240,4 +236,3 @@ CSRF_FAILURE_VIEW = 'manifold.manifoldproxy.csrf_failure'
 #IA_JS_FORMAT = "<script type='text/javascript' src='{URL}' />"
 # put stuff under static/
 # IA_MEDIA_PREFIX = '/code/'
-
index 8783260..9bfc26e 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -15,9 +15,9 @@ packages= [ os.path.dirname(init) for init in (glob("*/__init__.py")+glob("*/*/_
 setup(packages = packages,
       scripts = [],
       data_files = [ 
-        ( 'all-static/js', glob ('all-static/js/*')),
-        ( 'all-static/css', glob ('all-static/css/*')),
-        ( 'all-static/img', glob ('all-static/img/*')),
-        ( 'all-templates', glob ('all-templates/*')),
+        ( 'static/js', glob ('static/js/*')),
+        ( 'static/css', glob ('static/css/*')),
+        ( 'static/img', glob ('static/img/*')),
+        ( 'templates', glob ('templates/*')),
         ( 'apache', [ 'apache/myslice.conf', 'apache/myslice.wsgi' ]),
         ])
index 4fb3bbc..b40afe4 100644 (file)
@@ -39,6 +39,7 @@ class PluginFinder(FileSystemFinder):
         return [os.path.join(dir, name, 'static') for name in os.listdir(dir) 
                 if os.path.isdir(os.path.join(dir, name))]
 
+# as these are a django-specific notion
 class ThirdPartyFinder(BaseFinder):
     """
     A static files finder that looks in the directory of each third-party
@@ -47,7 +48,8 @@ class ThirdPartyFinder(BaseFinder):
     # third-party/MODULE/path/to/js
     extensions = {
         # PREFIX : EXTENSIONS
-        ''   : ('.html',),
+# third party stuff is not expected to provide templates,
+#        ''   : ('.html',),
         'js' : ('.js',),
         'css': ('.css',),
         'img': ('.png', '.ico',),
@@ -76,6 +78,7 @@ class ThirdPartyFinder(BaseFinder):
                         matched_path = os.path.join(path, file) 
                         if not all:
                             return matched_path
+                        print 'ThirdPartyFinder, adding',matched_path
                         matches.append(matched_path)
         return matches