Skip to content

Commit 8e64c2c

Browse files
authored
Merge pull request #5475 from mrpau/feature/5452-about-diagnose-page
About/Diagnose Page
2 parents 0dd7ebe + 2fde371 commit 8e64c2c

File tree

12 files changed

+155
-26
lines changed

12 files changed

+155
-26
lines changed

docs/installguide/release_notes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ New Features
2121
^^^^^^^^^^^^
2222

2323
* Enabled captions by default for English dubbed videos. :url-issue:`5464`
24+
* About/Diagnose page. :url-issue:`5452`
2425

2526

2627
0.17.1

kalite/cli.py

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -662,32 +662,7 @@ def status():
662662
STATUS_UNKNOW: 'Could not determine status',
663663
}
664664

665-
666-
def diagnose():
667-
"""
668-
This command diagnoses an installation of KA Lite
669-
670-
It has to be able to work with instances of KA Lite that users do not
671-
actually own, however it's assumed that the path and the 'kalite' commands
672-
are configured and work.
673-
674-
The function is currently non-robust, meaning that not all aspects of
675-
diagnose data collection is guaranteed to succeed, thus the command could
676-
potentially fail :(
677-
678-
Example: KALITE_HOME=/home/otheruser/.kalite kalite diagnose --port=7007
679-
"""
680-
681-
print("")
682-
print("KA Lite diagnostics")
683-
print("")
684-
685-
# Tell users we are calculating, because checking the size of the
686-
# content directory is slow. Flush immediately after.
687-
print("Calculating diagnostics...")
688-
sys.stdout.flush()
689-
print("")
690-
665+
def get_diagnostics():
691666
# Key, value store for diagnostics
692667
# Not using OrderedDict because of python 2.6
693668
diagnostics = []
@@ -733,6 +708,35 @@ def diagnose():
733708
except:
734709
diag("Device failure", traceback.format_exc())
735710

711+
return diagnostics
712+
713+
def diagnose():
714+
"""
715+
This command diagnoses an installation of KA Lite
716+
717+
It has to be able to work with instances of KA Lite that users do not
718+
actually own, however it's assumed that the path and the 'kalite' commands
719+
are configured and work.
720+
721+
The function is currently non-robust, meaning that not all aspects of
722+
diagnose data collection is guaranteed to succeed, thus the command could
723+
potentially fail :(
724+
725+
Example: KALITE_HOME=/home/otheruser/.kalite kalite diagnose --port=7007
726+
"""
727+
728+
print("")
729+
print("KA Lite diagnostics")
730+
print("")
731+
732+
# Tell users we are calculating, because checking the size of the
733+
# content directory is slow. Flush immediately after.
734+
print("Calculating diagnostics...")
735+
sys.stdout.flush()
736+
print("")
737+
738+
diagnostics = get_diagnostics()
739+
736740
for k, v in diagnostics:
737741

738742
# Pad all the values to match the key column
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<table class="table table-hover table-bordered">
2+
{{#each diagnostics }}
3+
<tr>
4+
<td>{{ @key }}</td>
5+
<td>{{ breaklines this }}</td>
6+
</tr>
7+
{{/each}}
8+
</table>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
var Backbone = require("base/backbone");
2+
3+
var diagnostics = {};
4+
5+
var AboutView = Backbone.View.extend({
6+
template: require("./hbtemplates/about.handlebars"),
7+
8+
initialize: function() {
9+
this.generate_diagnostics();
10+
},
11+
render: function() {
12+
console.log(JSON.stringify(diagnostics));
13+
this.$el.html(this.template({
14+
diagnostics: diagnostics
15+
}));
16+
17+
return this;
18+
},
19+
generate_diagnostics: function() {
20+
var self = this;
21+
$.ajax({
22+
type: 'get',
23+
url: 'data/',
24+
dataType: 'json',
25+
success: function(data) {
26+
if(data.status == 'success') {
27+
for(var diag in data.diagnostics) {
28+
diagnostics[data.diagnostics[diag][0].toUpperCase()] = data.diagnostics[diag][1];
29+
}
30+
self.render();
31+
}
32+
},
33+
error: function() {
34+
console.log("An error has occurred while calculating diagnostics.");
35+
}
36+
});
37+
}
38+
});
39+
40+
module.exports = {
41+
AboutView: AboutView
42+
};

kalite/distributed/static/js/distributed/base/handlebars.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,11 @@ Handlebars.registerHelper("current_language_is", function(lc, options) {
121121
}
122122
});
123123

124+
//from https://stackoverflow.com/questions/12331077/does-handlebars-js-replace-newline-characters-with-br/12397602#12397602
125+
Handlebars.registerHelper('breaklines', function(text) {
126+
text = Handlebars.Utils.escapeExpression(text);
127+
text = text.replace(/(\r\n|\n|\r)/gm, '<br>');
128+
return new Handlebars.SafeString(text);
129+
});
130+
124131
module.exports = Handlebars;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var $ = require("base/jQuery");
2+
var AboutView = require("../about/views").AboutView;
3+
4+
global.$ = $;
5+
global.AboutView = AboutView;

kalite/distributed/static/js/distributed/user/hbtemplates/navigation.handlebars

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
</li>
4646
<li role="presentation" class="divider"></li>
4747
{{/unless}}
48+
{{#if is_admin}}
49+
<li role="presentation">
50+
<a role="menuitem" tabindex="-1" href="{{ url "about" }}" id="nav_about">{{_ "About" }}</a>
51+
</li>
52+
{{/if}}
4853
{{!-- Logout goes at the bottom! --}}
4954
<li role="presentation" id="logout">
5055
<a role="menuitem" tabindex="-1" id="nav_logout" href="#">
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{% extends "distributed/base.html" %}
2+
{% load i18n %}
3+
{% load staticfiles %}
4+
5+
{% block title %}{% trans "About" %}{% endblock title %}
6+
{% block headjs %}
7+
{{ block.super }}
8+
<script src="{% static 'js/distributed/bundles/bundle_about.js' %}"></script>
9+
<script>
10+
$(function() {
11+
var about_view = new window.AboutView({
12+
el: $("#about-diagnostics-container")
13+
});
14+
});
15+
</script>
16+
{% endblock %}
17+
18+
{% block content %}
19+
<div class="container">
20+
<h2>{% trans "Diagnostics" %}</h2>
21+
<div id="about-diagnostics-container">
22+
<p><em>{% trans "Calculating diagnostics..." %}</em></p>
23+
<p>{% trans "This can take several minutes." %}</p>
24+
</div>
25+
</div>
26+
{% endblock content %}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from cli_tests import *
22
from url_tests import *
33
from browser_tests import *
4+
from about_tests import *
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from django.core.urlresolvers import reverse
2+
3+
from kalite.testing.base import KALiteTestCase
4+
5+
class AboutTestCase(KALiteTestCase):
6+
7+
def test_about(self):
8+
response = self.client.get(reverse('about'))
9+
self.assertEqual(response.status_code, 200)
10+
11+
def test_about_data(self):
12+
response = self.client.get(reverse('about_data'))
13+
self.assertIn('success', response.content)

0 commit comments

Comments
 (0)