Skip to content

Commit

Permalink
refactor: Add email search option in base.html and views.py
Browse files Browse the repository at this point in the history
This commit adds the email search option in the search dropdown menu of the base.html template. It also updates the views.py file to handle the email search query. This enhancement allows users to search for jobs based on email criteria, improving the search functionality of the website.
  • Loading branch information
QA2A committed Sep 8, 2024
1 parent ac6898d commit 2f254ba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 2 additions & 0 deletions website/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@
{% if request.GET.search_type == "role" %}selected{% endif %}>Role</option>
<option value="job"
{% if request.GET.search_type == "job" %}selected{% endif %}>Job</option>
<option value="email"
{% if request.GET.search_type == "email" %}selected{% endif %}>Email</option>
</select>
<!-- Search input -->
<input type="text"
Expand Down
14 changes: 6 additions & 8 deletions website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ def get_queryset(self):
if not self.queryset:
search_type = self.request.GET.get("search_type", "").strip()
search_query = re.sub(
r"[^a-zA-Z0-9,. ]", "", self.request.GET.get("search", "").strip()
r"[^a-zA-Z0-9,.@ ]", "", self.request.GET.get("search", "").strip()
)

if search_type == "skill":
Expand All @@ -711,6 +711,10 @@ def get_queryset(self):
# If search_type is 'job', return jobs where the job description contains the query
self.queryset = Job.objects.filter(description_markdown__icontains=search_query).select_related("company", "role").distinct()

elif search_type == "email" and search_query:
# If search_type is 'email', return jobs where the company email contains the query
self.queryset = Job.objects.filter(company__email__icontains=search_query).select_related("company", "role").distinct()

elif search_query:
# For general search query (if no specific search_type is provided)
query = SearchQuery(search_query)
Expand Down Expand Up @@ -741,13 +745,6 @@ def get_queryset(self):

if self.request.GET.get("view") == "grid":
self.template_name = "website/job_grid.html"

# if self.request.user.is_authenticated:
# # Exclude jobs the user has applied for
# applied_jobs = Application.objects.filter(
# user=self.request.user
# ).values_list("job_id", flat=True)
# self.queryset = self.queryset.exclude(id__in=applied_jobs)

ordering = self.request.GET.get("ordering")
if ordering and ordering.lstrip("-") in [
Expand All @@ -763,6 +760,7 @@ def get_queryset(self):

return self.queryset


def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
total_jobs = self.object_list.count() # Use count() on the object list
Expand Down

0 comments on commit 2f254ba

Please sign in to comment.