Skip to content
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

Pagination Updated - Items per page option added #1625

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Rishi-source
Copy link

Add pagination to Package Search and Vulnerability Search #1616 #1617

This change aligns Package Search functionality and Vulnerability Search, improving consistency across the application and enhancing user control over result display.

For Package Search:

Screenshot 2024-10-18 at 4 42 58 PM

For Vulnerability Search:

Screenshot 2024-10-18 at 4 43 39 PM

Signed-off-by: Rishi Garg [email protected]

@Rishi-source
Copy link
Author

Hi @pombredanne @TG1999 @keshav-space @Hritik14 , Can you please review this PR It has passed all workflow tests and was also working fine on my local server. Thank you

@pombredanne
Copy link
Member

@TG1999 ping .... @tdruez input welcomed too, as eventually we want to use the same approach across all projects.

vulnerabilities/templates/vulnerabilities.html Outdated Show resolved Hide resolved
vulnerabilities/templates/vulnerabilities.html Outdated Show resolved Hide resolved
vulnerabilities/views.py Outdated Show resolved Hide resolved
vulnerabilities/views.py Outdated Show resolved Hide resolved
vulnerabilities/views.py Outdated Show resolved Hide resolved
vulnerabilities/views.py Outdated Show resolved Hide resolved
vulnerabilities/templates/packages.html Outdated Show resolved Hide resolved
@Rishi-source Rishi-source force-pushed the Page-Updated branch 4 times, most recently from d8068aa to c28765a Compare October 29, 2024 18:44
@Rishi-source Rishi-source force-pushed the Page-Updated branch 2 times, most recently from e4a1a18 to 8d177c8 Compare November 2, 2024 05:37
@Rishi-source
Copy link
Author

@tdruez please see the changes now workflow tests are also successful .

@Rishi-source
Copy link
Author

@tdruez I would request you to please review the PR I have made changes In the code after you requested some changes after first review.

Copy link
Contributor

@tdruez tdruez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the various comments.
Generally, this implementation seems too complex and not "reusable" enough at it requires to many moving parts.

@@ -3,7 +3,7 @@
# VulnerableCode is a trademark of nexB Inc.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://github.com/aboutcode-org/vulnerablecode for support or download.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unwanted changes

@@ -12,26 +12,87 @@

from vulnerabilities.models import ApiUser

from .models import *
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid * imports.

widget=forms.Select(
attrs={
"class": "select is-small",
"onchange": "handlePageSizeChange(this.value)",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid inline JavaScript.

Comment on lines +46 to +47
def clean_search(self):
return self.cleaned_data.get("search", "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this?

Comment on lines +49 to +61
def get_queryset(self, query=None):
"""
Get queryset with search/filter/ordering applied.
Args:
query (str, optional): Direct query for testing
"""
if query is not None:
return self._search(query)

if not self.is_valid():
return self.model.objects.none()

return self._search(self.clean_search())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the need for this logic?

Comment on lines +73 to +80
def _search(self, query):
"""Execute package-specific search logic."""
return (
self.model.objects.search(query)
.with_vulnerability_counts()
.prefetch_related()
.order_by("package_url")
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not following the Django forms conventions.

Comment on lines +92 to +94
def _search(self, query):
"""Execute vulnerability-specific search logic."""
return self.model.objects.search(query=query).with_package_counts()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above.

Comment on lines +4 to +5
<a href="?page={{ page_obj.previous_page_number }}&search={{ search|urlencode }}&page_size={{ page_obj.paginator.per_page }}"
class="pagination-previous">Previous</a>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if other filters are active, those are lost when using the pagination?


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the complexity of those templates should likely be handled in Python.

model = models.Package
template_name = "packages.html"
ordering = ["type", "namespace", "name", "version"]
class BaseSearchView(ListView):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use the django_filters.views.FilterView instead of re-implementing it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants