hotpocket/services/backend/hotpocket_backend/apps/ui/views/integrations/ios.py
Tomek Wójcik b4338e2769
Some checks failed
CI / Checks (push) Failing after 13m2s
Release v1.0.0
2025-08-20 21:00:50 +02:00

48 lines
1.3 KiB
Python

# -*- coding: utf-8 -*-
from __future__ import annotations
import http
import logging
import django.db
from django.http import HttpRequest, HttpResponse
from django.shortcuts import render
from hotpocket_backend.apps.accounts.decorators import account_required
from hotpocket_backend.apps.ui.services.workflows import CreateSaveWorkflow
LOGGER = logging.getLogger(__name__)
@account_required
def shortcut(request: HttpRequest) -> HttpResponse:
LOGGER.debug('GET=`%s`', request.GET)
try:
with django.db.transaction.atomic():
assert request.user.is_anonymous is False, 'Login required'
assert 'url' in request.GET, 'Bad request: Missing `url`'
url = request.GET['url'].split('\n')[0].strip()
assert url != '', 'Bad request: Empty `url`'
return CreateSaveWorkflow().run(
request=request,
account=request.user,
url=url,
force_post_save=True,
)
except Exception as exception:
LOGGER.error(
'Unhandled exception: %s',
exception,
exc_info=exception,
)
return render(
request,
'ui/errors/internal_server_error.html',
# Returning 200 here to avoid browsers showing generic error pages.
status=http.HTTPStatus.OK,
)