kopia lustrzana https://github.com/wagtail/wagtail
Adds a user and a page to the validation form
rodzic
0451d65bc9
commit
5fdbae4be7
|
@ -11,6 +11,10 @@ from wagtail.wagtailadmin.forms import WagtailAdminPageForm
|
|||
class BaseForm(django.forms.Form):
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs.setdefault('label_suffix', '')
|
||||
|
||||
self.user = kwargs.pop('user', None)
|
||||
self.page = kwargs.pop('page', None)
|
||||
|
||||
super(BaseForm, self).__init__(*args, **kwargs)
|
||||
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ FORM_FIELD_CHOICES = (
|
|||
@python_2_unicode_compatible
|
||||
class AbstractFormSubmission(models.Model):
|
||||
"""
|
||||
Data for a survey submission.
|
||||
Data for a form submission.
|
||||
|
||||
You can create custom submission model based on this abstract model.
|
||||
For example, if you need to save additional data or a reference to a user.
|
||||
|
@ -226,7 +226,7 @@ class AbstractForm(Page):
|
|||
|
||||
def serve(self, request, *args, **kwargs):
|
||||
if request.method == 'POST':
|
||||
form = self.get_form(request.POST)
|
||||
form = self.get_form(request.POST, page=self, user=request.user)
|
||||
|
||||
if form.is_valid():
|
||||
self.process_form_submission(form)
|
||||
|
@ -239,7 +239,7 @@ class AbstractForm(Page):
|
|||
self.get_context(request)
|
||||
)
|
||||
else:
|
||||
form = self.get_form()
|
||||
form = self.get_form(page=self, user=request.user)
|
||||
|
||||
context = self.get_context(request)
|
||||
context['form'] = form
|
||||
|
|
|
@ -77,7 +77,7 @@ def list_submissions(request, page_id):
|
|||
response = HttpResponse(content_type='text/csv; charset=utf-8')
|
||||
response['Content-Disposition'] = 'attachment;filename=export.csv'
|
||||
|
||||
# Prevents UnicodeEncodeError for questions with non-ansi symbols
|
||||
# Prevents UnicodeEncodeError for labels with non-ansi symbols
|
||||
data_headings = [smart_str(label) for label in data_headings]
|
||||
|
||||
writer = csv.writer(response)
|
||||
|
|
Ładowanie…
Reference in New Issue