Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link feature to families #49

Merged
merged 6 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions grambank/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import functools

from pyramid.config import Configurator
from pyramid import httpexceptions
from sqlalchemy.orm import joinedload

from clld.interfaces import (
Expand Down Expand Up @@ -57,6 +58,17 @@ def link_attrs(req, obj, **kw):
return kw


def combine_feature_with_family(ctx, req):
if 'feature' in req.params and 'family' in req.params:
feature_id = req.params.get('feature')
family_id = req.params.get('family')
query = {'feature': feature_id}
raise httpexceptions.HTTPFound(
req.route_url('family', id=family_id, _query=query))
else:
raise httpexceptions.HTTPNotFound()


def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
Expand All @@ -66,6 +78,10 @@ def main(global_config, **settings):
config.include('clld_phylogeny_plugin')
config.register_datatable('familys', datatables.Families)
config.add_route_and_view('faq', '/faq', lambda *args, **kw: {}, renderer='faq.mako')
config.add_route_and_view(
'combine_feature_with_family',
'/_combine_feature_with_family',
combine_feature_with_family)

config.registry.registerUtility(GrambankCtxFactoryQuery(), ICtxFactoryQuery)
config.registry.registerUtility(GrambankMapMarker(), IMapMarker)
Expand Down
24 changes: 18 additions & 6 deletions grambank/templates/family/detail_html.mako
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<%block name="title">Family ${ctx.name}</%block>

<%! from sqlalchemy.orm import joinedload %>
<%! import sqlalchemy %>

<ul class="nav nav-pills" style="float: right">
<li class="">
Expand Down Expand Up @@ -43,17 +44,28 @@
<div id="feature-container" class="${'alert alert-info' if feature else 'well well-small'}">
<p>
To display the datapoints for a particular feature on the map and on the
classification tree, select the feauture then click "submit".
classification tree, select the feature then click "submit".
</p>
<form action="${request.route_url('family', id=ctx.id)}"
<form action="${request.route_url('combine_feature_with_family')}"
method="get"
class="form-inline">
<input type="hidden" name="family" value="${ctx.id}" />
<select id="ps" name="feature" class="input-xxlarge">
<label for="ps">Feature</label>
% for f in features:
<option value="${f.id}"${' selected="selected"' if feature and feature.id == f.id else ''}>
${f.id} ${f.name}
</option>
## XXX: This can probably be expressed in SQLAlchemy dot-notation.
<%! query = sqlalchemy.text('''
SELECT DISTINCT parameter.id, parameter.name
FROM value
JOIN valueset ON valueset.pk = value.valueset_pk
JOIN parameter ON parameter.pk = valueset.parameter_pk
JOIN grambanklanguage ON grambanklanguage.pk = valueset.language_pk
WHERE grambanklanguage.family_pk = :family_pk
ORDER BY parameter.id;''')
%>
% for feature_id, feature_name in request.db.execute(query, {'family_pk': ctx.pk}):
<option value="${feature_id}"${' selected="selected"' if feature and feature.id == feature_id else ''}>
${feature_id} ${feature_name}
</option>
% endfor
</select>
<button class="btn" type="submit">Submit</button>
Expand Down
31 changes: 31 additions & 0 deletions grambank/templates/parameter/detail_html.mako
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<%! active_menu_item = "parameters" %>
<%block name="title">Feature ${ctx.id}: ${ctx.name}</%block>

<%! import sqlalchemy %>

<%block name="head">
<link href="${request.static_url('clld:web/static/css/select2.css')}" rel="stylesheet">
<script src="${request.static_url('clld:web/static/js/select2.js')}"></script>
Expand Down Expand Up @@ -60,6 +62,35 @@ ${u.process_markdown(ctx.description, req)|n}

<br style="clear: right"/>

<div class="well well-small">
<p>
To display the datapoints for a particular language family on the map
and on the classification tree, select the family then click "submit".
</p>
<form action="${request.route_url('combine_feature_with_family')}"
method="get"
class="form-inline">
<input type="hidden" name="feature" value="${ctx.id}" />
<select id="fs" name="family">
<label for="fs">Family</label>
## XXX: This can probably be expressed in SQLAlchemy dot-notation.
<%! query = sqlalchemy.text('''
SELECT DISTINCT family.id, family.name
FROM value
JOIN valueset ON valueset.pk = value.valueset_pk
JOIN grambanklanguage ON grambanklanguage.pk = valueset.language_pk
JOIN family ON family.pk = grambanklanguage.family_pk
WHERE valueset.parameter_pk = :param_pk
ORDER BY family.name;''')
%>
% for family_id, family_name in request.db.execute(query, {'param_pk': ctx.pk}):
<option value="${family_id}">${family_name}</option>
% endfor
</select>
<button class="btn" type="submit">Submit</button>
</form>
</div>

<div class="well well-small">
<p>
You may combine this variable with a different variable by selecting on in the list below
Expand Down