<commit_before><!-- copow / pythononwheels list view template -->
<!-- for scaffolding views -->
<!-- www.pythononwheels.org -->



{% extends "layouts/main_layout.html" %}

{# this will be rendered in the content block of main.html view view #}

{% block content %}
{% import atest.config.settings as settings %}
{% set model = result %}
{% set server = settings.base["server"] %}
{% set port  = settings.base["port"] %}

<script>
    $(document).ready(function(){
        // Handler for .ready() called.
        $('#test').click( function() {
            //alert($('#update_form').serializeJSON() );
            console.log("copow: serialized to json:")
            console.log($('#update_form').serializeJSON());
            console.log("copow: stringified & serialized to json:")
            console.log(JSON.stringify($('#update_form').serializeJSON()));
            $("#flash_message_div").toggle();
        });
        // see: http://api.jquery.com/jQuery.ajax/#jqXHR
        $('#submit').click( function() {
                $.ajax( 
                    {
                        type: 'PUT',
                        url: "/{{model.modelname}}/{{model._id}}",
                        // The key needs to match your method's input parameter (case-sensitive).
                        data: (JSON.stringify($('#create_form').serializeJSON())),
                        contentType: "application/json",
                        dataType: "json"
                    }
                )
                .done(function(msg) {
                    //alert( "success" );
                    console.log(msg);
                    //var payload = JSON.parse(msg.responseText);
                    console.log(msg["data"]);
                    $("#flash_message").text("sucess:" + msg["data"]);
                    $("#flash_message_div").attr("class",
                        "alert alert-success alert-dismissible"
                     );
                    $("#flash_message_div").show();

                })
                .fail(function( msg ) {
                    //alert( "error" );
                    console.log(msg);
                    var payload = JSON.parse(msg.responseText);
                    console.log(payload["data"]);
                    $("#flash_message").text("Error :" + payload["data"]);
                     $("#flash_message_div").attr("class",
                        "alert alert-danger alert-dismissible"
                     )
                    $("#flash_message_div").show();
                })
                .always(function() {
                    //alert( "complete" );
                    console.log("complete")
                });
        });
    });
</script>


    <div class="panel panel-default">
    <!-- Default panel contents -->
        <div class="panel-heading"><b> This is the create view: </b>
            <a href="/{{model.modelname}}">show {{model.modelname}} list</a>
        </div>
        
        <!-- an optional flash-message -->
        <div class="" role="alert"  style="display: none;" id="flash_message_div">
            <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">
                &times;</span><span class="sr-only">Close</span></button>
            <strong>Info:</strong> <span id="flash_message"></span>
        </div>

        <div class="panel-body">
            <p>&nbsp;</p>
            <form id="create_form" class="form-horizontal" role="form">
                {% for att in model.schema.keys() %}
                    <div class="form-group">
                        <label for="{{att}}" class="col-sm-2 control-label">{{att}}</label>
                        <div class="col-sm-8">
                                <input  type="text" 
                                        class="form-control" 
                                        name="{{att}}" 
                                        id="{{att}}" 
                                        value="{{model.get(att)}}"
                                        {% if att == "_id" or att=="last_updated" %}
                                            readonly
                                        {% end %}
                                        >
                        </div>
                    </div>
                {% end %}
                
            </form>
            
            <button id="test" class="btn btn-warning">Test</button>

            <button id="submit" class="btn btn-primary">Submit</button>

            {% module form_select(model=result, attribute="title") %}
            
            To get this by using curl just cut and paste the snippet below to the command line:
            <pre>
                <code>
                curl -i -X POST --data "id=1234"  --header "Content-Type:application/json"  http://{{server}}:{{port}}/{{result.modelname}}/{{result._id}}/update
                </code>
            </pre>
        </div>
    </div><commit_msg>tested the curl REST API for create and put an example in create_form. works fine<commit_after><!-- copow / pythononwheels list view template -->
<!-- for scaffolding views -->
<!-- www.pythononwheels.org -->



{% extends "layouts/main_layout.html" %}

{# this will be rendered in the content block of main.html view view #}

{% block content %}
{% import atest.config.settings as settings %}
{% set model = result %}
{% set server = settings.base["server"] %}
{% set port  = settings.base["port"] %}

<script>
    $(document).ready(function(){
        // Handler for .ready() called.
        $('#test').click( function() {
            //alert($('#update_form').serializeJSON() );
            console.log("copow: serialized to json:")
            console.log($('#update_form').serializeJSON());
            console.log("copow: stringified & serialized to json:")
            console.log(JSON.stringify($('#update_form').serializeJSON()));
            $("#flash_message_div").toggle();
        });
        // see: http://api.jquery.com/jQuery.ajax/#jqXHR
        $('#submit').click( function() {
                $.ajax( 
                    {
                        type: 'PUT',
                        url: "/{{model.modelname}}/{{model._id}}",
                        // The key needs to match your method's input parameter (case-sensitive).
                        data: (JSON.stringify($('#create_form').serializeJSON())),
                        contentType: "application/json",
                        dataType: "json"
                    }
                )
                .done(function(msg) {
                    //alert( "success" );
                    console.log(msg);
                    //var payload = JSON.parse(msg.responseText);
                    console.log(msg["data"]);
                    $("#flash_message").text("sucess:" + msg["data"]);
                    $("#flash_message_div").attr("class",
                        "alert alert-success alert-dismissible"
                     );
                    $("#flash_message_div").show();

                })
                .fail(function( msg ) {
                    //alert( "error" );
                    console.log(msg);
                    var payload = JSON.parse(msg.responseText);
                    console.log(payload["data"]);
                    $("#flash_message").text("Error :" + payload["data"]);
                     $("#flash_message_div").attr("class",
                        "alert alert-danger alert-dismissible"
                     )
                    $("#flash_message_div").show();
                })
                .always(function() {
                    //alert( "complete" );
                    console.log("complete")
                });
        });
    });
</script>


    <div class="panel panel-default">
    <!-- Default panel contents -->
        <div class="panel-heading"><b> This is the create view: </b>
            <a href="/{{model.modelname}}">show {{model.modelname}} list</a>
        </div>
        
        <!-- an optional flash-message -->
        <div class="" role="alert"  style="display: none;" id="flash_message_div">
            <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">
                &times;</span><span class="sr-only">Close</span></button>
            <strong>Info:</strong> <span id="flash_message"></span>
        </div>

        <div class="panel-body">
            <p>&nbsp;</p>
            <form id="create_form" class="form-horizontal" role="form">
                {% for att in model.schema.keys() %}
                    <div class="form-group">
                        <label for="{{att}}" class="col-sm-2 control-label">{{att}}</label>
                        <div class="col-sm-8">
                                <input  type="text" 
                                        class="form-control" 
                                        name="{{att}}" 
                                        id="{{att}}" 
                                        value="{{model.get(att)}}"
                                        {% if att == "_id" or att=="last_updated" %}
                                            readonly
                                        {% end %}
                                        >
                        </div>
                    </div>
                {% end %}
                
            </form>
            
            <button id="test" class="btn btn-warning">Test</button>

            <button id="submit" class="btn btn-primary">Submit</button>

            {% module form_select(model=result, attribute="title") %}
            
            To get this by using curl just cut and paste the snippet below to the command line:
            <pre>
                <code>
                curl -H "Content-Type: application/json" -X PUT -d '{"content": "ahahahah", "last updated": "2014/07/09 23:01:24", "_id": "53bdc9c4a00ca7060b5e907d", "author": "klaas", "title": "test for curl", "tags": "aha oho aha"}' http://localhost:8000/post/create
                
                This is just an example. Please check twice if your model really has the attributes above.
                It will work right away if you use the model post from the documentation.
                </code>
            </pre>
        </div>
    </div>
{'fraction_non_alphanumeric': 0.1538013399359161, 'fraction_numerical': 0.0038838722206039423, 'mean_word_length': 1.3192974555280341, 'pattern_counts': {'":': 6, '<': 99, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6860507', 'n_tokens_mistral': 2627, 'n_tokens_neox': 2421, 'n_words': 538}