Commits

Paola Coccia committed eb3d8a9

Fixed "Multiple ratings" issue.

  • Participants
  • Parent commits 20d1bf0

Comments (0)

Files changed (2)

File ratings/forms/__init__.py

     """
     def get_score_widget(self, score_range, score_step, can_delete_vote):
         return SliderWidget(score_range[0], score_range[1], score_step,
-            instance=self.target_object, can_delete_vote=can_delete_vote)
+            instance=self.target_object, can_delete_vote=can_delete_vote, key=self.key)
         
         
 class StarVoteForm(VoteForm):
     """
     def get_score_widget(self, score_range, score_step, can_delete_vote):
         return StarWidget(score_range[0], score_range[1], score_step, 
-            instance=self.target_object, can_delete_vote=can_delete_vote)
+            instance=self.target_object, can_delete_vote=can_delete_vote, key=self.key)

File ratings/forms/widgets.py

 
 from django import forms
 from django.template.loader import render_to_string
+from django.template.defaultfilters import slugify
 
 class BaseWidget(forms.TextInput):
     """
         final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
         return final_attrs['id']
         
-    def get_widget_id(self, prefix, name):
+    def get_widget_id(self, prefix, name, key=""):
         if self.instance:
             opts = self.instance._meta
-            return '%s-%s-%s_%s-%s' % (prefix, name, opts.app_label, 
-                opts.module_name, self.instance.pk)
+            widget_id = '%s-%s-%s_%s-%s' % (prefix, name, opts.app_label, opts.module_name, self.instance.pk)
         else:
-            return '%s-%s' % (prefix, name)
+            widget_id = '%s-%s' % (prefix, name)
+        if key:
+            widget_id = '%s_%s' % (widget_id, slugify(key))
+        return widget_id
             
     def get_values(self, min_value, max_value, step=1):
         decimal_step = Decimal(str(step))
         });
     """
     def __init__(self, min_value, max_value, step, instance=None,
-        can_delete_vote=True, read_only=False, default='', 
+        can_delete_vote=True, key="", read_only=False, default='', 
         template='ratings/slider_widget.html', attrs=None):
         """
         The argument *default* is used when the initial value is None.
         self.read_only = read_only
         self.default = default
         self.template = template
+        self.key = key
     
     def get_context(self, name, value, attrs=None):
         # here we convert *min_value*, *max_value*, *step* and *value*
             'parent_id': self.get_parent_id(name, attrs),
             'value': str(value),
             'has_value': bool(value),
-            'slider_id': self.get_widget_id('slider', name),
+            'slider_id': self.get_widget_id('slider', name, self.key),
             'label_id': 'slider-label-%s' % name,
             'remove_id': 'slider-remove-%s' % name,
         }
         });
     """
     def __init__(self, min_value, max_value, step, instance=None,
-        can_delete_vote=True, read_only=False, 
+        can_delete_vote=True, key="", read_only=False, 
         template='ratings/star_widget.html', attrs=None):
         super(StarWidget, self).__init__(attrs)
         self.min_value = min_value
         self.can_delete_vote = can_delete_vote
         self.read_only = read_only
         self.template = template
+        self.key = key
         
     def get_context(self, name, value, attrs=None):
         # here we convert *min_value*, *max_value* and *step*
             split = u''
         else:
             values = self.get_values(self.min_value, self.max_value, self.step)
-            split = u' {split:%d}' % split_value
+            split = u' {split:%d}' % split_value            
         return {
             'min_value': str(self.min_value),
             'max_value': str(self.max_value),
             'parent': super(StarWidget, self).render(name, value, attrs),
             'parent_id': self.get_parent_id(name, attrs),
             'value': self._get_value(value, split_value),
-            'star_id': self.get_widget_id('star', name),
+            'star_id': self.get_widget_id('star', name, self.key),
         }
 
     def _get_value(self, original, split):