Skip to content

Commit 83d5dae

Browse files
committed
Use pagination to show package events
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 18309aa commit 83d5dae

5 files changed

Lines changed: 35 additions & 10 deletions

File tree

fedcode/templates/base.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<meta charset="utf-8">
77
<meta name="viewport" content="width=device-width, initial-scale=1">
88
<title>{% block title %}FederatedCode.io{% endblock %}</title>
9-
<link rel="icon" href="{% static 'images/favicon.ico' %}" />
9+
<link rel="icon" href="{% static 'images/aboutcode_favicon-32x32.png' %}" />
1010

1111
<link rel="stylesheet" href="{% static 'css/bulma.css' %}" />
1212
<link rel="stylesheet" href="{% static 'css/custom.css' %}" />
@@ -29,9 +29,9 @@
2929

3030
<script src="{% static 'js/notification.js' %}" defer></script>
3131
<script>
32-
// Since django can not determine the client’s time zone automatically.
33-
// Store client's timezone in cookies to enable localization.
34-
// https://docs.djangoproject.com/en/5.1/topics/i18n/timezones/#selecting-the-current-time-zone
32+
// Since django can not determine the client’s time zone automatically.
33+
// Store client's timezone in cookies to enable localization.
34+
// https://docs.djangoproject.com/en/5.1/topics/i18n/timezones/#selecting-the-current-time-zone
3535
const currentTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
3636
document.cookie = "user_timezone=" + currentTimeZone;
3737
</script>

fedcode/templates/home.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ <h1>My Packages</h1>
5050
<hr />
5151
<pre class="has-text-black">{{ note.content }}</pre>
5252
<hr />
53-
<button class="button" onclick="window.open('{% url 'note-page' note.id %}');">Reply 💬</button>
53+
<button class="button" onclick="window.open('{% url 'note-page' note.id %}');">Comment 💬</button>
5454
</div>
5555
</div>
5656
<div class="media-right">

fedcode/templates/pkg_profile.html

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</p>
2020

2121
<figure class="media-left">
22-
<p class="image is-64x64" style="margin: auto">
22+
<p class="image is-128x128" style="margin: auto">
2323
<img src="{{ package.acct | get_pkg_image }}" alt="purl-image">
2424
</p>
2525
</figure>
@@ -118,7 +118,7 @@
118118
<div class="container mt-5 mb-5">
119119
<article class="panel is-info mr-6">
120120
<p class="panel-heading">
121-
Updates
121+
Package Events
122122
</p>
123123
<div class="panel-block">
124124
<article class="media box" style="width: 100%">
@@ -136,6 +136,24 @@
136136
</div>
137137
</article>
138138
</div>
139+
{% if is_paginated %}
140+
<nav class="pagination is-centered px-6 pt-6 pb-4" role="navigation" aria-label="pagination">
141+
{% if page_obj.has_previous %}
142+
<a class="pagination-previous" href="?page={{ page_obj.previous_page_number }}">Previous</a>
143+
{% endif %}
144+
145+
{% if page_obj.has_next %}
146+
<a class="pagination-next" href="?page={{ page_obj.next_page_number }}">Next page</a>
147+
{% endif %}
148+
149+
<ul class="pagination-list">
150+
<li><a class="pagination-link" aria-label="Goto page 1" href="?page=1">1</a></li>
151+
<li><span class="pagination-ellipsis">&hellip;</span></li>
152+
<li><a class="pagination-link" aria-label="Goto page {{ page_obj.number }}"
153+
href="?page={{ page_obj.paginator.num_pages }}">{{ page_obj.paginator.num_pages }}</a></li>
154+
</ul>
155+
</nav>
156+
{% endif %}
139157
</article>
140158
</div>
141159
</div>

fedcode/views.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,16 @@ def get_success_url(self):
191191

192192
def get_context_data(self, **kwargs):
193193
context = super().get_context_data(**kwargs)
194-
# slug = purl_string
195194

196-
context["purl_notes"] = Note.objects.filter(acct=generate_webfinger(self.kwargs["slug"]))
195+
# Paginate Package updates.
196+
purl_note_paginate_by = 10
197+
purl_notes = Note.objects.filter(acct=generate_webfinger(self.kwargs["slug"]))
198+
paginator = Paginator(purl_notes, purl_note_paginate_by)
199+
page_number = self.request.GET.get("page")
200+
page_obj = paginator.get_page(page_number)
201+
context["purl_notes"] = page_obj
202+
context["is_paginated"] = purl_notes.count() > purl_note_paginate_by
203+
context["page_obj"] = page_obj
197204

198205
context["followers"] = Follow.objects.filter(package=self.object)
199206

@@ -324,7 +331,7 @@ class PackageListView(ListView, FormMixin):
324331
model = Package
325332
context_object_name = "package_list"
326333
template_name = "pkg_list.html"
327-
paginate_by = 20
334+
paginate_by = 30
328335
form_class = SearchPackageForm
329336

330337
def get_queryset(self):
1.39 KB
Loading

0 commit comments

Comments
 (0)