From 69f8eccf9c62f17d08177583e37839c88880403e Mon Sep 17 00:00:00 2001 From: Huw Fryer Date: Mon, 4 Nov 2019 21:52:56 +0000 Subject: [PATCH 1/2] Changes to docker-compose --- docker-compose.yaml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 7f588b4..38206de 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,19 +2,22 @@ version: '3' services: flask: - image: huwf/dictogloss:latest-alpine + image: huwf/dictogloss:0.3 ports: - - 127.0.0.1:5000:80 - - 127.0.0.1:5001:443 + - 127.0.0.1:5000:5000 +# - 127.0.0.1:5001:443 restart: always environment: FLASK_RUN_HOST: 0.0.0.0 VIRTUAL_HOST: dictogloss.huwfryer.co.uk VIRTUAL_PORT: 5000 - VIRTUAL_PROTO: https +# VIRTUAL_PROTO: https + LETSENCRYPT_HOST: dictogloss.huwfryer.co.uk + LETSENCRYPT_EMAIL: huwfryer@gmail.com volumes: - ./letsencrypt:/etc/letsencrypt - - site:/usr/src + - ./config.py:/usr/src/config.py + - mp3:/usr/src/static/mp3 # SEE: https://github.com/buchdag/letsencrypt-nginx-proxy-companion-compose/blob/master/2-containers/compose-v3/labels/docker-compose.yaml # For examples on how to set up the letsencrypt service @@ -50,7 +53,7 @@ services: volumes: - site: + mp3: conf: vhost: html: From ca765020a8647cb25ecb97ff319474529ff46b28 Mon Sep 17 00:00:00 2001 From: Huw Fryer Date: Thu, 7 Nov 2019 11:49:03 +0000 Subject: [PATCH 2/2] Bugfixes from server --- app.py | 7 +++---- docker-compose.yaml | 13 +++++++++---- static/scripts/scripts.js | 9 +++++++-- templates/base.html | 6 ++++-- templates/get_transcript.html | 6 +++--- templates/main.html | 3 ++- templates/solution.html | 10 +++++----- templates/view_solution.html | 13 +++++++++---- 8 files changed, 42 insertions(+), 25 deletions(-) diff --git a/app.py b/app.py index 0bc96d2..cc2fba4 100644 --- a/app.py +++ b/app.py @@ -7,7 +7,7 @@ from flask_login import current_user - +from requests.exceptions import HTTPError from database import db, init_db from models import get_base_info, get_segment, get_downloads, get_full_filename, User, Role from custom import ExtendedLoginForm @@ -87,8 +87,7 @@ def retrieve_transcript(file_id, position): file_id, position = _parse_args(file_id, position) try: obj = get_base_info(file_id) - if current_user.seconds_available < obj.segment_length: - from requests.exceptions import HTTPError + if current_user.seconds_available < obj.segment_length: raise HTTPError('You do not have enough credit available to download this segment') segment = get_segment(obj, file_id, position, update=True) current_user.seconds_available -= obj.segment_length @@ -155,7 +154,7 @@ def solution(file_id, position): re.sub(r'[\.,-]', '', segment.transcript.lower()) student_solution, google_solution = differ.diff_prettyHtml(differ.diff_main(student_solution, segment.transcript)) - return render_template('solution.html', obj=obj, file_id=file_id, segment=segment, + return render_template('solution.html', obj=obj, file_id=file_id, segment=segment, position=position, filename=full_filename, student_solution=student_solution, google_solution=google_solution, confidence='{:.2f}'.format(segment.confidence)) diff --git a/docker-compose.yaml b/docker-compose.yaml index 38206de..995c0ed 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,7 +2,7 @@ version: '3' services: flask: - image: huwf/dictogloss:0.3 + build: ./ ports: - 127.0.0.1:5000:5000 # - 127.0.0.1:5001:443 @@ -13,12 +13,17 @@ services: VIRTUAL_PORT: 5000 # VIRTUAL_PROTO: https LETSENCRYPT_HOST: dictogloss.huwfryer.co.uk - LETSENCRYPT_EMAIL: huwfryer@gmail.com + LETSENCRYPT_EMAIL: ${DEFAULT_EMAIL} + + DEFAULT_EMAIL: ${DEFAULT_EMAIL} + DEFAULT_PASSWORD: ${DEFAULT_PASSWORD} + volumes: - ./letsencrypt:/etc/letsencrypt - ./config.py:/usr/src/config.py - mp3:/usr/src/static/mp3 - + - ./database.db:/usr/src/database.db + - ./API_KEY.json:/usr/src/API_KEY.json # SEE: https://github.com/buchdag/letsencrypt-nginx-proxy-companion-compose/blob/master/2-containers/compose-v3/labels/docker-compose.yaml # For examples on how to set up the letsencrypt service nginx_proxy: @@ -52,7 +57,7 @@ services: restart: always volumes: - + db: mp3: conf: vhost: diff --git a/static/scripts/scripts.js b/static/scripts/scripts.js index 7dcd2e5..cf8ceca 100644 --- a/static/scripts/scripts.js +++ b/static/scripts/scripts.js @@ -36,7 +36,7 @@ $(document).ready(function () { // TODO: Don't know why this isn't working with jQuery, but this is simple enough for vanilla JS document.getElementById('retrieve').parentNode.parentNode.innerHTML = data; // Keep the "seconds available" up to date... - document.getElementById('seconds_available').innerHTML = parseInt($('audio')[0].duration); + $('#seconds_available').text(Math.floor(parseInt($('#seconds_available').text()) - $('audio')[0].duration)); $('.spinner-border').hide(); }); @@ -51,4 +51,9 @@ $(document).ready(function () { $('#playerSpeed').text(rate * 100); }); -}); \ No newline at end of file + // Only works on the POST solution view + $('#exercise').height($('#solution').height()); + +}); + + diff --git a/templates/base.html b/templates/base.html index dc9d93f..b891108 100644 --- a/templates/base.html +++ b/templates/base.html @@ -19,7 +19,9 @@

