Skip to content

Commit

Permalink
Merge pull request #4207 from jamalex/securesync_fixes
Browse files Browse the repository at this point in the history
Update central-develop from 0.14.x (plus some incoming fixes)
  • Loading branch information
jamalex committed Aug 5, 2015
2 parents 1f87909 + 967bca1 commit 8adb6f3
Show file tree
Hide file tree
Showing 23 changed files with 190 additions and 82 deletions.
7 changes: 7 additions & 0 deletions docs/usermanual/userman_admin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,13 @@ User restrictions
Disables user sign ups.


..note:: KA Lite uses caching of web pages, if you change ``LOCKDOWN`` or
``DISABLE_SELF_ADMIN``, you need to flush the cache. To do that, run
the following management command::
kalite manage cache clearweb


Online Synchronization
^^^^^^^^^^^^^^^^^^^^^^

Expand Down
2 changes: 1 addition & 1 deletion kalite/caching/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from django.core.urlresolvers import reverse
from django.test.client import Client

from fle_utils.internet.webcache import *
from fle_utils.internet.webcache import get_web_cache, has_cache_key, expire_page, caching_is_enabled, invalidate_web_cache
from kalite import i18n, topic_tools
from kalite.topic_tools.settings import DO_NOT_RELOAD_CONTENT_CACHE_AT_STARTUP

Expand Down
19 changes: 15 additions & 4 deletions kalite/coachreports/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def learner_logs(request):
# Look back a week by default
time_window = request.GET.get("time_window", 7)

start_date = request.GET.get("start_date", None)

end_date = request.GET.get("end_date", None)

topic_ids = request.GET.getlist("topic_id", [])

learners = get_learners_from_GET(request)
Expand All @@ -84,8 +88,9 @@ def learner_logs(request):

output_objects = []

start_date = datetime.datetime.now() - datetime.timedelta(time_window)
end_date = datetime.datetime.now()
end_date = datetime.datetime.strptime(end_date,'%Y/%m/%d') if end_date else datetime.datetime.now()

start_date = datetime.datetime.strptime(start_date,'%Y/%m/%d') if start_date else end_date - datetime.timedelta(time_window)

for log_type in log_types:
LogModel, fields, id_field, obj_ids, objects = return_log_type_details(log_type, topic_ids)
Expand Down Expand Up @@ -124,6 +129,10 @@ def aggregate_learner_logs(request):
# Look back a week by default
time_window = request.GET.get("time_window", 7)

start_date = request.GET.get("start_date", None)

end_date = request.GET.get("end_date", None)

topic_ids = request.GET.getlist("topic_id", [])

log_types = request.GET.getlist("log_type", ["exercise", "video", "content"])
Expand All @@ -135,8 +144,10 @@ def aggregate_learner_logs(request):
"exercise_attempts": 0,
"exercise_mastery": None,
}
start_date = datetime.datetime.now() - datetime.timedelta(time_window)
end_date = datetime.datetime.now()

end_date = datetime.datetime.strptime(end_date,'%Y/%m/%d') if end_date else datetime.datetime.now()

start_date = datetime.datetime.strptime(start_date,'%Y/%m/%d') if start_date else end_date - datetime.timedelta(time_window)

for log_type in log_types:

Expand Down
6 changes: 6 additions & 0 deletions kalite/coachreports/dynamic_assets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.conf import settings

from kalite.dynamic_assets import DynamicSettingsBase, fields

