Coder Social home page Coder Social logo

djpl-schnippjs's Introduction

djpl-schnippjs

A django_productline feature integrating schnipp-js. Hooks the schnipp-js javascript framework into your media_includes.html and provides a model to schnippform schema translation which generates a form schema from your django model.

Installation

  1. pip install - e git+https://github.com/tonimichel/djpl-schnippjs.git#djpl-schnippjs.git.

Generating schnippforms

Let's consider a simple example. Imagine your project consists of a News feature providing a News model. The frontend is fully javascript. As we need a programmtic form api and some MVC in our frontend code we decide to use schnippjs. Instead of declaring the form schema manually we just can convert our models to a schnippform schema and pass them to the template.

from django.shortcuts import render
from schnippjs.schnippforms import converter
from testproduct.models import News, Category
import json


def myview(request, id):

    n = News.objects.get(pk=id)
    form_schema = converter.form_for_model(n, fields=['name', 'category', 'teaser'], name='myform')
    form_context = converter.object_to_context(n)

    return render(request, 'testing.html', {
        'schema': json.dumps(form_schema),
        'context': json.dumps(form_context)
    })
$(function() {
    var form = schnipp.dynforms.form({{ schema|safe }}, {{ context|safe }});
    $('#b').append(form.render())
    form.initialize()

})

Take a look at the testproduct in products/testproduct for a complete example.

djpl-schnippjs's People

Contributors

henzk avatar tonimichel 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.