Skip to content

Commit

Permalink
make views work with Python/Django async
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneswilm committed Jan 15, 2025
1 parent 5b74949 commit 9843703
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions fiduswriter/phplist/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
@require_POST
@async_to_sync
async def subscribe_email(request):
if not hasattr(settings, "PHPLIST_BASE_URL"):
if (
not hasattr(settings, "PHPLIST_BASE_URL")
or not settings.PHPLIST_BASE_URL
):
return HttpResponse()
url = urljoin(settings.PHPLIST_BASE_URL, "/admin/")
login_data = {
Expand All @@ -36,7 +39,7 @@ async def subscribe_email(request):
)
response.raise_for_status()
except HTTPError:
return HttpResponse(status=404)
return HttpResponse(status=500)
# <input type="hidden" name="formtoken" value="1f...114" />
session_cookie = response.headers["Set-Cookie"]
formtoken_match = re.search(
Expand All @@ -47,7 +50,7 @@ async def subscribe_email(request):
return HttpResponse(status=404)
formtoken = formtoken_match.group(1)
email = request.POST["email"]
email_object = EmailAddress.objects.filter(email=email).first()
email_object = await EmailAddress.objects.filter(email=email).afirst()
if not email_object:
return HttpResponse(status=500)
data = {
Expand Down

0 comments on commit 9843703

Please sign in to comment.