add prev / next page

This commit is contained in:
Sanj 2012-02-28 15:22:04 +05:30
parent ee3b51a24e
commit 85cd14acba
2 changed files with 23 additions and 0 deletions

View File

@ -91,6 +91,7 @@ def translate(request, model, field, page_no=1):
m = models.__getattribute__(model) m = models.__getattribute__(model)
except AttributeError: except AttributeError:
return HttpResponse("no such model") return HttpResponse("no such model")
page_no = int(page_no)
response = [] response = []
if field not in m._meta.get_all_field_names(): if field not in m._meta.get_all_field_names():
return HttpResponse("no such field") return HttpResponse("no such field")
@ -119,6 +120,10 @@ def translate(request, model, field, page_no=1):
}) })
context = RequestContext(request, { context = RequestContext(request, {
'values': response, 'values': response,
'has_next': results.has_next(),
'next_page': int(page_no) + 1,
'previous_page': int(page_no) - 1,
'has_previous': results.has_previous(),
'page_no': page_no, 'page_no': page_no,
'num_pages': paginator.num_pages, 'num_pages': paginator.num_pages,
'model': model, 'model': model,

View File

@ -1,6 +1,16 @@
<!doctype html> <!doctype html>
<html> <html>
<head> <head>
<style type="text/css">
#prevButton {
float: left;
}
#nextButton {
float: right;
}
</style>
<script type="text/javascript" src="/media/js/jquery.js"></script> <script type="text/javascript" src="/media/js/jquery.js"></script>
<script type="text/javascript" src="/media/js/trans.js"></script> <script type="text/javascript" src="/media/js/trans.js"></script>
@ -26,6 +36,14 @@ var trans = {
{% endfor %} {% endfor %}
</table> </table>
<div id="prevNext">
{% if has_previous %}
<div id="prevButton"><a href="/trans/{{model}}/{{field}}/{{previous_page}}">Previous</a></div>
{% endif %}
{% if has_next %}
<div id="nextButton"><a href="/trans/{{model}}/{{field}}/{{next_page}}">Next</a></div>
{% endif %}
</div>
</body> </body>
</html> </html>