Added a filter_fields parameter to the ReferenceField widget
This paramater makes it possible to do 'hard coded' filtering.
Patch by: Sverre Rabbelier
--- a/app/soc/views/helper/templatetags/forms_helpers.py Fri Feb 13 21:51:41 2009 +0000
+++ b/app/soc/views/helper/templatetags/forms_helpers.py Fri Feb 13 21:52:10 2009 +0000
@@ -243,6 +243,7 @@
reference = attrs.get('reference_url')
filter = attrs.get('filter')
+ filter_fields = attrs.get('filter_fields')
if reference:
from soc.views.helper import redirects
@@ -252,6 +253,8 @@
if entity:
args = {}
+ for filter_field, filter_value in filter_fields.iteritems():
+ args[filter_field] = filter_value
for filter_field in (i for i in filter if hasattr(entity, i)):
args[filter_field] = getattr(entity, filter_field)
--- a/app/soc/views/helper/widgets.py Fri Feb 13 21:51:41 2009 +0000
+++ b/app/soc/views/helper/widgets.py Fri Feb 13 21:52:10 2009 +0000
@@ -136,7 +136,7 @@
"""Widget for selecting a reference to an Entity.
"""
- def __init__(self, reference_url, filter=None,
+ def __init__(self, reference_url, filter=None, filter_fields=None,
*args, **kwargs):
"""Initializes the widget with the specified url and filter.
"""
@@ -144,6 +144,7 @@
self.rf = {}
self.rf['reference_url'] = reference_url
self.rf['filter'] = filter if filter else []
+ self.rf['filter_fields'] = filter_fields if filter_fields else {}
super(ReferenceField, self).__init__(*args, **kwargs)