# Setup default values for forms.
class UserInitialPost():
- db = LIVE_DB
- user = ''
- password = ''
+ db = LIVE_DB
+ user = ''
+ password = ''
class AuthInitialPost():
- db = ''
- user = ''
- password = ''
+ db = ''
+ user = ''
+ password = ''
class UploadFileInitialPost(AuthInitialPost):
- upload_fmt = CSV
- datafile = ''
+ upload_fmt = CSV
+ datafile = ''
trim_upload = True
class UploadNullFileInitialPost(UploadFileInitialPost):
upload_null = True
- null_rep = ''
+ null_rep = ''
class UploadTableInitialPost(UploadNullFileInitialPost):
- table = ''
+ table = ''
# The wtforms that suck data out of the html.
# We don't actually use the labels, wanting the template to
# look (and render) like html, but I'll define them anyway
# just to keep my hand in.
- user = StringField('User:')
- password = PasswordField('Password:')
+ user = StringField('User:')
+ password = PasswordField('Password:')
- ivals = UserInitialPost
+ ivals = UserInitialPost
class AuthWTForm(UserWTForm):
# We don't actually use the labels, wanting the template to
# look (and render) like html, but I'll define them anyway
# just to keep my hand in.
- db = StringField('Database:')
+ db = StringField('Database:')
- ivals = AuthInitialPost
+ ivals = AuthInitialPost
class UploadFileWTForm(AuthWTForm):
# We don't actually use the labels, wanting the template to
# look (and render) like html, but I'll define them anyway
# just to keep my hand in.
- upload_fmt = RadioField('Upload Format:',
- choices=[('Upload CSV Data:', CSV),
- ('Upload tab delimited Data:', TAB)])
- datafile = FileField('File with CSV or Tab delimited Data:')
- trim_upload = BooleanField('Trim Leading/Trailing Spaces:')
+ upload_fmt = RadioField('Upload Format:',
+ choices=[('Upload CSV Data:', CSV),
+ ('Upload tab delimited Data:', TAB)])
+ datafile = FileField('File with CSV or Tab delimited Data:')
+ trim_upload = BooleanField('Trim Leading/Trailing Spaces:')
- ivals = UploadFileInitialPost
+ ivals = UploadFileInitialPost
class UploadNullFileWTForm(UploadFileWTForm):
# We don't actually use the labels, wanting the template to
# look (and render) like html, but I'll define them anyway
# just to keep my hand in.
- upload_null = BooleanField('Upload NULL Values:')
- null_rep = StringField('NULL Representation:')
+ upload_null = BooleanField('Upload NULL Values:')
+ null_rep = StringField('NULL Representation:')
- ivals = UploadNullFileInitialPost
+ ivals = UploadNullFileInitialPost
class UploadTableWTForm(UploadNullFileWTForm):
'''The wtform used for uploading arbitrary data into tables.'''
- table = StringField('Table or View:')
+ table = StringField('Table or View:')
- ivals = UploadTableInitialPost
+ ivals = UploadTableInitialPost
class LoadedForm(collections.MutableMapping):
self._store = store
self._fc = fc
- def __iter__(self): return next(self._store)
- def __len__(self): return len(self._store)
- def __getitem__(self, key): return self._store[key]
- def __setitem__(self, key, value): self._store[key] = value
- def __delitem__(self, key): del self._store[key]
+ def __iter__(self):
+ return next(self._store)
+
+ def __len__(self):
+ return len(self._store)
+
+ def __getitem__(self, key):
+ return self._store[key]
+
+ def __setitem__(self, key, value):
+ self._store[key] = value
+
+ def __delitem__(self, key):
+ del self._store[key]
def read(self):
'''
super(AuthLoadedForm, self).read()
# Keep form variables handy
- self['db'] = self._form.db.data
+ self['db'] = self._form.db.data
def write(self, result, errors):
Produces the dict pyramid will use to render the form.
'''
response = super(AuthLoadedForm, self).write(result, errors)
- response['db'] = self['db']
+ response['db'] = self['db']
return response
super(UploadFileForm, self).read()
# Read our own data
- self['upload_fmt'] = self._form.upload_fmt.data
- self['trim_upload'] = self._form.trim_upload.data
+ self['upload_fmt'] = self._form.upload_fmt.data
+ self['trim_upload'] = self._form.trim_upload.data
# Other POST variables involving a file
self['filename'] = ''
if self._form.datafile.data != '':
post = self.uh.request.POST
if hasattr(post['datafile'], 'filename'):
- self['filename'] = post['datafile'].filename
+ self['filename'] = post['datafile'].filename
if hasattr(post['datafile'], 'file'):
- self['localfh'] = post['datafile'].file
+ self['localfh'] = post['datafile'].file
def write(self, result, errors):
trim_upload_checked = UNCHECKED
response = super(UploadFileForm, self).write(result, errors)
- response['filename'] = self['filename']
+ response['filename'] = self['filename']
response['trim_upload'] = trim_upload_checked
- response['csv_value'] = CSV_VALUE
- response['tab_value'] = TAB_VALUE
+ response['csv_value'] = CSV_VALUE
+ response['tab_value'] = TAB_VALUE
response['csv_checked'] = csv_checked
response['tab_checked'] = tab_checked
return response
# Read our own data
post = self.uh.request.POST
if 'last_key' in post:
- self['last_key'] = post['last_key']
+ self['last_key'] = post['last_key']
else:
- self['last_key'] = ''
+ self['last_key'] = ''
def write(self, result, errors):
'''
Produces the dict pyramid will use to render the form.
'''
response = super(UploadDoubleFileForm, self).write(result, errors)
- response['last_key'] = self['last_key']
+ response['last_key'] = self['last_key']
return response
super(UploadNullFileForm, self).read()
# Read our own data
- self['upload_null'] = self._form.upload_null.data
- self['null_rep'] = self._form.null_rep.data
+ self['upload_null'] = self._form.upload_null.data
+ self['null_rep'] = self._form.null_rep.data
def write(self, result, errors):
upload_null_checked = UNCHECKED
response = super(UploadNullFileForm, self).write(result, errors)
- response['upload_null'] = upload_null_checked
- response['null_rep'] = self['null_rep']
+ response['upload_null'] = upload_null_checked
+ response['null_rep'] = self['null_rep']
return response
super(UploadTableForm, self).read()
# Read our own data
- self['table'] = self._form.table.data
+ self['table'] = self._form.table.data
def write(self, result, errors):
Produces the dict pyramid will use to render the form.
'''
response = super(UploadTableForm, self).write(result, errors)
- response['table'] = self['table']
+ response['table'] = self['table']
return response
# Read our own data
post = self.uh.request.POST
if 'last_key' in post:
- self['last_key'] = post['last_key']
+ self['last_key'] = post['last_key']
else:
- self['last_key'] = ''
+ self['last_key'] = ''
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']
+ response['last_key'] = self['last_key']
return response
request A pyramid request instance
'''
super(DBHandler, self).__init__()
- self.request = request
- self.uf = self.make_form()
+ self.request = request
+ self.uf = self.make_form()
def make_form(self):
'''
try:
conn = psycopg2.connect(
database = self.db,
- user = self.user,
+ user = self.user,
password = self.password,
- host = registry.settings['pg_host'],
- port = registry.settings['pg_port'])
+ host = registry.settings['pg_host'],
+ port = registry.settings['pg_port'])
except psycopg2.OperationalError:
errors = [self.authfailerror_factory()]
havecreds = False