Dictogloss

Downloads {% if current_user.is_authenticated %} - Seconds available: {{current_user.seconds_available}} +

+ Seconds available: {{current_user.seconds_available}} +

{% endif %} @@ -65,4 +67,4 @@

Dictogloss

- \ No newline at end of file + diff --git a/templates/get_transcript.html b/templates/get_transcript.html index 33ce44b..bfd4be5 100644 --- a/templates/get_transcript.html +++ b/templates/get_transcript.html @@ -1,12 +1,12 @@ {% if error %} -
+
Error code returned

There was an error retrieving the transcript. The details are:

{{error}}

{% else %} -
+
Success!

The transcript for segment {{position}} was successfully retrieved. View answer

-{% endif %} \ No newline at end of file +{% endif %} diff --git a/templates/main.html b/templates/main.html index bfc40d5..a80f588 100644 --- a/templates/main.html +++ b/templates/main.html @@ -64,7 +64,8 @@

Exercise

- + +
diff --git a/templates/solution.html b/templates/solution.html index 175eab7..65e9f37 100644 --- a/templates/solution.html +++ b/templates/solution.html @@ -16,23 +16,23 @@

{{obj.pretty_name}}

{% endif %} {% endblock %} -
+

Your answer

{{student_solution|safe}}
-
+

Transcript (Confidence {{confidence}})

{{google_solution|safe}}
{% if position > 1 %} - Prev + Prev {% endif %} {% if position < obj.segments|length %} - Next + Next {% endif %}
-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/templates/view_solution.html b/templates/view_solution.html index 73624e6..711d27e 100644 --- a/templates/view_solution.html +++ b/templates/view_solution.html @@ -7,12 +7,17 @@

There is no solution available for this segment.

-{% endif %} -{% endblock %} -
+{% else %} + +

Google answer (Confidence {{confidence}})

{{segment.transcript|safe}}
-{% endblock %} \ No newline at end of file +{% endif %} +{% endblock %} + + + +{% endblock %}