Skip to content

Commit

Permalink
Merge pull request #210 from ODM2/afterdjango2
Browse files Browse the repository at this point in the history
Afterdjango2
  • Loading branch information
Miguel Leon authored Oct 19, 2018
2 parents 876ed05 + 173e091 commit c3a0bc8
Show file tree
Hide file tree
Showing 47 changed files with 2,655 additions and 1,086 deletions.
16 changes: 12 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ env:
before_cache:
- rm -rf $HOME/miniconda/envs/TEST

services:
- postgresql
addons:
postgresql: "9.5"
apt:
packages:
- postgresql-9.5-postgis-2.3

matrix:
fast_finish: true
include:
Expand All @@ -29,6 +37,8 @@ matrix:


before_install:
- psql -U postgres -c "create extension postgis"
- psql -c "CREATE DATABASE test;" -U postgres
- |
URL="http://bit.ly/miniconda"
echo ""
Expand All @@ -44,14 +54,12 @@ before_install:
- conda config --add channels conda-forge --force
- conda create --name TEST python=$TRAVIS_PYTHON_VERSION libgdal --file requirements.txt --file requirements-dev.txt
- source activate TEST
- pip install --upgrade http://github.com/miguelcleon/django-admin-shortcuts/zipball/master
# - pip install --upgrade http://github.com/miguelcleon/django-admin-shortcuts/zipball/master


install:
- python setup.py sdist && version=$(python setup.py --version) && pushd dist && pip install odm2admin-${version}.tar.gz && popd

before_script:
- psql -c "CREATE DATABASE test;" -U postgres

script:
- if [[ $TEST_TARGET == 'default' ]]; then
python $TRAVIS_BUILD_DIR/manage.py test tests/;
Expand Down
68 changes: 39 additions & 29 deletions docker/docker-deploy/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'social_django.context_processors.backends',
'social_django.context_processors.login_redirect',
],
},
}]
Expand Down Expand Up @@ -103,36 +105,62 @@
""" MEDIA CONFIGURATION """
# Absolute filesystem path to the directory that will hold user-uploaded files.
MEDIA_ROOT = '{}/{}/upfiles/'.format(BASE_DIR, APP_NAME)
# URL that handles the media served from MEDIA_ROOT.
# URL that handles the media served from MEDIA_ROOT.
MEDIA_URL = '/{}/{}/media/'.format(os.path.basename(BASE_DIR), APP_NAME)
""" END MEDIA CONFIGURATION """

# Absolute filesystem path to the directory that will hold database export and import files
FIXTURE_DIR = '{}/{}/fixtures/'.format(BASE_DIR, APP_NAME)

""" STATIC FILE CONFIGURATION """
# Absolute path to the directory static files should be collected to. Don't put
# anything in this directory yourself; store your static files in apps' static/
# subdirectories and in STATICFILES_DIRS.
# STATIC_ROOT = '{}/{}/static'.format(BASE_DIR, APP_NAME)
STATIC_DIR = '{}/{}/static'.format(BASE_DIR, APP_NAME)
STATICFILES_DIRS = [STATIC_DIR]
STATIC_ROOT = '{}/{}/static'.format(BASE_DIR, APP_NAME)
# URL prefix for static files.
STATIC_URL = '/static/'
""" END STATIC FILE CONFIGURATION """

""" END PATH CONFIGURATION """

""" MIDDLEWARE CONFIGURATION """
MIDDLEWARE_CLASSES = (
MIDDLEWARE = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
#'corsheaders.middleware.CorsMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'social_django.middleware.SocialAuthExceptionMiddleware',
# 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', didn't work in production
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
# 'admin_reorder.middleware.ModelAdminReorder',
)
""" END MIDDLEWARE CONFIGURATION """

""" OAUTH SETTINGS """
AUTHENTICATION_BACKENDS = (
'social_core.backends.open_id.OpenIdAuth',
'social_core.backends.google.GoogleOpenId',
'social_core.backends.google.GoogleOAuth2',
#'odm2admin.hydroshare_backend.HydroShareOAuth2',
'social_core.backends.google.GoogleOAuth',
'django.contrib.auth.backends.ModelBackend',
)
# Oauth CORS_ORIGIN_ALLOW_ALL = True

SOCIAL_AUTH_URL_NAMESPACE = 'social'
SOCIAL_AUTH_PIPELINE = (
'social_core.pipeline.social_auth.social_details',
'social_core.pipeline.social_auth.social_uid',
'social_core.pipeline.social_auth.social_user',
'social_core.pipeline.user.get_username',
'social_core.pipeline.user.create_user',
'social_core.pipeline.social_auth.associate_user',
'social_core.pipeline.social_auth.load_extra_data',
'social_core.pipeline.user.user_details',
'social_core.pipeline.social_auth.associate_by_email',
)
""" END OAUTH SETTINGS """

