def csvviresult(): global table # data = request.form['text'] # table = TableFu.from_file('app/vi-csv.csv') table = TableFu.from_file('app/vi-csv.csv') # return render_template('vi-template.html', table=table) return render_template('vi-template.html', table=table)
def test_set_columns(self): arra = TableFu.from_file(self.filename) arra.columns = ["State", "County", "Urban Area"] tabled = Table( title="That Stimulus", added_by=self.user, file=File(self.file), columns=["State", "County", "Urban Area"] ) tabled.save() self.assertEqual(arra.columns, tabled.data.columns)
def virtualissueautomate(): myDOIs = str(request.form["text"]).split('\r\n') # run python process createVI(myDOIs) global table # data = request.form['text'] table = TableFu.from_file('vi-csv.csv') return render_template('vi-template.html', table=table, results=results)
def podcastupload(): if request.method == 'POST': # Get the name of uploaded file file = request.files['file'] # Check if the file is an allowed extension if file and allowed_file(file.filename): # Make the filename safe - remove unsupported characters filename = secure_filename(file.filename) # # Move the file from the temp folder to the upload folder file.save(os.path.join(app.config["UPLOAD_FOLDER"], filename)) # Use tablefu to template out the uploaded CSV file global table table = TableFu.from_file('app/static/uploads/' + filename) return render_template('podcastresults.html', table=table)
def data_import(generator, content=None): if not content: # Then it's a page, not an article #pdb.set_trace() contents = getattr(generator, 'pages') else: # An article, so content is only one element # To make it work with pages (where content is an array) # we need to create an array contents = [content] for content_obj in contents: if hasattr(content_obj, 'data') and len(content_obj.data) > 0: # if isinstance(content.data, (str, basestring)): # make string into 1-item list # data = [content.data] # else: # data = content.data data = content_obj.data.split('|') #print data datatables = [] for d in data: logger.debug("Loading data <%s> for article %s" % (d, content_obj.slug)) #logger.debug(os.getcwd()) #pdb.set_trace() filepath = os.path.join(os.getcwd(), generator.settings['PATH'], generator.settings['DATA_PATH'], d) try: _data = TableFu.from_file(filepath) datatables.append(_data) #setattr(content, 'datatable', data) except: #raise logger.warn("Could not load data file for %s: %s" % (content_obj.slug, filepath)) setattr(content_obj, 'datatables', datatables) elif hasattr(content_obj, 'mapdata') and len(content_obj.mapdata) > 0: # If mapdata but no data, add empty datatables object so that # figure titles and captions will work datatable = {'rows': [], 'columns': []} setattr(content_obj, 'datatables', [datatable])
def facet(starter, *facets): table = TableFu.from_file(starter) out_dir = os.path.dirname(starter) files = [] for f in facets: try: tables = table.facet_by(f) except KeyError: sys.stderr.write('Bad column name: %s\n' % f) sys.stderr.write('Available columns: %s\n\n' % ', '.join(table.columns)) continue for t in tables: out = open(os.path.join(out_dir, '%s.csv' % t.faceted_on), 'wb') out.write(t.csv().getvalue()) out.close() files.append(out.name) return files
def data(self): """Return a TableFu instance with data for this model""" if hasattr(self, '_data') and self._data is not None: return self._data if self.file: # this gets wrapped in a with block for cleanliness d = TableFu.from_file(self.file.path) elif self.url: d = TableFu.from_url(self.url) else: return None if self.columns: d.columns = self.columns self._data = d return self._data
def podcastresult(): global table table = TableFu.from_file('app/chembio.csv') return render_template('podcastresultsnano.html', table=table)
def test_from_file(self): t1 = TableFu.from_file('tests/arra.csv') t2 = TableFu(open('tests/arra.csv')) self.assertEqual(t1.table, t2.table)
def test_from_file(self): arra = TableFu.from_file(self.filename) tabled = Table(title="That Stimulus", added_by=self.user, file=File(self.file)) tabled.save() self.assertEqual(arra.table, tabled.data.table)