class BulkTaskImportForm(Form): csv_url = TextField('CSV URL', [ validators.Required(message="You must " "provide a URL"), validators.URL(message="Oops! That's not a" "valid URL. You must provide a valid URL") ])
class BulkTaskCSVImportForm(BulkTaskImportForm): msg_required = lazy_gettext("You must provide a URL") msg_url = lazy_gettext("Oops! That's not a valid URL. " "You must provide a valid URL") csv_url = TextField(lazy_gettext('URL'), [ validators.Required(message=msg_required), validators.URL(message=msg_url) ]) template_id = "csv" form_id = "csvform" form_detector = "csv_url" def get_data_url(self, form): return form.csv_url.data def tasks(self, form): dataurl = self.get_data_url(form) r = requests.get(dataurl) return self.get_csv_data_from_request(r)
class BulkTaskGDImportForm(BulkTaskImportForm): msg_required = lazy_gettext("You must provide a URL") msg_url = lazy_gettext("Oops! That's not a valid URL. " "You must provide a valid URL") googledocs_url = TextField(lazy_gettext('URL'), [ validators.Required(message=msg_required), validators.URL(message=msg_url) ]) template_id = "gdocs" form_id = "gdform" form_detector = "googledocs_url" def get_data_url(self, form): return ''.join([form.googledocs_url.data, '&output=csv']) def tasks(self, form): dataurl = self.get_data_url(form) r = requests.get(dataurl) return self.get_csv_data_from_request(r) @property def variants(self): return [("-".join([self.template_id, mode])) for mode in googledocs_urls.keys()]