From: Thierry Parmentelat Date: Fri, 21 Dec 2012 11:20:03 +0000 (+0100) Subject: polished for others to use more easily X-Git-Tag: myslice-django-0.1-1~111 X-Git-Url: http://git.onelab.eu/?p=myslice.git;a=commitdiff_plain;h=3528c308c23c63774cccf92e473abed0d85893e0 polished for others to use more easily --- diff --git a/README b/README index 3e2416eb..eb38a31b 100644 --- a/README +++ b/README @@ -1,17 +1,67 @@ This file documents the contents of this module -See devel/ for more devel-oriented doc. +See the devel/ subdir for more devel-oriented doc. -==================== 1st level subdirs +==================== 1 minute howto + +* requirement is to have python + django installed django +** should be straightforward +** see devel/django-install.txt in case of trouble + +* git clone git://git.onelab.eu/myslice-django.git +-- or -- +* git clone ssh://yourlogin@git.onelab.eu/git/myslice-django.git + +* edit myslice/settings.py and +** change DEVELOPER_ROOT if you didnt clone into ~/git/myslice-django +** change the location of your backend API (not yet supported) + +* 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 + feedbakc on this is appreciated] + +* run a local server: +$ manage.py runserver 0.0.0.0:8000 + +* use it from your browser + + +==================== Status + +For now there's not much in here; + +* Logging in should be easy using one of the few hard coded accounts + this was the simplest possible way to demonstrate deferring authorization elsewhere +* To logout, click on 'logged as *jean*', this shows a confirmation page.. + +Right now the UI has 4 views: + +* the most useful one being the 'Plugin' view which demonstrates all the available plugins + see test_plugin_view in engine/views.py + +* slice view : only demonstrates how to use URLs to pass arguments along +* scroll view : forget about that one, but it does illustrate that some pages can be made public (no need to login) +* tab view : a hand-made tab widget + +(last three from slice/views.py) + +==================== Contents: 1st level subdirs + +========== code from git * myslice: - this is the sjango project', where to look for - . settings - . urls - . common static files + this is the django 'project', where to look for + . settings.py + . urls.py -* 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 - much like our past drupal_set_html_head() +* engine: + the code for building / rendering plugins + +* plugins: + the actual code for plugins * auth: a django 'app' that deals with authentication; see especially @@ -22,32 +72,37 @@ See devel/ for more devel-oriented doc. * slice: a django app for dealing with slice views +* 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/ * static/ - initially I had started to keep: - * templates (html templates with embedded python-like django chunks) + some global stuff: + * templates (django templates, i.e. (essentially html) fragments that can be specializied) * static files (css, js, images..) - locally in the app were they belong - but I ended up with having the need to move up and down the tree endlessly - so for the beginning at least, I have moved everything in a unique place - this convention is subject to change + see more about that below ---- * devel: no code in there, only various notes and other scripts useful for developers +========== 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 make has convenience targets to refresh this area $ make clean-static $ make static -==================== initial conventions for templates and static +* myslice.sqlite3 + this is where django stores its own stuff, as per settings.py + + +==================== conventions for templates and static * templates: we store this under templates/ within the corresponding app, e.g. auth/templates/login.html - for now this is only about html, but the engine can be used for rendering anything including json or whatever.. + for now this is mostly about html, but the engine can be used for rendering anything including js(on) or whatever.. * static files: we chose to have all static files (images, but also javascript and stylesheets) in the various @@ -57,7 +112,8 @@ See devel/ for more devel-oriented doc. img/ css/ js/ - the stuff I have so far is in myslice/ because it looks common to all apps.. +NOTE. in essence any of these files can be moved around (from e.g. one templates/ dir to another) +at any time without any change needed in the code diff --git a/engine/views.py b/engine/views.py index 52e22d23..bb7ba160 100644 --- a/engine/views.py +++ b/engine/views.py @@ -5,6 +5,8 @@ from django.template import RequestContext from django.template.loader import render_to_string from django.shortcuts import render_to_response +from django.contrib.auth.decorators import login_required + from plugins.verticallayout import VerticalLayout from plugins.tabs import Tabs from plugins.simplelist import SimpleList @@ -14,6 +16,7 @@ from plugins.raw import Raw from myslice.viewutils import topmenu_items, the_user from myslice.viewutils import hard_wired_slice_names, hard_wired_list, lorem_p, lorem +@login_required def test_plugin_view (request): # variables that will get passed to this template diff --git a/myslice/settings.py b/myslice/settings.py index d88a3356..ece937db 100644 --- a/myslice/settings.py +++ b/myslice/settings.py @@ -1,8 +1,17 @@ # Django settings for myslice project. +import os.path + DEBUG = True TEMPLATE_DEBUG = DEBUG +# change these if you use a different convention + +DEVELOPER_ROOT=os.path.expanduser("~/git/myslice-django") + +PRODUCTION_ROOT="/root/myslice" + +#################### ADMINS = ( # ('Your Name', 'your_email@example.com'), ) @@ -16,10 +25,13 @@ import os, os.path ROOT='' def init_root (): global ROOT - if os.path.exists("/root/myslice"): - ROOT="/root/myslice" + if os.path.exists(PRODUCTION_ROOT): + ROOT=PRODUCTION_ROOT + elif os.path.exists (DEVELOPER_ROOT): + ROOT=DEVELOPER_ROOT else: - ROOT=os.path.expanduser("~/git/myslice-django") + raise Exception,"Cannot find ROOT for myslice (neither %s nor %s)"%(PRODUCTION_ROOT,DEVELOPER_ROOT) + init_root() DATABASES = { diff --git a/myslice/urls.py b/myslice/urls.py index b4a1b1c8..c76ad8be 100644 --- a/myslice/urls.py +++ b/myslice/urls.py @@ -19,7 +19,7 @@ urlpatterns = patterns( # Uncomment the next line to enable the admin: # url(r'^admin/', include(admin.site.urls)), - (r'^/?$', 'slice.views.fake_slice_view'), + (r'^/?$', 'engine.views.test_plugin_view'), # seems to be what login_required uses to redirect ... (r'^accounts/login/$', 'auth.views.login_user'), (r'^login/?$', 'auth.views.login_user'), diff --git a/myslice/viewutils.py b/myslice/viewutils.py index 374417e1..80b4f788 100644 --- a/myslice/viewutils.py +++ b/myslice/viewutils.py @@ -2,11 +2,11 @@ from copy import deepcopy -standard_topmenu_items = [ { 'label':'Slice', 'href': '/slice/'}, - { 'label':'Scroll', 'href': '/scroll/'}, - { 'label':'Tab', 'href': '/tab/'}, - { 'label':'Plugin', 'href': '/plugin/'}, - ] +standard_topmenu_items = [ { 'label':'Plugin', 'href': '/plugin/'}, + { 'label':'Slice', 'href': '/slice/'}, + { 'label':'Scroll', 'href': '/scroll/'}, + { 'label':'Tab', 'href': '/tab/'}, + ] #login_out_items = { False: { 'label':'Login', 'href':'/login/'}, # True: { 'label':'Logout', 'href':'/logout/'}} diff --git a/slice/views.py b/slice/views.py index 994e9151..ecfeb8cf 100644 --- a/slice/views.py +++ b/slice/views.py @@ -40,7 +40,6 @@ def tab_view (request): return render_to_response ('view-tab.html', tab_env, context_instance=RequestContext(request)) -@login_required def scroll_view (request): return render_to_response ('view-scroll.html', {'title':'Toy page for scrolling',