Giter Club home page Giter Club logo

django-respite's Introduction

Hi there ๐Ÿ‘‹

django-respite's People

Contributors

djromero avatar espenhogbakk avatar graingert avatar guzru avatar jgorset avatar timkurvers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

django-respite's Issues

'resource' function empties 'routes.all'

I'm trying to do something like:

from django.conf.urls.defaults import *
from respite.urls import resource
from some.views import v1, v2

urlpatterns = resource(prefix = '/bar', views = v1)
urlpatterns += resource(prefix = '/foo', views = v2)

It doesn't work because the first call to resource empties routes.all. I have a dirt and quick hack but it'd be great if code like above is supported out of the box.

Thanks.

Respite assumes "application/*" is encoded in Latin 1

Respite incorrectly assumes that any media type that doesn't specify an encoding are encoded in ISO-8859-1, but this is only true for media subtypes of the text type. application/json, for example, defaults to UTF-8:

JSON text SHALL be encoded in Unicode. The default encoding is UTF-8. โ€“ RFC-2616

Respite "allows" stupid browsers to break the internet

So old versions of webkit browser and IE has stupid default accept headers. This is a problem if you have set your respite view to support xml.

To give an example, older versions of webkit (seems to be fixed around march 2011) sends this as default accept headers:

Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

It prefers, xhtml over html, thats bad, but okay i guess, but it actually prefers application/xml and image/png over text/html as well. This is of course a problem, cause that meens that visitors that uses these browser will get XML(!) instad of HTML.

See this article with good examples for a more thorough explanation.

I don't know how to fix this, since it's the browsers error, but removing "application/xml" and just relying on "text/xml" should fix it, but thats not to nice either.

This is not a problem if your supported formats list does not include xml

Respite does not serialize foreign relationships

Respite currently uses Model._meta.fields to retrieve the properties of a model, this does not include fields that are not actually present in the database table for that model. E.g foreign keys located on the related model and ManyToMany-fields.

404s return HTML regardless of accepted formats

Respite's default views render a HTML representation of the 404 Not Found page regardless of accepted formats. It should facilitate for serializing the error message as JSON and XML, too.

Better routing for custom actions

Respite should facilitate for several view functions sharing the same path and delegating the request based on the request method, like the default actions work.

Error when testing PUT with django.test.Client

Using Django 1.4 and given the following test:

from django.test import TestCase, Client

class ResourceIndexView(TestCase):
    def test_put_should_update_resource(self):
        """
        A PUT request should result in the resource being updated.
        """
        resource = Resource(name="bob")
        resource.save()
        response = Client().post('/tasks/' + str(task.id), {
            "_method": "PUT",
            'name': "sally"
        })
        self.assertTrue(Resource.objects.all().exists())

I receive this error

======================================================================
ERROR: test_put_should_update_resource (resources.tests.ResourceIndexView)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/user/Workspace/Git/django-todo/resources/tests.py", line 105, in test_put_should_update_resource
    'description': "sally"
  File "/Users/user/Workspace/Git/django-todo/venv/lib/python2.7/site-packages/django/test/client.py", line 449, in post
    response = super(Client, self).post(path, data=data, content_type=content_type, **extra)
  File "/Users/user/Workspace/Git/django-todo/venv/lib/python2.7/site-packages/django/test/client.py", line 262, in post
    return self.request(**r)
  File "/Users/user/Workspace/Git/django-todo/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 89, in get_response
    response = middleware_method(request)
  File "/Users/user/Workspace/Git/django-todo/venv/lib/python2.7/site-packages/respite/middleware.py", line 25, in process_request
    request._raw_post_data = re.sub(r'_method=(PUT|PATCH|DELETE)&?', '', request.raw_post_data)
  File "/Users/user/Workspace/Git/django-todo/venv/lib/python2.7/site-packages/django/http/__init__.py", line 337, in raw_post_data
    return self.body
  File "/Users/user/Workspace/Git/django-todo/venv/lib/python2.7/site-packages/django/http/__init__.py", line 326, in body
    raise Exception("You cannot access body after reading from request's data stream")
Exception: You cannot access body after reading from request's data stream

If I instead use client.put the view does not have a populated request.POST dictionary. When I output request.raw_post_data I get the following unexpected string:

