Issue 310 (#311)
* fix item previous and next links #310 * fix get_next comment #310 * ensure correct formatting for flake8 #310 * change id to id_ * change previous to prev * fix ref * Update item.html Co-authored-by: Tom Kralidis <tomkralidis@gmail.com>
This commit is contained in:
committed by
Tom Kralidis
parent
09efa01b0b
commit
f0006c92f0
@@ -265,6 +265,44 @@ class PostgreSQLProvider(BaseProvider):
|
||||
|
||||
return feature_collection
|
||||
|
||||
def get_previous(self, cursor, identifier):
|
||||
"""
|
||||
Query previous ID given current ID
|
||||
|
||||
:param identifier: feature id
|
||||
|
||||
:returns: feature id
|
||||
"""
|
||||
sql = 'SELECT {} AS id FROM {} WHERE {}<%s ORDER BY {} DESC LIMIT 1'
|
||||
cursor.execute(SQL(sql).format(
|
||||
Identifier(self.id_field),
|
||||
Identifier(self.table),
|
||||
Identifier(self.id_field),
|
||||
Identifier(self.id_field),
|
||||
), (identifier,))
|
||||
item = cursor.fetchall()
|
||||
id_ = item[0]['id']
|
||||
return id_
|
||||
|
||||
def get_next(self, cursor, identifier):
|
||||
"""
|
||||
Query next ID given current ID
|
||||
|
||||
:param identifier: feature id
|
||||
|
||||
:returns: feature id
|
||||
"""
|
||||
sql = 'SELECT {} AS id FROM {} WHERE {}>%s ORDER BY {} LIMIT 1'
|
||||
cursor.execute(SQL(sql).format(
|
||||
Identifier(self.id_field),
|
||||
Identifier(self.table),
|
||||
Identifier(self.id_field),
|
||||
Identifier(self.id_field),
|
||||
), (identifier,))
|
||||
item = cursor.fetchall()
|
||||
id_ = item[0]['id']
|
||||
return id_
|
||||
|
||||
def get(self, identifier):
|
||||
"""
|
||||
Query the provider for a specific
|
||||
@@ -298,6 +336,8 @@ class PostgreSQLProvider(BaseProvider):
|
||||
row_data = cursor.fetchall()[0]
|
||||
feature = self.__response_feature(row_data)
|
||||
|
||||
feature['prev'] = self.get_previous(cursor, identifier)
|
||||
feature['next'] = self.get_next(cursor, identifier)
|
||||
return feature
|
||||
|
||||
def __response_feature(self, row_data):
|
||||
|
||||
@@ -37,7 +37,28 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6 col-sm-12">
|
||||
<div id="items-map"></div>
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<div id="items-map"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
{% if data['prev'] or data['next'] %}
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
{% for link in data['links'] %}
|
||||
{% if link['rel'] == 'prev' %}
|
||||
<a role="button" href="./{{ data['prev'] }}">Previous</a>
|
||||
{% elif link['rel'] == 'next' %}
|
||||
<a role="button" href="./{{ data['next'] }}">Next</a>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6 col-sm-12">
|
||||
<table class="striped">
|
||||
@@ -72,17 +93,6 @@
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
{% for link in data['links'] %}
|
||||
{% if link['rel'] == 'prev' %}
|
||||
<a role="button" href="{{ link['href'] }}?f=html">Prev</a>
|
||||
{% elif link['rel'] == 'next' %}
|
||||
<a role="button" href="{{ link['href'] }}?f=html">Next</a>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user