Add basic db explorer
This commit is contained in:
parent
dd89826a8d
commit
d9b9e10d56
58
db_explorer/db_explorer/app.py
Normal file
58
db_explorer/db_explorer/app.py
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
|
||||||
|
import urllib.parse
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
|
from flask import Flask, render_template
|
||||||
|
from flask_pymongo import PyMongo
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
app.config["MONGO_URI"] = os.environ["MONGO_URI"]
|
||||||
|
mongo = PyMongo(app)
|
||||||
|
|
||||||
|
@app.template_filter('filter_vtt')
|
||||||
|
def filter_vtt(text):
|
||||||
|
compendium_re = re.compile(r"@Compendium\[([^\]]+)\]\{([^\}]+)\}")
|
||||||
|
def compendium_return(m):
|
||||||
|
return f"<a>{m.group(2)}</a>"
|
||||||
|
macro_re = re.compile(r"\[\[\/\S?r\s(?:(?P<sdice>[^\{\] ]+)[^\{\]]*|(?:\{(?P<ldice>[^\}]+)\}\[[^\]]+\])?)\]\](?:\{(?P<alt>[^\}]+)\})?")
|
||||||
|
def macro_return(m):
|
||||||
|
if m.group('alt') is not None:
|
||||||
|
return m.group('alt')
|
||||||
|
return m.group('sdice')
|
||||||
|
text = compendium_re.sub(compendium_return, text)
|
||||||
|
text = macro_re.sub(macro_return, text)
|
||||||
|
return text
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
def list_types():
|
||||||
|
types = [ {"name": "Actions", "href": "action"} ]
|
||||||
|
return render_template("list.html", header="All types", items=types)
|
||||||
|
|
||||||
|
@app.route("/action")
|
||||||
|
def list_actions():
|
||||||
|
items = list(map(lambda x: {"name": x["name"], "href": "./action/" + urllib.parse.quote(x["name"], safe='')}, mongo.db.action.find({}, {"name": 1}).sort("name", 1)))
|
||||||
|
return render_template("list.html", header="All actions", items=items)
|
||||||
|
|
||||||
|
@app.route("/action/<name>")
|
||||||
|
def show_action(name):
|
||||||
|
item = mongo.db.action.find_one_or_404({"name": name})
|
||||||
|
print(item)
|
||||||
|
if item["data"]["actions"]["value"] == None:
|
||||||
|
if item["data"]["actionType"]["value"] == 'passive':
|
||||||
|
item['_action_icon'] = None
|
||||||
|
elif item["data"]["actionType"]["value"] == 'reaction':
|
||||||
|
item['_action_icon'] = 'r'
|
||||||
|
elif item["data"]["actionType"]["value"] == 'free':
|
||||||
|
item['_action_icon'] = 0
|
||||||
|
else:
|
||||||
|
raise ValueError(f'Unknown action type: {item["data"]["actionType"]["value"]}')
|
||||||
|
elif item["data"]["actions"]["value"] in (1,2,3):
|
||||||
|
item['_action_icon'] = item["data"]["actions"]["value"]
|
||||||
|
else:
|
||||||
|
raise ValueError(f'Unknown action: {item["data"]["actionType"]["value"]} - {item["data"]["actions"]["value"]}')
|
||||||
|
|
||||||
|
return render_template("action.html", action=item)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run()
|
2
db_explorer/db_explorer/blueprints/core/__init__.py
Normal file
2
db_explorer/db_explorer/blueprints/core/__init__.py
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
from flask import Blueprint
|
BIN
db_explorer/db_explorer/static/activity/free.webp
Normal file
BIN
db_explorer/db_explorer/static/activity/free.webp
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
db_explorer/db_explorer/static/activity/one.webp
Normal file
BIN
db_explorer/db_explorer/static/activity/one.webp
Normal file
Binary file not shown.
After Width: | Height: | Size: 1000 B |
BIN
db_explorer/db_explorer/static/activity/reaction.webp
Normal file
BIN
db_explorer/db_explorer/static/activity/reaction.webp
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
BIN
db_explorer/db_explorer/static/activity/three.webp
Normal file
BIN
db_explorer/db_explorer/static/activity/three.webp
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
BIN
db_explorer/db_explorer/static/activity/two.webp
Normal file
BIN
db_explorer/db_explorer/static/activity/two.webp
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
10
db_explorer/db_explorer/static/css/base.css
Normal file
10
db_explorer/db_explorer/static/css/base.css
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
.action-icon {
|
||||||
|
height: 26px;
|
||||||
|
margin-left: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sourcebook {
|
||||||
|
text-align: right;
|
||||||
|
font-size: 0.8em;
|
||||||
|
}
|
15
db_explorer/db_explorer/templates/_base.html
Normal file
15
db_explorer/db_explorer/templates/_base.html
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{% import "_const.html" as c -%}
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
{% block head %}
|
||||||
|
<title>{% block title %}PF2 DB{% endblock %}</title>
|
||||||
|
{% endblock %}
|
||||||
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/base.css') }}"
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{% block body %}
|
||||||
|
<i>This page is unintentionally left empty</i>
|
||||||
|
{% endblock %}
|
||||||
|
</body>
|
||||||
|
</html>
|
16
db_explorer/db_explorer/templates/_const.html
Normal file
16
db_explorer/db_explorer/templates/_const.html
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{% macro _abase(url) -%}
|
||||||
|
<img class="action-icon" src="{{ url }}">
|
||||||
|
{%- endmacro %}
|
||||||
|
{% set afree = _abase(url_for("static", filename="activity/free.webp")) -%}
|
||||||
|
{% set aone = _abase(url_for("static", filename="activity/one.webp")) -%}
|
||||||
|
{% set atwo = _abase(url_for("static", filename="activity/two.webp")) -%}
|
||||||
|
{% set athree = _abase(url_for("static", filename="activity/three.webp")) -%}
|
||||||
|
{% set areaction = _abase(url_for("static", filename="activity/reaction.webp")) -%}
|
||||||
|
{% set actions = {
|
||||||
|
None: "",
|
||||||
|
0: afree,
|
||||||
|
1: aone,
|
||||||
|
2: atwo,
|
||||||
|
3: athree,
|
||||||
|
'r': areaction
|
||||||
|
} -%}
|
7
db_explorer/db_explorer/templates/action.html
Normal file
7
db_explorer/db_explorer/templates/action.html
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{% extends "_base.html" %}
|
||||||
|
{% block title %}{{action.name}} - PF2 DB{% endblock %}
|
||||||
|
{% block body %}
|
||||||
|
<h1>{{action["name"]}}{{c.actions[action["_action_icon"]]|safe}}</h1>
|
||||||
|
<p>{{action["data"]["description"]["value"]|filter_vtt|safe}}</p>
|
||||||
|
<p class="sourcebook">{{action["data"]["source"]["value"]}}</p>
|
||||||
|
{% endblock %}
|
10
db_explorer/db_explorer/templates/list.html
Normal file
10
db_explorer/db_explorer/templates/list.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{% extends "_base.html" %}
|
||||||
|
{% block title %}{{header}} - PF2 DB {% endblock %}
|
||||||
|
{% block body %}
|
||||||
|
<h1>{{ header }}</h1>
|
||||||
|
<ul>
|
||||||
|
{% for item in items -%}
|
||||||
|
<li><a href="{{item.href}}">{{item.name}}</a></li>
|
||||||
|
{%- endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endblock %}
|
17
db_explorer/pyproject.toml
Normal file
17
db_explorer/pyproject.toml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
[tool.poetry]
|
||||||
|
name = "db-explorer"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = ""
|
||||||
|
authors = ["Michal Kunc <michkunc@gmail.com>"]
|
||||||
|
readme = "README.md"
|
||||||
|
packages = [{include = "db_explorer"}]
|
||||||
|
|
||||||
|
[tool.poetry.dependencies]
|
||||||
|
python = "^3.8"
|
||||||
|
Flask = "^2.0.2"
|
||||||
|
Flask-PyMongo = "^2.3.0"
|
||||||
|
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["poetry-core"]
|
||||||
|
build-backend = "poetry.core.masonry.api"
|
Loading…
Reference in New Issue
Block a user