From 50b56e8d775b05bf54c69f41ef23490c2d667ee7 Mon Sep 17 00:00:00 2001
From: Michael Gallaspy
Date: Fri, 11 Dec 2015 17:24:13 -0800
Subject: [PATCH 01/20] Export defaults to all users
---
kalite/control_panel/api_resources.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/kalite/control_panel/api_resources.py b/kalite/control_panel/api_resources.py
index 2b50dfc358..4bdab8b6ae 100644
--- a/kalite/control_panel/api_resources.py
+++ b/kalite/control_panel/api_resources.py
@@ -105,7 +105,6 @@ def _get_facility_users(self, bundle):
# They must have a zone_id, and may have a facility_id and group_id.
# Try to filter from most specific, to least
- facility_user_objects = []
if group_id:
facility_user_objects = FacilityUser.objects.filter(group__id=group_id)
elif facility_id:
@@ -118,6 +117,9 @@ def _get_facility_users(self, bundle):
facility_user_objects = []
for zone_id in zone_ids:
facility_user_objects += FacilityUser.objects.by_zone(get_object_or_None(Zone, id=zone_id))
+ else:
+ facility_user_objects = FacilityUser.objects.all()
+
# TODO(dylanjbarth) errors commented out so we can pass a blank CSV if not found.
# in future, should handle these more gracefully, with a redirect, an AJAX warning,
# and reset the fields. see: https://gist.github.com/1116962/58b7db0364de837ce229cdd8ef524bc9ff6da19f
From 5f69e7b8630f4e0934b1df23a444e0857436494f Mon Sep 17 00:00:00 2001
From: Michael Gallaspy
Date: Mon, 14 Dec 2015 17:18:19 -0800
Subject: [PATCH 02/20] Refactor export view, fix bug where Facility selector
is disabled
I dug through the commit messages to determine that the intent was
to disable the Facility selector when the requesting user is a
FacilityUser (not an admin). Instead of a conditional in the
View's render function, I tried to make the intent more explicit
by exposing a new context variable and putting the disable logic
in the View's is_disabled function.
Also fixes a bug where the Facility selector is erroneously
disabled when some resources are selected.
---
.../js/control_panel/data_export/models.js | 2 +-
.../js/control_panel/data_export/views.js | 32 ++++++++-----------
.../templates/control_panel/data_export.html | 3 +-
kalite/control_panel/views.py | 1 +
4 files changed, 17 insertions(+), 21 deletions(-)
diff --git a/kalite/control_panel/static/js/control_panel/data_export/models.js b/kalite/control_panel/static/js/control_panel/data_export/models.js
index 67e2f8b4a5..72a03a57cf 100644
--- a/kalite/control_panel/static/js/control_panel/data_export/models.js
+++ b/kalite/control_panel/static/js/control_panel/data_export/models.js
@@ -35,5 +35,5 @@ module.exports = {
DataExportStateModel: DataExportStateModel,
ZoneCollection: ZoneCollection,
FacilityCollection: FacilityCollection,
- GroupCollection: GroupCollection,
+ GroupCollection: GroupCollection
};
diff --git a/kalite/control_panel/static/js/control_panel/data_export/views.js b/kalite/control_panel/static/js/control_panel/data_export/views.js
index 102ba66e33..50419d3d6f 100644
--- a/kalite/control_panel/static/js/control_panel/data_export/views.js
+++ b/kalite/control_panel/static/js/control_panel/data_export/views.js
@@ -182,22 +182,12 @@ var FacilitySelectView = Backbone.View.extend({
},
render: function() {
- var template_context;
-
- if (this.model.get("facility_id") !== "") {
- template_context = {
- facilities: this.facility_list.toJSON(),
- selection: this.model.get("facility_id"),
- is_disabled: true
- };
- } else {
- template_context = {
- facilities: this.facility_list.toJSON(),
- selection: this.model.get("facility_id"),
- // Facility select is enabled only if zone_id has been set
- is_disabled: this.is_disabled()
- };
- }
+
+ var template_context = {
+ facilities: this.facility_list.toJSON(),
+ selection: this.model.get("facility_id"),
+ is_disabled: this.is_disabled()
+ };
this.$el.html(this.template(template_context));
@@ -205,9 +195,13 @@ var FacilitySelectView = Backbone.View.extend({
},
is_disabled: function() {
- // Helper function to quickly check whether the facility select input
- // should be enabled or disabled based on conditions that matter to it.
- if (this.model.get("resource_id") === "device_log") {
+ /*
+ * Determines whether FacilitySelect should be enabled or disabled. It should be enabled if:
+ * The resource selected is a DeviceLog -- devices don't have an associated Facility,
+ * OR The requesting user is a FacilityUser -- then the Facility is set (enforced by the Django view),
+ * OR the last condition (MCGallaspy: which I'm not sure where it comes from)
+ */
+ if (this.model.get("resource_id") === "device_log" || window.IS_FACILITY_USER) { // IS_FACILITY_USER exposed in template.
return true;
}
return ((this.model.get("zone_id") === undefined || this.model.get("zone_id") === "") && this.model.get("is_central"));
diff --git a/kalite/control_panel/templates/control_panel/data_export.html b/kalite/control_panel/templates/control_panel/data_export.html
index 545647723b..60d501a9ee 100644
--- a/kalite/control_panel/templates/control_panel/data_export.html
+++ b/kalite/control_panel/templates/control_panel/data_export.html
@@ -20,7 +20,8 @@
var ATTEMPT_LOG_CSV_URL = "{% url 'api_dispatch_list' resource_name='attempt_log_csv' %}";
var EXERCISE_LOG_CSV_URL = "{% url 'api_dispatch_list' resource_name='exercise_log_csv' %}";
var DEVICE_LOG_CSV_URL = "{% url 'api_dispatch_list' resource_name='device_log_csv' %}";
- var CONTENT_RATING_CSV_URL = "{% url 'api_dispatch_list' resource_name='content_rating_csv' %}"
+ var CONTENT_RATING_CSV_URL = "{% url 'api_dispatch_list' resource_name='content_rating_csv' %}";
+ var IS_FACILITY_USER = {{ is_facility_user }};
diff --git a/kalite/control_panel/views.py b/kalite/control_panel/views.py
index 472a471228..6bcb2555e0 100644
--- a/kalite/control_panel/views.py
+++ b/kalite/control_panel/views.py
@@ -197,6 +197,7 @@ def data_export(request):
"all_zones_url": all_zones_url,
"org": org,
"zone": zone,
+ "is_facility_user": "true" if "facility_user" in request.session else "false",
}
return context
From c10251cda0c83c79ade12e883a30214a5e60f426 Mon Sep 17 00:00:00 2001
From: Benjamin Bach
Date: Mon, 2 May 2016 21:20:53 +0200
Subject: [PATCH 03/20] Use current year instead of hard coded 2015
---
kalite/distributed/templates/distributed/partials/_footer.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kalite/distributed/templates/distributed/partials/_footer.html b/kalite/distributed/templates/distributed/partials/_footer.html
index b798097631..9428fccb4e 100644
--- a/kalite/distributed/templates/distributed/partials/_footer.html
+++ b/kalite/distributed/templates/distributed/partials/_footer.html
@@ -23,7 +23,7 @@
{% if channel_data.footer_text %}