Support additional logos, starting with THW
This commit is contained in:
parent
88d5455296
commit
65b9c44579
12
app/app.py
12
app/app.py
@ -23,16 +23,21 @@ class Generator:
|
||||
GENERATOR_SCAD_FILE_NAME = "generator.scad"
|
||||
GENERATED_STL_FILE_NAME = "generated.stl"
|
||||
|
||||
def __init__(self, name: str, tempdir: Path | str):
|
||||
def __init__(self, name: str, tempdir: Path | str, logo: str = None):
|
||||
self._name = name
|
||||
self._tempdir = Path(tempdir)
|
||||
|
||||
# sanitize input
|
||||
if "/" in logo:
|
||||
raise ValueError("invalid logo name")
|
||||
self._logo = Path(logo).name
|
||||
|
||||
def _generate_scad_template(self) -> str:
|
||||
return f"""
|
||||
use <bottle-clip.scad>
|
||||
$fn=180;
|
||||
// one name tag for 0.5l Club Mate and similar bottles
|
||||
bottle_clip(name="{self._name}", logo="thing-logos/fablab.dxf");
|
||||
bottle_clip(name="{self._name}", logo="thing-logos/{self._logo}.dxf");
|
||||
"""
|
||||
|
||||
def _generate_files_in_temp_dir(self):
|
||||
@ -83,6 +88,7 @@ async def generate():
|
||||
raise ValueError
|
||||
|
||||
name = data["name"]
|
||||
logo = data.get("logo", None)
|
||||
|
||||
except (TypeError, KeyError, ValueError):
|
||||
abort(400)
|
||||
@ -90,7 +96,7 @@ async def generate():
|
||||
|
||||
async with semaphore:
|
||||
with tempfile.TemporaryDirectory(prefix="fablab-bottle-clip-generator-") as tempdir:
|
||||
generator = Generator(name, tempdir)
|
||||
generator = Generator(name, tempdir, logo)
|
||||
|
||||
generated_stl_file_name = await generator.generate_stl()
|
||||
|
||||
|
2180
app/openscad/thing-logos/thw.dxf
Normal file
2180
app/openscad/thing-logos/thw.dxf
Normal file
File diff suppressed because it is too large
Load Diff
@ -26,6 +26,7 @@
|
||||
data() {
|
||||
return {
|
||||
name: "",
|
||||
logo: "fablab",
|
||||
fetching: false,
|
||||
error: false,
|
||||
}
|
||||
@ -50,6 +51,7 @@
|
||||
method: "post",
|
||||
body: JSON.stringify({
|
||||
"name": this.name,
|
||||
"logo": this.logo,
|
||||
}),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@ -87,6 +89,10 @@
|
||||
<form ref="form" action="{{ url_for('generate') }}" method="post">
|
||||
<label for="name">Name:</label>
|
||||
<input type="text" id="name" name="name" style="text-align: center;" placeholder="Name" v-model="name" :disabled="fetching" :aria-invalid="name === ''">
|
||||
<select id="logo" name="logo" v-model="logo" :disabled="fetching" aria-label="Logo auswählen" required>
|
||||
<option value="fablab">FabLab</option>
|
||||
<option value="thw">THW</option>
|
||||
</select>
|
||||
<button v-if="!fetching" ref="submitButton" type="submit" @click="generate" :disabled="name === ''">Generieren</button>
|
||||
<button v-if="fetching" style="display: none" v-show="true" type="button" disabled="true" aria-busy="true">Generiere...</button>
|
||||
</form>
|
||||
|
Loading…
Reference in New Issue
Block a user