class DynamicSettings(DynamicSettingsBase):
default_coach_report_day_range = fields.IntegerField(default=getattr(settings, "DEFAULT_COACH_REPORT_DAY_RANGE", 7), minimum=0)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<label for="time-set">{{_ "Date Range" }}&nbsp;&nbsp;&nbsp;</label>
<div class="input-daterange input-group" id="datepicker">
<input type="text" id="start" class="form-control date-range" value={{ start_date }} name="start" />
<span class="input-group-addon">→</span>
<input type="text" id="end" class="form-control date-range" value={{ end_date }} name="end" />
<span class="input-group-addon btn btn-success setrange"><i class="glyphicon glyphicon-refresh"></i></span>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<h1 class="status_name">{{ status.facility_name }}{{#if status.group_name }}: {{ status.group_name }}{{/if}}{{#if data.learner_events }}<button id="show_tabular_report" class="btn btn-success pull-right">{{_ "Show Tabular Report" }}</button>{{/if}}</h1>
<div id="radial_chartblock">
<div id="chartcontainer">
<h3>{{_ "This week" }}</h3>
<h3>{{#if start_date}}{{ start_date }}{{#if end_date }}{{ end_date }}{{/if}}{{else}}{{_ "This week" }}{{/if}}</h3>
<div class="circlechart">
<div id="full_circle1">
<p>{{#if data.total_time_logged }}{{ data.total_time_logged }}{{else}}{{_ "N/A" }}{{/if}}</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@
{{!-- Insert group select template here --}}
</div>
</div>
<div class="col-sm-3">
<div id="time-set-container" class="form-group">
{{!-- Insert group select template here --}}
</div>
</div>
</form>
<div id="student_report_container"></div>
8 changes: 8 additions & 0 deletions kalite/coachreports/static/css/coachreports/landing_view.css
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,11 @@ ul {
color: #000;

}

#datepicker {
top: 0px;
}

span.setrange {
color: #fff;
}
12 changes: 10 additions & 2 deletions kalite/coachreports/static/js/coachreports/coach_reports/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ var CoachReportModel = Backbone.Model.extend({
initialize: function(options) {
this.facility = options.facility;
this.group = options.group;
this.start_date = options.start_date;
this.end_date = options.end_date;
},

url: function() {
return setGetParamDict(Urls.learner_logs(), {
facility_id: this.facility,
group_id: this.group
group_id: this.group,
start_date: this.start_date,
end_date: this.end_date
});
}
});
Expand All @@ -46,12 +50,16 @@ var CoachReportAggregateModel = Backbone.Model.extend({
initialize: function(options) {
this.facility = options.facility;
this.group = options.group;
this.start_date = options.start_date;
this.end_date = options.end_date;
},

url: function() {
return setGetParamDict(Urls.aggregate_learner_logs(), {
facility_id: this.facility,
group_id: this.group
group_id: this.group,
start_date: this.start_date,
end_date: this.end_date
});
}
});
87 changes: 78 additions & 9 deletions kalite/coachreports/static/js/coachreports/coach_reports/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ CoachReportView:
- DetailPanelBodyView
*/

var date_string = function(date) {
if (date) {
return date.getFullYear() + "/" + (date.getMonth() + 1) + "/" + date.getDate();
}
};

var DetailsPanelBodyView = BaseView.extend({
/*
This view displays details of individual attempt logs
Expand Down Expand Up @@ -327,7 +333,7 @@ var TabularReportView = BaseView.extend({
});

this.append_views(row_views, ".student-data");

this.$('.headrowuser').css("min-width", this.$('.headrow.data').outerWidth());

if(this.complete_callback) {
Expand All @@ -344,7 +350,9 @@ var TabularReportView = BaseView.extend({
var self = this;
this.data_model = new CoachReportModel({
facility: this.model.get("facility"),
group: this.model.get("group")
group: this.model.get("group"),
start_date: date_string(this.model.get("start_date")),
end_date: date_string(this.model.get("end_date"))
});
if (this.model.get("facility")) {
this.data_model.fetch().then(function() {
Expand Down Expand Up @@ -380,6 +388,57 @@ var TabularReportView = BaseView.extend({

});

var TimeSetView = BaseView.extend({
template: HB.template("coach_nav/datepicker"),

events: {
"click .setrange": "set_range"
},

initialize: function () {
var server_date_now = new Date(new Date().getTime() - window.statusModel.get("client_server_time_diff"));
var default_start_date = new Date(server_date_now.getTime())
default_start_date = new Date(default_start_date.setDate(default_start_date.getDate()-ds.coachreports.default_coach_report_day_range));

this.model.set({
"start_date": default_start_date,
"end_date": server_date_now
});
this.render();
},

render: function() {
this.$el.html(this.template({
start_date: icu.getDateFormat("SHORT").format(this.model.get("start_date")),
end_date: icu.getDateFormat("SHORT").format(this.model.get("end_date"))
}));

var format = icu.getDateFormatSymbols().order_short;

format = format[0] + "/" + format[1] + "/" + format[2];

format = format.toLowerCase().replace("y", "yy");

this.datepicker = this.$('.date-range').each(function(){
$(this).datepicker({
format: format,
endDate: "0d",
todayBtn: "linked",
todayHighlight: true
});
});
},

set_range: function() {
this.model.set({
start_date: this.$("#start").datepicker("getDate"),
end_date: this.$("#end").datepicker("getDate")
});
this.model.trigger("set_time");
return false;
}
});

var CoachSummaryView = BaseView.extend({
/*
This view displays summary stats for the currently selected facility (and optionally group)
Expand All @@ -395,20 +454,26 @@ var CoachSummaryView = BaseView.extend({
_.bindAll(this);
this.listenTo(this.model, "change:facility", this.set_data_model);
this.listenTo(this.model, "change:group", this.set_data_model);
this.listenTo(this.model, "set_time", this.set_data_model);
this.set_data_model();
},

set_data_model: function (){
if (this.data_model) {
if (this.data_model.get("facility") !== this.model.get("facility") || this.data_model.get("group") !== this.model.get("group")) {
var check_fields = ["facility", "group", "start_date", "end_date"];
var data_fields = _.pick(this.data_model.attributes, check_fields);
var status_fields = _.pick(this.model.attributes, check_fields);
if (!_.isEqual(data_fields, status_fields)) {
delete this.data_model;
}
}

if (!this.data_model) {
this.data_model = new CoachReportAggregateModel({
facility: this.model.get("facility"),
group: this.model.get("group")
group: this.model.get("group"),
start_date: date_string(this.model.get("start_date")),
end_date: date_string(this.model.get("end_date"))
});
if (this.model.get("facility")) {
this.listenTo(this.data_model, "sync", this.render);
Expand All @@ -420,7 +485,9 @@ var CoachSummaryView = BaseView.extend({
render: function() {
this.$el.html(this.template({
status:this.model.attributes,
data: this.data_model.attributes
data: this.data_model.attributes,
start_date: icu.getDateFormat("SHORT").format(this.model.get("start_date")),
end_date: icu.getDateFormat("SHORT").format(this.model.get("end_date"))
}));

clear_messages();
Expand All @@ -429,7 +496,7 @@ var CoachSummaryView = BaseView.extend({
var ref, ref1;

if ((this.data_model != null ? this.data_model.get("learner_events") != null ? this.data_model.get("learner_events").length : void 0 : void 0) === 0) {
show_message("warning", "No recent learner data for this group is available.");
show_message("warning", gettext("No recent learner data for this group is available."));
}

delete this.tabular_report_view;
Expand All @@ -442,12 +509,12 @@ var CoachSummaryView = BaseView.extend({
this.$("#show_tabular_report").text("Loading");
this.$("#show_tabular_report").attr("disabled", "disabled");
this.tabular_report_view = new TabularReportView({model: this.model, complete: function() {
self.$("#show_tabular_report").text("Hide Tabular Report");
self.$("#show_tabular_report").text(gettext("Hide Tabular Report"));
self.$("#show_tabular_report").removeAttr("disabled");
}});
this.$("#detailed_report_view").append(this.tabular_report_view.el);
} else {
this.$("#show_tabular_report").text("Show Tabular Report");
this.$("#show_tabular_report").text(gettext("Show Tabular Report"));
this.tabular_report_view.remove();
delete this.tabular_report_view;
}
Expand Down Expand Up @@ -593,6 +660,7 @@ var CoachReportView = BaseView.extend({
this.facility_select_view = new FacilitySelectView({model: this.model});
this.group_select_view = new GroupSelectView({model: this.model});
this.coach_summary_view = new CoachSummaryView({model: this.model});
this.time_set_view = new TimeSetView({model: this.model});

this.render();
},
Expand All @@ -601,6 +669,7 @@ var CoachReportView = BaseView.extend({
this.$el.html(this.template());
this.$('#group-select-container').append(this.group_select_view.el);
this.$('#facility-select-container').append(this.facility_select_view.el);
this.$("#time-set-container").append(this.time_set_view.el);
this.$("#student_report_container").append(this.coach_summary_view.el);
}
});
});
2 changes: 2 additions & 0 deletions kalite/coachreports/templates/coachreports/coach.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<link rel="stylesheet" type="text/css" href="{% static 'css/coachreports/tabular_view.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'css/coachreports/events_view.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'css/coachreports/landing_view.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'css/bootstrap-datepicker3.min.css' %}" />
{% endblock headcss %}

{% block headjs %}{{ block.super }}
Expand All @@ -18,6 +19,7 @@
var GROUP_RESOURCE_URL = "{% url 'api_dispatch_list' resource_name='group' %}";
var FACILITY_ID = {% if facility_id %}"{{ facility_id }}"{% else %}undefined{% endif %};
</script>
<script src="{% static 'js/bootstrap-datepicker.min.js' %}"></script>
<script src="{% url 'handlebars_templates' module_name='coach_nav' %}"></script>
<script src="{% url 'handlebars_templates' module_name='tabular_reports' %}"></script>
<script src="{% static 'js/distributed/exercises/models.js' %}"></script>
Expand Down
3 changes: 0 additions & 3 deletions kalite/distributed/management/commands/initialize_kalite.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ def setup_server_if_needed(self):

def reinitialize_server(self):
"""Reset the server state."""
logging.info("Invalidating the web cache.")
from fle_utils.internet.webcache import invalidate_web_cache
invalidate_web_cache()

# Next, call videoscan.
logging.info("Running videoscan.")
Expand Down
6 changes: 3 additions & 3 deletions kalite/distributed/templates/distributed/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@
<script src="{% static 'django_js_reverse/js/reverse.js' %}"></script>
{% endif %}

<!-- JS translation file statically included as a back-up, so that if the saved file below isn't available, we don't choke. -->
<script type="text/javascript" src="{% static 'js/i18n/en.js' %}"></script>

{% if current_language != "en" %}
<!-- JS translation files dynamically generated by django, then saved to the static file below -->
<script type="text/javascript" src="{{ settings.CONTENT_URL }}locale/js/i18n/{{ request.language }}.js"></script>
{% endif %}

{% compress js file basejs %}

<!-- JS translation file statically included as a back-up, so that if the saved file below isn't available, we don't choke. -->
<script type="text/javascript" src="{% static 'js/i18n/en.js' %}"></script>

{# Older versions of IE didn't have a JSON object, so this library adds it back in if needed #}
<script type="text/javascript" src="{% static 'js/json2.js' %}"></script>

Expand Down
2 changes: 0 additions & 2 deletions kalite/distributed/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

from fle_utils.internet.classes import JsonResponseMessageError
from fle_utils.internet.functions import get_ip_addresses, set_query_params
from fle_utils.internet.webcache import backend_cache_page
from fle_utils.django_utils.paginate import paginate_data
from kalite import topic_tools
from kalite.shared.decorators.auth import require_admin
from securesync.api_client import BaseClient
Expand Down
Loading

0 comments on commit 8adb6f3

Please sign in to comment.