Exemple #1
0
 def toss(self, request, **kwargs):
     self.method_check(request, allowed=['post'])
     self.throttle_check(request)
     draw_id = kwargs['pk']
     try:
         bom_draw = self._client.retrieve_draw(draw_id)
     except mongodb.MongoDriver.NotFoundError:
         raise exceptions.ImmediateHttpResponse(
             response=http.HttpNotFound())
     if not bom_draw.check_write_access(request.user):
         raise exceptions.ImmediateHttpResponse(
             response=http.HttpUnauthorized("Only the owner can toss"))
     result = bom_draw.toss()
     if bom_draw.is_shared:
         mail_toss(bom_draw)
     self._client.save_draw(bom_draw)
     self.log_throttled_access(request)
     return self.create_response(request, result)
Exemple #2
0
 def toss(self, request, **kwargs):
     self.method_check(request, allowed=['post'])
     self.throttle_check(request)
     draw_id = kwargs['pk']
     try:
         bom_draw = self._client.retrieve_draw(draw_id)
     except mongodb.MongoDriver.NotFoundError:
         raise exceptions.ImmediateHttpResponse(
             response=http.HttpNotFound())
     if not bom_draw.check_write_access(request.user):
         raise exceptions.ImmediateHttpResponse(
             response=http.HttpUnauthorized("Only the owner can toss"))
     result = bom_draw.toss()
     if bom_draw.is_shared:
         mail_toss(bom_draw)
     self._client.save_draw(bom_draw)
     self.log_throttled_access(request)
     return self.create_response(request, result)
Exemple #3
0
 def schedule_toss(self, request, **kwargs):
     self.method_check(request, allowed=['post'])
     self.throttle_check(request)
     draw_id = kwargs['pk']
     try:
         schedule = kwargs['schedule']
         schedule = dateutil.parser.parse(schedule).astimezone(pytz.utc)
         bom_draw = self._client.retrieve_draw(draw_id)
     except (ValueError, KeyError):
         raise exceptions.ImmediateHttpResponse(
             response=http.HttpBadRequest("Invalid 'schedule'"))
     except mongodb.MongoDriver.NotFoundError:
         raise exceptions.ImmediateHttpResponse(
             response=http.HttpNotFound())
     if not bom_draw.check_write_access(request.user):
         raise exceptions.ImmediateHttpResponse(
             response=http.HttpUnauthorized(
                 "Only the owner can schedule a toss"))
     result = bom_draw.timed_toss(schedule)
     self._client.save_draw(bom_draw)
     if bom_draw.is_shared:
         mail_toss(bom_draw)
     self.log_throttled_access(request)
     return self.create_response(request, result)
Exemple #4
0
 def schedule_toss(self, request, **kwargs):
     self.method_check(request, allowed=['post'])
     self.throttle_check(request)
     draw_id = kwargs['pk']
     try:
         schedule = kwargs['schedule']
         schedule = dateutil.parser.parse(schedule).astimezone(pytz.utc)
         bom_draw = self._client.retrieve_draw(draw_id)
     except (ValueError, KeyError):
         raise exceptions.ImmediateHttpResponse(
             response=http.HttpBadRequest("Invalid 'schedule'"))
     except mongodb.MongoDriver.NotFoundError:
         raise exceptions.ImmediateHttpResponse(
             response=http.HttpNotFound())
     if not bom_draw.check_write_access(request.user):
         raise exceptions.ImmediateHttpResponse(
             response=http.HttpUnauthorized(
                 "Only the owner can schedule a toss"))
     result = bom_draw.timed_toss(schedule)
     self._client.save_draw(bom_draw)
     if bom_draw.is_shared:
         mail_toss(bom_draw)
     self.log_throttled_access(request)
     return self.create_response(request, result)