Question

[background below] I've got my data modelled out in SQLObject in Python on the back-end. Right now I'm converting an SQLObject to a dict, and grabbing all the keys from the dict and then exporting that as a JSON document (so just a JavaScript array). I was planning on doing something like:

Spine.Model.extend({
    fromList: function(name, list){
        var model = Spine.Model.setup(name, list);
        return model;
    }
});

Is this a good idea? Does Spine already provide this functionality? Is this the best way to extend the Spine.Model class?

BACKGROUND:

So. I've got a Python application that I've been porting from a GUI app to a web app using Flask.

I'm to the point where I'm doing the view part and realized that it would make a lot of sense to use a JavaScript framework for manipulation of the data/controlling the app/etc.

After a bunch of research I've settled on Spine (the API made the most sense to me on the first read, plus the author wrote the O'Reilly book JavaScript Web Applications so there's a decent reference).

Since I've already got my data modelled out on the backend, I'd like to export that configuration and automate the creation of the Spine models using this so that the data they're recording is always in sync (this way if I change my back-end model, the front-end automatically changes at next page load).

Was it helpful?

Solution

It looks like you are thinking about dynamically creating models with client side JavaScript based on a model in your database with a python dictionary -> JSON as the linking representation between the two.

This sounds complicated and I really don't have an answer. It may even be unnecessarily complicated :), but that's for you to decide. I do however, have an alternative solution.

Why not generate the Spine models from Python dynamically and just serve the static files? Then all you have to do is write a python program that outputs valid code for a spine model in JavaScript or CoffeeScript (perhaps as part of your build process if models change often or simply as necessary during development).

Again, this may be unnecessarily complicated if you do not have a LARGE amount of models, that change regularly to generate. Even then perhaps all you need is a verification tool that verifies your backend data is modeled correctly in Spine, and just hand code everything. It's fairly easy to hand code the models to contain the data they need http://spinejs.com/docs/models

Really, setting up the actual "data" in the spine model is as simple as @configure "Contact", "first_name", "last_name" Now the spine model has a first_name and a last_name...

Make sure you didn't put on your Complicator Gloves, before you came up with this idea :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top