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()
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)
class PollResource(resources.ModelResource): class Meta: model = models.Poll slug = 'id' id = attributes.IntegerAttribute('id') question = attributes.TextAttribute('question') available = attributes.BooleanAttribute('available')
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']
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