""" URL AND WSGI CONFIGURATION """
ROOT_URLCONF = 'templatesAndSettings.urls'

Expand All @@ -145,9 +173,11 @@
'djangocms_admin_style',
'{}'.format(APP_NAME),
'import_export',
'social_django',
'admin_shortcuts',
'daterange_filter',
'captcha',
'fixture_magic',
# 'dal',
# 'dal_select2',
'ajax_select',
Expand Down Expand Up @@ -215,26 +245,6 @@
""" END ADMIN SHORTCUTS CONFIGURATION """


""" AJAX LOOKUPS CONFIGURATION """
AJAX_LOOKUP_CHANNELS = dict(
cv_variable_name=('{}.lookups'.format(APP_NAME), 'CvVariableNameLookup'),
cv_variable_type=('{}.lookups'.format(APP_NAME), 'CvVariableTypeLookup'),
cv_unit_type=('{}.lookups'.format(APP_NAME), 'CvUnitTypeLookup'),
cv_speciation=('{}.lookups'.format(APP_NAME), 'CvVariableSpeciationLookup'),
featureaction_lookup=('{}.lookups'.format(APP_NAME), 'FeatureactionsLookup'),
result_lookup=('{}.lookups'.format(APP_NAME), 'ResultsLookup'),
profileresult_lookup=('{}.lookups'.format(APP_NAME), 'ProfileResultsLookup'),
measurementresult_lookup=('{}.lookups'.format(APP_NAME), 'MeasurementResultsLookup'),
timeseriesresult_lookup=('{}.lookups'.format(APP_NAME), 'TimeseriesResultsLookup'),
sampling_feature_lookup=('{}.lookups'.format(APP_NAME), 'SamplingFeatureLookup'),
cv_taxonomic_classifier_type=('{}.lookups'.format(APP_NAME), 'CvTaxonomicClassifierTypeLookup'),
cv_method_type=('{}.lookups'.format(APP_NAME), 'CvMethodTypeLookup'),
cv_site_type=('{}.lookups'.format(APP_NAME), 'CvSitetypeLookup'),
cv_action_type=('{}.lookups'.format(APP_NAME), 'CvActionTypeLookup'),
cv_sampling_feature_type=('{}.lookups'.format(APP_NAME), 'CvSamplingFeatureTypeLookup'),
cv_sampling_feature_geo_type=('{}.lookups'.format(APP_NAME), 'CvSamplingFeatureGeoTypeLookup'),
cv_elevation_datum=('{}.lookups'.format(APP_NAME), 'CvElevationDatumLookup'))
""" END AJAX LOOKUPS CONFIGURATION """

""" SAMPLING FEATURE TYPE LEGEND MAPPING """
LEGEND_MAP = {
Expand Down Expand Up @@ -266,7 +276,7 @@
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://redis:6379/0",
"LOCATION": "redis://127.0.0.1:6379/1",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient"
},
Expand All @@ -276,4 +286,4 @@

