From 701bd0b19f12ba97fc8449b440c0f989a80e93d8 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Mon, 19 Jun 2023 13:55:40 -0700 Subject: [PATCH] Item add improvements --- intake/app.py | 31 +++++++++++++++++--- intake/templates/home.jinja2 | 55 +++++++++++++++++++++--------------- 2 files changed, 60 insertions(+), 26 deletions(-) diff --git a/intake/app.py b/intake/app.py index ff1507f..a1b3af7 100644 --- a/intake/app.py +++ b/intake/app.py @@ -332,16 +332,39 @@ def add_item(): ) source = LocalSource(source_path.parent, source_path.name) - # Clean up the fields - fields = {key: value for key, value in request.form.items() if value} - fields["id"] = "{:x}".format(getrandbits(16 * 4)) - # TODO: this doesn't support tags or ttX fields correctly + fields = {"id": "{:x}".format(getrandbits(16 * 4))} + if form_title := request.form.get("title"): + fields["title"] = form_title + if form_link := request.form.get("link"): + fields["link"] = form_link + if form_body := request.form.get("body"): + fields["body"] = form_body + if form_tags := request.form.get("tags"): + fields["tags"] = [ + tag.strip() + for tag in form_tags.split() + if tag.strip() + ] + if form_tts := request.form.get("tts"): + fields["tts"] = _get_ttx_for_date(datetime.fromisoformat(form_tts)) + if form_ttl := request.form.get("ttl"): + fields["ttl"] = _get_ttx_for_date(datetime.fromisoformat(form_ttl)) + if form_ttd := request.form.get("ttd"): + fields["ttd"] = _get_ttx_for_date(datetime.fromisoformat(form_ttd)) + item = Item.create(source, **fields) source.save_item(item) return redirect(url_for("source_feed", name="default")) +def _get_ttx_for_date(dt: datetime) -> int: + """Get the relative time difference between now and a date.""" + ts = int(dt.timestamp()) + now = int(time.time()) + return ts - now + + def wsgi(): # init_default_logging() return app diff --git a/intake/templates/home.jinja2 b/intake/templates/home.jinja2 index c6aa3b4..8f12fec 100644 --- a/intake/templates/home.jinja2 +++ b/intake/templates/home.jinja2 @@ -29,6 +29,10 @@ summary { summary:focus { outline: 1px dotted gray; } +.wide { + width: 100%; + resize: vertical; +} @@ -65,28 +69,35 @@ summary:focus {
Add item
- - -
- -
- -
- - -
- - -
- - -
- - -
- - -
+

+{# #} + +

+

+{# #} + +

+

+{# #} + +

+

+{# #} + +

+

+ + +

+

+ + +

+

+ + +

+