Permalink
Browse files

Added .pyc to .gitignore and now have pagination working in flask for…

… emails; orm:chapterpdf chapter_7
  • Loading branch information...
rjurney committed Apr 5, 2012
1 parent 3fd3941 commit 1b65d4f54cd4ac9148e850f7384556421c85c0b6
View
@@ -1 +1,3 @@
lib/
+*.pyc
+.pyc
View
Binary file not shown.
@@ -1,7 +1,8 @@
# helpers.py - a helper library for index.py
+# Calculate email offsets for fetchig lists of emails from MongoDB
def get_offsets(offset1, offset2, increment):
offsets = {}
- offsets['next'] = {'top': offset2 + increment, 'bottom': offset1 + increment}
- offsets['previous'] = {'top': offset2 - increment, 'bottom': offset2 - increment}
+ offsets['Next'] = {'top': offset2 + increment, 'bottom': offset1 + increment}
+ offsets['Previous'] = {'top': offset2 - increment, 'bottom': offset1 - increment}
return offsets
View
@@ -11,6 +11,7 @@
# Simple configuration and helpers
import config, helpers
+from helpers import *
app = Flask(__name__)
connection = Connection()
@@ -3,28 +3,11 @@
<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) -%}
+<!-- Display a pair of navigation links for previous/next page in the email list -->
+{% macro display_nav(offsets) -%}
<div style="text-align: center">
- {{ nav_link('Previous', offset1, offset2, increment) }}
- {{ nav_link('Next', offset1, offset2, increment )}}
+ {% for key, values in offsets.items() -%}
+ <a href="/emails/{{ values['bottom'] }}/{{ values['top'] }}">{{ key }}</a>
+ {% endfor -%}
</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 -%}
@@ -26,7 +26,7 @@
<th>From</th><th>Subject</th><th>Date</th>
</thead>
<tbody>
- {% for email in emails %}
+ {% for email in data['emails'] %}
<tr>
<td>{{ display_emails(email['from']) }}</td>
<td>{{ common.display_link(email['message_id'], '/email', email['subject'])|safe }}</td>
@@ -35,5 +35,5 @@
{% endfor %}
</tbody>
</table>
- {{ common.display_v_links(data['offset1'], data['offset2'], 20) }}
+ {{ common.display_nav(data['nav_offsets'])|safe }}
{% endblock -%}

0 comments on commit 1b65d4f

Please sign in to comment.