# Cache time to live is 15 minutes.
CACHE_TTL = 60 * 15
""" END REDIS CACHING CONFIGURATION"""
""" END REDIS CACHING CONFIGURATION"""
6 changes: 5 additions & 1 deletion docker/docker-deploy/settings/development.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
Development settings and globals.
"""

from base import *
from .base import *

""" DEBUG CONFIGURATION """
# Disable debugging by default.
DEBUG = True
""" END DEBUG CONFIGURATION """

""" EXPORTDB FLAG CONFIGURATION - if set to true this will use Camel case table names for SQLite"""
EXPORTDB = False
""" EXPORTDB FLAG CONFIGURATION """

""" ALLOWED HOSTS CONFIGURATION """
ALLOWED_HOSTS = ['127.0.0.1',]
""" END ALLOWED HOSTS CONFIGURATION """
Expand Down
7 changes: 4 additions & 3 deletions docker/odm2admin/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ RUN apt-get update --fix-missing && apt-get install --yes apt-utils postgresql-c

EXPOSE 8000

RUN git clone "https://github.com/miguelcleon/ODM2-Admin"
RUN cd ODM2-Admin && latest=$(git describe --tags) && git checkout ${latest}
# && latest=$(git describe --tags) && git checkout ${latest}
RUN git clone -b django2 "https://github.com/ODM2/ODM2-Admin"
RUN cd ODM2-Admin

WORKDIR /ODM2-Admin

VOLUME templatesAndSettings/settings/

RUN conda create --yes -n odm2adminenv -c conda-forge python=2.7 pytz gdal --file requirements.txt
RUN conda create --yes -n odm2adminenv -c conda-forge python=3.6 libgdal boost pytz gdal --file requirements.txt

COPY odm2database/odm2adminDB.sql /odm2adminDB.sql
COPY odm2database/cvload.py /cvload.py
Expand Down
3 changes: 2 additions & 1 deletion docker/odm2admin/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
echo "Activating environment..."
source activate odm2adminenv
conda install --yes -c conda-forge sqlalchemy
# pip install git+git://github.com/miguelcleon/django-admin-shortcuts --upgrade

#echo "Building database..."
#su - postgres -c 'pg_restore -d odm2_db -1 -v "/ODM2-Admin/ODM2AdminDBBlank"'
Expand All @@ -17,4 +18,4 @@ wget https://raw.githubusercontent.com/ODM2/ODM2/master/src/load_cvs/cvload.py
python cvload.py postgresql+psycopg2://postgres:test@db:5432/odm2

echo "Running server..."
python manage.py runserver 0.0.0.0:8000
python manage.py runserver 0.0.0.0:8000
20 changes: 19 additions & 1 deletion docker/odm2admin/wait-for-postgres.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,25 @@ until psql -h "$host" -U "postgres" -c '\l'; do
sleep 1
done

psql -v ON_ERROR_STOP=1 --host "$host" --username "postgres" -c "CREATE DATABASE odm2;"


# sql to check whether given database exist
sql1="select count(1) from pg_catalog.pg_database where datname = 'odm2'"

# depending on how PATH is set psql may require a fully qualified path
cmd="psql -h \"$host\" -U \"postgres\" -t -c \"$sql1\""

db_exists=`eval $cmd`

if [ $db_exists -eq 0 ] ; then
# create the database, discard the output
>&2 echo " create odm2 db 1 time "
psql -v ON_ERROR_STOP=1 --host "$host" --username "postgres" -c "CREATE DATABASE odm2;"
eval $cmd
fi


# psql -v ON_ERROR_STOP=1 --host "$host" --username "postgres" -c "CREATE DATABASE odm2;"
psql -v ON_ERROR_STOP=1 --host "$host" --username "postgres" --dbname "odm2" --file /odm2adminDB.sql

>&2 echo "Postgres is up - executing command"
Expand Down
2 changes: 1 addition & 1 deletion docs/source/DataQAQC.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ points position in the set of points selected.
:ref:`5) Data visualization and URL parameters <Data-Visualization>`

* :ref:`ODM2 Admin docs home page<ODM2-Admin>`
* :ref:`Search the docs <search>`
* :ref:`Search the docs <search>`
18 changes: 11 additions & 7 deletions docs/source/ODM2AdminDemo.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
OODM2 Admin Walkthrough
ODM2 Admin Walkthrough
======================
.. 2017 BiG-CZ / ODM2 Hands-On Workshop, November 15-16, 2017 at UC Riverside, CA.
..
This walthough explains many of the features of ODM2 Admin. This tutorial was developed for the CUAHSI Tools
Below is a tutorial which explains many of the features of ODM2 Admin. This tutorial was developed for the CUAHSI Tools
and Services for Managing Research Data Workshop at the CUAHSI Biennial Colloquium on July 7-31-2018. It is meant as a
demonstration of the capabilities of ODM2 Admin and as a use case for ODM2. Links contained here access a demonstartion
version of ODM2 Admin populated with data from the `Luquillo Critical Zone Observatory <http://criticalzone.org/luquillo/>`_
Expand Down Expand Up @@ -49,10 +49,15 @@ The Authentication and Authorization link will allow you to create users and gro
The ODM2 Admin Administration link will take you to a list of all 44 ODM2 entities that can be directly managed in
ODM2 Admin. See the ODM2 Admin Forms for details about the ODM2 Admin Forms :ref:`ODM2-Administration`.

Some entities described by the ODM2 data model do not have forms associated with them in ODM2 Admin and need to be
managed with another tool such as with the ODM2PythonAPI. Django models exist for each ODM2 entity so it is also
possible to write Python scripts using the Django Object relational mapper. See :ref:`Managing-ODM2-With-The-Django-ORM`
for details on using the Django ORM with ODM2 databases.
The recent actions section shows changes you have recently completed in ODM2 Admin such as adding or editing an item
in the forms. In the example above we can see that a method, a data result and a variable were recently changed.

The Authentication and Authorization link will allow you to create users and groups so others can login to the system.

Additional entities exist within the ODM2 information model these need to be managed with another tool
Such as with the ODM2PythonAPI. Django models exist for each ODM2 entity so it is also possible to write Python scripts
using the Django Object relational mapper. See :ref:`Managing-ODM2-With-The-Django-ORM` for details on using the Django
ORM with ODM2 databases.


.. toctree::
Expand All @@ -69,4 +74,3 @@ for details on using the Django ORM with ODM2 databases.

* :ref:`ODM2 Admin docs home page <ODM2-Admin>`
* :ref:`Search the docs <search>`

Binary file modified docs/source/images/offsetanddriftcorrect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions manageexport.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "templatesAndSettings.settings.exportdb")

from django.core.management import execute_from_command_line
print(sys.argv)
execute_from_command_line(sys.argv)
Loading

0 comments on commit c3a0bc8

Please sign in to comment.