-# Copyright (C) 2020 The Meme Factory, Inc. http://www.karlpinc.com/
+# Copyright (C) 2020, 2021 The Meme Factory, Inc. http://www.karlpinc.com/
# This file is part of PGWUI_Upload_Core.
#
# Karl O. Pinc <kop@karlpinc.com>
from pgwui_common import checkset
+from pgwui_upload_core import exceptions as upload_core_ex
UPLOAD_SETTINGS = ['menu_label',
'literal_column_headings',
'trim',
'null',
+ 'file_format'
]
REQUIRED_SETTINGS = []
BOOLEAN_SETTINGS = []
'null']
+def validate_file_format(component, errors, settings):
+ '''Make sure the values are those allowed
+ '''
+ value = settings.get('file_format')
+ if value not in ('csv', 'tab'):
+ errors.append(
+ upload_core_ex.BadFileFormatError(component, value))
+
+
def check_settings(
component, all_setngs, required_setngs, boolean_setngs,
boolean_choice_setngs, component_config):
-# Copyright (C) 2020 The Meme Factory, Inc. http://www.karlpinc.com/
+# Copyright (C) 2020, 2021 The Meme Factory, Inc. http://www.karlpinc.com/
# This file is part of PGWUI_Upload.
#
pass
+class BadFileFormatError(UploadError):
+ def __init__(self, component, value):
+ super().__init__(
+ f'The "pgwui:{component}:file_format" PGWUI setting is ({value}) '
+ 'it must be either "csv" or "tab" or the setting be omitted')
+
+
class NoTableError(UploadError):
'''No table uploaded'''
def __init__(self, e, descr='', detail=''):
-# Copyright (C) 2015, 2018, 2020 The Meme Factory, Inc.
+# Copyright (C) 2015, 2018, 2020, 2021 The Meme Factory, Inc.
# http://www.karlpinc.com/
# This file is part of PGWUI_Upload_Core.
UploadData,
doublequote,
)
+from pgwui_core.constants import (
+ CSV,
+ TAB,
+)
from pgwui_upload_core import exceptions as upload_ex
# otherwise the result is never displayed on the page.
return (val == 'yes-always' or val == 'choice-yes')
+ def find_upload_fmt(self, upload_settings):
+ if upload_settings['file_format'] == 'csv':
+ return CSV
+ else:
+ return TAB
+
def build(self, settings={}):
super().build(settings)
upload_settings = settings['pgwui'][self.component]
+ self.upload_fmt = self.find_upload_fmt(upload_settings)
self.upload_null = self.boolean_choice(upload_settings, 'null')
self.trim_upload = self.boolean_choice(upload_settings, 'trim')
self.literal_col_headings = self.boolean_choice(