Scott Baker | ab2a168 | 2014-11-25 11:23:04 -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 | ab2a168 | 2014-11-25 11:23:04 -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 | 56f799b | 2014-11-25 11:35:19 -0800 | [diff] [blame] | 16 | print "function xos_get_validators() {" |
Scott Baker | ab2a168 | 2014-11-25 11:23:04 -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 | |
Scott Baker | 56f799b | 2014-11-25 11:35:19 -0800 | [diff] [blame] | 28 | fields = c.getValidators(); |
Scott Baker | ab2a168 | 2014-11-25 11:23:04 -0800 | [diff] [blame] | 29 | |
| 30 | fields_json = json.dumps(fields) |
| 31 | |
| 32 | print " this." + classname + " = " + fields_json + ";" |
| 33 | |
| 34 | print "};" |
Scott Baker | 56f799b | 2014-11-25 11:35:19 -0800 | [diff] [blame] | 35 | print "xosvalidators = new xos_get_validators();" |
Scott Baker | ab2a168 | 2014-11-25 11:23:04 -0800 | [diff] [blame] | 36 | |