-
Notifications
You must be signed in to change notification settings - Fork 2
DiamondBase - Upgrade #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
2dbec02
0859fa2
d81084d
fe9a4d9
6d8b587
89ebf9f
882d773
8af4040
3624e91
0355195
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,39 +45,61 @@ | |
| 'foundation', | ||
| 'slack', | ||
| 'about', | ||
| 'custom_middleware' | ||
| 'login_required' | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ...since login is now managed by https://pypi.org/project/django-login-required-middleware/. |
||
| ) | ||
|
|
||
| MIDDLEWARE_CLASSES = ( | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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/' | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = '/' | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
|
|
@@ -92,6 +114,9 @@ | |
|
|
||
| USE_TZ = True | ||
|
|
||
| USE_I18N = False | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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/ | ||
|
|
@@ -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/'),) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| DELIMITER // | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| from django.conf.urls import patterns, include, url | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
|
|
@@ -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: | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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,}) | ||
| 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 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'), | ||
| ) | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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') | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| from django.conf import settings | ||
| from re import compile | ||
|
|
||
| from django.core.urlresolvers import reverse | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(): | ||
|
|
@@ -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): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../django-zurb-foundation/foundation/ | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. django-zurb-foundation has been externalized to facilitate updating it. This is a symbolic link to its installation folder. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed anymore...