mirror of
https://github.com/wahyd4/links.git
synced 2026-08-09 05:06:16 +10:00
Fix add page
This commit is contained in:
+19
-2
@@ -23,6 +23,8 @@ from pathlib import Path
|
||||
from datetime import datetime
|
||||
from rest_framework.decorators import action
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.contrib import messages
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
class PageListView(ListView):
|
||||
model = Page
|
||||
@@ -42,8 +44,23 @@ class PageCreateView(CreateView):
|
||||
|
||||
def form_valid(self, form):
|
||||
response = super().form_valid(form)
|
||||
# Use delay() to call the task asynchronously
|
||||
capture_screenshot.delay(self.object.id)
|
||||
page = self.object
|
||||
|
||||
# Create a pending screenshot record
|
||||
screenshot = Screenshot.objects.create(
|
||||
page=page,
|
||||
status=Screenshot.Status.PENDING
|
||||
)
|
||||
|
||||
# Start processing the page
|
||||
try:
|
||||
process_page.delay(page.id)
|
||||
messages.success(self.request, _('Page created successfully and processing started.'))
|
||||
except Exception as e:
|
||||
messages.error(self.request, _('Page created but processing failed to start.'))
|
||||
page.error_message = str(e)
|
||||
page.save()
|
||||
|
||||
return response
|
||||
|
||||
class PageUpdateView(UpdateView):
|
||||
|
||||
Reference in New Issue
Block a user