Add custom target distance forsingle targets

This commit is contained in:
bogo
2024-09-28 08:09:44 +02:00
parent 1dbd33abdc
commit fc6a6d7b9a
8 changed files with 185 additions and 10 deletions

38
app.py
View File

@@ -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

View File

@@ -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
</a>
<a href="{{ url_for('custom') }}"
class="{{ 'shadow-inner shadow-blue-900' if current_url == url_for('custom') else '' }} bg-blue-500 text-white py-2 px-4 rounded-md hover:bg-blue-600 transition-colors">
Custom
</a>
</div>
<div class="flex justify-center mt-4">

44
templates/custom.html Normal file
View File

@@ -0,0 +1,44 @@
{% extends "base.html" %}
{% block title %}El Presidente{% endblock %}
{% block content %}
<form class="" action="/generate-pdf-custom" method="post">
{% include 'setup.html' %}
<div class="mb-6 max-w-2xl mx-auto">
<h2>{%trans%}Select the stage{%endtrans%}</h2>
<div class="mb-6 max-w-2xl mx-auto mt-4">
<h2>{%trans%}Simulated distance{%endtrans%} [m]</h2>
<input type="number" id="simulated_distance" name="simulated_distance" min="1" max="300" class="w-full p-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-400" required>
</div>
<div id="stage" class="grid grid-cols-1 gap-4">
<div>
<label for="ipsc">
<p>IPSC</p>
{% with target_width=4.5, target_height=5.8 %}
{%include 'ipsc_svg.html'%}
{% endwith %}
<input type="radio" id="ipsc" name="target_type" value="ipsc" required>
</label>
</div>
<div>
<label for="idpa">
<p>IDPA</p>
{% with target_width=4.6, target_height=7.8 %}
{%include 'idpa_svg.html'%}
{% endwith %}
<input type="radio" id="idpa" name="target_type" value="idpa">
</label>
</div>
</div>
</div>
<div class="text-center">
<button type="submit"
class="bg-green-500 text-white py-2 px-4 rounded-md hover:bg-green-600 transition-colors">
{%trans%}Generate PDF{%endtrans%}
</button>
</div>
</form>
{% endblock %}

View File

@@ -0,0 +1,82 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Steel Training | {%trans%}Target{%endtrans%}: {{ target_type|upper }} | {%trans%}Simulated distance{%endtrans%}: {{ simulated_distance }}m | {%trans%}Place target on{%endtrans%}: {{distance}}cm</title>
<style>
@page {
size: {{size}};
margin: 5mm;
}
body {
font-family: sans-serif;
}
.target {
margin: auto;
text-align: center;
}
.page-break {
page-break-after: always;
}
.content {
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
.mounting-point {
height: 10mm;
width: 0.5mm;
background-color: #ccc;
margin: auto;
}
.mounting-info {
font-size: xx-small;
color: #ccc;
text-align: center;
}
.preview {
display: block;
border-bottom: solid 1px black;
border-top: solid 1px black;
width: 100%;
height: 75mm;
position: relative;
}
.preview-target {
position: absolute;
bottom: 30%;
}
</style>
</head>
<body>
<div class="page-break">
<div class="content">
{% with target_width=target_width, target_height=target_height %}
{%if target_type == 'ipsc' %}
{%include 'ipsc_svg.html'%}
{%else%}
{%include 'idpa_svg.html'%}
{%endif%}
{% endwith %}
<br>
<div class="mounting-info">
{%trans%}Target{%endtrans%}: {{ target_type|upper }} | {%trans%}Simulated distance{%endtrans%}: {{ simulated_distance }}m | {%trans%}Place target on{%endtrans%}: {{distance}}cm
<br>
Steel Training
</div>
</div>
</div>
</body>
</html

View File

@@ -62,7 +62,7 @@
<body>
<div class="page-break">
<h1>Steel Training</h1>
<h1>Paper Challenge</h1>
<h2>IPSC - El Presidente</h2>
<div class="preview">
{% for i in range(3) %}

View File

@@ -7,13 +7,14 @@
class="w-40 h-auto">
<input type="radio" id="floor" name="distance_type" value="floor" required>
</label>
<label for="wall"
class="cursor-pointer border-2 border-transparent rounded-lg overflow-hidden transition-all hover:border-blue-400">
<img src="{{ url_for('static', filename='images/wall.webp') }}" alt="{%trans%}Wall length{%endtrans%}"
class="w-40 h-auto">
<input type="radio" id="wall" name="distance_type" value="wall" required>
</label>
{% if current_url != url_for('custom') %}
<label for="wall"
class="cursor-pointer border-2 border-transparent rounded-lg overflow-hidden transition-all hover:border-blue-400">
<img src="{{ url_for('static', filename='images/wall.webp') }}" alt="{%trans%}Wall length{%endtrans%}"
class="w-40 h-auto">
<input type="radio" id="wall" name="distance_type" value="wall" required>
</label>
{% endif %}
</div>
<div class="mb-6 max-w-2xl mx-auto mt-4">

View File

@@ -76,5 +76,11 @@ msgstr "Umieść na ścianie pozostałe cele zgodnie z odległościami podanymi
msgid "ZERO point"
msgstr "punkt ZERO"
msgid "from ZERO point"
msgstr "od punktu ZERO"
msgid "Simulated distance"
msgstr "Symulowany dystans"
msgid "Place target on"
msgstr "Umieść cel w odległości"
msgid "Target"
msgstr "Cel"