Skip to content
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

Django version upgrade plus features #12

Merged
merged 9 commits into from
Jun 21, 2019
Merged
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
31 changes: 31 additions & 0 deletions base/static/base/js/jquery.are-you-sure-shim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*!
* An experimental shim to partially emulate onBeforeUnload on iOS.
* Part of https://github.com/codedance/jquery.AreYouSure/
*
* Copyright (c) 2012-2014, Chris Dance and PaperCut Software http://www.papercut.com/
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
* Author: [email protected]
* Date: 19th May 2014
*/
$(function() {
if (!navigator.userAgent.toLowerCase().match(/iphone|ipad|ipod|opera/)) {
return;
}
$('a').bind('click', function(evt) {
var href = $(evt.target).closest('a').attr('href');
if (href !== undefined && !(href.match(/^#/) || href.trim() == '')) {
var response = $(window).triggerHandler('beforeunload', response);
if (response && response != "") {
var msg = response + "\n\n"
+ "Press OK to leave this page or Cancel to stay.";
if (!confirm(msg)) {
return false;
}
}
window.location.href = href;
return false;
}
});
});
192 changes: 192 additions & 0 deletions base/static/base/js/jquery.are-you-sure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
/*!
* jQuery Plugin: Are-You-Sure (Dirty Form Detection)
* https://github.com/codedance/jquery.AreYouSure/
*
* Copyright (c) 2012-2014, Chris Dance and PaperCut Software http://www.papercut.com/
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
* Author: [email protected]
* Version: 1.9.0
* Date: 13th August 2014
*/
(function($) {

$.fn.areYouSure = function(options) {

var settings = $.extend(
{
'message' : 'You have unsaved changes!',
'dirtyClass' : 'dirty',
'change' : null,
'silent' : false,
'addRemoveFieldsMarksDirty' : false,
'fieldEvents' : 'change keyup propertychange input',
'fieldSelector': ":input:not(input[type=submit]):not(input[type=button])"
}, options);

var getValue = function($field) {
if ($field.hasClass('ays-ignore')
|| $field.hasClass('aysIgnore')
|| $field.attr('data-ays-ignore')
|| $field.attr('name') === undefined) {
return null;
}

if ($field.is(':disabled')) {
return 'ays-disabled';
}

var val;
var type = $field.attr('type');
if ($field.is('select')) {
type = 'select';
}

switch (type) {
case 'checkbox':
case 'radio':
val = $field.is(':checked');
break;
case 'select':
val = '';
$field.find('option').each(function(o) {
var $option = $(this);
if ($option.is(':selected')) {
val += $option.val();
}
});
break;
default:
val = $field.val();
}

return val;
};

var storeOrigValue = function($field) {
$field.data('ays-orig', getValue($field));
};

var checkForm = function(evt) {

var isFieldDirty = function($field) {
var origValue = $field.data('ays-orig');
if (undefined === origValue) {
return false;
}
return (getValue($field) != origValue);
};

var $form = ($(this).is('form'))
? $(this)
: $(this).parents('form');

// Test on the target first as it's the most likely to be dirty
if (isFieldDirty($(evt.target))) {
setDirtyStatus($form, true);
return;
}

$fields = $form.find(settings.fieldSelector);

if (settings.addRemoveFieldsMarksDirty) {
// Check if field count has changed
var origCount = $form.data("ays-orig-field-count");
if (origCount != $fields.length) {
setDirtyStatus($form, true);
return;
}
}

// Brute force - check each field
var isDirty = false;
$fields.each(function() {
$field = $(this);
if (isFieldDirty($field)) {
isDirty = true;
return false; // break
}
});

setDirtyStatus($form, isDirty);
};

var initForm = function($form) {
var fields = $form.find(settings.fieldSelector);
$(fields).each(function() { storeOrigValue($(this)); });
$(fields).unbind(settings.fieldEvents, checkForm);
$(fields).bind(settings.fieldEvents, checkForm);
$form.data("ays-orig-field-count", $(fields).length);
setDirtyStatus($form, false);
};

var setDirtyStatus = function($form, isDirty) {
var changed = isDirty != $form.hasClass(settings.dirtyClass);
$form.toggleClass(settings.dirtyClass, isDirty);

// Fire change event if required
if (changed) {
if (settings.change) settings.change.call($form, $form);

if (isDirty) $form.trigger('dirty.areYouSure', [$form]);
if (!isDirty) $form.trigger('clean.areYouSure', [$form]);
$form.trigger('change.areYouSure', [$form]);
}
};

var rescan = function() {
var $form = $(this);
var fields = $form.find(settings.fieldSelector);
$(fields).each(function() {
var $field = $(this);
if (!$field.data('ays-orig')) {
storeOrigValue($field);
$field.bind(settings.fieldEvents, checkForm);
}
});
// Check for changes while we're here
$form.trigger('checkform.areYouSure');
};

var reinitialize = function() {
initForm($(this));
}

if (!settings.silent && !window.aysUnloadSet) {
window.aysUnloadSet = true;
$(window).bind('beforeunload', function() {
$dirtyForms = $("form").filter('.' + settings.dirtyClass);
if ($dirtyForms.length == 0) {
return;
}
// Prevent multiple prompts - seen on Chrome and IE
if (navigator.userAgent.toLowerCase().match(/msie|chrome/)) {
if (window.aysHasPrompted) {
return;
}
window.aysHasPrompted = true;
window.setTimeout(function() {window.aysHasPrompted = false;}, 900);
}
return settings.message;
});
}

return this.each(function(elem) {
if (!$(this).is('form')) {
return;
}
var $form = $(this);

$form.submit(function() {
$form.removeClass(settings.dirtyClass);
});
$form.bind('reset', function() { setDirtyStatus($form, false); });
// Add a custom events
$form.bind('rescan.areYouSure', rescan);
$form.bind('reinitialize.areYouSure', reinitialize);
$form.bind('checkform.areYouSure', checkForm);
initForm($form);
});
};
})(jQuery);
12 changes: 10 additions & 2 deletions base/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
<!-- Adding jQueryUI for some interactions -->
<script src="{% static 'base/js/jquery-ui.min.js' %}" type="text/javascript"></script>

<!-- jQuery AYS: track unsaved changes and alert on close without save
Source: https://github.com/codedance/jquery.AreYouSure -->
<script src="{% static 'base/js/jquery.are-you-sure.js' %}" type="text/javascript"></script>
<!-- jQuery AYS shim to work with iOS browsers -->
<script src="{% static 'base/js/jquery.are-you-sure-shim.js' %}" type="text/javascript"></script>
{% block additional_head_content %}{% endblock %}
</head>

Expand Down Expand Up @@ -76,7 +81,7 @@
{% endif %}
</ul>
{% if not user.is_authenticated %}
<form class="navbar-form navbar-right" role="form" method="POST" action="{% url 'django.contrib.auth.views.login' %}">
<form class="navbar-form navbar-right" role="form" method="POST" action="{% url 'login' %}">
{% csrf_token %}
<div class="form-group">
<input id="id_username" type="text" placeholder="Username" name="username" class="form-control">
Expand Down Expand Up @@ -117,7 +122,7 @@
<div class="row">
<footer class="footer">
<hr>
<p>&copy; 2017 Lockheed Martin Corporation | <a href="{% url 'about' %}">About</a>
<p>&copy; {% now "Y" %} Lockheed Martin Corporation | <a href="{% url 'about' %}">About</a>
<small class="pull-right">v{{ DART_VERSION_NUMBER }}</small>
</p>
</footer>
Expand Down Expand Up @@ -161,6 +166,9 @@
var shiftWindow = function() {scrollBy(0, -85) };
if (location.hash) shiftWindow();
window.addEventListener("hashchange", shiftWindow);

//Add change tracking for all input fields within forms
$('form').areYouSure();
});

