def json_editor(): from rerodoc.dojson.utils import get_schema schema = get_schema("book") return """ <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>JSON Editor to Test Submission</title> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"> <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css"> <script src="/static/bower_components/json-editor/dist/jsoneditor.js"></script> </head> <style type='text/css'> body { width: 960px; margin: auto auto; } </style> <body> <h1>Basic JSON Editor Example</h1> <div id='editor_holder'></div> <button id='submit'>Submit (console.log)</button> <script> // Initialize the editor with a JSON schema var editor = new JSONEditor(document.getElementById('editor_holder'),{ ajax: true, theme: 'bootstrap3', iconlib: 'fontawesome4', //disable_collapse: true, disable_edit_json: true, disable_properties: true, schema: { "title": "Choose", "oneOf": [ %s, { $ref: "static/simple-0.0.1.json", title: "Title Only" } ] }, // Disable additional properties no_additional_properties: true, // Require all properties by default required_by_default: true }); </script> </body> </html> """ % json.dumps(schema, indent=2)
def validate(record, schema_name="book"): """Record validation with a given schema.""" from jsonschema import validate from rerodoc.dojson.utils import get_schema schema = get_schema(schema_name) try: validate(record, schema) except: print("Error cannot validate")
def book_schema(): """Session-wide book schema.""" from rerodoc.dojson.utils import get_schema return get_schema("book")
def get_schema(self): from rerodoc.dojson.utils import get_schema return get_schema('access_restriction', 'common')
def get_schema(self): from rerodoc.dojson.utils import get_schema return get_schema('content_note', 'common')
def get_schema(self): from rerodoc.dojson.utils import get_schema return get_schema('publication_date', 'common')
def get_schema(self): from rerodoc.dojson.utils import get_schema return get_schema('submission_number', 'common')
def get_schema(self): from rerodoc.dojson.utils import get_schema return get_schema('institution', 'common')
def get_schema(self): from rerodoc.dojson.utils import get_schema return get_schema('subject', 'common')
def edit_angular(doc_type, recid): from rerodoc.dojson.utils import get_schema, get_form schema = get_schema(doc_type, doc_type) form = get_form(doc_type, doc_type) import json return """ <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>JSON Editor to Test Submission</title> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css"> <script type="text/javascript" src="/static/bower_components/angular/angular.min.js"></script> <script type="text/javascript" src="/static/bower_components/angular-sanitize/angular-sanitize.min.js"></script> <script type="text/javascript" src="/static/bower_components/tv4/tv4.js"></script> <script type="text/javascript" src="/static/bower_components/objectpath/lib/ObjectPath.js"></script> <script type="text/javascript" src="/static/bower_components/angular-schema-form/dist/schema-form.min.js"></script> <script type="text/javascript" src="/static/bower_components/angular-schema-form/dist/bootstrap-decorator.min.js"></script> <script type="text/javascript" src="/static/bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script> <script type="text/javascript" src="/static/bower_components/angular-uuid/uuid.min.js"></script> <script type="text/javascript" src="/static/bower_components/angular-jsonrpc/jsonrpc.js"></script> <script type="text/javascript" src="/static/js/app.js"></script> <script type="text/javascript" src="/static/js/services/data.js"></script> <script type="text/javascript" src="/static/js/directives/typeahead.js"></script> <script type="text/javascript" src="/static/js/controllers/autocomplete.js"></script> </head> <style type='text/css'> body { max-width: 960px; padding: 100px; margin: auto auto; } .autocomplete .dropdown-menu { max-height: 200px; overflow-y: scroll; } </style> <body ng-app="test"> <h1>Angular JSON Editor Example</h1> <div ng-controller="MyFormController"> <form sf-schema="schema" sf-form="form" sf-model="model"></form> </div> <script> app.controller('MyFormController', function($scope) { $scope.schema =%s; $scope.form = %s; $scope.model = %s; }); </script> </body> </html> """ % ( json.dumps(schema, indent=2), json.dumps(form, indent=2), json.dumps(get_record(recid)), )
def test_get_wrong_schema(self): from rerodoc.dojson.utils import get_schema assert get_schema("not_exists") == None
def get_schema(base, name): from rerodoc.dojson.utils import get_schema schema = get_schema(name, base) return jsonify(schema)
def get_schema(self): from rerodoc.dojson.utils import get_schema return get_schema('isbn10', 'book')
def get_schema(self): from rerodoc.dojson.utils import get_schema return get_schema('external_link', 'common')
def get_schema(self): from rerodoc.dojson.utils import get_schema return get_schema("title", "common")
def get_schema(self): from rerodoc.dojson.utils import get_schema return get_schema('document_type', 'common')
def get_schema(self): from rerodoc.dojson.utils import get_schema return get_schema('meeting', 'common')
def get_schema(self): from rerodoc.dojson.utils import get_schema return get_schema('authors', 'common')
def get_schema(self): from rerodoc.dojson.utils import get_schema return get_schema('other_edition', 'common')
def get_schema(self): from rerodoc.dojson.utils import get_schema return get_schema('keyword', 'common')