def render_rules(): app.logger.info('Rendering rules.') from flask import current_app sbuffer = Rule.renderall() fpath = current_app.config['RENDERED_RULES_PATH'] with open(fpath, 'w') as rfile: rfile.write(sbuffer) app.logger.info('Finished rendering rules.')
def get_rules(): # Getting active rules. if request.args.get("plaintext") in ["1", "true"]: # Requested rendered rules in plaintext. resp = make_response(Rule.renderall()) resp.headers["Content-Disposition"] = "attachment; filename=mhn.rules" return resp else: # Responding with active rules. rules = Rule.query.filter_by(is_active=True).group_by(Rule.sid).having(func.max(Rule.rev)) resp = make_response(json.dumps([ru.to_dict() for ru in rules])) resp.headers["Content-Type"] = "application/json" return resp
def get_rules(): # Getting active rules. if request.args.get('plaintext') in ['1', 'true']: # Requested rendered rules in plaintext. resp = make_response(Rule.renderall()) resp.headers['Content-Disposition'] = "attachment; filename=mhn.rules" return resp else: # Responding with active rules. rules = Rule.query.filter_by(is_active=True).\ group_by(Rule.sid).\ having(func.max(Rule.rev)) resp = make_response(json.dumps([ru.to_dict() for ru in rules])) resp.headers['Content-Type'] = "application/json" return resp