Skip to content

Commit

Permalink
Preparing the widgets in order to add conditional queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
versae committed Mar 9, 2011
1 parent 194f61d commit a8812e7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion django_qbe/media/django_qbe/js/qbe.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ qbe.Core = function() {};
$("#"+ domTo).attr("disabled", "disabled");
$("#"+ domTo).val("");
}
if ($("#"+ domTo).is("input")) {
if ($("#"+ domTo).is('input[type="text"]')) {
appModel = $("#"+ prefix +"-model").val();
appModelSplits = appModel.split(".");
fields = qbe.Models[appModelSplits[0]][appModelSplits[1]].fields;
Expand Down
30 changes: 29 additions & 1 deletion django_qbe/widgets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
from django.forms.widgets import MultiWidget, Select, TextInput
from django.forms.util import flatatt
from django.forms.widgets import MultiWidget, Select, TextInput, Widget
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext as _


Expand All @@ -23,12 +25,38 @@
)


class CheckboxLabelWidget(Widget):

def __init__(self, attrs=None, label=None, prelabel=None, *args, **kwargs):
super(CheckboxLabelWidget, self).__init__(*args, **kwargs)
self.attrs = attrs or {}
self.label = label or _('Check this')
self.prelabel = prelabel

def render(self, name, value=None, attrs=None, prelabel=None):
self.attrs.update(attrs or {})
final_attrs = self.build_attrs(self.attrs, name=name)
prelabel = prelabel or self.prelabel
if prelabel:
out = u'<label for="%s" >%s</label><input type="checkbox"%s >' \
% (self.attrs.get("id", ""), value or self.label,
flatatt(final_attrs))
else:
out = u'<input type="checkbox"%s ><label for="%s" >%s</label>' \
% (flatatt(final_attrs), self.attrs.get("id", ""),
value or self.label)
return mark_safe(out)


class CriteriaInput(MultiWidget):

class Media:
js = ('django_qbe/js/qbe.widgets.js', )

def __init__(self, *args, **kwargs):
# widgets = [CheckboxLabelWidget(label=_("Inverse")),
# Select(choices=OPERATOR_CHOICES), TextInput(),
# CheckboxLabelWidget(label=_("Nothing"))]
widgets = [Select(choices=OPERATOR_CHOICES), TextInput()]
super(CriteriaInput, self).__init__(widgets=widgets, *args, **kwargs)

Expand Down

0 comments on commit a8812e7

Please sign in to comment.