def get(self, action=None, cid=-1, source=None): if action == "create": return flask.render_template("create_campaign.html", sources=miners.all_miner_info()) elif cid != -1 and not source: # a campaign view is requested campaign = flask.g.db.get_campaign(flask.session.get("user"), cid) if not campaign: flask.abort(404) tasks = flask.g.db.get_tasks(campaign["_id"]) data = flask.g.db.get_data(tasks) return flask.render_template("campaign.html", campaign=campaign, data=data) elif cid != -1 and source: # data from source of campaign is requested campaign = flask.g.db.get_campaign(flask.session.get("user"), cid) if not campaign: flask.abort(404) task = flask.g.db.get_campaign_task(source, campaign["_id"]) if not task: flask.abort(404) data = flask.g.db.get_data([task]) # hack to return csv data if flask.request.args.get("fmt") is not None: return self.fmt(source, data) else: return flask.render_template(source + ".html", campaign=campaign, data=data) else: campaigns = flask.g.db.list_campaigns(flask.session.get("user")) return flask.render_template("campaigns.html", campaigns=campaigns)
def get(self, action=None, cid=-1, source=None): if action == 'create': return flask.render_template("create_campaign.html", sources=miners.all_miner_info()) elif cid != -1 and not source: # a campaign view is requested campaign = flask.g.db.get_campaign(flask.session.get('user'), cid) if not campaign: flask.abort(404) tasks = flask.g.db.get_tasks(campaign['_id']) data = flask.g.db.get_data(tasks) return flask.render_template("campaign.html", campaign=campaign, data=data) elif cid != -1 and source: # data from source of campaign is requested campaign = flask.g.db.get_campaign(flask.session.get('user'), cid) if not campaign: flask.abort(404) task = flask.g.db.get_campaign_task(source, campaign['_id']) if not task: flask.abort(404) data = flask.g.db.get_data([task]) # hack to return csv data if flask.request.args.get('fmt') is not None: return self.fmt(source, data) else: return flask.render_template(source + ".html", campaign=campaign, data=data) else: campaigns = flask.g.db.list_campaigns(flask.session.get('user')) return flask.render_template("campaigns.html", campaigns=campaigns)
def create(self): """ Creates a new campaign. Expects sources to be a JSON string. Title and query are strings. """ sources = miners.all_miner_info() print sources campaign_req = set(["title"]) missing = {} params = {} for r in campaign_req: value = flask.request.form.get(r) if not value: missing[r] = "Required" params[r] = value # if missing: # return flask.render_template("create_campaigns.html", errs=missing) # find out if source in request. if so, check if required fields are included # and save as a task for this campaign tasks = [] source_req = set(["query", "frequency"]) for source in sources: fields = [x.split("_", 1)[1] for x in flask.request.form if x.split("_")[0] == source] print fields for r in source_req: if not r in fields: missing[source + "_" + r] = "Required" # attributes are not required, but if they're present must # check if source supports the attribute attrs = [x for x in fields if x not in source_req] for attr in attrs: if attr not in sources[source]: attrs.remove(attr) if flask.request.form.get(source + "_query") != "": # only create task if query not null tasks.append( { "name": source, "query": flask.request.form.get(source + "_query"), "frequency": flask.request.form.get(source + "_frequency"), "attributes": attrs, } ) desc = flask.request.form.get("description", "") flask.g.db.create_campaign(flask.session.get("user"), params["title"], tasks, description=desc) return flask.redirect(flask.url_for("index"))
def create(self): """ Creates a new campaign. Expects sources to be a JSON string. Title and query are strings. """ sources = miners.all_miner_info() print sources campaign_req = set(['title']) missing = {} params = {} for r in campaign_req: value = flask.request.form.get(r) if not value: missing[r] = 'Required' params[r] = value # if missing: # return flask.render_template("create_campaigns.html", errs=missing) # find out if source in request. if so, check if required fields are included # and save as a task for this campaign tasks = [] source_req = set(['query', 'frequency']) for source in sources: fields = [ x.split('_', 1)[1] for x in flask.request.form if x.split('_')[0] == source ] print fields for r in source_req: if not r in fields: missing[source + '_' + r] = 'Required' # attributes are not required, but if they're present must # check if source supports the attribute attrs = [x for x in fields if x not in source_req] for attr in attrs: if attr not in sources[source]: attrs.remove(attr) if flask.request.form.get( source + '_query') != '': # only create task if query not null tasks.append({ 'name': source, 'query': flask.request.form.get(source + '_query'), 'frequency': flask.request.form.get(source + '_frequency'), 'attributes': attrs }) desc = flask.request.form.get('description', '') flask.g.db.create_campaign(flask.session.get('user'), params['title'], tasks, description=desc) return flask.redirect(flask.url_for('index'))