SachaG/Telescope — pull request #28 by lyudmil (2012-11-13 21:27:48+00:00)
Title: Cleaning up the settings form code

Hey Sacha,

I think I'm done with my first task on Telescope.

So, what I understood the task to be was not only go generate the HTML for the form using `jsonform`, but also to clean up the code that saves and updates the settings.

I managed to make things a lot less verbose by adopting a bunch of conventions.

First, I created a `Setting` model to represent the schema of the documents we will be storing in `Settings`.

Then, I built a class that takes such an object and generates a form for each of its fields with sane defaults (`Boolean` fields become checkboxes, `String` fields become input fields). This form object has a `submit` method, which uses the conventions set up by `jsonform` to find the form element that was generated for this field to grab the appropriate value from the form and set it on the model. Once the model contains the values from the form, I just pass it on to Mongo and it saves or updates it for me.

There's some magic, but I think overall the code is better. Take a look and let me know if it works, if you want me to change anything, etc.

Thanks,
Lyudmil

P. S. That was fun.