Skip to content

Commit

Permalink
added sidebar to search page and added the ability to search and see …
Browse files Browse the repository at this point in the history
…everything (OWASP-BLT#3268)

* initial commit

* second commit

* third commit
  • Loading branch information
tsu-ki authored Jan 26, 2025
1 parent cee5bec commit 13da0aa
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
12 changes: 9 additions & 3 deletions website/templates/includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
action="{% url 'search' %}"
method="get">
<i class="lg:!flex hidden fa fa-search absolute left-4 text-[#9CA3AF] z-10 my-auto"></i>
<input type="hidden" name="type" id="filter-type" value="organizations">
<input type="hidden" name="type" id="filter-type" value="all">
<!-- Search Input -->
<input type="text"
name="query"
Expand All @@ -161,14 +161,20 @@
<button id="organizations-btn"
type="button"
class="flex items-center text-xl lg:text-base h-16 bg-[#ededed] p-5 font-semibold text-[#9CA3AF] outline-none rounded-r-2xl">
<i id="selected-icon" class="fas fa-building mr-2"></i>
<span id="selected-filter">{% trans "Organizations" %}</span>
<i id="selected-icon" class="fas fa-search mr-2"></i>
<span id="selected-filter">{% trans "All" %}</span>
<i class="fa fa-chevron-down ml-2"></i>
</button>
<!-- Dropdown Menu -->
<div id="organizations-dropdown"
class="hidden absolute bg-white border rounded-lg shadow-md mt-2 w-48 z-50 right-0 top-full">
<div class="py-1">
<!-- Default All category-->
<a href="#"
data-value="all"
class="filter-option flex items-center px-3 py-2 hover:bg-gray-100 text-sm">
<i class="fas fa-search mr-2"></i> {% trans "All" %}
</a>
<a href="#"
data-value="organizations"
class="filter-option flex items-center px-3 py-2 hover:bg-gray-100 text-sm">
Expand Down
2 changes: 2 additions & 0 deletions website/templates/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
{% endblock og_description %}
{% load humanize %}
{% block content %}
<!-- Include Sidenav -->
{% include "includes/sidenav.html" %}
<style>
.bottom-right {
position: absolute;
Expand Down
36 changes: 34 additions & 2 deletions website/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,45 @@ def find_key(request, token):

def search(request, template="search.html"):
query = request.GET.get("query")
stype = request.GET.get("type", "organizations")
stype = request.GET.get("type", "all")
context = None
if query is None:
return render(request, template)
query = query.strip()

if stype == "issues":
if stype == "all":
# Search across multiple models
organizations = Organization.objects.filter(name__icontains=query)
issues = Issue.objects.filter(Q(description__icontains=query), hunt=None).exclude(
Q(is_hidden=True) & ~Q(user_id=request.user.id)
)[0:20]
domains = Domain.objects.filter(Q(url__icontains=query), hunt=None)[0:20]
users = (
UserProfile.objects.filter(Q(user__username__icontains=query))
.annotate(total_score=Sum("user__points__score"))
.order_by("-total_score")[0:20]
)
projects = Project.objects.filter(Q(name__icontains=query) | Q(description__icontains=query))
repos = Repo.objects.filter(Q(name__icontains=query) | Q(description__icontains=query))
context = {
"query": query,
"type": stype,
"organizations": organizations,
"issues": issues,
"domains": domains,
"users": users,
"projects": projects,
"repos": repos,
}

for userprofile in users:
userprofile.badges = UserBadge.objects.filter(user=userprofile.user)
for org in organizations:
d = Domain.objects.filter(organization=org).first()
if d:
org.absolute_url = d.get_absolute_url()

elif stype == "issues":
context = {
"query": query,
"type": stype,
Expand Down

0 comments on commit 13da0aa

Please sign in to comment.