0

I am using DjangoRatings for a web app which allows anonymous ratings from registered as well as nonregistered users. After I set the IPLimit integer in the DjangoRatings settings.py file, everything works fine; however, when I exceed the number of votes that I have allowed per IP, the entire web page gets reloaded with an “RaiseIPLimit()” error and the entire site goes down which necessitates reloading the previous page via back button. My question is, what can I add to my views.py file to tell django that when DjangoRatings passes the RaiseIPLimit() error, simply print something like “You can only vote once!” message to the user and leave the loaded web page as it is instead of crashing the entire site.

If there’s an easier way to do this general IP checking besides DjangoRatings, I am open to implementing other ways, but DjangoRatings just seems much easier than anything else since the only thing I need IP limits on is rating stuff. To be more clear, here is the exact error that DjangoRatings gives me:

IPLimitReached at /myapp/rating /page1 

And this is straight from the DjangoRatings source code:

              num_votes = Vote.objects.filter(
                  content_type=kwargs['content_type'],
                  object_id=kwargs['object_id'],
                  key=kwargs['key'],
                  ip_address=ip_address,
              ).count()
              if num_votes >= getattr(settings, 'RATINGS_VOTES_PER_IP', RATINGS_VOTES_PER_IP):
                  raise IPLimitReached() ...
          kwargs.update(defaults)
          if use_cookies:
              # record with specified cookie was not found ...
              cookie = defaults['cookie'] # ... thus we need to replace old cookie (if presented) with new one
              kwargs.pop('cookie__isnull', '') # ... and remove 'cookie__isnull' (if presented) from .create()'s **kwargs
          rating, created = Vote.objects.create(**kwargs), True
nathanchere
  • 8,008
  • 15
  • 65
  • 86
EazyC
  • 809
  • 1
  • 10
  • 30

0 Answers0