1 from unfold.composite import Composite
2 from unfold.plugin import Plugin
4 class CreateForm (Plugin):
6 def __init__ (self, **settings):
7 Plugin.__init__(self, **settings)
8 print "SETTINGS", settings
9 assert 'page' in settings, "You should specify page"
10 assert 'object' in settings, "You should specify object"
12 if 'object' in settings:
13 self.object = settings['object']
15 if 'fields' in settings:
17 for field in settings['fields']:
19 'name' : field.get('name', ''),
20 'field' : field.get('field', ''),
21 'type' : field.get('type', 'input'),
22 'description' : field.get('description', ''),
23 'validate_rx' : field.get('validate_rx', ''),
24 'validate_err' : field.get('validate_err', ''),
29 # Attempt to retrieve object fields from metadata
30 metadata = settings['page'].get_metadata()
31 md_o = metadata.details_by_object(settings['object'])
32 self.fields = md_o['column']
34 def requirements (self):
35 # Some should be included by default by manifold
36 return { 'js_files' : ['js/manifold.js', 'js/spin-presets.js', 'js/spin.min.js', 'js/jquery.spin.js',
37 'js/form.js', 'js/jquery.validate.js', ],
38 'css_files' : ['css/form.css']
40 def export_json_settings(self):
41 # We need initialization, even though we are not associated with a query
44 def template_env (self, request):
46 env.update(self.__dict__)
49 def template_file (self):
52 def json_settings_list (self): return ['plugin_uuid', 'object', 'fields']