Skip to content

Pagination on containers #12

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions .reviewboardrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
REVIEWBOARD_URL = "sand10.scholarsportal.info/reviews"
REPOSITORY = "Swiftbrowser"
BRANCH = "master"
LAND_DEST_BRANCH = "master"
4 changes: 4 additions & 0 deletions swiftbrowser/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@
STATIC_URL = "http://cdnjs.cloudflare.com/ajax/libs/"

ALLOWED_HOSTS = ['127.0.0.1', 'insert_your_hostname_here']

SWIFT_BROWSER_SETTINGS = {
"containers_per_page" : 5
}
43 changes: 31 additions & 12 deletions swiftbrowser/templates/containerview.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
{% include "messages.html" %}
<ul class="breadcrumb">
<li><a href="{% url "containerview" %}">Containers</a></li>
</ul>
</ul>

<table class="table table-striped">

<thead>
<tr>
<th style="width: 1em;" class="hidden-phone"></th>
Expand All @@ -20,7 +20,7 @@
<th style="width: 1em;">

<a href="{% url "create_container" %}" class="btn btn-mini btn-danger">
<i class="icon-plus icon-white"></i>
<i class="icon-plus icon-white"></i>
</a>

</th>
Expand All @@ -43,7 +43,7 @@
<li><a href="{{ edit_acl_url }}"><i class="icon-user"></i> {% trans 'Sharing' %}</a></li>
<li class="divider" />
{% endif %}

<li>
<a href="{% url "delete_container" container=container.name %}" onclick="return confirm('{% trans 'Delete container' %} {{container.name}}?');">
<i class="icon-trash"></i> {% trans 'Delete container' %}
Expand All @@ -53,31 +53,50 @@
</div>
</td>

</tr>
</tr>

{% empty %}
<tr>
<td colspan="5">
<strong><center>{% trans 'There are no containers in this account yet. Create a new container by clicking the red button.' %}<center></strong>
</td>
</tr>
</tr>

{% endfor %}
</tbody>
</tbody>

<tfoot>
<tr>
<th colspan="5" class="center">
{{account_stat.x_account_bytes_used|filesizeformat}}
{{account_stat.x_account_bytes_used|filesizeformat}}
{% if account_stat.x_account_meta_quota_bytes %}
{% trans 'of' %}
{{account_stat.x_account_meta_quota_bytes|filesizeformat}}
{{account_stat.x_account_meta_quota_bytes|filesizeformat}}
{% endif %}
{% trans 'used' %}
</th>
</tr>
</tfoot>
</table>
<nav class="pagination">
<form method="POST" action="/" class="form-horizontal">
{% csrf_token %}

<ul class="pager">
<li>
<a href="#">
<input type="submit" name="get_previous" value="Previous"/>
</a>
</li>
<li>
<a href="#">
<input type="submit" name="get_next" value="Next"/>
</a>
</li>
</ul>

</form>
</nav>
</div>
</div>
{% endblock %}
Expand Down
51 changes: 50 additions & 1 deletion swiftbrowser/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,46 @@ def containerview(request):
storage_url = request.session.get('storage_url', '')
auth_token = request.session.get('auth_token', '')

# "markers" is a list used to keep track of container names for pagination.
if "markers" not in request.session:

# The initial marker with an empty string.
request.session["markers"] = ['']
marker = ""

if("get_next" in request.POST):

# If requesting the next page, and there are none,
# the marker should be the last not None marker.
if request.session["markers"][-1] is None:
request.session["markers"].pop()

# Use the latest marker to get the next page.
marker = request.session["markers"][-1]

elif ("get_previous" in request.POST):

# Remove the "next" marker
request.session["markers"].pop()

# Remove the "current" marker if we're not at the very beginning.
if len(request.session["markers"]) != 1:
request.session["markers"].pop()

# Use the "previous" marker
marker = request.session["markers"][-1]

else:
# Reset marker stack.
request.session["markers"] = ['']
marker = ""

try:
account_stat, containers = client.get_account(storage_url, auth_token)
account_stat, containers = client.get_account(
storage_url,
auth_token,
marker,
settings.SWIFT_BROWSER_SETTINGS["containers_per_page"])
except client.ClientException as exc:
if exc.http_status == 403:
account_stat = {}
Expand All @@ -68,6 +106,17 @@ def containerview(request):
else:
return redirect(login)

# Add the last result to the markers list.
if len(containers) == 5:
new_marker = containers[-1]["name"]
else:
new_marker = None

request.session["markers"].append(new_marker)

# Save the session
request.session.modified = True

account_stat = replace_hyphens(account_stat)

return render_to_response('containerview.html', {
Expand Down