'--BoUnDaRyStRiNg\r\nContent-Disposition: form-data; name="name"\r\n\r\nsally\r\n--BoUnDaRyStRiNg--\r\n'

Is there an example in this repo of how to use the test client with a PUT request or is this truly a bug?

Thanks

Resource#create should return 201 Created, not 303 See Other

According to the HTTP specification...

If a resource has been created on the origin server, the response SHOULD be 201 (Created) and contain an entity which describes the status of the request and refers to the new resource, and a Location header (see section 14.30).

Support HTTP PATCH

We should look into the HTTP PATCH method and consider implementing it; updating resources is a common use-case.

Exclude HTML-format from OPTIONS

Since issuing an OPTIONS-request from a webbrowser is not particularly common, we should consider excluding the HTML-format from the OPTIONS-view by default using @override_supported_formats.

Conveniently, doing so would also solve an issue with Microsoft Office Protocol Discovery which will kick in once somebody copy-pastes images into a Microsoft Word-backed e-mail client. To determine server capabilities this protocol discovery service will request OPTIONS - with an accept header that encompasses HTML - which in turn throws a 500 if no template is available.

Views#options raises UnknownSerializer on unserializable formats

Issuing HTTP OPTIONS requests for a format that Respite doesn't know how to serialize (such as HTML) will result in an UnknownSerializer exception.

Views#options should either override the supported formats to a list of serializable formats, or reference a template that may be populated by the end-user (and preferably fail gracefully if none exists).

setup.py

Missing 'respite.views' in packages.

Incorrect view names for models in MixedCase

Respite names views for models in MixedCase incorrectly. For example, the view name for a model PhoneNumber in the phone_numbers module should be phone_numbers_phone_number, not phone_numbers_phonenumber.

Strange routing

Apparently, you can suffix URLs with arbitrary data and they will still work. For example, http://example.org/resources/new is interchangeable with http://example.org/resources/newwwwwww.

Huh.

Respite's serializer should raise an exception in case of recursiveness

Description

The default serializer of a model would follow a foreignkey to another model, and then serialize that model. This causes a problem if the parent model also serializes the reverse relationship of the foreignkey. In development in only shuts down the runserver, but i'm not sure what would happen in production.

Here is an example that would cause this recursive bug

class Question(models.Model):
    question = models.CharField()
    created = models.DateTimeField()

    def serialize(self):
        return {
            'id': self.id,
            'question': self.question,
            'created': self.created,
            'votes': self.votes.all()
        }

class Vote(models.Model):
    question = models.ForeignKey('Question', related_name="votes")
    choice = models.IntegerField()

Since self.votes.all() would serialize a list of votes, that again with the default serializer would serialize self.questionwe get a recursive problem.

Current behavior

I haven't tried it on a apache server, but when you run the devserver (runserver) it justs quits the runserver without any warnings what so ever.

Expected behavior

Respite should eiter:

  1. Don't serialize foreignkeys by default, this would be a hazzle, cause you often want to do this
  2. Throw an exception if there is going to be a recursive lookup, this would make the programmer aware of the problem, and not just shut down the server

Id dependent view resources should accept **kwargs

After overriding a view resource (destroy) only to have it accept more than one keyword argument (id), it hit me that that resources that takes the 'id' argument should probably accept '**kwargs' insted of 'id'. And then do a kwargs lookup. This way you don't have to override a 'id' dependent view, just because your routing sends the resource several kwargs.

I haven't actually tried not overriding the view, but logically it would complain about being fed to many kwargs if i didn't.

Tests

We really, really, really need tests.

ugettext is not being evaluated

when trying to localize the prefix using ugettext_lazy, strange things happen:

http://localhost:8000/nachrichten/%3Cdjango.utils.functional.__proxy__%20object%20at%200x2161910%3Eindex.html

JSONMiddleware doesn't propagate nested JSON

JSONMiddleware cannot propagate nested JSON objects to request.POST due to limitations in the QueryDict class, which can only be initialized from an urlencoded string. We need to find a way to initialize a QueryDict instance in a way that isn't detrimental to our data integrity.

Can't mark views as CSRF exempt

Respite is incompatible with the csrf_exempt decorator since we're using an intermediate view to delegate the request according to its HTTP method.

NoReverseMatch exception

Respite raises a NoReverseMatch exception upon creating a new item if the "show" action isn't routed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.