Skip to content

Commit

Permalink
Simplified extra_context() processor (#703)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottx611x committed Nov 18, 2015
1 parent 96b48c1 commit bc151fe
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 57 deletions.
80 changes: 29 additions & 51 deletions refinery/core/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,32 @@


def extra_context(context):
site_model = serializers.serialize("json", Site.objects.all())

ui_accessible_settings = {}

# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# WARNING: Be careful adding Django settings to this dictionary as
# `globally_available_settings` does exactly as it states and exposes each
# of these settings to the template context/javascript console!
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

globally_available_settings = [
"ADMINS",
"CURRENT_COMMIT",
"REFINERY_CSS",
"REFINERY_MAIN_LOGO",
"REFINERY_INNER_NAVBAR_HEIGHT",
"REFINERY_BASE_URL",
"REFINERY_SOLR_BASE_URL",
"REFINERY_GOOGLE_ANALYTICS_ID",
"REFINERY_INSTANCE_NAME",
"REFINERY_REPOSITORY_MODE",
"REFINERY_CONTACT_EMAIL",
"REGISTRATION_OPEN",
"REFINERY_REGISTRATION_CLOSED_MESSAGE",
"ACCOUNT_ACTIVATION_DAYS",
"REFINERY_BANNER",
"REFINERY_BANNER_ANONYMOUS_ONLY",
"REFINERY_EXTERNAL_AUTH",
"REFINERY_EXTERNAL_AUTH_MESSAGE",
"STATIC_URL"
]

# Add settings from the Site model
ui_accessible_settings["REFINERY_BASE_URL"] = json.loads(site_model)[
0]["fields"]["domain"]
ui_accessible_settings["REFINERY_INSTANCE_NAME"] = json.loads(
site_model)[0]["fields"]["name"]

# populate ui_accessible_settings based on the settings specified within
# UI_ACCESSIBLE_SETTINGS in config.json
for setting in globally_available_settings:
try:
ui_accessible_settings[setting] = getattr(settings, setting)
except AttributeError:
logger.warn("%s not found in config.json" % setting)

# Allow for access within js i.e. refinerySettings.ADMINS[0][1]
ui_accessible_settings["refinerySettings"] = json.dumps(
ui_accessible_settings)

return ui_accessible_settings
"""return values you want as a dictionary"""
"""!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
WARNING: Be careful adding Django settings to this dictionary as
it exposes each of these settings to the template context/javascript
console!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
"""
return {
"ADMINS": settings.ADMINS[0][1],
"REFINERY_CSS": settings.REFINERY_CSS,
"REFINERY_MAIN_LOGO": settings.REFINERY_MAIN_LOGO,
"REFINERY_INNER_NAVBAR_HEIGHT": settings.REFINERY_INNER_NAVBAR_HEIGHT,
"REFINERY_BASE_URL": Site.objects.get_current().domain,
"REFINERY_SOLR_BASE_URL": settings.REFINERY_SOLR_BASE_URL,
"REFINERY_GOOGLE_ANALYTICS_ID": settings.REFINERY_GOOGLE_ANALYTICS_ID,
"REFINERY_INSTANCE_NAME": Site.objects.get_current().name,
"REFINERY_REPOSITORY_MODE": settings.REFINERY_REPOSITORY_MODE,
"REFINERY_CONTACT_EMAIL": settings.DEFAULT_FROM_EMAIL,
"REGISTRATION_OPEN": settings.REGISTRATION_OPEN,
"REFINERY_REGISTRATION_CLOSED_MESSAGE":
settings.REFINERY_REGISTRATION_CLOSED_MESSAGE,
"ACCOUNT_ACTIVATION_DAYS": settings.ACCOUNT_ACTIVATION_DAYS,
"REFINERY_BANNER": settings.REFINERY_BANNER,
"REFINERY_BANNER_ANONYMOUS_ONLY":
settings.REFINERY_BANNER_ANONYMOUS_ONLY,
"REFINERY_EXTERNAL_AUTH": settings.REFINERY_EXTERNAL_AUTH,
"REFINERY_EXTERNAL_AUTH_MESSAGE":
settings.REFINERY_EXTERNAL_AUTH_MESSAGE,
}
4 changes: 2 additions & 2 deletions refinery/static/source/js/refinery/solr/solr_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ SolrClient.prototype.initialize = function ( query, resetQuery, callback ) {
"<p>" +
"Please contact your " +
"<a href='mailto:" +
refinerySettings.ADMINS[0][1] +
admins +
"?Subject=Refinery%20Error' target='_top'>System Administrator</a>" +
".</p>"
);
Expand Down Expand Up @@ -121,7 +121,7 @@ SolrClient.prototype.run = function ( query, queryComponents, callback ) {
"<p>" +
"Please contact your " +
"<a href='mailto:" +
refinerySettings.ADMINS[0][1] +
admins +
"?Subject=Refinery%20Error' target='_top'>System Administrator</a>" +
".</p>"
);
Expand Down
3 changes: 1 addition & 2 deletions refinery/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,12 @@

var username = '{{ user.username }}';
var user_id = '{{ user.id }}';
var admins = '{{ ADMINS|safe }}';
if (username === 'None' || user_id === 'None') {
username = undefined;
user_id = undefined;
}

var refinerySettings = JSON.parse("{{refinerySettings|escapejs}}");

function sizing() {
var windowWidth = $(window).width(),
windowHeight = $(window).height();
Expand Down
2 changes: 0 additions & 2 deletions refinery/ui/source/js/dashboard/controllers/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ function DashboardCtrl (
this.dataSetServiceLoading = false;
this.expandedDataSetPanelBorder = false;

this.adminMail = refinerySettings.ADMINS[0][1];

// Check authentication
// This should ideally be moved to the global APP controller, which we don't
// have right now.
Expand Down

0 comments on commit bc151fe

Please sign in to comment.