From fc6a6d7b9a07b8ad6efe9ab4e91ee196f06272b6 Mon Sep 17 00:00:00 2001 From: bogo Date: Sat, 28 Sep 2024 08:09:44 +0200 Subject: [PATCH] Add custom target distance forsingle targets --- app.py | 38 +++++++++++ templates/base.html | 4 ++ templates/custom.html | 44 +++++++++++++ templates/pdf_template_custom.html | 82 ++++++++++++++++++++++++ templates/pdf_template_ipsc.html | 2 +- templates/setup.html | 15 +++-- translations/pl/LC_MESSAGES/messages.mo | Bin 2878 -> 2972 bytes translations/pl/LC_MESSAGES/messages.po | 10 ++- 8 files changed, 185 insertions(+), 10 deletions(-) create mode 100644 templates/custom.html create mode 100644 templates/pdf_template_custom.html diff --git a/app.py b/app.py index f2c56e6..dd54947 100644 --- a/app.py +++ b/app.py @@ -143,6 +143,10 @@ def shootoff(): def ipsc(): return render_template('ipsc.html', current_url=request.path) +@app.route('/custom') +def custom(): + return render_template('custom.html', current_url=request.path) + @app.route('/generate-pdf', methods=['POST']) def generate_pdf(): distance = int(request.form.get('distance', 1) or 1) @@ -264,6 +268,40 @@ def generate_pdf_ipsc(): return send_file(pdf_file, download_name=filename, as_attachment=False) +@app.route('/generate-pdf-custom', methods=['POST']) +def generate_pdf_custom(): + distance = int(request.form.get('distance', 1) or 1) + simulated_distance_meters = int(request.form.get('simulated_distance') or 1) + simulated_distance = simulated_distance_meters * 100 + size = request.form.get('size') + target_type = request.form.get('target_type') + scale = distance / simulated_distance + print(distance,simulated_distance_meters, simulated_distance, scale) + original_target_height= IPSC_TARGET_HEIGHT if target_type == 'ipsc' else IDPA_TARGET_HEIGHT + + rendered_html = render_template( + 'pdf_template_custom.html', + distance=distance, + size=size, + target_height=scale * original_target_height, + target_width=scale * IPSC_TARGET_WIDTH, + gap=scale * IPSC_GAP + scale * IPSC_TARGET_WIDTH, + target_type=target_type, + simulated_distance=simulated_distance_meters + ) +# return rendered_html + + pdf_file = io.BytesIO() + HTML(string=rendered_html).write_pdf(pdf_file) + pdf_file.seek(0) + filename = 'Steel Training - '+target_type.upper()+' - Sim: ' + str(simulated_distance_meters) + 'm - ' + str(distance) + 'cm-' + size + '.pdf' + + return send_file(pdf_file, download_name=filename, as_attachment=False) + + + + + def calculate_distance(desired_wall_length, stage, size): wall_extra_space_for_paper = 297 if size == 'a3' else 210 diff --git a/templates/base.html b/templates/base.html index 18a5348..6be841d 100644 --- a/templates/base.html +++ b/templates/base.html @@ -42,6 +42,10 @@ class="{{ 'shadow-inner shadow-blue-900' if current_url == url_for('ipsc') else '' }} bg-blue-500 text-white py-2 px-4 rounded-md hover:bg-blue-600 transition-colors"> El Presidente + + Custom +
diff --git a/templates/custom.html b/templates/custom.html new file mode 100644 index 0000000..11f2b27 --- /dev/null +++ b/templates/custom.html @@ -0,0 +1,44 @@ +{% extends "base.html" %} +{% block title %}El Presidente{% endblock %} +{% block content %} + + +
+ {% include 'setup.html' %} +
+

{%trans%}Select the stage{%endtrans%}

+ +
+

{%trans%}Simulated distance{%endtrans%} [m]

+ +
+ +
+
+ +
+
+ +
+
+
+
+ +
+
+{% endblock %} diff --git a/templates/pdf_template_custom.html b/templates/pdf_template_custom.html new file mode 100644 index 0000000..0c56137 --- /dev/null +++ b/templates/pdf_template_custom.html @@ -0,0 +1,82 @@ + + + + + + + Steel Training | {%trans%}Target{%endtrans%}: {{ target_type|upper }} | {%trans%}Simulated distance{%endtrans%}: {{ simulated_distance }}m | {%trans%}Place target on{%endtrans%}: {{distance}}cm + + + + +
+
+ {% with target_width=target_width, target_height=target_height %} + {%if target_type == 'ipsc' %} + {%include 'ipsc_svg.html'%} + {%else%} + {%include 'idpa_svg.html'%} + {%endif%} + {% endwith %} +
+
+ {%trans%}Target{%endtrans%}: {{ target_type|upper }} | {%trans%}Simulated distance{%endtrans%}: {{ simulated_distance }}m | {%trans%}Place target on{%endtrans%}: {{distance}}cm +
+ Steel Training +
+
+
+ + +
-

Steel Training

+

Paper Challenge

IPSC - El Presidente

{% for i in range(3) %} diff --git a/templates/setup.html b/templates/setup.html index 825b06a..a1846ea 100644 --- a/templates/setup.html +++ b/templates/setup.html @@ -7,13 +7,14 @@ class="w-40 h-auto"> - - + {% if current_url != url_for('custom') %} + + {% endif %}
diff --git a/translations/pl/LC_MESSAGES/messages.mo b/translations/pl/LC_MESSAGES/messages.mo index e4741d002cfde11d8371eecb8ab9062edea88b56..9420a6bfd21d57920f097a5c9a7a5609dcfac2f7 100644 GIT binary patch delta 550 zcmYk&ze~eF6u|MYGR;;c8*D@+KQu{K+o2z<$&B`nu3OeE ImbsM54`Z@hasU7T delta 487 zcmYk&F-yZh6u|Lo+G=gJ)}VH1kqFYkO+;K21Qi@wEQ&*gf}w^IYLgJtN(JfS(z)oO z;&(70P7Y!R7je@`5Eln0H(m69SivKAzkBbJ%ey;GUXM1P)zFckjnLEdTN(UoI{_gg z#8p(Wj+fZNeq2y~^EuRsx3GXWn8$QbhNPm<9)v; z`#@R9Hy&V&D&#G-P~OCO*9%M$caTTCFwEjR#&Lp8WPVz1wq)*lx>Yj%CjMC<8}L6B zO-Xoq+0Y!