Skip to content

Commit

Permalink
cleanup loadcachespage command
Browse files Browse the repository at this point in the history
  • Loading branch information
ychab committed Dec 28, 2023
1 parent 01fb4d4 commit c69ac1a
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions folioblog/core/management/commands/loadcachepages.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,12 @@ class Command(BaseCommand):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.session = requests.session()
self.requests_kwargs = {}

def add_arguments(self, parser):
parser.add_argument("--auth-user")
parser.add_argument("--auth-passwd")

def handle(self, *args, **options):
# First clear the cache before rebuilding it!
self.stdout.write(self.style.WARNING("WARNING: clearing cache...\n"))
cache.clear()

# Prepare request options for HTTP auth if needed.
if options["auth_user"] and options["auth_passwd"]: # pragma: no cover
self.requests_kwargs["auth"] = (
options["auth_user"],
options["auth_passwd"],
)

# Then iterate over each sites to fetch their pages.
for site in Site.objects.all():
self.process_site(site, FolioBlogSettings.for_site(site))
Expand Down Expand Up @@ -97,9 +85,8 @@ def process_view(self, site):
def request_page(self, url, method="get", status=None, **kwargs):
self.stdout.write(f'Requesting: {method.upper()} "{url}"')

requests_kwargs = self.requests_kwargs | kwargs
try:
response = getattr(self.session, method)(url, **requests_kwargs)
response = getattr(self.session, method)(url, **kwargs)
except RequestException as e:
self.stdout.write(self.style.ERROR(f"Error on page {url} with exc {e}\n"))
else:
Expand Down

0 comments on commit c69ac1a

Please sign in to comment.