return response
-class UploadDoubleFileForm(UploadFileForm):
+class UploadFormBaseMixin():
'''
+ Mixins add to attributes to self, and to response.
+ '''
+ def write_response(self, response):
+ return response
+
+
+class UploadDoubleFileFormMixin(UploadFormBaseMixin):
+ '''
+ Adds a last_key attribute to self, from POST
+
Acts like a dict, but with extra methods.
Attributes:
Methods:
read() Load form from pyramid request object.
'''
- def __init__(self, uh, fc=UploadFileWTForm, data={}, **kwargs):
- data.update(kwargs)
- super(UploadDoubleFileForm, self).__init__(uh, fc, data)
def read(self):
'''
Read form data from the client
'''
- # Read parent's data
- super(UploadDoubleFileForm, self).read()
+ super().read()
- # Read our own data
post = self.uh.request.POST
if 'last_key' in post:
self['last_key'] = post['last_key']
else:
self['last_key'] = ''
- def write(self, result, errors):
+ def write_response(self, response):
'''
Produces the dict pyramid will use to render the form.
'''
- response = super(UploadDoubleFileForm, self).write(result, errors)
response['last_key'] = self['last_key']
- return response
+ return super().write_response(response)
-class UploadNullFileForm(UploadFileForm):
+class UploadDoubleFileForm(UploadDoubleFileFormMixin, UploadFileForm):
'''
Acts like a dict, but with extra methods.
Methods:
read() Load form from pyramid request object.
'''
- def __init__(self, uh, fc=UploadNullFileWTForm, data={}, **kwargs):
+ def __init__(self, uh, fc=UploadFileWTForm, data={}, **kwargs):
data.update(kwargs)
- super(UploadNullFileForm, self).__init__(uh, fc, data)
+ super().__init__(uh, fc, data)
def read(self):
'''
Read form data from the client
'''
+ # Read parents' data
+ super().read()
- # Read parent's data
- super(UploadNullFileForm, self).read()
+ def write(self, result, errors):
+ '''
+ Produces the dict pyramid will use to render the form.
+ '''
+ response = super().write(result, errors)
+ return super().write_response(response)
- # Read our own data
+
+class UploadNullMixin(UploadFormBaseMixin):
+ '''
+ Acts like a dict, but with extra methods.
+
+ Attributes:
+ uh The UploadHandler instance using the form
+
+ Methods:
+ read() Load form from pyramid request object.
+ '''
+ def read(self):
+ '''
+ Read form data from the client
+ '''
+ super().read()
self['upload_null'] = self._form.upload_null.data
self['null_rep'] = self._form.null_rep.data
- def write(self, result, errors):
+ def write_response(self, response):
'''
Produces the dict pyramid will use to render the form.
'''
else:
upload_null_checked = UNCHECKED
- response = super(UploadNullFileForm, self).write(result, errors)
response['upload_null'] = upload_null_checked
response['null_rep'] = self['null_rep']
- return response
+ return super().write_response(response)
-class UploadTableForm(UploadNullFileForm):
+class UploadTableForm(UploadNullMixin, UploadFileForm):
'''
Acts like a dict, but with extra methods.
'''
def __init__(self, uh, fc=UploadTableWTForm, data={}, **kwargs):
data.update(kwargs)
- super(UploadTableForm, self).__init__(uh, fc, data)
+ super().__init__(uh, fc, data)
def read(self):
'''
Read form data from the client
'''
- # Read parent's data
- super(UploadTableForm, self).read()
-
+ # Read parents' data
+ super().read()
# Read our own data
self['table'] = self._form.table.data
'''
Produces the dict pyramid will use to render the form.
'''
- response = super(UploadTableForm, self).write(result, errors)
+ response = super().write(result, errors)
response['table'] = self['table']
- return response
+ return super().write_response(response)
-class UploadDoubleTableForm(UploadTableForm):
+class UploadDoubleTableForm(UploadDoubleFileFormMixin, UploadTableForm):
'''
Acts like a dict, but with extra methods.
'''
def __init__(self, uh, fc=UploadTableWTForm, data={}, **kwargs):
data.update(kwargs)
- super(UploadDoubleTableForm, self).__init__(uh, fc, data)
+ super().__init__(uh, fc, data)
def read(self):
'''
Read form data from the client
'''
- # Read parent's data
- super(UploadDoubleTableForm, self).read()
-
- # Read our own data
- post = self.uh.request.POST
- if 'last_key' in post:
- self['last_key'] = post['last_key']
- else:
- self['last_key'] = ''
+ # Read parents' data
+ super().read()
def write(self, result, errors):
'''
Produces the dict pyramid will use to render the form.
'''
- response = super(UploadDoubleTableForm, self).write(result, errors)
- response['last_key'] = self['last_key']
- return response
+ response = super().write(result, errors)
+ return super().write_response(response)
# Utility functions
udl An UploadDataLine instance
'''
- raise core_ex.NotImplementedError
+ raise NotImplementedError
class NoOpProcessor(DataLineProcessor):
Return an instantiation of the upload form needed
by the upload handler.
'''
- raise core_ex.NotImplementedError
+ raise NotImplementedError
def get_data(self):
'''
Put something that will go into the db into the 'data' attribute.
'''
- raise core_ex.NotImplementedError
+ raise NotImplementedError
def val_input(self):
'''