コード例 #1
0
class DirectModelConnectorMixinResource(DirectModelConnectorMixin,
                                        resources.ModelResource):
    class Meta:
        model = models.Poll

    id = attributes.IntegerAttribute('id')

    def delete(self, request, response):
        self.response.status = 405
        self.destroy()
コード例 #2
0
class ModelDirectResource(resources.ModelResource):
    class Meta:
        model = models.Poll

    id = attributes.IntegerAttribute('id')

    question = attributes.TextAttribute('question')

    def route(self, request, response):
        return super(ModelDirectResource, self).route(request, response)
コード例 #3
0
class PollResource(resources.ModelResource):
    class Meta:
        model = models.Poll

        slug = 'id'

    id = attributes.IntegerAttribute('id')

    question = attributes.TextAttribute('question')

    available = attributes.BooleanAttribute('available')
コード例 #4
0
class DirectModelConnectorResource(resources.ModelResource):
    class Meta:
        model = models.Poll

    id = attributes.IntegerAttribute('id')

    def route(self, request, response):
        response.status = 205
        return super(DirectModelConnectorResource,
                     self).route(request, response)

    def get(self, request, response):
        response.write(json.dumps(self.read()).encode('utf8'))

    def read(self):
        return ['Hello', 'World']
コード例 #5
0
class PollValidResource(PollResource):

    votes = attributes.IntegerAttribute('votes')

    def clean_votes(self, value):
        assert value > 0, 'Must be greater than 0.'
        assert value < 51, 'Must be less than 51.'
        return value

    def clean_question(self, value):
        errors = []

        if len(value) <= 15:
            errors.append('Must be more than 15 characters.')

        if value.find('?') == -1:
            errors.append('Must have at least one question mark.')

        if errors:
            raise exceptions.ValidationError(*errors)

        return value