Skip to content

Commit

Permalink
refactor: Remove commented out code for updating website status in Co…
Browse files Browse the repository at this point in the history
…mpanyJobDetailView
  • Loading branch information
QA2A committed Sep 12, 2024
1 parent 37a94b8 commit d22b7ae
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1385,35 +1385,35 @@ def get_next_company(self, company):
cache.set(next_company_cache_key, next_company, timeout=60 * 60 * 24) # Cache for 24 hours
return next_company

def update_website_status(self, company):
"""
Update the website status of the company.
"""
website_status_cache_key = f"website_status_{company.id}"
website_status_info = cache.get(website_status_cache_key)

if not website_status_info:
if not company.website_status_updated or (timezone.now() - company.website_status_updated).days >= 7:
website = company.website or f"https://{company.slug}.com"
try:
response = requests.get(website, timeout=10)
company.website_status_updated = timezone.now()
if not company.website and company.name.lower() in response.text.lower():
company.website = response.url
company.website_status = response.status_code
except RequestException:
company.website_status = 500
company.website_status_updated = timezone.now()
finally:
company.save(update_fields=["website", "website_status", "website_status_updated"])
website_status_info = {
"website_status": company.website_status,
"website_status_updated": company.website_status_updated,
"website": company.website,
}
cache.set(website_status_cache_key, website_status_info, timeout=60 * 60 * 24)

return website_status_info
# def update_website_status(self, company):
# """
# Update the website status of the company.
# """
# website_status_cache_key = f"website_status_{company.id}"
# website_status_info = cache.get(website_status_cache_key)

# if not website_status_info:
# if not company.website_status_updated or (timezone.now() - company.website_status_updated).days >= 7:
# website = company.website or f"https://{company.slug}.com"
# try:
# response = requests.get(website, timeout=10)
# company.website_status_updated = timezone.now()
# if not company.website and company.name.lower() in response.text.lower():
# company.website = response.url
# company.website_status = response.status_code
# except RequestException:
# company.website_status = 500
# company.website_status_updated = timezone.now()
# finally:
# company.save(update_fields=["website", "website_status", "website_status_updated"])
# website_status_info = {
# "website_status": company.website_status,
# "website_status_updated": company.website_status_updated,
# "website": company.website,
# }
# cache.set(website_status_cache_key, website_status_info, timeout=60 * 60 * 24)

# return website_status_info

def get_context_data(self, **kwargs):
obj = self.get_object()
Expand All @@ -1428,14 +1428,14 @@ def get_context_data(self, **kwargs):
self.get_user_applications(jobs, self.request.user) # Attach user applications to jobs
context['jobs'] = jobs
context["next_company"] = self.get_next_company(obj)
context["website_status_info"] = self.update_website_status(obj)
#context["website_status_info"] = self.update_website_status(obj)
elif isinstance(obj, Job):
company = obj.company
jobs = company.job_set.all()
self.get_user_applications(jobs, self.request.user)
context['jobs'] = jobs
context["next_company"] = self.get_next_company(obj.company)
context["website_status_info"] = self.update_website_status(obj.company)
#context["website_status_info"] = self.update_website_status(obj.company)

return context

Expand Down

0 comments on commit d22b7ae

Please sign in to comment.