mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
AsyncFormView: Pass locale and timezone to task
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
import logging
|
||||
|
||||
import celery.exceptions
|
||||
import pytz
|
||||
from celery.result import AsyncResult
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
@@ -29,7 +30,9 @@ from django.core.exceptions import ValidationError
|
||||
from django.http import JsonResponse
|
||||
from django.shortcuts import redirect, render
|
||||
from django.test import RequestFactory
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils import timezone, translation
|
||||
from django.utils.timezone import get_current_timezone
|
||||
from django.utils.translation import get_language, gettext as _
|
||||
from django.views.generic import FormView
|
||||
|
||||
from pretix.base.models import User
|
||||
@@ -201,7 +204,7 @@ class AsyncFormView(AsyncMixin, FormView):
|
||||
known_errortypes = ['ValidationError']
|
||||
|
||||
def __init_subclass__(cls):
|
||||
def async_execute(self, request_path, form_kwargs, organizer=None, event=None, user=None):
|
||||
def async_execute(self, *, request_path, form_kwargs, locale, tz, organizer=None, event=None, user=None):
|
||||
view_instance = cls()
|
||||
view_instance.request = RequestFactory().post(request_path)
|
||||
if organizer:
|
||||
@@ -218,7 +221,8 @@ class AsyncFormView(AsyncMixin, FormView):
|
||||
form_kwargs = view_instance.get_async_form_kwargs(form_kwargs, organizer, event)
|
||||
|
||||
form = form_class(**form_kwargs)
|
||||
return view_instance.async_form_valid(self, form)
|
||||
with translation.override(locale), timezone.override(pytz.timezone(tz)):
|
||||
return view_instance.async_form_valid(self, form)
|
||||
|
||||
cls.async_execute = app.task(
|
||||
base=ProfiledEventTask,
|
||||
@@ -253,6 +257,8 @@ class AsyncFormView(AsyncMixin, FormView):
|
||||
kwargs = {
|
||||
'request_path': self.request.path,
|
||||
'form_kwargs': form_kwargs,
|
||||
'locale': get_language(),
|
||||
'tz': get_current_timezone().zone,
|
||||
}
|
||||
if hasattr(self.request, 'organizer'):
|
||||
kwargs['organizer'] = self.request.organizer.pk
|
||||
|
||||
Reference in New Issue
Block a user