From 9a62ec0dc3ee3e859f3563da29d9c838a658b140 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Fri, 20 Sep 2013 16:40:52 +0200 Subject: [PATCH] separate templates from static files we're now rather consistent with django mainstream's default layout even if it's not always very convenient (use symlinks in your workdir) --- .gitignore | 5 +- Makefile | 25 ++-- README | 129 +++++++++--------- auth/{ => static}/css/login.css | 0 auth/{ => static}/css/logout.css | 0 auth/{ => static}/img/form_input_password.png | Bin auth/{ => static}/js/logout.js | 0 devel/server-loop.sh | 5 +- manifold/{ => static}/css/manifold.css | 0 manifold/{ => static}/js/class.js | 0 manifold/{ => static}/js/manifold-query.js | 0 manifold/{ => static}/js/manifold.js | 0 manifold/{ => static}/js/metadata.js | 0 manifold/{ => static}/js/plugin-sample.html | 0 manifold/{ => static}/js/plugin.js | 0 myslice/settings.py | 21 ++- .../{static => templates}/active_filters.html | 0 .../{static => templates}/code_editor.html | 0 .../{static => templates}/debug_platform.html | 0 plugins/form/{static => templates}/form.html | 0 .../{static => templates}/googlemap.html | 0 .../{static => templates}/hazelnut.html | 0 .../{static => templates}/simplelist.html | 0 .../{static => templates}/staticlist.html | 0 .../{static => templates}/messages.html | 0 .../{static => templates}/myplugin.html | 0 .../{static => templates}/pres_view.html | 0 .../filter_input_integer.html | 0 .../filter_input_others.html | 0 .../filter_input_string.html | 0 .../filter_input_string_values.html | 0 .../{static => templates}/query_editor.html | 0 .../{static => templates}/querycode.html | 0 .../{static => templates}/quickfilter.html | 0 .../resources_selected.html | 0 .../{static => templates}/senslabmap.html | 0 .../stack/{static => templates}/stack.html | 0 plugins/tabs/{static => templates}/tabs.html | 0 .../{static => templates}/updater.html | 0 .../wizard/{static => templates}/test.html | 0 .../wizard/{static => templates}/wizard.html | 0 setup.py | 8 +- trash/{ => static}/css/dashboard.css | 0 trash/{ => static}/css/sample.css | 0 unfold/collectstatic.py | 5 +- unfold/{ => static}/css/plugin.css | 0 unfold/{ => static}/js/messages-runtime.js | 0 unfold/{ => static}/js/plugin_helper.js | 0 unfold/{ => static}/js/spin.presets.js | 0 unfold/{ => static}/js/unfold-helper.js | 0 views/{ => static}/css/layout-unfold2.css | 0 views/{ => static}/css/topmenu.css | 0 views/{ => static}/img/favicon.ico | Bin views/{ => static}/img/myslice-logo.png | Bin views/{ => static}/img/onelab-logo.png | Bin 55 files changed, 105 insertions(+), 93 deletions(-) rename auth/{ => static}/css/login.css (100%) rename auth/{ => static}/css/logout.css (100%) rename auth/{ => static}/img/form_input_password.png (100%) rename auth/{ => static}/js/logout.js (100%) rename manifold/{ => static}/css/manifold.css (100%) rename manifold/{ => static}/js/class.js (100%) rename manifold/{ => static}/js/manifold-query.js (100%) rename manifold/{ => static}/js/manifold.js (100%) rename manifold/{ => static}/js/metadata.js (100%) rename manifold/{ => static}/js/plugin-sample.html (100%) rename manifold/{ => static}/js/plugin.js (100%) rename plugins/active_filters/{static => templates}/active_filters.html (100%) rename plugins/code_editor/{static => templates}/code_editor.html (100%) rename plugins/debug_platform/{static => templates}/debug_platform.html (100%) rename plugins/form/{static => templates}/form.html (100%) rename plugins/googlemap/{static => templates}/googlemap.html (100%) rename plugins/hazelnut/{static => templates}/hazelnut.html (100%) rename plugins/lists/{static => templates}/simplelist.html (100%) rename plugins/lists/{static => templates}/staticlist.html (100%) rename plugins/messages/{static => templates}/messages.html (100%) rename plugins/myplugin/{static => templates}/myplugin.html (100%) rename plugins/pres_view/{static => templates}/pres_view.html (100%) rename plugins/query_editor/{static => templates}/filter_input_integer.html (100%) rename plugins/query_editor/{static => templates}/filter_input_others.html (100%) rename plugins/query_editor/{static => templates}/filter_input_string.html (100%) rename plugins/query_editor/{static => templates}/filter_input_string_values.html (100%) rename plugins/query_editor/{static => templates}/query_editor.html (100%) rename plugins/querycode/{static => templates}/querycode.html (100%) rename plugins/quickfilter/{static => templates}/quickfilter.html (100%) rename plugins/resources_selected/{static => templates}/resources_selected.html (100%) rename plugins/senslabmap/{static => templates}/senslabmap.html (100%) rename plugins/stack/{static => templates}/stack.html (100%) rename plugins/tabs/{static => templates}/tabs.html (100%) rename plugins/updater/{static => templates}/updater.html (100%) rename plugins/wizard/{static => templates}/test.html (100%) rename plugins/wizard/{static => templates}/wizard.html (100%) rename trash/{ => static}/css/dashboard.css (100%) rename trash/{ => static}/css/sample.css (100%) rename unfold/{ => static}/css/plugin.css (100%) rename unfold/{ => static}/js/messages-runtime.js (100%) rename unfold/{ => static}/js/plugin_helper.js (100%) rename unfold/{ => static}/js/spin.presets.js (100%) rename unfold/{ => static}/js/unfold-helper.js (100%) rename views/{ => static}/css/layout-unfold2.css (100%) rename views/{ => static}/css/topmenu.css (100%) rename views/{ => static}/img/favicon.ico (100%) rename views/{ => static}/img/myslice-logo.png (100%) rename views/{ => static}/img/onelab-logo.png (100%) diff --git a/.gitignore b/.gitignore index 62df77b7..2f9285bb 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/Makefile b/Makefile index bb7da6d9..49935483 100644 --- 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 2b129de6..1266c965 100644 --- 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) ========= diff --git a/auth/css/login.css b/auth/static/css/login.css similarity index 100% rename from auth/css/login.css rename to auth/static/css/login.css diff --git a/auth/css/logout.css b/auth/static/css/logout.css similarity index 100% rename from auth/css/logout.css rename to auth/static/css/logout.css diff --git a/auth/img/form_input_password.png b/auth/static/img/form_input_password.png similarity index 100% rename from auth/img/form_input_password.png rename to auth/static/img/form_input_password.png diff --git a/auth/js/logout.js b/auth/static/js/logout.js similarity index 100% rename from auth/js/logout.js rename to auth/static/js/logout.js diff --git a/devel/server-loop.sh b/devel/server-loop.sh index 06a56eec..1ac43e44 100755 --- a/devel/server-loop.sh +++ b/devel/server-loop.sh @@ -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 diff --git a/manifold/css/manifold.css b/manifold/static/css/manifold.css similarity index 100% rename from manifold/css/manifold.css rename to manifold/static/css/manifold.css diff --git a/manifold/js/class.js b/manifold/static/js/class.js similarity index 100% rename from manifold/js/class.js rename to manifold/static/js/class.js diff --git a/manifold/js/manifold-query.js b/manifold/static/js/manifold-query.js similarity index 100% rename from manifold/js/manifold-query.js rename to manifold/static/js/manifold-query.js diff --git a/manifold/js/manifold.js b/manifold/static/js/manifold.js similarity index 100% rename from manifold/js/manifold.js rename to manifold/static/js/manifold.js diff --git a/manifold/js/metadata.js b/manifold/static/js/metadata.js similarity index 100% rename from manifold/js/metadata.js rename to manifold/static/js/metadata.js diff --git a/manifold/js/plugin-sample.html b/manifold/static/js/plugin-sample.html similarity index 100% rename from manifold/js/plugin-sample.html rename to manifold/static/js/plugin-sample.html diff --git a/manifold/js/plugin.js b/manifold/static/js/plugin.js similarity index 100% rename from manifold/js/plugin.js rename to manifold/static/js/plugin.js diff --git a/myslice/settings.py b/myslice/settings.py index f02b10f7..3a39ab92 100644 --- a/myslice/settings.py +++ b/myslice/settings.py @@ -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 = "