Add basic item adding
This commit is contained in:
parent
f4b6ef2f1c
commit
0de40b1b5c
@ -1,5 +1,6 @@
|
||||
from datetime import datetime, timedelta
|
||||
from pathlib import Path
|
||||
from random import getrandbits
|
||||
from typing import List
|
||||
import json
|
||||
import os
|
||||
@ -299,6 +300,33 @@ def _parse_channels_config(config_str: str):
|
||||
return (None, parsed)
|
||||
|
||||
|
||||
@app.post("/add")
|
||||
def add_item():
|
||||
# Ensure the default source exists
|
||||
source_path = intake_data_dir() / "default"
|
||||
if not source_path.exists():
|
||||
source_path.mkdir()
|
||||
config_path = source_path / "intake.json"
|
||||
if not config_path.exists():
|
||||
config_path.write_text(json.dumps({
|
||||
"action": {
|
||||
"fetch": {
|
||||
"exe": "true"
|
||||
}
|
||||
}
|
||||
}, indent=2))
|
||||
source = LocalSource(source_path.parent, source_path.name)
|
||||
|
||||
# Clean up the fields
|
||||
item = {key: value for key, value in request.form.items() if value}
|
||||
item["id"] = '{:x}'.format(getrandbits(16 * 4))
|
||||
# TODO: this doesn't support tags or ttX fields correctly
|
||||
|
||||
source.new_item(item)
|
||||
|
||||
return redirect(url_for("source_feed", name="default"))
|
||||
|
||||
|
||||
def wsgi():
|
||||
# init_default_logging()
|
||||
return app
|
||||
|
@ -61,6 +61,37 @@ summary:focus {
|
||||
</details>
|
||||
</div>
|
||||
|
||||
<div class="readable-item">
|
||||
<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>
|
||||
<input type="submit" value="Add">
|
||||
</form>
|
||||
</details>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user