Skip to content

Commit

Permalink
Use pagination to show package events
Browse files Browse the repository at this point in the history
Signed-off-by: Keshav Priyadarshi <[email protected]>
  • Loading branch information
keshav-space committed Jan 3, 2025
1 parent 18309aa commit 83d5dae
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
8 changes: 4 additions & 4 deletions fedcode/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}FederatedCode.io{% endblock %}</title>
<link rel="icon" href="{% static 'images/favicon.ico' %}" />
<link rel="icon" href="{% static 'images/aboutcode_favicon-32x32.png' %}" />

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

<script src="{% static 'js/notification.js' %}" defer></script>
<script>
// Since django can not determine the client’s time zone automatically.
// Store client's timezone in cookies to enable localization.
// https://docs.djangoproject.com/en/5.1/topics/i18n/timezones/#selecting-the-current-time-zone
// Since django can not determine the client’s time zone automatically.
// Store client's timezone in cookies to enable localization.
// https://docs.djangoproject.com/en/5.1/topics/i18n/timezones/#selecting-the-current-time-zone
const currentTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
document.cookie = "user_timezone=" + currentTimeZone;
</script>
Expand Down
2 changes: 1 addition & 1 deletion fedcode/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h1>My Packages</h1>
<hr />
<pre class="has-text-black">{{ note.content }}</pre>
<hr />
<button class="button" onclick="window.open('{% url 'note-page' note.id %}');">Reply 💬</button>
<button class="button" onclick="window.open('{% url 'note-page' note.id %}');">Comment 💬</button>
</div>
</div>
<div class="media-right">
Expand Down
22 changes: 20 additions & 2 deletions fedcode/templates/pkg_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</p>

<figure class="media-left">
<p class="image is-64x64" style="margin: auto">
<p class="image is-128x128" style="margin: auto">
<img src="{{ package.acct | get_pkg_image }}" alt="purl-image">
</p>
</figure>
Expand Down Expand Up @@ -118,7 +118,7 @@
<div class="container mt-5 mb-5">
<article class="panel is-info mr-6">
<p class="panel-heading">
Updates
Package Events
</p>
<div class="panel-block">
<article class="media box" style="width: 100%">
Expand All @@ -136,6 +136,24 @@
</div>
</article>
</div>
{% if is_paginated %}
<nav class="pagination is-centered px-6 pt-6 pb-4" role="navigation" aria-label="pagination">
{% if page_obj.has_previous %}
<a class="pagination-previous" href="?page={{ page_obj.previous_page_number }}">Previous</a>
{% endif %}

{% if page_obj.has_next %}
<a class="pagination-next" href="?page={{ page_obj.next_page_number }}">Next page</a>
{% endif %}

<ul class="pagination-list">
<li><a class="pagination-link" aria-label="Goto page 1" href="?page=1">1</a></li>
<li><span class="pagination-ellipsis">&hellip;</span></li>
<li><a class="pagination-link" aria-label="Goto page {{ page_obj.number }}"
href="?page={{ page_obj.paginator.num_pages }}">{{ page_obj.paginator.num_pages }}</a></li>
</ul>
</nav>
{% endif %}
</article>
</div>
</div>
Expand Down
13 changes: 10 additions & 3 deletions fedcode/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,16 @@ def get_success_url(self):

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
# slug = purl_string

context["purl_notes"] = Note.objects.filter(acct=generate_webfinger(self.kwargs["slug"]))
# Paginate Package updates.
purl_note_paginate_by = 10
purl_notes = Note.objects.filter(acct=generate_webfinger(self.kwargs["slug"]))
paginator = Paginator(purl_notes, purl_note_paginate_by)
page_number = self.request.GET.get("page")
page_obj = paginator.get_page(page_number)
context["purl_notes"] = page_obj
context["is_paginated"] = purl_notes.count() > purl_note_paginate_by
context["page_obj"] = page_obj

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

Expand Down Expand Up @@ -324,7 +331,7 @@ class PackageListView(ListView, FormMixin):
model = Package
context_object_name = "package_list"
template_name = "pkg_list.html"
paginate_by = 20
paginate_by = 30
form_class = SearchPackageForm

def get_queryset(self):
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 83d5dae

Please sign in to comment.