diff --git a/.gitignore b/.gitignore index f3b4af2..90e4664 100644 --- a/.gitignore +++ b/.gitignore @@ -136,3 +136,4 @@ node_modules wanikani.db config.py /static/*.map +/static/*.js diff --git a/requirements.txt b/requirements.txt index d4e0a08..0501f2c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,5 @@ flask-login flask-sqlalchemy flask-wtf flask-testing -ujson \ No newline at end of file +blinker +ujson diff --git a/static/quiz_item.js b/static/quiz_item.js deleted file mode 100644 index cffd4d4..0000000 --- a/static/quiz_item.js +++ /dev/null @@ -1,240 +0,0 @@ -// Generated by CoffeeScript 1.10.0 -(function() { - var filterQuestions, getItemTypeFilters, getSrsTypeFilters, itemMax, linearCount, linearMode, refreshQuestion, refreshQuizCounter, selection, toggleQuizMode, updateQuizItemStats; - - linearMode = false; - - linearCount = 0; - - selection = null; - - itemMax = 1; - - refreshQuestion = function() { - var input_element, items; - if (sessionStorage.getItem('user_items')) { - items = JSON.parse(sessionStorage.getItem('user_items')); - itemMax = items.length; - if (linearMode) { - selection = items[linearCount]; - linearCount++; - refreshQuizCounter(); - if (linearCount >= items.length) { - linearCount = 0; - } - } else { - selection = items[Math.floor(Math.random() * items.length)]; - } - $("#help-area").text(''); - $("#kana").removeClass("correct").val(''); - $("#question-area").text(''); - $("#question-image").attr("src", ''); - $('#answer').addClass('hidden'); - $('#answer').text(selection['answer']); - input_element = document.getElementById('kana'); - $("#question-image").hide(); - if (selection['item_type'] === 'radical') { - $("#kana").attr("placeholder", "Meaning"); - document.body.style.backgroundColor = "deepskyblue"; - wanakana.unbind(input_element); - if (selection['question'].indexOf('http') >= 0) { - $("#question-image").attr("src", selection['question']); - $("#question-image").show(); - } else { - $("#question-area").text(selection['question']); - } - return document.getElementById('view-on-wk').href = "https://www.wanikani.com/radicals/" + selection['answer']; - } else { - if (selection['item_type'] === 'kanji') { - document.body.style.backgroundColor = "deeppink"; - } else { - document.body.style.backgroundColor = "darkviolet"; - } - $("#question-area").text(selection['question']); - if (selection['answer_type'] === 'eng') { - $("#kana").attr("placeholder", "Meaning"); - wanakana.unbind(input_element); - } else { - $("#kana").attr("placeholder", "かな"); - wanakana.bind(input_element); - } - return document.getElementById('view-on-wk').href = "https://www.wanikani.com/" + selection['item_type'] + "/" + selection['question']; - } - } - }; - - updateQuizItemStats = function() { - $('#radical-num').text(sessionStorage.getItem('radical_count')); - $('#kanji-num').text(sessionStorage.getItem('kanji_count')); - $('#vocab-num').text(sessionStorage.getItem('vocabulary_count')); - return $('#total-num').text(parseInt(sessionStorage.getItem('radical_count')) + parseInt(sessionStorage.getItem('kanji_count')) + parseInt(sessionStorage.getItem('vocabulary_count'))); - }; - - getSrsTypeFilters = function() { - var s, srs_levels; - srs_levels = ['burnedcheck', 'enlightencheck', 'mastercheck', 'gurucheck', 'apprenticecheck']; - return ((function() { - var i, len, results; - results = []; - for (i = 0, len = srs_levels.length; i < len; i++) { - s = srs_levels[i]; - if (document.getElementById(s).checked) { - results.push(document.getElementById(s).value); - } - } - return results; - })()).toString(); - }; - - getItemTypeFilters = function() { - var item_types, s; - item_types = ['radicalcheck', 'kanjicheck', 'vocabcheck']; - return ((function() { - var i, len, results; - results = []; - for (i = 0, len = item_types.length; i < len; i++) { - s = item_types[i]; - if (document.getElementById(s).checked) { - results.push(document.getElementById(s).value); - } - } - return results; - })()).toString(); - }; - - filterQuestions = function() { - var target_url; - sessionStorage.removeItem('user_items'); - sessionStorage.removeItem('radical_count'); - sessionStorage.removeItem('kanji_count'); - sessionStorage.removeItem('vocabulary_count'); - target_url = "/user_items?level_range=" + $('#filter-input').val() + "&item_state=" + getSrsTypeFilters() + "&item_types=" + getItemTypeFilters(); - return $.ajax({ - url: target_url, - dataType: 'json', - success: function(e) { - if (e.hasOwnProperty('error')) { - document.getElementById('filter-input').value = ''; - $('#error-text').text(e['error']); - return $('#error-area').show(); - } else { - sessionStorage.setItem('user_items', JSON.stringify(e['item_list'])); - sessionStorage.setItem('radical_count', e['radical_count']); - sessionStorage.setItem('kanji_count', e['kanji_count']); - sessionStorage.setItem('vocabulary_count', e['vocabulary_count']); - updateQuizItemStats(); - return refreshQuestion(); - } - } - }); - }; - - $('#filter-form').submit(function(e) { - e.preventDefault(); - $('#error-area').hide(); - filterQuestions(); - $('#modal-filter').modal('hide'); - return linearCount = 0; - }); - - toggleQuizMode = function() { - linearMode = !linearMode; - if (linearMode) { - document.getElementById('quiz-counter').style.visibility = "visible"; - $('#mode-toggle').text("Linear Mode"); - } else { - linearCount = 0; - document.getElementById('quiz-counter').style.visibility = "hidden"; - $('#mode-toggle').text("Random Mode"); - } - return refreshQuestion(); - }; - - refreshQuizCounter = function() { - document.getElementById('current-quiz').value = linearCount; - return document.getElementById('total-quiz').textContent = "/" + itemMax; - }; - - $(document).keypress(function(e) { - if (e.which === 13) { - return $("#submit-answer").click(); - } else { - if ($("#kana").hasClass("wrong")) { - return $("#kana").removeClass("wrong"); - } - } - }); - - $("#submit-answer").click(function(e) { - var expected_answer, input_answer; - e.preventDefault(); - if ($("#kana").hasClass("correct")) { - return refreshQuestion(); - } else { - input_answer = document.getElementById('kana').value; - expected_answer = selection['answer'].split(/[,\.]/g).map(function(x) { - return x.trim(); - }); - if (selection["item_type"] === "radical") { - expected_answer = expected_answer.map(function(x) { - return x.replace("-", " "); - }); - } - if (expected_answer.indexOf(input_answer) !== -1) { - return $("#kana").addClass("correct").removeClass("wrong"); - } else { - return $("#kana").addClass("wrong").removeClass("correct").val(''); - } - } - }); - - $("#get-help").click(function(e) { - e.preventDefault(); - return $("#answer").removeClass('hidden'); - }); - - $("#api-refresh").click(function(e) { - e.preventDefault(); - $("#api-refresh").find('img').addClass('glyphicon-spin'); - return $.post("/refresh").success(function() { - refreshQuestion(); - $("#api-refresh").find('img').removeClass('glyphicon-spin'); - return $('#success-area').show(); - }).fail(function() { - $('#error-area').show(); - $('#error-text').text("Cannot refresh API. Try again later."); - return $("#api-refresh").find('img').removeClass('glyphicon-spin'); - }); - }); - - $('#error-area').find('button').click(function() { - return $('#error-area').hide(); - }); - - $('#success-area').find('button').click(function() { - return $('#success-area').hide(); - }); - - $('#skip-to-item').click(function(e) { - var targetValue; - e.preventDefault(); - targetValue = document.getElementById('current-quiz').value - 1; - if (targetValue >= 0 && targetValue < itemMax) { - linearCount = targetValue; - return refreshQuestion(); - } else { - return refreshQuizCounter(); - } - }); - - $(function() { - return $(document).ready(function() { - $('[data-toggle="tooltip"]').tooltip(); - document.getElementById('mode-toggle').onclick = toggleQuizMode; - return filterQuestions(); - }); - }); - -}).call(this); - -//# sourceMappingURL=quiz_item.js.map diff --git a/static/style.css b/static/style.css index a768e46..672db7b 100644 --- a/static/style.css +++ b/static/style.css @@ -73,4 +73,4 @@ body{ -webkit-transform: rotate(359deg); transform: rotate(359deg); } -} \ No newline at end of file +} diff --git a/tests.py b/tests.py index b778f9f..fdc9f45 100644 --- a/tests.py +++ b/tests.py @@ -93,7 +93,7 @@ class TestFormats(unittest.TestCase): def test_custom_datetime_format(self): test_time = datetime.min output = datetime_format(test_time) - self.assertEqual(output, "01 January 0001 12:00AM") + self.assertEqual(output, "01 January 1 12:00AM") def test_parse_range_empty(self): self.assertIsNone(parse_range("")) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..59f8fda --- /dev/null +++ b/tox.ini @@ -0,0 +1,13 @@ +# Tox (http://tox.testrun.org/) is a tool for running tests +# in multiple virtualenvs. This configuration file will run the +# test suite on all supported python versions. To use it, "pip install tox" +# and then run "tox" from this directory. + +[tox] +envlist = py34 +skipsdist = True + +[testenv] +commands = python3 tests.py +deps = -rrequirements.txt +