~dylanmccall/harvest/harvest-dylan-m

« back to all changes in this revision

Viewing changes to harvest/filters/filters.py

  • Committer: Dylan McCall
  • Date: 2010-06-27 21:05:08 UTC
  • Revision ID: dylanmccall@gmail.com-20100627210508-827xf0zw50oodtup
Fixed a bug where serialize_value, given an empty set for value, used the current value instead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
103
103
    
104
104
    def serialize(self, value = None): #final
105
105
        """
106
 
        Creates a dictionary of parameters that can be added to an HTTP query
107
 
        to assign the given value to this object in the future.
 
106
        Creates a dictionary of parameters to describe this object, either
 
107
        as-is or with a new value.
108
108
        The result can be sent to FilterSystem.get_url_with_parameters.
109
 
        @param value: the value to serialize, in a format native to this Filter (see get_value). Leave blank to use the current value.
 
109
        @param value: a different value to use, in a format native to this Filter (see get_value)
110
110
        @return: a dictionary of key:value pairs referring to the object and its value.
111
111
        """
112
 
        if not value: value = self.get_value()
 
112
        if value == None: value = self.get_value()
113
113
        key = self.get_full_name()
114
114
        value_str = self.serialize_value(value)
115
115
        return {key : value_str}
122
122
        """
123
123
        container = self.get_container()
124
124
        params = dict()
125
 
        if isinstance(container, FilterGroup): 
 
125
        if isinstance(container, FilterGroup):
126
126
            params = container.serialize(container.get_value_with_selection(self.get_id()))
127
127
        return params
128
128
    
151
151
        @return: a unicode string containing html representing this filter
152
152
        """
153
153
        system = self.get_system()
154
 
        toggle_params = self.get_container_toggle_parameters() 
 
154
        toggle_params = self.get_container_toggle_parameters()
155
155
        href = system.get_url_with_parameters(toggle_params)
156
156
        
157
157
        return mark_safe(u'<a href="%s">(%s)</a>'
182
182
    
183
183
    def render_html(self):
184
184
        system = self.get_system()
185
 
        toggle_params = self.get_container_toggle_parameters() 
 
185
        toggle_params = self.get_container_toggle_parameters()
186
186
        href = system.get_url_with_parameters(toggle_params)
187
187
        
188
188
        return mark_safe(u'<a href="%s">%s: %s</a>'
216
216
        @param item_id: id for the item to toggle
217
217
        @return: the value of this SetFilter with the given item toggled on or off
218
218
        """
219
 
        select = self.selected_set.copy()
 
219
        select = self.get_value()
220
220
        if item_id in select:
221
221
            select.remove(item_id)
222
222
        else: