Paola Coccia avatar Paola Coccia committed 5f550e0

Fix issue #12: moved check for max number of votes per ip address in pre_vote method of the handler.

Comments (0)

Files changed (1)

ratings/handlers.py

         If anonymous votes are allowed, this method checks for ip adresses too.
         """
         if self.allow_anonymous:
-            ip_address = request.META.get("REMOTE_ADDR")
-            if ip_address is None:
-                # anonymous user must at least own an ip adreess
-                return False
-            if self.votes_per_ip_address:
-                # in case of vote-per-ip cap, check if this ip
-                # can continue voting this object
-                count = models.Vote.objects.filter_for(instance,
-                    user__isnull=True, ip_address=ip_address).count()
-                return count < self.votes_per_ip_address
-            return True
+            # anonymous user must at least own an ip adreess
+            return bool(request.META.get("REMOTE_ADDR"))
         else:
             # for normal user voting the user must be authenticated
             return request.user.is_authenticated()
         another listener to the signal: the voting process is killed if 
         just one receiver returns False.
         """
+        if self.allow_anonymous and self.votes_per_ip_address:
+            # in case of vote-per-ip cap, check if this ip
+            # can continue voting this object
+            ip_address = request.META.get("REMOTE_ADDR")
+            if ip_address is None:
+                return False
+            count = models.Vote.objects.filter_for(vote.content_object,
+                user__isnull=True, ip_address=ip_address).count()
+            return count < self.votes_per_ip_address
         return self.can_change_vote if vote.id else True
         
     def vote(self, request, vote):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.