def create_view(self, cls, add_filters, name, label, dimension, breakdown=None, view_filters={}): '''\ Create a view. The view will be computed when you call :meth:`finalize`. ``cls`` A model class (inheriting from :class:`openspending.model.Base`) ``add_filters`` A :term:`mongodb query spec` used as a query to select the instances of *cls* that will be used for the view. ``name`` A name for the view. This name must be unique for all views for *cls* in an Open Spending site. ``label`` A label that can be displayed to the user. ``dimensions`` The dimensions that will be used to compute the view ``breakdown`` ... ``view_filters`` ... Returns: A :class:`openspending.lib.views.View` object. ''' log.debug("pre-aggregating view %s on %r where %r", name, cls, view_filters) view = View(self.dataset, name, label, dimension, breakdown, cuts=view_filters) view.apply_to(cls, add_filters) view.compute() Dataset.c.update({'name': self.dataset.name}, {'$set': {'cubes': self.dataset.get('cubes', {})}}) self.dataset = Dataset.by_id(self.dataset.name) return view
def report(): dataset_id = request.args.get("id", None) if not dataset_id: raise dataset = Dataset.by_id(dataset_id) if not dataset: raise lr = LoadReport(dataset) return Response(lr.get_output(), mimetype='application/zip', headers={'Content-Disposition':'attachment;filename=%s.zip'%dataset.name})
def report(): dataset_id = request.args.get("id", None) if not dataset_id: raise dataset = Dataset.by_id(dataset_id) if not dataset: raise lr = LoadReport(dataset) return Response(lr.get_output(), mimetype='application/zip', headers={ 'Content-Disposition': 'attachment;filename=%s.zip' % dataset.name })
def reload_all(**args): """Reload all sources with mapping. This will take a while""" datasets = Dataset.all().all() ids = [] for dataset in datasets: ids.append(dataset.id) total = 0 ran = 0 for id in ids: dataset = Dataset.by_id(id) total += 1 #has mapping and source if dataset.mapping and dataset.source: print "working on ", dataset load_source(dataset.source.id) ran += 1 print "Ran", ran, "out of", total
def reload_all(**args): """Reload all sources with mapping. This will take a while""" datasets = Dataset.all().all() ids = [] for dataset in datasets: ids.append(dataset.id) total = 0 ran = 0 for id in ids: dataset = Dataset.by_id(id) total +=1 #has mapping and source if dataset.mapping and dataset.source: print "working on ", dataset load_source(dataset.source.id) ran +=1 print "Ran", ran, "out of", total