function updateAttackTime() {
Expand Down
52 changes: 31 additions & 21 deletions dart/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,12 @@
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

DART_VERSION_NUMBER = '2.0.0'
DART_VERSION_NUMBER = '2.1.0'

# SECURITY WARNING
# We are not randomizing this key for you.
SECRET_KEY = '5s9G+t##Trga48t594g1g8sret*(#*/rg-dfgs43wt)((dh/*d'

# SECURITY WARNING
# We run in debug mode so that static files are automatically served
# out by the built-in django webserver for ease of setup. Since you're already running
# this on a trusted network (remember the security warning at the top of this file) you
# are probably okay doing the same.
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []

# Application definition
Expand Down Expand Up @@ -68,16 +59,34 @@
#'missions.middleware.RequiredInterstitial', # Uncomment and see related setting below if you require an interstitial
)

TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"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",
"missions.contextprocessors.context_processors.version_number",
)
DEBUG=True

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
#Hard coding path for now. Try without this path or use Base_dir as described here; #https://stackoverflow.com/questions/3038459/django-template-path
'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',
'missions.contextprocessors.context_processors.version_number',
],
# SECURITY WARNING
# We run in debug mode so that static files are automatically served
# out by the built-in django webserver for ease of setup. Since you're already running
# this on a trusted network (remember the security warning at the top of this file) you
# are probably okay doing the same.
'debug': DEBUG,
},
},
]

