Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 40 additions & 14 deletions DiamondBase/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,39 +45,61 @@
'foundation',
'slack',
'about',
'custom_middleware'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed anymore...

'login_required'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)

MIDDLEWARE_CLASSES = (
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

MIDDLEWARE = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'login_required.middleware.LoginRequiredMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'custom_middleware.middleware.LoginRequiredMiddleware',
)
TEMPLATE_CONTEXT_PROCESSORS=("django.contrib.auth.context_processors.auth",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upgrade to Django 3

"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.contrib.messages.context_processors.messages",
"django.core.context_processors.request",
"sample_database.context_processors.action_types",
"sample_database.context_processors.lab_name")
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
"django.contrib.auth.context_processors.auth",
"django.template.context_processors.debug",
"django.template.context_processors.i18n",
"django.template.context_processors.media",
"django.template.context_processors.static",
"django.template.context_processors.tz",
"django.contrib.messages.context_processors.messages",
"django.template.context_processors.request",
"sample_database.context_processors.action_types",
"sample_database.context_processors.lab_name"
],
},
},
]

ROOT_URLCONF = 'DiamondBase.urls'

WSGI_APPLICATION = 'DiamondBase.wsgi.application'

LOGIN_URL = '/login/'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Configuration of login_required plugin


LOGIN_URL_NAME = 'login'

LOGIN_EXEMPT_URLS = (
r'^slack/',
)

LOGIN_REDIRECT_URL = '/'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Configuration of login_required plugin


LOGOUT_REDIRECT_URL = '/'

LOGIN_REQUIRED_IGNORE_VIEW_NAMES = [
'login',
'logout'
]

# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

Expand All @@ -92,6 +114,9 @@

USE_TZ = True

USE_I18N = False
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disable Django's translation system


#USE_L10N = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
Expand All @@ -100,4 +125,5 @@
MEDIA_URL = '/media/'
# MEDIA_ROOT defined in .env
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(PROJECT_ROOT_PATH, 'static/')
STATIC_ROOT = os.path.join(PROJECT_ROOT_PATH, 'static/')
#STATICFILES_DIRS = (os.path.join(PROJECT_ROOT_PATH, 'static/'),)
69 changes: 69 additions & 0 deletions DiamondBase/triggers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
DELIMITER //
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is intended to be applied to a SQL database used with Diamondbase when setting up the app. The triggers assign default parameter values to action and data objects when new parameter types have been linked to action type or data type objects.


CREATE OR REPLACE PROCEDURE AddActionParamProc()
MODIFIES SQL DATA
SQL SECURITY INVOKER
COMMENT 'To be executed (by trigger) if new parameter is assigned to an Action_Type'
BEGIN
INSERT INTO sample_database_param_value_action (value, action_id, param_id) (
SELECT IF(p.default_value IS NULL, '', p.default_value) AS value,
a.id AS action_id,
atp.param_id AS param_id
FROM sample_database_action_type_params AS atp
LEFT JOIN sample_database_param AS p ON atp.param_id = p.id,
sample_database_action AS a
WHERE atp.action_type_id = a.action_type_id AND
(a.id, atp.param_id) NOT IN (
SELECT a.id, pva.param_id
FROM sample_database_param_value_action AS pva
INNER JOIN sample_database_action_type_params AS atp ON pva.param_id = atp.param_id
LEFT JOIN sample_database_action AS a ON pva.action_id = a.id
WHERE a.action_type_id = atp.action_type_id
)
);
END//

CREATE OR REPLACE PROCEDURE AddDataParamProc()
MODIFIES SQL DATA
SQL SECURITY INVOKER
COMMENT 'To be executed (by trigger) if new parameter is assigned to a Data_Type'
BEGIN
INSERT INTO sample_database_param_value_data (value, data_id, param_id) (
SELECT IF(p.default_value IS NULL, '', p.default_value) AS value,
d.id AS data_id,
dtp.param_id AS param_id
FROM sample_database_data_type_params AS dtp
LEFT JOIN sample_database_param AS p ON dtp.param_id = p.id,
sample_database_data AS d
WHERE dtp.data_type_id = d.data_type_id AND
(d.id, dtp.param_id) NOT IN (
SELECT d.id, pvd.param_id
FROM sample_database_param_value_data AS pvd
INNER JOIN sample_database_data_type_params AS dtp ON pvd.param_id = dtp.param_id
LEFT JOIN sample_database_data AS d ON pvd.data_id = d.id
WHERE d.data_type_id = dtp.data_type_id
)
);
END//

CREATE OR REPLACE TRIGGER AddActionParamInsertTrigger
AFTER INSERT ON sample_database_action_type_params
FOR EACH ROW
CALL AddActionParamProc();

CREATE OR REPLACE TRIGGER AddActionParamUpdateTrigger
AFTER UPDATE ON sample_database_action_type_params
FOR EACH ROW
CALL AddActionParamProc();

