Git Product home page Git Product logo

django-yamlfield's Introduction

Yb  dP    db    8b    d8 88     888888 88 888888 88     8888b.
 YbdP    dPYb   88b  d88 88     88__   88 88__   88      8I  Yb
  8P    dP__Yb  88YbdP88 88  .o 88""   88 88""   88  .o  8I  dY
 dP    dP""""Yb 88 YY 88 88ood8 88     88 888888 88ood8 8888Y"  

A Django database field for storing YAML data

Build Status PyPI version Coverage Status

YamlField in Templates

By default, YamlField returns the contents as an OrderedDitc. To display a yamlfield in a template as text, use the template filter as_text::

{% load yamltags %}

 <textarea name="settings">{{ object.settings|as_text }}</textarea>

To edit with the Ace Editor::

<textarea name="settings" id="id_settings" style="display:none;">{{ object.settings|as_text }}</textarea>
<div id="ace_settings"></div>

To setup Ace Editor (see more here: https://ace.c9.io/)::

  <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.6/ace.js" type="text/javascript" charset="utf-8"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.6/mode-yaml.js" type="text/javascript" charset="utf-8"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.6/theme-github.js" type="text/javascript" 
  
  <script>
    var options = {
      theme: "ace/theme/github",
      mode: "ace/mode/yaml",
      maxLines: 10,
      minLines: 6,
      wrap: true,
      autoScrollEditorIntoView: true
  };

  // setup ace editor to edit yaml contents
  // put editor in a div and sync changes in the div back to the hidden textarea

  var edit_settings = ace.edit("ace_settings",options);
  edit_settings.session.setValue($("#id_settings").val());
  edit_settings.getSession().on("change", function () {
      $("#id_settings").val(edit_settings.getSession().getValue());
  });
  
  
  // on submit make sure textarea is up to date
  $('form').on("submit", function() {

	   $("#id_settings").val(edit_settings.getSession().getValue());

  });
  
</script>

django-yamlfield's People

Contributors

btubbs avatar drmeers avatar glow-mdsol avatar palewire avatar phoebebright avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.