ROOT_URLCONF = 'dart.urls'

Expand Down Expand Up @@ -107,8 +116,9 @@

# Bootstrap Settings
BOOTSTRAP3 = {
'css_url': STATIC_URL + 'base/css/bootstrap.min.css',
'javascript_url': STATIC_URL + 'base/js/bootstrap.min.js',
'jquery_url': STATIC_URL + 'base/js/jquery.min.js',
'base_url': STATIC_URL + 'base/',
'required_css_class': 'required',
}

Expand Down
15 changes: 8 additions & 7 deletions dart/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,25 @@
# limitations under the License.
#

from django.conf.urls import patterns, include, url
from django.conf.urls import include, url
from django.contrib import admin
from django.views.generic import RedirectView
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
import missions.views
from django.contrib.auth.decorators import login_required
from django.contrib.auth.views import logout, login
from django.views.static import serve
from django.conf import settings

urlpatterns = patterns('',

urlpatterns = [
url(r'^missions/', include('missions.urls')),

url(r'^$', RedirectView.as_view(url='/missions/', permanent=False)),

url(r'^admin/', include(admin.site.urls)),

url(r'^accounts/logout/$', 'django.contrib.auth.views.logout', name='logout'),
url(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}, name='login'),
url(r'^accounts/logout/$', logout, name='logout'),
url(r'^accounts/login/$', login, {'template_name': 'login.html'}, name='login'),
url(r'^accounts/$', RedirectView.as_view(url='/', permanent=False)),
url(r'^accounts/profile/$', RedirectView.as_view(url='/', permanent=False)),

Expand Down Expand Up @@ -63,7 +64,7 @@
url(r'^data/(?P<supportingdata>\d+)/$',
login_required(missions.views.DownloadSupportingDataView.as_view()), name='data-view'),
url(r'^data/(?P<path>.*)$',
'django.views.static.serve',{'document_root': settings.MEDIA_ROOT, 'show_indexes': False}),
)
serve,{'document_root': settings.MEDIA_ROOT, 'show_indexes': False}),
]

urlpatterns += staticfiles_urlpatterns()
2 changes: 2 additions & 0 deletions install/online/prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def download_pip_requirements(self):

if self.BYPASS_CERTIFICATE_VALIDATION:
pip_download_cmd += ['--trusted-host', 'pypi.python.org']
pip_download_cmd += ['--trusted-host', 'pypi.org']
pip_download_cmd += ['--trusted-host', 'files.pythonhosted.org']

# Download lxml wheels for multiple architectures
lxml_win32 = [
Expand Down
Loading