Example #1
0
 def obj_create(self, bundle, **kwargs):
     data = bundle.data
     LOG.info("Creating draw with data: {}".format(data))
     for attr in self.FORBIDDEN_ATTRIBUTES:
         if attr in data:
             raise exceptions.ImmediateHttpResponse(
                 response=http.HttpBadRequest("{0} is forbidden".format(
                     attr)))
     try:
         type_ = data.pop('type')
         draw = draw_factory.create_draw(type_, data)
         draw.validate()
     except KeyError:
         raise exceptions.ImmediateHttpResponse(
             response=http.HttpBadRequest("Missing draw type"))
     except draw_factory.DrawNotRegistered:
         raise exceptions.ImmediateHttpResponse(
             response=http.HttpBadRequest("Invalid draw type"))
     except bom.InvalidDraw as e:
         raise exceptions.ImmediateHttpResponse(
             response=http.HttpBadRequest(e.serialize()))
     draw.owner = bundle.request.user.pk
     if not draw.is_shared:
         draw.toss()
     self._client.save_draw(draw)
     bundle.obj = draw
     return bundle
Example #2
0
    def try_draw(self, request, **_):
        self.method_check(request, allowed=['post'])
        self.throttle_check(request)
        try:
            data = json.loads(request.body)
        except TypeError:
            data = json.loads(request.body.decode('utf-8'))

        try:
            type_ = data.pop('type')
            draw = draw_factory.create_draw(type_, data)
            draw.validate()
        except KeyError:
            raise exceptions.ImmediateHttpResponse(
                response=http.HttpBadRequest("Missing draw type"))
        except draw_factory.DrawNotRegistered:
            raise exceptions.ImmediateHttpResponse(
                response=http.HttpBadRequest("Invalid draw type"))
        except bom.InvalidDraw as e:
            raise exceptions.ImmediateHttpResponse(
                response=http.HttpBadRequest(e.serialize()))
        self._client.save_draw(draw)
        result = draw.toss()
        self.log_throttled_access(request)
        return self.create_response(request, result)
Example #3
0
 def obj_create(self, bundle, **kwargs):
     data = bundle.data
     LOG.info("Creating draw with data: {}".format(data))
     for attr in self.FORBIDDEN_ATTRIBUTES:
         if attr in data:
             raise exceptions.ImmediateHttpResponse(
                 response=http.HttpBadRequest("{0} is forbidden".format(
                     attr)))
     try:
         type_ = data.pop('type')
         draw = draw_factory.create_draw(type_, data)
         draw.validate()
     except KeyError:
         raise exceptions.ImmediateHttpResponse(
             response=http.HttpBadRequest("Missing draw type"))
     except draw_factory.DrawNotRegistered:
         raise exceptions.ImmediateHttpResponse(
             response=http.HttpBadRequest("Invalid draw type"))
     except bom.InvalidDraw as e:
         raise exceptions.ImmediateHttpResponse(
             response=http.HttpBadRequest(e.serialize()))
     draw.owner = bundle.request.user.pk
     if not draw.is_shared:
         draw.toss()
     self._client.save_draw(draw)
     bundle.obj = draw
     return bundle
Example #4
0
    def try_draw(self, request, **_):
        self.method_check(request, allowed=['post'])
        self.throttle_check(request)
        try:
            data = json.loads(request.body)
        except TypeError:
            data = json.loads(request.body.decode('utf-8'))

        try:
            type_ = data.pop('type')
            draw = draw_factory.create_draw(type_, data)
            draw.validate()
        except KeyError:
            raise exceptions.ImmediateHttpResponse(
                response=http.HttpBadRequest("Missing draw type"))
        except draw_factory.DrawNotRegistered:
            raise exceptions.ImmediateHttpResponse(
                response=http.HttpBadRequest("Invalid draw type"))
        except bom.InvalidDraw as e:
            raise exceptions.ImmediateHttpResponse(
                response=http.HttpBadRequest(e.serialize()))
        self._client.save_draw(draw)
        result = draw.toss()
        self.log_throttled_access(request)
        return self.create_response(request, result)
Example #5
0
def build_draw(doc):
    """Given a python dict that represnets a draw, builds it"""
    try:
        return draw_factory.create_draw(doc["draw_type"], doc)
    except draw_factory.DrawNotRegistered:
        return eval(doc["draw_type"])(**doc)
    except Exception as e:
        logger.error("Error when decoding a draw. Exception: {1}. Draw: {0} ".format(doc, e))
        raise
Example #6
0
    def obj_create(self, bundle, **kwargs):
        data = bundle.data
        if 'type' not in data:
            raise exceptions.ImmediateHttpResponse(
                response=http.HttpBadRequest("Missing draw type"))
        type_ = data.pop('type')

        for attr in self.FORBIDDEN_ATTRIBUTES:
            if attr in data:
                raise exceptions.ImmediateHttpResponse(
                    response=http.HttpBadRequest("{0} is forbidden".format(
                        attr)))

        draw = draw_factory.create_draw(type_, data)
        draw.owner = bundle.request.user.pk
        if not draw.is_feasible():
            raise exceptions.ImmediateHttpResponse(
                response=http.HttpBadRequest("Not feasible"))
        self._client.save_draw(draw)
        bundle.obj = draw
        return bundle