1 from unfold.plugin import Plugin
3 from django.template.loader import render_to_string
5 # XXX We need naming helpers in the python Plugin class also, used in template
7 class ColumnsEditor(Plugin):
8 def __init__ (self, query, query_all = None, **settings):
9 Plugin.__init__ (self, **settings)
11 self.query_uuid = query.query_uuid
12 self.query_all = query_all
13 self.query_all_uuid = query_all.query_uuid if query_all else None
15 def template_file(self):
16 return "columns_editor.html"
18 def requirements (self):
22 'js/columns_editor.js',
25 'css/query_editor.css',
31 def export_json_settings (self):
34 def template_env(self, request):
36 #hidden_columns = self.hidden_columns
37 metadata = self.page.get_metadata()
38 md_fields = metadata.details_by_object('resource')
40 # XXX use django templating system here
41 for md_field in md_fields['column']:
42 if md_field['type'] == 'string':
43 if 'allowed_values' in md_field:
44 allowed_values = md_field['allowed_values'].split(',')
47 for v in allowed_values:
49 options.append(v_desc[0])
55 filter_input = render_to_string('filter_input_string_values.html', env)
59 'field': md_field['name']
61 filter_input = render_to_string('filter_input_string.html', env)
63 elif md_field['type'] == 'int':
64 allowed_values = md_field.get('allowed_values', '0,0').split(',')
67 'field': md_field['name'],
68 'min' : allowed_values[0],
69 'max' : allowed_values[1]
71 filter_input = render_to_string('filter_input_integer.html', env)
75 'field': md_field['name']
77 filter_input = render_to_string('filter_input_others.html', env)
80 'name': md_field['name'],
81 'type': md_field['type'],
82 'resource_type': 'N/A',
83 'filter_input': filter_input,
85 'checked': md_field['name'] in self.query.get_select()
87 #return { 'fields': fields, 'hidden_columns': hidden_columns }
88 #return { 'fields': fields , 'query_uuid': self.query_uuid, 'query_all_uuid': self.query_all_uuid }
89 return { 'fields': fields }
91 def json_settings_list (self): return ['plugin_uuid', 'domid', 'query_uuid', 'query_all_uuid', ]