Scott Baker | 566f34d | 2014-11-11 17:10:16 -0800 | [diff] [blame] | 1 | import os |
| 2 | import sys |
Scott Baker | 1af3d5c | 2015-02-04 17:07:56 -0800 | [diff] [blame] | 3 | XOS_DIR="/opt/xos" |
| 4 | os.chdir(XOS_DIR) |
| 5 | sys.path.append(XOS_DIR) |
Scott Baker | 76a840e | 2015-02-11 21:38:09 -0800 | [diff] [blame] | 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings") |
Scott Baker | 566f34d | 2014-11-11 17:10:16 -0800 | [diff] [blame] | 7 | import django |
| 8 | import core.models |
| 9 | from django.db import models |
| 10 | django.setup()
|
| 11 | from django.forms.models import model_to_dict |
| 12 | import inspect |
| 13 | from django.core import serializers |
| 14 | import json |
| 15 | |
Scott Baker | a34d8c4 | 2014-11-11 18:02:35 -0800 | [diff] [blame] | 16 | print "function xos_get_defaults() {" |
Scott Baker | 566f34d | 2014-11-11 17:10:16 -0800 | [diff] [blame] | 17 | |
| 18 | for c in dir(core.models): |
| 19 | c = getattr(core.models,c) |
| 20 | if inspect.isclass(c) and issubclass(c, models.Model): |
| 21 | c=c() |
| 22 | classname = c.__class__.__name__ |
| 23 | classname = classname[0].lower() + classname[1:] |
| 24 | |
| 25 | if (classname in ["plCoreBase", "singletonModel"]): |
| 26 | continue |
| 27 | |
| 28 | fieldNames = [f.name for f in c._meta.fields] |
| 29 | |
| 30 | fields = json.loads(serializers.serialize("json",[c],fields=fieldNames))[0]["fields"] |
| 31 | |
| 32 | for f in fields.keys(): |
| 33 | if f in ['created', 'updated', 'enacted']: |
| 34 | fields[f] = None |
| 35 | |
| 36 | fields_json = json.dumps(fields) |
| 37 | |
| 38 | print " this." + classname + " = " + fields_json + ";" |
| 39 | |
| 40 | print "};" |
Scott Baker | a34d8c4 | 2014-11-11 18:02:35 -0800 | [diff] [blame] | 41 | print "xosdefaults = new xos_get_defaults();" |
Scott Baker | 566f34d | 2014-11-11 17:10:16 -0800 | [diff] [blame] | 42 | |