8.4. Manage the CRATE web server
The CRATE web front end uses Django, which comes with a number of built-in management comments; to these, CRATE adds some more. All are available as subcommands of
crate_django_manage
The available commands are:
Type 'crate_django_manage help <subcommand>' for help on a specific subcommand.
Available subcommands:
[auth]
changepassword
createsuperuser
[consent]
email_rdbm
fetch_optouts
lookup_consent
lookup_patient
make_ethics_pack
populate
resubmit_unprocessed_tasks
test_email
[contenttypes]
remove_stale_contenttypes
[core]
ensuresuperuser
runcpserver
[debug_toolbar]
debugsqlshell
[django]
check
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
makemigrations
migrate
sendtestemail
shell
showmigrations
sqlflush
sqlmigrate
sqlsequencereset
squashmigrations
startapp
startproject
test
testserver
[django_extensions]
admin_generator
clean_pyc
clear_cache
compile_pyc
create_command
create_jobs
create_template_tags
delete_squashed_migrations
describe_form
drop_test_database
dumpscript
export_emails
find_template
generate_password
generate_secret_key
graph_models
list_model_info
list_signals
mail_debug
merge_model_instances
notes
pipchecker
print_settings
print_user_for_session
reset_db
reset_schema
runjob
runjobs
runprofileserver
runscript
runserver_plus
set_default_site
set_fake_emails
set_fake_passwords
shell_plus
show_template_tags
show_urls
sqlcreate
sqldiff
sqldsn
sync_s3
syncdata
unreferenced_files
update_permissions
validate_templates
[drf_spectacular]
spectacular
[rest_framework]
generateschema
[sessions]
clearsessions
[sslserver]
runsslserver
[staticfiles]
collectstatic
findstatic
runserver
Particularly relevant functions are as follows.
8.4.1. [auth]
8.4.1.1. changepassword
Change a user’s password from the command line.
USAGE: crate_django_manage changepassword [-h] [--database DATABASE]
[--version] [-v {0,1,2,3}]
[--settings SETTINGS]
[--pythonpath PYTHONPATH]
[--traceback] [--no-color]
[--force-color]
[username]
Change a user's password for django.contrib.auth.
POSITIONAL ARGUMENTS:
username Username to change password for; by default, it's the
current username.
OPTIONAL ARGUMENTS:
-h, --help show this help message and exit
--database DATABASE Specifies the database to use. Default is "default".
--version show program's version number and exit
-v, --verbosity {0,1,2,3}
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Raise on CommandError exceptions
--no-color Don't colorize the command output.
--force-color Force colorization of the command output.
8.4.1.2. createsuperuser
Create a superuser from the command line.
USAGE: crate_django_manage createsuperuser [-h] [--username USERNAME]
[--noinput] [--database DATABASE]
[--email EMAIL] [--version]
[-v {0,1,2,3}]
[--settings SETTINGS]
[--pythonpath PYTHONPATH]
[--traceback] [--no-color]
[--force-color] [--skip-checks]
Used to create a superuser.
OPTIONAL ARGUMENTS:
-h, --help show this help message and exit
--username USERNAME Specifies the login for the superuser.
--noinput, --no-input
Tells Django to NOT prompt the user for input of any
kind. You must use --username with --noinput, along
with an option for any other required field.
Superusers created with --noinput will not be able to
log in until they're given a valid password.
--database DATABASE Specifies the database to use. Default is "default".
--email EMAIL Specifies the email for the superuser.
--version show program's version number and exit
-v, --verbosity {0,1,2,3}
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Raise on CommandError exceptions
--no-color Don't colorize the command output.
--force-color Force colorization of the command output.
--skip-checks Skip system checks.
8.4.2. [consent]
8.4.2.1. fetch_optouts
Show PIDs/MPIDs for patients who have opted out entirely from the anonymised
research database. See
crate_anon.crateweb.consent.management.commands.fetch_optouts.Command
.
This functionality is also available from the :ref`front-end web site, for
RDBMs <rdbm_view_optouts>`.
USAGE: crate_django_manage fetch_optouts [-h] --pidfile PIDFILE --mpidfile
MPIDFILE [--version] [-v {0,1,2,3}]
[--settings SETTINGS]
[--pythonpath PYTHONPATH]
[--traceback] [--no-color]
[--force-color] [--skip-checks]
Fetch patient IDs (PIDs) and master patient IDs (MPIDs, e.g. NHS numbers) from
the clinical consent-mode lookup database, and store them in a file (e.g. for
use by the CRATE anonymiser).
OPTIONAL ARGUMENTS:
-h, --help show this help message and exit
--pidfile PIDFILE Filename to store PIDs in (one line per PID)
--mpidfile MPIDFILE Filename to store MPIDs in (one line per PID)
--version show program's version number and exit
-v, --verbosity {0,1,2,3}
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Raise on CommandError exceptions
--no-color Don't colorize the command output.
--force-color Force colorization of the command output.
--skip-checks Skip system checks.
8.4.2.2. lookup_consent
Tests patient identity lookup from the command line, without saving anything.
See
crate_anon.crateweb.consent.management.commands.lookup_consent.Command
.
This functionality is also available from the :ref`front-end web site, for
developers <dev_lookup_consent_mode>`.
USAGE: crate_django_manage lookup_consent [-h] --nhs_numbers NHS_NUMBERS
[NHS_NUMBERS ...] [--version]
[-v {0,1,2,3}] [--settings SETTINGS]
[--pythonpath PYTHONPATH]
[--traceback] [--no-color]
[--force-color] [--skip-checks]
Tests lookup of the consent mode from the relevant CLINICAL database.
OPTIONAL ARGUMENTS:
-h, --help show this help message and exit
--nhs_numbers NHS_NUMBERS [NHS_NUMBERS ...]
NHS numbers to look up
--version show program's version number and exit
-v, --verbosity {0,1,2,3}
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Raise on CommandError exceptions
--no-color Don't colorize the command output.
--force-color Force colorization of the command output.
--skip-checks Skip system checks.
8.4.2.3. lookup_patient
Tests patient identity lookup from the command line, without saving anything.
See
crate_anon.crateweb.consent.management.commands.lookup_patient.Command
.
This functionality is also available from the :ref`front-end web site, for
developers <dev_lookup_patient>`.
USAGE: crate_django_manage lookup_patient [-h] --nhs_numbers NHS_NUMBERS
[NHS_NUMBERS ...] [--version]
[-v {0,1,2,3}] [--settings SETTINGS]
[--pythonpath PYTHONPATH]
[--traceback] [--no-color]
[--force-color] [--skip-checks]
Tests lookup of patient details from the relevant CLINICAL database.
OPTIONAL ARGUMENTS:
-h, --help show this help message and exit
--nhs_numbers NHS_NUMBERS [NHS_NUMBERS ...]
NHS numbers to look up
--version show program's version number and exit
-v, --verbosity {0,1,2,3}
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Raise on CommandError exceptions
--no-color Don't colorize the command output.
--force-color Force colorization of the command output.
--skip-checks Skip system checks.
8.4.2.4. populate
Ensures the database has entries for all the master leaflets used by CRATE. (Will not destroy any existing leaflet records.)
See
USAGE: crate_django_manage populate [-h] [--version] [-v {0,1,2,3}]
[--settings SETTINGS]
[--pythonpath PYTHONPATH] [--traceback]
[--no-color] [--force-color]
[--skip-checks]
Populate the database with leaflet entries if necessary
OPTIONAL ARGUMENTS:
-h, --help show this help message and exit
--version show program's version number and exit
-v, --verbosity {0,1,2,3}
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Raise on CommandError exceptions
--no-color Don't colorize the command output.
--force-color Force colorization of the command output.
--skip-checks Skip system checks.
8.4.2.5. resubmit_unprocessed_tasks
Ask Celery to catch up on any unprocessed CRATE tasks. Use this with caution!
See crate_anon.crateweb.consent.tasks.resubmit_unprocessed_tasks_task()
.
USAGE: crate_django_manage resubmit_unprocessed_tasks [-h] [--version]
[-v {0,1,2,3}]
[--settings SETTINGS]
[--pythonpath PYTHONPATH]
[--traceback]
[--no-color]
[--force-color]
[--skip-checks]
Resubmit unprocessed tasks (in case Celery jobs have been lost)
OPTIONAL ARGUMENTS:
-h, --help show this help message and exit
--version show program's version number and exit
-v, --verbosity {0,1,2,3}
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Raise on CommandError exceptions
--no-color Don't colorize the command output.
--force-color Force colorization of the command output.
--skip-checks Skip system checks.
8.4.2.6. test_email
Tests the backend and e-mail systems by sending an e-mail to the RDBM. Also available from the front-end web site.
USAGE: crate_django_manage test_email [-h] [--version] [-v {0,1,2,3}]
[--settings SETTINGS]
[--pythonpath PYTHONPATH] [--traceback]
[--no-color] [--force-color]
[--skip-checks]
Test email to RDBM (without saving to database)
OPTIONAL ARGUMENTS:
-h, --help show this help message and exit
--version show program's version number and exit
-v, --verbosity {0,1,2,3}
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Raise on CommandError exceptions
--no-color Don't colorize the command output.
--force-color Force colorization of the command output.
--skip-checks Skip system checks.
8.4.2.7. email_rdbm
E-mails the RDBM.
USAGE: crate_django_manage email_rdbm [-h] [--subject SUBJECT] [--text TEXT]
[--queue] [--version] [-v {0,1,2,3}]
[--settings SETTINGS]
[--pythonpath PYTHONPATH] [--traceback]
[--no-color] [--force-color]
[--skip-checks]
Email the RDBM
OPTIONAL ARGUMENTS:
-h, --help show this help message and exit
--subject SUBJECT Subject
--text TEXT Text body
--queue E-mail via backend task queue (rather than
immediately)
--version show program's version number and exit
-v, --verbosity {0,1,2,3}
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Raise on CommandError exceptions
--no-color Don't colorize the command output.
--force-color Force colorization of the command output.
--skip-checks Skip system checks.
8.4.3. [core]
8.4.3.1. runcpserver
Launches the CherryPy web server.
USAGE: crate_django_manage runcpserver [-h] [--host HOST] [--port PORT]
[--server_name SERVER_NAME]
[--threads THREADS]
[--ssl_certificate SSL_CERTIFICATE]
[--ssl_private_key SSL_PRIVATE_KEY]
[--log_screen] [--no_log_screen]
[--debug_static]
[--root_path ROOT_PATH] [--version]
[-v {0,1,2,3}] [--settings SETTINGS]
[--pythonpath PYTHONPATH] [--traceback]
[--no-color] [--force-color]
[--skip-checks]
Run this project in a CherryPy webserver. To do this, CherryPy is required
(pip install cherrypy).
OPTIONAL ARGUMENTS:
-h, --help show this help message and exit
--host HOST hostname to listen on (default: 127.0.0.1)
--port PORT port to listen on (default: 8088)
--server_name SERVER_NAME
CherryPy's SERVER_NAME environ entry (default:
localhost)
--threads THREADS Number of threads for server to use (default: 10)
--ssl_certificate SSL_CERTIFICATE
SSL certificate file (e.g.
/etc/ssl/certs/ssl-cert-snakeoil.pem)
--ssl_private_key SSL_PRIVATE_KEY
SSL private key file (e.g.
/etc/ssl/private/ssl-cert-snakeoil.key)
--log_screen log access requests etc. to terminal (default)
--no_log_screen don't log access requests etc. to terminal
--debug_static show debug info for static file requests
--root_path ROOT_PATH
Root path to serve CRATE at. Default:
/crate/root/path/
--version show program's version number and exit
-v, --verbosity {0,1,2,3}
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Raise on CommandError exceptions
--no-color Don't colorize the command output.
--force-color Force colorization of the command output.
--skip-checks Skip system checks.
8.4.4. [staticfiles]
8.4.4.1. collectstatic
Copy relevant static files from their source location to the place that CRATE will serve them to users (or another front-end server, like Apache, will on its behalf). Needs to be run as part of site setup.
USAGE: crate_django_manage collectstatic [-h] [--noinput] [--no-post-process]
[-i PATTERN] [-n] [-c] [-l]
[--no-default-ignore] [--version]
[-v {0,1,2,3}] [--settings SETTINGS]
[--pythonpath PYTHONPATH]
[--traceback] [--no-color]
[--force-color] [--skip-checks]
Collect static files in a single location.
OPTIONAL ARGUMENTS:
-h, --help show this help message and exit
--noinput, --no-input
Do NOT prompt the user for input of any kind.
--no-post-process Do NOT post process collected files.
-i, --ignore PATTERN Ignore files or directories matching this glob-style
pattern. Use multiple times to ignore more.
-n, --dry-run Do everything except modify the filesystem.
-c, --clear Clear the existing files using the storage before
trying to copy or link the original file.
-l, --link Create a symbolic link to each file instead of
copying.
--no-default-ignore Don't ignore the common private glob-style patterns
(defaults to 'CVS', '.*' and '*~').
--version show program's version number and exit
-v, --verbosity {0,1,2,3}
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Raise on CommandError exceptions
--no-color Don't colorize the command output.
--force-color Force colorization of the command output.
--skip-checks Skip system checks.
8.4.4.2. runserver
Launches the Django test web server.
USAGE: crate_django_manage runserver [-h] [--ipv6] [--nothreading]
[--noreload] [--nostatic] [--insecure]
[--version] [-v {0,1,2,3}]
[--settings SETTINGS]
[--pythonpath PYTHONPATH] [--traceback]
[--no-color] [--force-color]
[addrport]
Starts a lightweight Web server for development and also serves static files.
POSITIONAL ARGUMENTS:
addrport Optional port number, or ipaddr:port
OPTIONAL ARGUMENTS:
-h, --help show this help message and exit
--ipv6, -6 Tells Django to use an IPv6 address.
--nothreading Tells Django to NOT use threading.
--noreload Tells Django to NOT use the auto-reloader.
--nostatic Tells Django to NOT automatically serve static files
at STATIC_URL.
--insecure Allows serving static files even if DEBUG is False.
--version show program's version number and exit
-v, --verbosity {0,1,2,3}
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Raise on CommandError exceptions
--no-color Don't colorize the command output.
--force-color Force colorization of the command output.