Example #1
0
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)
Example #2
0
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")
Example #3
0
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')
Example #5
0
 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')
Example #8
0
 def get_schema(self):
     from rerodoc.dojson.utils import get_schema
     return get_schema('institution', 'common')
Example #9
0
 def get_schema(self):
     from rerodoc.dojson.utils import get_schema
     return get_schema('subject', 'common')
Example #10
0
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)),
    )
Example #11
0
 def test_get_wrong_schema(self):
     from rerodoc.dojson.utils import get_schema
     assert get_schema("not_exists") == None
Example #12
0
def get_schema(base, name):
    from rerodoc.dojson.utils import get_schema

    schema = get_schema(name, base)
    return jsonify(schema)
Example #13
0
 def get_schema(self):
     from rerodoc.dojson.utils import get_schema
     return get_schema('isbn10', 'book')
Example #14
0
 def get_schema(self):
     from rerodoc.dojson.utils import get_schema
     return get_schema('external_link', 'common')
Example #15
0
    def get_schema(self):
        from rerodoc.dojson.utils import get_schema

        return get_schema("title", "common")
Example #16
0
 def get_schema(self):
     from rerodoc.dojson.utils import get_schema
     return get_schema('document_type', 'common')
Example #17
0
 def get_schema(self):
     from rerodoc.dojson.utils import get_schema
     return get_schema('meeting', 'common')
Example #18
0
 def get_schema(self):
     from rerodoc.dojson.utils import get_schema
     return get_schema('authors', 'common')
Example #19
0
 def get_schema(self):
     from rerodoc.dojson.utils import get_schema
     return get_schema('other_edition', 'common')
Example #20
0
 def get_schema(self):
     from rerodoc.dojson.utils import get_schema
     return get_schema('keyword', 'common')