Skip to content

Commit

Permalink
Much half-working work
Browse files Browse the repository at this point in the history
  • Loading branch information
rjurney committed Apr 4, 2012
1 parent c736435 commit 3fd3941
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/python/web/config.py
@@ -0,0 +1,2 @@
# config.py - a configuration file for index.py
EMAIL_RANGE = 20
Binary file added src/python/web/config.pyc
Binary file not shown.
7 changes: 7 additions & 0 deletions src/python/web/helpers.py
@@ -0,0 +1,7 @@
# helpers.py - a helper library for index.py

def get_offsets(offset1, offset2, increment):
offsets = {}
offsets['next'] = {'top': offset2 + increment, 'bottom': offset1 + increment}
offsets['previous'] = {'top': offset2 - increment, 'bottom': offset2 - increment}
return offsets
9 changes: 7 additions & 2 deletions src/python/web/index.py
Expand Up @@ -9,6 +9,9 @@
# ElasticSearch
import json, pyelasticsearch

# Simple configuration and helpers
import config, helpers

app = Flask(__name__)
connection = Connection()
db = connection.agile_data
Expand Down Expand Up @@ -36,12 +39,14 @@ def email(message_id):
default_offsets={'offset1': 0, 'offset2': 20}
@app.route('/emails', defaults=default_offsets)
@app.route('/emails/', defaults=default_offsets)
@app.route("/emails/<offset1>/<offset2>")
@app.route("/emails/<int:offset1>/<int:offset2>")
def list_emaildb(offset1, offset2):
offset1 = int(offset1)
offset2 = int(offset2)
emails = emaildb.find()[offset1:offset2] # Uses a MongoDB cursor
return render_template('partials/emails.html', emails=emails)
nav_offsets = get_offsets(offset1, offset2, config.EMAIL_RANGE)
data = {'emails': emails, 'nav_offsets': nav_offsets}
return render_template('partials/emails.html', data=data)

@app.route("/emails/search/<query>")
def search_email(query):
Expand Down
26 changes: 26 additions & 0 deletions src/python/web/templates/macros.jnj
Expand Up @@ -2,3 +2,29 @@
{% macro display_link(value, base_path, display) -%}
<div class="span" style="display: inline-block"><a href="{{ base_path }}/{{ value }}">{{ display }}</a></div>
{% endmacro -%}

<!-- Display a pair of nav links -->
{% macro display_nav_links(offset1, offset2, increment) -%}
<div style="text-align: center">
{{ nav_link('Previous', offset1, offset2, increment) }}
{{ nav_link('Next', offset1, offset2, increment )}}
</div>
{% endmacro -%}

<!-- Display a single nav link -->
{% macro nav_link(label, offset1, offset2, increment) -%}
{% set bottom = get_increment(offset1, increment, label) -%}
{% set top = get_increment(offset2, increment, label) -%}
{% if bottom > 0 -%}
<a href="/emails/{{ bottom }}/{{ top }}">{{ label }}</a>
{% endif -%}
{% endmacro -%}

{% macro get_increment( offset, increment, label ) -%}
{% if label == 'Previous' -%}
{{ offset - increment }}
{% endif -%}
{% if label == 'Next' -%}
{{ offset + increment }}
{% endif -%}
{% endmacro -%}
3 changes: 2 additions & 1 deletion src/python/web/templates/partials/emails.html
Expand Up @@ -35,4 +35,5 @@
{% endfor %}
</tbody>
</table>
{% endblock -%}
{{ common.display_v_links(data['offset1'], data['offset2'], 20) }}
{% endblock -%}

0 comments on commit 3fd3941

Please sign in to comment.