README: updated south migration steps
[myslice.git] / README
1 This file documents the contents of this module
2 change
3 Last update 4 sept. 2013
4
5 See the devel/ subdir for more devel-oriented doc.
6
7 ==================== 1 minute howto
8
9 *  REQUIREMENTS  is to have python + django (1.5.2) installed django
10 ** should be straightforward
11 ** see devel/django-install.txt in case of trouble
12 $ apt-get install python-django
13 $ apt-get install python-django-south
14
15 * git clone git://git.onelab.eu/myslice.git
16 -- or --
17 * git clone ssh://yourlogin@git.onelab.eu/git/myslice.git
18
19 * edit/create myslice/myslice.ini and enter the details of your manifold backend
20
21 $ apt-get install python-django-south
22 * init django
23 ** when django prompts for creating an admin account, create it and 
24 ** keep the username and password safe
25 $ ./manage.py syncdb
26 $ ./manage.py migrate
27
28 * gather static files
29 $ ./manage.py collectstatic 
30 -- or --
31 $ ./manage.py collectstatic --noinput
32 -- or --
33 $ make static (which is a shorthand for cleaning up and run manage collectstatic --noinput)
34
35 * gather templates files 
36   for now we still seem to rely on a make-based templates-collection process
37   that creates templates/ 
38 $ make templates [$ make redo (each time when you pull, do that and restart the server)]
39
40
41 ## Whenever doing a git pull the following operations are recommended:
42
43 $ make static # will refresh static/ from all the pieces in the project
44 $ make templates # same, for templates
45 $ make redo-static # clears up (rm -rf) static/ first, then make static
46 $ make redo-templates # ditto for templates
47 $ make redo == make redo-static redo-templates
48
49
50 * run a local server:
51 $ ./manage.py runserver 0.0.0.0:8000
52 -- or -- my advice:
53 $ devel/server-loop.sh
54 when you just need to hit ^C yourself when your static files need to be refreshed - see below
55
56 * use it from your browser 
57 (See more notes on using the development server below)
58
59 * install dependencies 
60 $ pip install -r path/to/requirements/file.txt
61 Note. not quite sure what this is about, I could not spot this file..
62
63 =====APACHE Config=====
64 if are running apache please do:
65
66 $ chown www-data:www-data /var/myslice-f4f
67
68 otherwise you may get the following error:
69 "DatabaseError: unable to open database file"
70
71 ==================== Status
72
73 *** Authentication ***
74
75 Should be mostly fine
76 Not quite sure if/how the user gets proper notifications when
77 . his session has expired (i.e. his frontend is not logged into the backend any longer)
78 . his credentials have expired (i.e. the uploaded credentials, e.g. SFA delegated cred)
79   expired and she needs to run e.g. sfi myslice again
80
81 Hard-coded accounts (from a very early stage) are gone
82
83
84 *** Packaging ***
85
86 I've done a very rough attempt at packaging for rpm.
87 The logic seems about right but needs more work, in particular in terms of installing myslice.conf
88 in the httpd conf.d directory. 
89 It seems like our app won't work on f14 as is because Django is only 1.3.1 on f14
90 Plan is to target f18 but I lack a test machine.
91 Also of course I'll try to tackle debian/ubunti at some point.
92
93 There also is a working packaging for debian(s) and ubuntu(s) that we use 
94 on an almost daily basis to upgrade manifold.pl.sophia.inria.fr
95
96
97 ==================== 
98
99 Third party tools shipped:
100
101 * jquery
102 * datatables
103 * spin
104 * bootstrap
105
106 Others are added as we build the system when they become needed
107 Look in third-party/ for a more detailed list
108
109 As a rule of thumb, please try to keep in mind that these will need to
110 be upgraded over time I've tried to keep track of the version I picked
111 and to have an easy upgrade path (depending on the way the original
112 package is published)
113
114 ==================== Contents: 1st level subdirs
115
116 ========== code from git
117
118 * myslice/
119   this is the django 'project', where to look for
120   . settings.py
121   . urls.py
122
123 * manifold/
124   the code for dealing with queries, sending them to the backend, and offering the /manifold/proxy/ URL
125
126 * unfold/
127   the code for building / rendering plugins 
128
129 * plugins/
130   the actual code for plugins
131
132 * auth/ 
133   a django 'app' that deals with authentication; see especially
134   auth.backend.MyCustomBackend 
135   for how to use a separate authentication system, 
136   as well as settings.py for how to enable it
137
138 * ui/
139   provides building blocks for the UI, especially layouts (1 or 2 columns) as
140   well as the topmenu widget
141   + some global static files (css, js, images..)
142
143 * portal/
144   this is where the first implementation of myslice, with complete
145   user-management including registration, is taking place
146
147 * trash/
148   rough/preliminary scaffolding views are in here
149   as the name suggests this is temporary
150
151 * insert_above: 
152   a third-party django app for adding on-the-fly mentions to css or js files that need to go in the header
153
154 * third-party/
155    * third party javascript and css stuff (bootstrapfs, jquery, this kind of things)
156      see more about that below too
157
158 * devel:
159   no code in there, only various notes and other scripts useful for developers
160
161 ========== automatically generated 
162
163 * static/: (generated by collectstatic, see above, do not source-control)
164   $ manage.py [ --noinput ] collectstatic
165
166 * templates/
167
168 * myslice.sqlite3
169   this is where django stores its own stuff, as per settings.py
170
171 ==================== conventions for templates & static files
172 ==================== and NOTES on using the development server
173
174 . first off, running manage.py runserver is provided by django as a development convenience but
175   SHOULD NOT be used in production
176
177 . second, when you do use it for developement purposes, please be aware that:
178
179 .. the recommended layout for the various files and pieces (py, html, js and css) with django is e.g.
180       plugins/quickfilter/___init__.py, 
181       plugins/quickfilter/templates/quickfilter.html,
182       plugins/quickfilter/static/js/quickfilter.js 
183       plugins/quickfilter/static/css/quickfilter.css
184       plugins/quickfilter/static/img/some-image.png
185
186 .. the files actually used by the development server are the ones located in
187  static/
188  templates/
189
190 you can and should use the following make targets to refresh the
191 contents of these directories when running a developement server
192 $ make static                 to refresh static/
193 $ make redo-static            to clean up static/ and then refresh its contents
194 $ make templates              to refresh templates/
195 $ make redo-templates         to clean up templates/ and then refresh its contents
196 $ make redo                   equivalent to make redo-static redo-templates
197
198 .. as far as possible, please make sure to use third-party to store
199 any javascript tool or utility that your plugin depends upon
200
201 also we have the convention that all material in third-party should be
202 tagged with a version number, with a symlink pointing to the version
203 being used, like this
204
205 ~/git/myslice/third-party $ ls -ld spin*
206 lrwxr-xr-x  1 parmentelat  staff   10 Sep  6 17:55 spin -> spin-1.3.0
207 drwxr-xr-x  7 parmentelat  staff  238 Sep  6 17:55 spin-1.2.8
208 drwxr-xr-x  7 parmentelat  staff  238 Sep  6 17:55 spin-1.3.0
209
210 finally, as far as possible we keep track of the urls used to pull
211 stuff in the first place so that upgrades are easier
212
213 . third, be careful when importing third party material, to stay away from demo-oriented material
214
215 e.g. at some point we were using demo_page.css and demo_table.css from the datatables demo and sample pages
216 unfortunately these are not tailored for production use as they are setting styles on a very wide scope 
217 that breaks a lot of stuff, so please refrain from using these altogether
218
219
220 ======== update django database to reflect changes in existing models without any migration system (e.g., south) =========
221
222 # older version
223 $python manage.py reset <your_app>
224
225 #Django 1.5.1 or later
226 $python manage.py flush
227
228 This will update the database tables for your app, but will completely destroy any data that existed in those tables. 
229 If the changes you made to your app model do not break your old schema (for instance, you added a new, optional field) 
230 you can simply dump the data before and reload it afterwards, like so:
231
232 $python manage.py syncdb
233 $python manage.py dumpdata <your_app> > temp_data.json
234 $python manage.py flush
235 $python manage.py loaddata temp_data.json
236
237 If your changes break your old schema this won't work - in which case tools like south or django evolution are great.
238
239
240 Add a new model to the DB
241
242 $python manage.py schemamigration <your_app> --auto
243 $python manage.py migrate
244
245 ======== update django database to reflect changes in existing models with migration system (e.g., south) =========
246
247 As south is already installed , you just have to do:
248
249 # ./manage.py schemamigration portal --initial
250 # sqlite3 /var/unfold/unfold.sqlite3
251         sqlite> DROP TABLE "portal_institution";
252         sqlite> DROP TABLE "portal_pendinguser";
253         sqlite> DROP TABLE "portal_pendingauthority";
254         sqlite> DROP TABLE "portal_pendingslice";
255         sqlite> .quit
256 # ./manage.py migrate portal