-
Notifications
You must be signed in to change notification settings - Fork 2
Django Basics
The Django project is the brains of the OPS server. It's what controls all of the functionality (not including map generation) on the OPS server.
/vagrant/conf/django/*
is the GitHub repo checkout location on the OPS server.
/var/django/*
is the root path to the django project on the OPS server.
To copy a new version of the Django project from the repo to the server enter the following:
cd /vagrant
git pull
sh conf/tools/updateDjangoProject.sh
django/
ops/
rds/
fixtures/
initial_data.json
__init__.py
models.py
accum/
fixtures/
initial_data.json
__init__.py
models.py
snow/
fixtures/
initial_data.json
__init__.py
models.py
kuband/
fixtures/
initial_data.json
__init__.py
models.py
opsuser/
__init__.py
models.py
ops/
__init__.py
authip.py
monitor.py
settings.py
urls.py
utility.py
views.py
wsgi.py
manage.py
rds/ accum/ snow/ kuband/
These are the application directories for the OPS Django product. Normally applications are stand-alone pieces (like a blog, or a news feed) but in this case we separate the different systems into there own applications. Essentially each application is identical in structure and will contain identically structured data but this organization allows us to easily separate the different data. Each application (app) contains 3 files:
app/fixtures/initial_data.json
This is a file containing JSON formatted data that is inserted into the database the first time the Django project is synced.
app/__init__.py
You can ignore this file, it does nothing.
app/models.py
This file defines the applications structure (schema) in the database. It also is the file that we end up using as the template for using the Django database access API.
opsuser/
is the directory that contains the files that define the models of the OPS user and user profile. The models.py
file defines the OPS user profile (create with a 1-1 relationship with each new user). This is a custom implementation of the user profile in Django. The event post_save.connect(create_profile,sender=User)
command is used to create an associated user profile each time a new user is saved.
ops/ops/
is the top-level project directory. Normally each application will have it's own "views" but we have decided to use a project-level views because each application contains the exact same shared logic. This practice is not "pure django" but it works and others do it too.
ops/ops/views.py
This file contains all of the views (python functions) that perfom the logic on the OPS system (for example getLayerPoints, getSystemInfo, createLayers, ...) are all defined in this file.
ops/ops/urls.py
Maps the function in views.py to specific URLS on the OPS server. This file is what allows a user to call ops.cresis.ku.edu/ops/get/system/info and get a result from the system.
ops/ops/utility.py
This file defines various utility functions used by the main logic file views.py.
ops/ops/settings.py
This is the main Django settings file where the database connection, and all other Django settings are defined. Take a look, it's pretty simple.
There are a few more files in the ops/ops directory but they are not very important and pretty self-explanatory.
The file manage.py allows you to manage the Django application. Below are some of the useful functions.
python /var/django/ops/mange.py syncdb
This runs the database synchronization and actually creates the full structure defined by Django models in the database defined in settings.py.
python /var/django/ops/mange.py flush
DO NOT RUN THIS IN PRODUCTION!!! This command completely wipes the database and returns it to the a state directly after the syncdb command was originally run.
python /var/django/ops/mange.py sqlall [appName]
This will print all of the actual SQL generated by the models file for the specified app.
More on manage.py here