CREATE OR REPLACE TRIGGER AddDataParamInsertTrigger
AFTER INSERT ON sample_database_data_type_params
FOR EACH ROW
CALL AddDataParamProc();

CREATE OR REPLACE TRIGGER AddDataParamUpdateTrigger
AFTER UPDATE ON sample_database_data_type_params
FOR EACH ROW
CALL AddDataParamProc();

DELIMITER ;
30 changes: 15 additions & 15 deletions DiamondBase/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.conf.urls import patterns, include, url
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upgrade to Django 3 and views for login/logout and password change.

from django.conf.urls import include, url
from django.conf import settings
from django.http import HttpResponseRedirect, HttpResponse, Http404
from django.contrib.auth.views import login
from django.contrib.auth import views as auth_views
import os
from django.contrib import admin
admin.autodiscover()
Expand All @@ -18,18 +18,18 @@ def my_redirect(name):
return HttpResponse('Machine exists, but either shutdown or error with client.')
return HttpResponseRedirect('http://%s'%cpu.ip)

urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls),name='admin'),
url(r'^about/', include('about.urls', namespace='about')),
url(r'^DB/', include('sample_database.urls',namespace='DB')),
url(r'^IP/', include('ip_tracker.urls',namespace='IP')),
url(r'^slack/', include('slack.urls',namespace='slack')),
url(r'^login/', login, name='login'),
urlpatterns = [
url(r'^admin/', admin.site.urls,name='admin'),
url(r'^about/', include(('about.urls', 'about'), namespace='about')),
url(r'^DB/', include(('sample_database.urls', 'DB'), namespace='DB')),
url(r'^IP/', include(('ip_tracker.urls', 'IP'), namespace='IP')),
url(r'^slack/', include(('slack.urls', 'slack'), namespace='slack')),
url(r'^login/', auth_views.LoginView.as_view(redirect_authenticated_user=True), name='login'),
url(r'^logout/', auth_views.LogoutView.as_view(next_page='/'), name='logout'),
url(r'^pwchange/', auth_views.PasswordChangeView.as_view(success_url='/'), name='pwchange'),
url(r'^$',lambda r: HttpResponseRedirect('DB/')),
url(r'^%s(?P<path>.*)$'%settings.MEDIA_URL[1:],views.media_xsendfile)
)
url(r'^%s(?P<path>.*)$'%settings.MEDIA_URL[1:],views.media_xsendfile),
]

if settings.DEBUG:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not work with Django 3

urlpatterns += patterns("django.views",
url(r"%s(?P<path>.*)$" % settings.MEDIA_URL[1:], "static.serve", {"document_root": settings.MEDIA_ROOT,})
)
#if settings.DEBUG:
# urlpatterns += url(r"%s(?P<path>.*)$" % settings.MEDIA_URL[1:], "static.serve", {"document_root": settings.MEDIA_ROOT,})
6 changes: 3 additions & 3 deletions about/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.views.generic import TemplateView
from django.conf.urls import patterns, url
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upgrade to Django 3

from django.conf.urls import url

urlpatterns = patterns('',
urlpatterns = [
url(r'^$', TemplateView.as_view(template_name='about/about.htm'), name='index'),
)
]
1 change: 1 addition & 0 deletions apache/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

sys.path.insert(0,BASE_DIR)
sys.path.append('/var/www/DiamondBase/sample_database')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some configuration. Otherwise it does not run?

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "DiamondBase.settings")

from django.core.wsgi import get_wsgi_application
Expand Down
26 changes: 1 addition & 25 deletions custom_middleware/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.conf import settings
from re import compile

from django.core.urlresolvers import reverse
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upgrade to Django 3

from django.urls import reverse


def get_login_url():
Expand All @@ -14,27 +14,3 @@ def get_exempts():
if hasattr(settings, 'LOGIN_EXEMPT_URLS'):
exempts += [compile(expr) for expr in settings.LOGIN_EXEMPT_URLS]
return exempts


class LoginRequiredMiddleware(object):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed anymore since login is now managed by login_required plugin.

"""
Middleware that requires a user to be authenticated to view any page other
than reverse(LOGIN_URL_NAME). Exemptions to this requirement can optionally
be specified in settings via a list of regular expressions in
LOGIN_EXEMPT_URLS (which you can copy from your urls.py).

Requires authentication middleware and template context processors to be
loaded. You'll get an error if they aren't.
"""
def process_request(self, request):
assert hasattr(request, 'user'), "The Login Required middleware\
requires authentication middleware to be installed. Edit your\
MIDDLEWARE_CLASSES setting to insert\
'django.contrib.auth.middlware.AuthenticationMiddleware'. If that\
doesn't work, ensure your TEMPLATE_CONTEXT_PROCESSORS setting includes\
'django.core.context_processors.auth'."
if not request.user.is_authenticated():
path = request.path.lstrip('/')
if not any(m.match(path) for m in get_exempts()):
return HttpResponseRedirect(
get_login_url() + "?next=" + request.path)
1 change: 1 addition & 0 deletions foundation
Loading