Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Experimenting with returning field html

  • Loading branch information...
commit d57c0f6baa67ddb28f3320aecde7b0fd112b0f60 1 parent 11b1eb7
@coleifer authored
View
24 flask_peewee/filters.py
@@ -270,17 +270,24 @@ def get_form(self, field_dict):
field_dict,
)
+ def get_form_data(self, field_name, form):
+ data = form.data
+ import ipdb; ipdb.set_trace()
+ for piece in field_name.split(self.separator):
+ data = data[piece]
+ return data
+
+ def get_query_field(self, field_name, form):
+ field = form
+ for piece in field_name.split(self.separator):
+ field = field[piece]
+ return field
+
def get_query_value(self, raw_field_name, form=None):
if form is None:
return request.args.getlist(raw_field_name)
- if self.separator in raw_field_name:
- pieces = raw_field_name.split(self.separator)
- data = form.data[pieces[0]]
- for piece in pieces[1:]:
- data = data[piece]
- else:
- data = form.data[raw_field_name]
+ data = self.get_form_data(raw_field_name, form)
if not isinstance(data, list):
data = [data]
return data
@@ -336,7 +343,8 @@ def process_request(self, query):
q_objects = []
for filter_idx, filter_value in zip(filter_idx_list, filter_value_list):
idx = int(filter_idx)
- cleaned.append((qf_s, idx, qf_v, filter_value))
+ form_field = self.get_query_field(qf_v, form)
+ cleaned.append((qf_s, idx, qf_v, filter_value, form_field))
query_filter = self._query_filters[field][idx]
q_objects.append(query_filter.query(filter_value))
View
10 flask_peewee/static/js/admin.js
@@ -123,11 +123,15 @@ var Admin = window.Admin || {};
});
}
- ModelAdminFilter.prototype.add_row = function(qf_v, qf_s, ival, sval) {
+ ModelAdminFilter.prototype.add_row = function(qf_v, qf_s, ival, sval, ifield) {
var select_elem = this.lookups_elem.find('#'+qf_s),
input_elem = this.lookups_elem.find('#'+qf_v),
field_label = $('#filter-'+qf_s).text();
+ if (ifield) {
+ input_elem = $(ifield);
+ }
+
var self = this,
select_clone = select_elem.clone(),
input_clone = input_elem.clone(),
@@ -173,8 +177,8 @@ var Admin = window.Admin || {};
}
/* pull request data and simulate adding a filter */
- ModelAdminFilter.prototype.add_filter_request = function(qf_s, filter_idx, qf_v, filter_val) {
- return this.add_row(qf_v, qf_s, filter_val, filter_idx);
+ ModelAdminFilter.prototype.add_filter_request = function(qf_s, filter_idx, qf_v, filter_val, filter_field) {
+ return this.add_row(qf_v, qf_s, filter_val, filter_idx, filter_field);
}
/* export */
View
4 flask_peewee/templates/admin/models/base_filters.html
@@ -13,9 +13,9 @@
* special-case foreign key lookups since they have a `repr` that we'll
* need to display on the button
*/
- {% for qf_s, filter_idx, qf_v, filter_val in active_filters %}
+ {% for qf_s, filter_idx, qf_v, filter_val, form_field in active_filters %}
admin_filter.add_filter_request(
- '{{ qf_s }}', {{ filter_idx }}, '{{ qf_v }}', {{ filter_val|tojson|safe }}
+ '{{ qf_s }}', {{ filter_idx }}, '{{ qf_v }}', null, '{{ form_field()|safe }}'
);
{% endfor %}
});
Please sign in to comment.
Something went wrong with that request. Please try again.