def evaluate(request): """Method which will evaluate a formed rule given in the GET request. It will return a JSONResponse with the result of the evaluation.""" try: ruleexpr = request.GET.get('rule').strip() rule = Rule(ruleexpr) result = rule.evaluate({}) return JSONResponse(True, result, {"msg": rule.msg}) except: msg = "Can not evaluate rule '%s'" % ruleexpr log.error(msg) return JSONResponse(False, False, {"msg": msg})
def mapdata(request): """Will return the track data of the activity as Geojson.""" item = get_item_from_request(request) if item.has_streams: gj = a2gj(item) else: gj = {} return JSONResponse(True, gj)
def rest_read(request, callback=None): """Base method to handle read requests on the REST interface. Returns a JSON object of a specific item. :request: Current request :callback: Current function which is called after the item has been read. :returns: JSON object. """ handle_callback(request, callback, mode="pre,default") return JSONResponse(True, get_item_from_request(request))
def rest_list(request): """Returns a JSON objcet with all item of a clazz. The list does not have any capabilities for sorting or filtering :request: Current request. :returns: JSON object. """ clazz = request.context.__model__ listing = get_item_list(request, clazz, user=request.user) return JSONResponse(True, listing)
def rest_delete(request, callback=None): """Deletes an item of type clazz. The item is deleted based on the unique id value provided in the matchtict object in the current DELETE request. The data will be deleted without any futher confirmation! :clazz: Class of item to delete :request: Current request :returns: JSON object. """ item = get_item_from_request(request) request.db.delete(item) return JSONResponse(True, item)
def rest_update(request, callback=None): """Updates an item of type clazz. The item is loaded based on the unique id value provided in the matchtict object in the current request. The item will be updated with the data submitted in the current PUT request. Before updating the item the data will be validated against the "update" form of the item. If the validation fails the item will not be updated. In all cases the item is return as JSON object with the item and updated values back to the client. The JSON Response will include further details on the reason why the validation failed. :request: Current request :returns: JSON object. """ item = get_item_from_request(request) form = get_item_form('update', request) if form.validate(request.params): item.save(form.data, request) return JSONResponse(True, item) else: # Validation fails! return item return JSONResponse(False, item)
def render(request): """Will return a JSONResponse with a rendererd form. The form defintion and the formid is provided in the POST request.""" _ = request.translate form_config = request.POST.get("definition") config_name = request.POST.get("formid") out = [] try: config = Config(parse(form_config)) form_config = config.get_form(config_name) form = Form(form_config, None, request.db, csrf_token=request.session.get_csrf_token()) out.append(form.render(buttons=False, outline=False)) except Exception as ex: out.append(_('ERROR: %s' % str(ex))) data = {"form": "".join(out)} return JSONResponse(True, data, {"msg": "Ole!"})
def keepalive(request): """Endpoint for simple requests to trigger refreshing the logouttimer""" return JSONResponse(True, "I'm alive!", {})