From a3926fc96d8e29d27ab4f85f2f6210c75e431bad Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Thu, 14 Mar 2013 13:35:11 +0100 Subject: [PATCH] forget about manage.py collectstatic and come up with our own brew --- .gitignore | 2 +- Makefile | 78 +++++++++++++++++++++++------ README | 47 +++++++++++------ devel/server-loop.sh | 2 + myslice/settings.py | 9 ++-- plugins/tabs.py | 7 ++- trash/sampleviews.py | 2 +- views/__init__.py | 0 views/templates/layout-myslice.html | 2 +- views/templates/widget-topmenu.html | 4 +- 10 files changed, 110 insertions(+), 43 deletions(-) create mode 100644 views/__init__.py diff --git a/.gitignore b/.gitignore index 048f5386..0c2bdeea 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ TAGS *.sqlite3 *~ all-static/ -DataTables-1.9.4/ +all-templates/ diff --git a/Makefile b/Makefile index a29b5b3a..c267b499 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ force: #################### compute emacs tags # list files under git but exclude third-party stuff like bootstrap and jquery myfiles: force - @git ls-files | egrep -v 'insert(_|-)above|static/bootstrap|/jquery/|datatables/' + @git ls-files | egrep -v 'insert(_|-)above|/third-party/|/play/' # in general it's right to rely on the contents as reported by git tags: force @@ -17,25 +17,70 @@ tags: force ftags: force find . -type f | fgrep -v '/.git/' | xargs etags -list-html: force - @find . -type f -name '*.html' -list-js: force - @find . -type f -name '*.js' | grep -v '/all-static/' -list-css: force - @find . -type f -name '*.css' | grep -v '/all-static/' -list-img: force - @find . -type f -name '*.png' | grep -v '/all-static/' +#################### third-party layout is kind of special +# because we have differents versions and all +THIRD-PARTY-RESOURCES = +# ignore variants, use the main symlink third-party/bootstrap +THIRD-PARTY-RESOURCES += $(shell ls third-party/bootstrap/*/*) +# just the single js as identified with a symlink +THIRD-PARTY-RESOURCES += $(shell ls third-party/datatables/js/dataTables.js) +# likewise +THIRD-PARTY-RESOURCES += $(shell ls third-party/jquery/js/jquery.js) +# spin comes in plain or min, + the jquery plugin, and our own settings +THIRD-PARTY-RESOURCES += $(shell ls third-party/spin/*.js) -list-all list-resources: list-html list-js list-css list-img +thirdparty-js: + @find $(THIRD-PARTY-RESOURCES) -name '*.js' +thirdparty-css: + @find $(THIRD-PARTY-RESOURCES) -name '*.css' +thirdparty-img: + @find $(THIRD-PARTY-RESOURCES) -name '*.png' + +# we might have any of these as templates - e.g. ./engine/templates/plugin-setenv.js +# so if there's a /templates/ in the path ignore the file +other-js: force + @find . -type f -name '*.js' | egrep -v '/all-(static|templates)/|/third-party/|/templates/' +other-css: force + @find . -type f -name '*.css' | egrep -v 'all-(static|templates)/|/third-party/|/templates/' +other-img: force + @find . -type f -name '*.png' | egrep -v 'all-(static|templates)/|/third-party/|/templates/' + +list-js: thirdparty-js other-js +list-css: thirdparty-css other-css +list-img: thirdparty-img other-img + +# having templates in a templates/ subdir is fine most of the time except for plugins +list-templates: force + @find plugins -type f -name '*.html' #################### manage static contents (extract from all the modules into the single all-static location) -static: force - ./manage.py collectstatic --noinput +static run-static static-run: force + mkdir -p ./all-static/js all-static/css all-static/img + ln -sf $(foreach x,$(shell $(MAKE) list-js),../../$(x)) ./all-static/js + ln -sf $(foreach x,$(shell $(MAKE) list-css),../../$(x)) ./all-static/css + ln -sf $(foreach x,$(shell $(MAKE) list-img),../../$(x)) ./all-static/img +# rsync -av $(shell $(MAKE) list-js) ./all-static/js +# rsync -av $(shell $(MAKE) list-css) ./all-static/css +# rsync -av $(shell $(MAKE) list-img) ./all-static/img + +clean-static static-clean: force + rm -rf ./all-static + +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) list-templates),.../$(x)) ./all-templates +# rsync -av $(shell $(MAKE) list-templates) ./all-templates + +clean-templates templates-clean: force + rm -rf ./all-templates -clean-static: force - rm -rf ./all-static/ +all-templates: clean-templates run-templates -allst: clean-static static +#################### +list-all list-resources: list-templates list-js list-css list-img #################### sync : push current code on a (devel) box running myslice SSHURL:=root@$(MYSLICEBOX):/ @@ -44,7 +89,7 @@ SSHCOMMAND:=ssh root@$(MYSLICEBOX) ### rsync options # the config file should probably not be overridden ?? # --exclude settings.py -LOCAL_RSYNC_EXCLUDES := --exclude '*.pyc' --exclude devel --exclude DataTables-1.9.4 --exclude all-static --exclude '*.sqlite3' +LOCAL_RSYNC_EXCLUDES := --exclude '*.pyc' --exclude config.py --exclude all-static --exclude all-templates --exclude '*.sqlite3' # usual excludes RSYNC_EXCLUDES := --exclude .git --exclude '*~' --exclude TAGS --exclude .DS_Store $(LOCAL_RSYNC_EXCLUDES) # make -n will propagate as rsync -n @@ -53,6 +98,7 @@ RSYNC_COND_DRY_RUN := $(if $(findstring n,$(MAKEFLAGS)),--dry-run,) RSYNC := rsync -a -v $(RSYNC_COND_DRY_RUN) $(RSYNC_EXCLUDES) # xxx until we come up with a packaging this is going to be a wild guess +# on debian04 I have stuff in /usr/share/myslice and a symlink in /root/myslice #INSTALLED=/usr/share/myslice INSTALLED=/root/myslice diff --git a/README b/README index a8a6bbc8..f1680239 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -This file documents the contents of this module +his file documents the contents of this module See the devel/ subdir for more devel-oriented doc. @@ -20,16 +20,30 @@ See the devel/ subdir for more devel-oriented doc. * init django $ manage.py syncdb -[[ at this point point it *might* be needed to run -$ make allst - but as far as running a local server is concerned you should be good without that - feedback on this is appreciated]] + +* gather static files +$ make static * run a local server: $ manage.py runserver 0.0.0.0:8000 +-- or -- my advice: +$ devel/server-loop.sh +when you just need to hit ^C yourself when your static files need to be refreshed - see below * use it from your browser +.......... NOTES on using the development server +. first off, running manage.py runserver is provided by django as a development convenience but SHOULD NOT be used in production +. 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) qith django is really painful + we should use e.g. plugins/simplelist.py, plugins/templates/plugins.html, plugins/static/js/simplelist.js and plugins/static/css/simplelist.css +.. as that does not make sense IMHO, I've rewritten the tool for gathering these pieces in such a layout but from a completely flat codebase + I mean I want to be able to store all the files building a plugin in a single (git) directory + 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 + ==================== Status @@ -108,11 +122,14 @@ I've tried to keep track of the version I picked and to have an easy upgrade pat * insert_above: a third-party django app for adding on-the-fly mentions to css or js files that need to go in the header -* templates/ - * some global templates (django templates, i.e. (essentially html) fragments that can be specializied) - more on this below +* trash/ + rough/preliminary views in here - as the name suggests this is temporary -* static/ +* views/ + will receive actual views over time + currently has some global html templates as well + +* third-party/ * third party stuff (bootstrapfs, jquery, datatables) * + some global static files (css, js, images..) see more about that below too @@ -123,21 +140,23 @@ I've tried to keep track of the version I picked and to have an easy upgrade pat ========== automatically generated * all-static: (generated, no need to source-control) - this is where 'manage.py collectstatic' will gather all your static contents if you run a local server + this is where 'make static' will gather all your static contents if you run a local server make has convenience targets to refresh this area - $ make clean-static $ make static + $ make clean-static * myslice.sqlite3 this is where django stores its own stuff, as per settings.py - -==================== conventions for templates and static +==================== conventions for templates * 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.. + for now this is mostly about html, but the engine can be used for rendering anything + including js(on) or whatever.. + +==================== conventions for static files * static files: we chose to have all static files (images, but also javascript and stylesheets) in the various diff --git a/devel/server-loop.sh b/devel/server-loop.sh index 9c9d7272..a108f93d 100755 --- a/devel/server-loop.sh +++ b/devel/server-loop.sh @@ -6,6 +6,8 @@ cd $DIRNAME/.. hostname | grep -q '^z' && port=8080 || port=80 [[ -n "$@" ]] && port=$1 +make all-static all-templates while true; do ./manage.py runserver 0.0.0.0:$port + make static templates done diff --git a/myslice/settings.py b/myslice/settings.py index 20cdbed8..a4a32214 100644 --- a/myslice/settings.py +++ b/myslice/settings.py @@ -9,7 +9,7 @@ TEMPLATE_DEBUG = DEBUG DEVELOPER_ROOT=os.path.expanduser("~/git/myslice-django") -PRODUCTION_ROOT="/root/myslice" +PRODUCTION_ROOT="/usr/share/myslice" #################### ADMINS = ( @@ -81,7 +81,7 @@ MEDIA_URL = '' # Don't put anything in this directory yourself; store your static files # in apps' "static/" subdirectories and in STATICFILES_DIRS. # Example: "/home/media/media.lawrence.com/static/" -STATIC_ROOT = os.path.join(ROOT,'all-static') +STATIC_ROOT = os.path.join(ROOT,'django-static') # URL prefix for static files. # Example: "http://media.lawrence.com/static/" @@ -92,7 +92,7 @@ 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. - os.path.join(ROOT,'static'), + os.path.join(ROOT,'all-static'), ) # List of finder classes that know how to find static files in @@ -132,7 +132,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,"templates"), + os.path.join(ROOT,"all-templates"), ) INSTALLED_APPS = ( @@ -148,6 +148,7 @@ INSTALLED_APPS = ( 'auth', 'engine', 'plugins', + 'views', 'trash', # Uncomment the next line to enable the admin: # 'django.contrib.admin', diff --git a/plugins/tabs.py b/plugins/tabs.py index c91f4cf8..d487eec6 100644 --- a/plugins/tabs.py +++ b/plugins/tabs.py @@ -3,10 +3,9 @@ from engine.composite import Composite class Tabs (Composite): def requirements (self): - return { 'js_files' : 'bootstrap/js/bootstrap.js', - 'css_files' : ['bootstrap/css/bootstrap.css', - 'css/tabs.css', - ] } + return { 'js_files' : 'js/bootstrap.js', + 'css_files' : ['css/bootstrap.css', 'css/tabs.css', ] + } def template_file (self): return "tabs.html" diff --git a/trash/sampleviews.py b/trash/sampleviews.py index 33702e45..7147dbb2 100644 --- a/trash/sampleviews.py +++ b/trash/sampleviews.py @@ -12,7 +12,7 @@ from myslice.viewutils import lorem, hard_wired_slice_names @login_required def tab_view (request): - prelude=Prelude( js_files='bootstrap/js/bootstrap.js', css_files='bootstrap/css/bootstrap.css') + prelude=Prelude( js_files='js/bootstrap.js', css_files='css/bootstrap.css') prelude_env = prelude.template_env() tab_env = {'title':'Page for playing with Tabs', 'topmenu_items': topmenu_items('tab',request), diff --git a/views/__init__.py b/views/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/views/templates/layout-myslice.html b/views/templates/layout-myslice.html index 98c6f789..80070936 100644 --- a/views/templates/layout-myslice.html +++ b/views/templates/layout-myslice.html @@ -8,7 +8,7 @@ {{ header_prelude }} {# let's add these ones no matter what #} -{% insert_str prelude "jquery/js/jquery.js" %} +{% insert_str prelude "js/jquery.js" %} {# {% insert prelude_js %} jQuery.noConflict(); {% endinsert %} #} {% insert_str prelude "js/plugin-init.js" %} {% insert_str prelude "css/myslice.css" %} diff --git a/views/templates/widget-topmenu.html b/views/templates/widget-topmenu.html index 97d20f1f..97249f07 100644 --- a/views/templates/widget-topmenu.html +++ b/views/templates/widget-topmenu.html @@ -1,6 +1,6 @@ {# #} -{% insert_str prelude "bootstrap/js/bootstrap.js" %} -{% insert_str prelude "bootstrap/css/bootstrap.css" %} +{% insert_str prelude "js/bootstrap.js" %} +{% insert_str prelude "css/bootstrap.css" %} {% insert_str prelude "css/topmenu.css" %}