Skip to content

Commit

Permalink
Merge pull request #604 from ODM2/develop
Browse files Browse the repository at this point in the history
Release v0.13.0
  • Loading branch information
ptomasula committed Apr 28, 2022
2 parents 932d2ce + 0f07124 commit 771915a
Show file tree
Hide file tree
Showing 104 changed files with 38,340 additions and 795 deletions.
10 changes: 7 additions & 3 deletions doc/deployment_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ While deploying the web application server, I recommend following the instructio
- `conda activate ODM2DataSharingPortal`
3. **Create a symlink so the Web App will use the settings.json file in the config repo:** Note the instructions below use the development/staging settings. You may need to point to a different file for the production deployment.
- `sudo ln -s /opt/ODM2DataSharingPortalConfig/django/staging.settings.json /opt/ODM2DataSharingPortal/src/WebSDL/settings/settings.json`
4. **Set Up Gunicorn:**
4. **Collect static files** The application now supports cache busting using the [ManifestStaticFilesStorage](https://docs.djangoproject.com/en/3.2/ref/contrib/staticfiles/#manifeststaticfilesstorage). This meant locating the static files in a seperate location on the server. Django can automatically copy the statics files and applying the correct hashing with the `collectstatic command`
- `cd /opt/ODM2DataSharingPortal/src`
- `conda activate ODM2DataSharingPortal`
- `python manage.py collectstatic --noinput`
5. **Set Up Gunicorn:**
- Gunicorn is not in the default mini conda channel, so we'll need to get it from conda forge.
- `conda config --add channels conda-forge`
- `conda install -c conda-forge gunicorn`
Expand All @@ -48,7 +52,7 @@ While deploying the web application server, I recommend following the instructio
- `chmod +755 wsgi.py`
- Now we just need to start the GUnicorn service we created
- `sudo systemctl start gunicorn``
5. **Set up nginx**
6. **Set up nginx**
- Install nginx
- `sudo apt install nginx`
- Create symlink between config repo and nginx
Expand All @@ -58,7 +62,7 @@ While deploying the web application server, I recommend following the instructio
- If there were no errors during the test, start nginx which should make the site accessable online.
- `sudo systemctl start nginx`
6. **Set up SSL certificate**
7. **Set up SSL certificate**

- The following commands are taken verbatim from https://certbot.eff.org/lets-encrypt/ubuntufocal-nginx.html:

Expand Down
42 changes: 17 additions & 25 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@ channels:
- defaults

dependencies:
# For ODM2DataSharingPortal migration to AWS
- python =3.8.10 # May 3, 2021: final regular Py 3.8 release. https://www.python.org/downloads/release/python-3810/
# - django =2.2.* # Installs 2.2.14 but lastest is 2.2.24. Use pip to install.
# https://docs.djangoproject.com/en/3.2/releases
- python =3.9.*

# # Other Requirements
# - beautifulsoup4 =4.9.3 # with python 3.8
- coverage >=5.5
- google-api-python-client >=2.12.0
- hs_restclient >=1.3.7 # https://github.com/hydroshare/hs_restclient
- markdown >=3.3.4
# - oauthlib >=3.1.1 # with google api
- pandas >=1.3
- psycopg2 >=2.9.1
- python-crontab >=2.5.1
# - requests # with python 3.8
# - six # with python 3.8
- python-crontab >=2.5.1
- sqlalchemy >=1.4.0

#django
#additional django dependencies installed with pip
- django ==3.2.*
- djangorestframework
- django-debug-toolbar
- django-widget-tweaks

# Dev tools
- python-language-server
Expand All @@ -32,19 +31,12 @@ dependencies:
- conda-build
- pip

# Dependency versions not available on conda-forge
- pip:
# - codegen >=1.0 # necessary? Last updated in 2012. https://pypi.org/project/codegen/
- django ==2.2.24
- django-admin-select2 # >=1.0.1
- django-debug-toolbar # >=1.11.1
- django-discover-runner # >=1.0
- django-reset-migrations # >=0.3.1
- django-webtest # >=1.8.0
- django-widget-tweaks # >=1.4.1
- djangorestframework
# - patterns >=0.3 # necessary? Last updated in 2014. https://pypi.org/project/patterns/
# - sqlparse # with django=2.2
# - waitress # with django extensions
# - WebOb # with django extensions
# - WebTest # with django extensions
- django-admin-select2
- django-discover-runner
- django-reset-migrations
- django-webtest
- django-cprofile-middleware
#used for unicode_compatiblity
#should confirm if this is still a dependency
- django-utils-six
25 changes: 0 additions & 25 deletions src/WebSDL/db_routers.py

This file was deleted.

19 changes: 10 additions & 9 deletions src/WebSDL/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
logging.basicConfig(level=logging.INFO)

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

# Loads settings configuration data from settings.json file
data = {}
try:
with open(os.path.join(BASE_DIR, 'settings', 'settings.json')) as data_file:
with open(os.path.join(BASE_DIR, 'WebSDL','settings', 'settings.json')) as data_file:
data = json.load(data_file)
except IOError:
print("You need to setup the settings data file (see instructions in base.py file.)")
Expand All @@ -45,14 +45,12 @@
INSTALLED_APPS = [
# 'debug_toolbar',
'rest_framework',
'tsa.apps.TsaConfig',
'accounts.apps.AccountsConfig',
'dataloader.apps.DataloaderConfig',
'dataloaderservices.apps.DataloaderservicesConfig',
'dataloaderinterface.apps.DataloaderinterfaceConfig',
'hydroshare',
'leafpack',
'django_admin_select2',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
Expand Down Expand Up @@ -126,6 +124,7 @@
'CONN_MAX_AGE': 0,
'TEST': database['test'] if 'test' in database else {},
}
DATAMODELCACHE = os.path.join(BASE_DIR, 'odm2', 'modelcache.pkl')

# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
Expand Down Expand Up @@ -153,8 +152,6 @@
USE_I18N = True
USE_L10N = True
LOGIN_URL = '/login/'
DATABASE_ROUTERS = ['WebSDL.db_routers.WebSDLRouter']


# Security and SSL
#
Expand All @@ -166,14 +163,15 @@
RECAPTCHA_USER_KEY = data["recaptcha_user_key"] if "recaptcha_user_key" in data else ""
RECAPTCHA_VERIFY_URL = "https://www.google.com/recaptcha/api/siteverify"

EMAIL_SENDER = data['password_email_sender'] if 'password_email_sender' in data else '',
EMAIL_SENDER = data['email_from'] if 'email_from' in data else '',
NOTIFY_EMAIL = data['notify_email_sender'] if 'notify_email_sender' in data else ''
DEFAULT_FROM_EMAIL = EMAIL_SENDER[0] if isinstance(EMAIL_SENDER, tuple) else EMAIL_SENDER
NOTIFY_EMAIL_SENDER = NOTIFY_EMAIL[0] if isinstance(NOTIFY_EMAIL, tuple) else NOTIFY_EMAIL
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_SERVER = data['email_host'] if 'email_host' in data else '',
EMAIL_HOST = EMAIL_SERVER[0] if isinstance(EMAIL_SERVER, tuple) else EMAIL_SERVER
EMAIL_HOST_USER = data['email_user'] if 'email_user' in data else ''
EMAIL_PORT = data['email_port']
EMAIL_HOST_USER = data['email_username'] if 'email_username' in data else ''
EMAIL_HOST_PASSWORD = data['email_password'] if 'email_password' in data else ''
EMAIL_USE_TLS = True

Expand All @@ -197,4 +195,7 @@

AUTH_USER_MODEL = 'accounts.User'

DEBUG = True if 'debug_mode' in data and data['debug_mode'] == "True" else False
#Static cache busting
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'

DEBUG = True if 'debug_mode' in data and data['debug_mode'] == "True" else False
18 changes: 0 additions & 18 deletions src/WebSDL/settings/settings_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,6 @@
"password": "{{database password}}",
"host": "{{database server address}}",
"port": "5432"
},
{
"name": "odm2",
"schema": "odm2",
"engine": "django.db.backends.postgresql_psycopg2",
"user": "{{database user}}",
"password": "{{database password}}",
"host": "{{database server address}}",
"port": "5432"
},
{
"name": "tsa_catalog",
"schema": "tsa_catalog",
"engine": "django.db.backends.postgresql_psycopg2",
"user": "{{database user}}",
"password": "{{database password}}",
"host": "{{database server address}}",
"port": "5432"
}
],
"hydroshare_oauth": {
Expand Down
15 changes: 8 additions & 7 deletions src/WebSDL/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.urls import reverse_lazy
from django.conf.urls.static import static

from accounts.views import UserRegistrationView, UserUpdateView
from accounts.views import UserRegistrationView, UserUpdateView, logout_view


#BASE_URL = settings.SITE_URL[1:]
Expand All @@ -42,21 +43,21 @@
}

urlpatterns = [
url(r'^' + BASE_URL + 'password-reset/$', auth_views.PasswordChangeView, password_reset_configuration, name='password_reset'),
url(r'^' + BASE_URL + 'password-reset/done/$', auth_views.PasswordChangeView, name='password_reset_done'),
url(r'^' + BASE_URL + 'password-reset/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$', auth_views.PasswordResetConfirmView, password_done_configuration, name='password_reset_confirm'),
url(r'^' + BASE_URL + 'password-reset/completed/$', auth_views.PasswordResetCompleteView, name='password_reset_complete'),
url(r'^' + BASE_URL + 'password-reset/$', auth_views.PasswordResetView.as_view(), password_reset_configuration, name='password_reset'),
url(r'^' + BASE_URL + 'password-reset/done/$', auth_views.PasswordChangeView.as_view(), name='password_reset_done'),
url(r'^' + BASE_URL + 'password-reset/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$', auth_views.PasswordResetConfirmView.as_view(), password_done_configuration, name='password_reset_confirm'),
url(r'^' + BASE_URL + 'password-reset/completed/$', auth_views.PasswordResetCompleteView.as_view(), name='password_reset_complete'),
url(r'^' + BASE_URL + 'admin/', admin.site.urls),
url(r'^' + BASE_URL + 'login/$', auth_views.LoginView.as_view(), login_configuration, name='login'),
url(r'^' + BASE_URL + 'logout/$', auth_views.LogoutView.as_view(), logout_configuration, name='logout'),
url(r'^' + BASE_URL + 'logout/$', logout_view, name='logout'),
url(r'^' + BASE_URL + 'register/$', UserRegistrationView.as_view(), name='user_registration'),
url(r'^' + BASE_URL + 'account/$', UserUpdateView.as_view(), name='user_account'),
url(r'^' + BASE_URL + 'api-auth/', include('rest_framework.urls', namespace='rest_framework')),
url(r'^' + BASE_URL + 'hydroshare/', include('hydroshare.urls', namespace='hydroshare')),
url(BASE_URL, include('dataloaderinterface.urls')),
url(BASE_URL, include('dataloaderservices.urls')),
url(BASE_URL, include('timeseries_visualization.urls'))
]
] + static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)

# if settings.DEBUG:
# import debug_toolbar
Expand Down
3 changes: 0 additions & 3 deletions src/WebSDL/wsgi.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
"""

import os
import crontab_jobs

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "WebSDL.settings.linux_server")

crontab_jobs.start_jobs()

application = get_wsgi_application()
2 changes: 1 addition & 1 deletion src/accounts/templates/registration/login.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "dataloaderinterface/base.html" %}
{% load widget_tweaks staticfiles %}
{% load widget_tweaks static %}

{% block content %}
<div class="container-fluid login-page-headline">
Expand Down
28 changes: 28 additions & 0 deletions src/accounts/templates/registration/logout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% extends "dataloaderinterface/base.html" %}

{% load static %}

{% block content %}
<div class="container-fluid login-page-headline">
<div class="row">
<div class="col">
<h1 class="mdl-typography--display-1 text-white text-center text-shadow">Thank you for using the Water-Quality Data Portal</h1>
<p class="mdl-typography--title text-white text-center text-shadow">You have been successfully logged out.</p>
</div>
</div>
</div>

<span id="bg-image" data-image-url="{% static "dataloaderinterface/images/login_bg.jpg" %}" class="hidden"></span>
{% endblock %}

{% block scripts %}
{{ block.super }}
<script>
$(document).ready(function(){
var path = $("#bg-image").attr("data-image-url");
$("#wrapper").css('background-image', 'url("' + path + '")');
$("#wrapper").css('background-size', 'cover');
$("#wrapper").css('background-repeat', 'no-repeat');
});
</script>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "dataloaderinterface/base.html" %}
{% load widget_tweaks staticfiles %}
{% load widget_tweaks static %}

{% block title %}Password reset complete{% endblock %}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "dataloaderinterface/base.html" %}
{% load widget_tweaks staticfiles %}
{% load widget_tweaks static %}

{% block title %}Setting New password{% endblock %}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "dataloaderinterface/base.html" %}
{% load widget_tweaks staticfiles %}
{% load widget_tweaks static %}

{% block title %}Password reset successful{% endblock %}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "dataloaderinterface/base.html" %}
{% load widget_tweaks staticfiles %}
{% load widget_tweaks static %}

{% block title %}Reset Password{% endblock %}

Expand Down
6 changes: 0 additions & 6 deletions src/accounts/tests.py

This file was deleted.

9 changes: 9 additions & 0 deletions src/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,12 @@ def post(self, request, *args, **kwargs):
login(request, form.instance)

return response

def logout_view(request):
# use django to log user out, and render a custom logout page to fix issue #558
from django.contrib.auth import logout
logout(request)
return render (
request,
'registration/logout.html'
)
3 changes: 0 additions & 3 deletions src/dataloader/admin.py

This file was deleted.

Loading

0 comments on commit 771915a

Please sign in to comment.