def post_data(): title = request.form["plottitle"] type = request.form["plottype"] var_list = request.form["varlist"] var_type = json.loads(request.form["vartype"]) # ensure var_type is a list if isinstance(var_type, basestring): var_type = [var_type] var_names = json.loads(request.form["varnames"]) # ensure var_names is a list if isinstance(var_names, basestring): var_names = [var_names] d3params = request.form["d3Params"] obj = HealthVis( type=type, title=title, var_type=var_type, var_names=var_names, var_list=var_list, d3params=d3params ) memcache_key = "hm_%d" % uuid4() try: res = memcache.set(key=memcache_key, value=obj) except: return "error" if res: return memcache_key try: obj.put() except: return "error" return "hs_%d" % obj.key().id()
def post_data(): title = request.form['plottitle'] type = request.form['plottype'] var_list = request.form['varlist'] var_type = json.loads(request.form['vartype']) var_names = json.loads(request.form['varnames']) d3params = request.form['d3Params'] obj = HealthVis(type=type, title=title, var_type=var_type, var_names=var_names, var_list=var_list, d3params=d3params) memcache_key='hm_%d' % uuid4() try: res=memcache.set(key=memcache_key, value=obj) except: return "error" if res: return memcache_key try: obj.put() except: return "error" return 'hs_%d' % obj.key().id()
def display(id): obj = HealthVis.get_by_id(id) if obj is None: return render_template("500.html") form = generate_form(obj) if obj.type not in supported_types: return render_template("500.html") return render_template("base.html", obj=obj, form=form)
def post_data(): title = request.form['plottitle'] type = request.form['plottype'] var_list = request.form['varlist'] var_type = json.loads(request.form['vartype']) var_names = json.loads(request.form['varnames']) d3params = request.form['d3Params'] obj = HealthVis(type=type, title=title, var_type=var_type, var_names=var_names, var_list=var_list, d3params=d3params) try: obj.put() except: return "error" return str(obj.key().id())
def save(id): obj = HealthVis.get_by_id(id) if obj is None: return render_template("500.html") obj.saved = True try: obj.put() except: return render_template("500.html") return redirect(url_for('display', id=id))
def remove_unsaved(): now = datetime.now() objs = HealthVis.all().filter("saved =", False) for obj in objs: if (obj.timestamp - now) < timedelta(hours=6): continue try: obj.delete() except: logging.info("Couldn't delete object " + str(obj)) continue
def find_object(id): # parse id to see if the object is in memcache or datastore m = re.search(r"h(s|m)_(\d+)", id) if m is None: return None storeid = int(m.group(2)) obj = None if m.group(1) == 's': # object stored in datastore obj = HealthVis.get_by_id(storeid) elif m.group(1) == 'm': # object in memcache obj = memcache.get(id) else: return None return obj
def find_object(plotid): # parse id to see if the object is in memcache or datastore m = re.search(r"h(s|m)_(\d+)", plotid) if m is None: return None storeid = int(m.group(2)) obj = None if m.group(1) == "s": # object stored in datastore obj = HealthVis.get_by_id(storeid) elif m.group(1) == "m": # object in memcache obj = memcache.get(plotid) else: return None return obj
def get_params(id): obj = HealthVis.get_by_id(id) if obj is None: return render_template("500.html") return obj.d3params