diff options
Diffstat (limited to 'ishtar_common/widgets.py')
-rw-r--r-- | ishtar_common/widgets.py | 43 |
1 files changed, 16 insertions, 27 deletions
diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index 1ddabe7c7..c34642cf1 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -277,6 +277,7 @@ class SquareMeterWidget(forms.TextInput): rendered = t.render(dct) return mark_safe(rendered) + AreaWidget = forms.TextInput if settings.SURFACE_UNIT == 'square-metre': @@ -424,6 +425,8 @@ class JQueryAutoComplete(forms.TextInput): attrs_select['id'] = 'id_select_%s' % name if 'class' not in attrs_select: attrs_select['class'] = 'autocomplete' + + attrs_select['class'] += ' form-control' new = '' if self.new: model_name = self.associated_model._meta.object_name.lower() @@ -440,11 +443,11 @@ class JQueryAutoComplete(forms.TextInput): url_new = reverse(url_new, args=args) new = u' <a href="#" class="add-button" '\ u'onclick="open_window(\'%s\');">+</a>' % url_new - html = u'''<input%(attrs_select)s/>%(new)s\ + html = u"""<input%(attrs_select)s/>%(new)s\ <input type="hidden"%(attrs_hidden)s/>\ <script type="text/javascript"><!--// %(js)s//--></script> - ''' % { + """ % { 'attrs_select': flatatt(attrs_select), 'attrs_hidden': flatatt(attrs_hidden), 'js': self.render_js(name), @@ -651,22 +654,14 @@ class JQueryPersonOrganization(forms.TextInput): return html -class JQueryJqGrid(forms.RadioSelect): - COL_TPL = "{name:'%(idx)s', index:'%(idx)s', sortable:true}" - - # class Media: - # js = ['%s/js/i18n/grid.locale-%s.js' % (settings.STATIC_URL, - # settings.COUNTRY), - # '%s/js/jquery.jqGrid.min.js' % settings.STATIC_URL] - # css = {'all': ['%s/media/ui.jqgrid.css' % settings.STATIC_URL]} - +class DataTable(forms.RadioSelect): def __init__(self, source, form, associated_model, attrs={}, table_cols='TABLE_COLS', multiple=False, multiple_cols=[2], new=False, new_message="", source_full=None, multiple_select=False, sortname="__default__", col_prefix=''): """ - JQueryJqGrid widget init. + DataTable widget init. :param source: url to get the item from -- get_item :param form: @@ -682,7 +677,7 @@ class JQueryJqGrid(forms.RadioSelect): :param sortname: column name (model attribute) to use to sort :param col_prefix: prefix to remove to col_names """ - super(JQueryJqGrid, self).__init__(attrs=attrs) + super(DataTable, self).__init__(attrs=attrs) self.source = source self.form = form if not attrs: @@ -742,21 +737,14 @@ class JQueryJqGrid(forms.RadioSelect): else: jq_col_names.append(settings.JOINT.join( [f for f in field_verbose_names if f])) - if not python: - jq_col_names[-1] = u'"%s"' % jq_col_names[-1] - if python: - extra_cols.append(field_name) - else: - extra_cols.append(self.COL_TPL % {'idx': field_name}) - if not python: - jq_col_names = jq_col_names and ", ".join(jq_col_names) or "" - extra_cols = extra_cols and ", ".join(extra_cols) or "" + extra_cols.append(field_name) return jq_col_names, extra_cols def render(self, name, value, attrs=None, renderer=None): - t = loader.get_template('blocks/form_flex_snippet.html') + # t = loader.get_template('blocks/form_flex_snippet.html') + t = loader.get_template('blocks/bs_form_snippet.html') form = self.form() - rendered = t.render({'form': form, 'flex': True}) + rendered = t.render({'form': form, 'search': True}) dct = {} if self.new: model_name = self.associated_model._meta.object_name.lower() @@ -792,10 +780,11 @@ class JQueryJqGrid(forms.RadioSelect): dct['extra_sources'].append(( imp.slug, imp.name, reverse('get-by-importer', args=[imp.slug]))) + source = unicode(self.source) dct.update({'name': name, 'col_names': col_names, 'extra_cols': extra_cols, - 'source': unicode(self.source), + 'source': source, 'col_idx': col_idx, 'no_result': unicode(_("No results")), 'loading': unicode(_("Loading...")), @@ -804,7 +793,7 @@ class JQueryJqGrid(forms.RadioSelect): 'multiple': self.multiple, 'multiple_select': self.multiple_select, 'multi_cols': ",".join((u'"%d"' % col - for col in self.multiple_cols))}) - t = loader.get_template('blocks/JQueryJqGrid.html') + for col in self.multiple_cols))}) + t = loader.get_template('blocks/DataTables.html') rendered += t.render(dct) return mark_safe(rendered) |