Item add improvements
This commit is contained in:
parent
095c6a7a41
commit
701bd0b19f
|
@ -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
|
||||
|
|
|
@ -29,6 +29,10 @@ summary {
|
|||
summary:focus {
|
||||
outline: 1px dotted gray;
|
||||
}
|
||||
.wide {
|
||||
width: 100%;
|
||||
resize: vertical;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -65,28 +69,35 @@ summary:focus {
|
|||
<details open>
|
||||
<summary><span class="item-title">Add item</span></summary>
|
||||
<form action="add" method="post">
|
||||
<label for="title">Title</label>
|
||||
<input type="text" name="title">
|
||||
<br>
|
||||
<label for="body">Body</label>
|
||||
<br>
|
||||
<textarea name="body"></textarea>
|
||||
<br>
|
||||
<label for="link">Link</label>
|
||||
<input type="text" name="link">
|
||||
<br>
|
||||
<label for="tags">Tags</label>
|
||||
<input type="text" name="tags">
|
||||
<br>
|
||||
<label for="tts">TTS</label>
|
||||
<input type="text" name="tts">
|
||||
<br>
|
||||
<label for="ttl">TTL</label>
|
||||
<input type="text" name="ttl">
|
||||
<br>
|
||||
<label for="ttd">TTD</label>
|
||||
<input type="text" name="ttd">
|
||||
<br>
|
||||
<p>
|
||||
{# <label for="title">Title</label> #}
|
||||
<input type="text" name="title" class="wide" placeholder="Title">
|
||||
</p>
|
||||
<p>
|
||||
{# <label for="link">Link</label> #}
|
||||
<input type="url" name="link" class="wide" placeholder="Link">
|
||||
</p>
|
||||
<p>
|
||||
{# <label for="body">Body</label> #}
|
||||
<textarea name="body" class="wide" placeholder="Body"></textarea>
|
||||
</p>
|
||||
<p>
|
||||
{# <label for="tags">Tags</label> #}
|
||||
<input type="text" name="tags" class="wide" placeholder="Tags, comma-separated">
|
||||
</p>
|
||||
<p>
|
||||
<label for="tts">TTS:</label>
|
||||
<input type="datetime-local" name="tts">
|
||||
</p>
|
||||
<p>
|
||||
<label for="ttl">TTL:</label>
|
||||
<input type="datetime-local" name="ttl">
|
||||
</p>
|
||||
<p>
|
||||
<label for="ttd">TTD:</label>
|
||||
<input type="datetime-local" name="ttd">
|
||||
</p>
|
||||
<p>
|
||||
<input type="submit" value="Add">
|
||||
</form>
|
||||
</details>
|
||||
|
|
Loading…
Reference in New Issue