Start work on IsA page

This commit is contained in:
Edward Betts 2021-10-22 10:02:52 +01:00
parent 14abffe79c
commit bd9323006b
2 changed files with 127 additions and 2 deletions

87
templates/isa.html Normal file
View file

@ -0,0 +1,87 @@
{% extends "base.html" %}
{% block title %}{{ item.label() }} ({{ item.qid }}) {% endblock %}
{% block content %}
<div class="container my-2">
<h1>{{ self.title() }}</h1>
<div><a href="https://www.wikidata.org/wiki/{{ item.qid }}">
view on Wikidata
<i class="fa fa-external-link"></i>
</a></div>
<div class="my-2">
<form method="POST">
<input type="hidden" name="action" value="refresh">
<input type="submit" value="refresh item" class="btn btn-sm btn-primary">
</form>
</div>
{% set description = item.description() %}
{% set aliases = item.get_aliases() %}
{% set osm_tag_list = item.get_claim("P1282") %}
<div class="my-3">
{% if description %}
<strong>description</strong>:
{{ description }}<br>
{% endif %}
{% if aliases %}
<strong>aliases</strong>:
{{ aliases | join("; ") }}
{% endif %}
</div>
<h4>subclass of</h4>
<div class="mb-3">
{% if subclass_list %}
{% for subclass in subclass_list %}
<a href="{{ subclass.isa_page_url }}">{{ subclass.label }}</a>
({{ subclass.qid }})
&ndash; {{ subclass.description }}
<br>
{% endfor %}
{% else %}
<p>no subclasses</p>
{% endif %}
</div>
<h4>OpenStreetMap tags/keys from Wikidata</h4>
{% if osm_tag_list %}
<ul>
{% for tag_or_key in osm_tag_list %}
<li>{{ tag_or_key }}</li>
{% endfor %}
</ul>
{% else %}
<p>no tags/keys from Wikidata</p>
{% endif %}
<h4>extra OpenStreetMap tags/keys</h4>
{% if extra %}
<ul>
{% for tag_or_key in extra %}
<li>{{ tag_or_key }} <a href="#">🗙 remove</a></li>
{% endfor %}
</ul>
{% else %}
<p>no extra tags/keys</p>
{% endif %}
<form method="POST" class="row row-cols-lg-auto g-3 align-items-center">
<div class="col-12">
<div class="input-group">
<input class="form-control" id="tag-or-key" name="tag_or_key" placeholder="tag or key">
</div>
</div>
<div class="col-12">
<button type="submit" class="btn btn-primary">add</button>
</div>
</form>
</div>
{% endblock %}

View file

@ -128,6 +128,44 @@ def redirect_from_root():
def index_page(): def index_page():
return render_template("index.html") return render_template("index.html")
def get_username():
user = flask_login.current_user
if user.is_authenticated:
return user.username
@app.route("/isa/Q<int:item_id>", methods=["GET", "POST"])
def isa_page(item_id):
item = api.get_item(item_id)
if request.method == "POST":
return redirect(url_for(request.endpoint, item_id=item_id))
q = model.ItemExtraKeys.query.filter_by(item=item)
extra = [e.tag_or_key for e in q]
subclass_property = "P279"
subclass_list = []
for s in item.get_claim(subclass_property):
subclass = api.get_item(s["numeric-id"])
subclass_list.append({
"qid": s["id"],
"item_id": s["numeric-id"],
"label": subclass.label(),
"description": subclass.description(),
"isa_page_url": url_for("isa_page", item_id=s["numeric-id"]),
})
return render_template(
"isa.html",
item=item,
extra=extra,
subclass_list=subclass_list,
username=get_username()
)
@app.route("/admin/skip_isa") @app.route("/admin/skip_isa")
def admin_skip_isa_list(): def admin_skip_isa_list():
q = model.Item.query.join(model.SkipIsA).order_by(model.Item.item_id) q = model.Item.query.join(model.SkipIsA).order_by(model.Item.item_id)
@ -254,8 +292,8 @@ def map_location(zoom, lat, lon):
zoom=zoom, zoom=zoom,
lat=lat, lat=lat,
lon=lon, lon=lon,
radius=request.args.get('radius'), radius=request.args.get("radius"),
username=username, username=get_username(),
mode="map", mode="map",
q=None, q=None,
) )