-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Views are using a subclass or HttpRequest #141
Conversation
…able directly on the request - see #128
Nice one! |
I'll update the examples, and correct the wrong tests. Concerning the docs, I am not really sure where it should be updated. Ideas ? Also, while I am at it, what would you change ? |
Rather than create a new class at runtime, subclassing from request, I'd instead store the original request object in ._request and delegate any getattr, setattr calls through to the original request object. Then you don't need the request factory stuff. t. On 23 Jan 2012, at 06:03, [email protected] wrote:
|
Yep ... that's one of the suggestions I listed here : #128 Like I said there - the solution you suggest feels like the most hackish to me, especially when you need to do a method overriding :
And if it's for doing that, subclassing HttpRequest makes actually no sense ; also you loose the original request class (which can be a WSGIRequest or smthg else ...). That said, if you still think it's the best solution ... let's go for it. But you should really weight the pros and cons. And do you really think it'll make for less hackish code ? |
Sorry I hadn't read through that yet. Yup those look like the 3 possibilities to me too. For overriding existing methods you'd do...
I'm fairly sure it'll be pretty nice and clean, but if there's any issues happy to rethink. |
Re. docs. in terms of this pull request I'm only really concerned with making sure that any examples that are in there at the moment are updated if they need to be. |
Aw ... yeah, I don't know what I had in mind with that snippet !!! You're absolutely right. On the other hand ... is it just a matter of preference ? Or is there an actual difference between the two solutions ? Because, as it works like that ... if it's just for cosmetics, we can also change it later. |
Yep ... I'll update the examples. What about the doc ? |
Just make sure there's nowhere in the docs that's broken I guess. On 23 Jan 2012, at 09:44, [email protected] wrote:
|
Examples didn't need any modification (or so it seemed). I checked, I didn't see any place where |
|
Er, with |
Note that in this pull request I didn't touch to |
And some doc + example in the browsable API |
Looking good! |
I think it sounds good ! |
… renamed ErrorResponse to ImmediateResponse
Ok @tomchristie . The responses are done too. Now would be a good time to review it, and maybe think of merging it to the trunk at last !!! |
Great! It might take a little while before it gets pulled in - it's such a big backwards-incompatible change that I'd like to really go through it well before it gets released. There's a few bits & pieces that I'd tweak - How would you like my to tackle that? - Do you want me to review and you make the changes, or would you like me to go ahead and make 'em myself. (Aware that you've already put a lot of time into this, so don't want to ask too much!) |
raise ErrorResponse(status.HTTP_404_NOT_FOUND, | ||
{'detail': 'That page contains no results'}) | ||
raise ImmediateResponse( | ||
content={'detail': 'That page contains no results'}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop the content
keyword arg.
Looking good! |
Ok ... I made the suggested fixes. It would be great now if you could pull - so I can get this nice change set off my hands :) I know there are still a bunch of stuff to do, but we can create tickets for those, so that anybody motivated can also do it. For example, the examples - and DocumentingRenderer - are a bit broken, and I don't have time to fix them now. |
I would say - if you do pull - there's 4 stuff still to be done :
|
Yo. Also see my notes on #8 re. Going to need to start documenting all this pretty soon. The end goal is that we should end up with 5 very nicely decoupled areas:
|
Hmm you forget to mention a huge bit :
And that's part of the problems mentioned in #158. It's going to be complicated mostly because Django folks have made the choice (bad choice imo), to put together deserialization and validation in forms. And we wanna use forms right !? But I'd really really like those 2 steps to be tweakable separately. And that'll require a lot of niftiness and creativity !!! |
Also I'm not entirely convinced that more stuff should live with request/response. How will you ensure after that everything is uncoupled ? request/parsers and response/renderers make sense because renderers and parsers are useless alone, and response and request are useless alone. But that's not the case for serialization or authentication !!! I would say the parts should be :
Because all of those are atomic bits that you might want to use separately |
The auth stuff has to be part of the request, because we have to force If we don't do that then we end up with both The serialization going onto the response let's three things happen:
I don't think we need to go into lots of detail about validation/deserialization right now, that's one for another day. Have faith! ;-p |
NB. I'm more likely to be swayed that the serializers bit might not be needed, but I think the auth part definitely is. |
Absolutely right. In fact, I haven't really looked at the I'm totally convinced by 3. !!! I was thinking about that yesterday actually : what if ??? I tried to render all my pages AND json API with the same view from drf ? And that kind of give an answer to it !!! Although now (introducing So, yeah ... I keep faith !!! |
Ace! |
(And comments noted.) |
So ... apart from all that, is there still anything holding you from pulling this in ? Should I fix anything else ? |
there is still something I couldn't fix, cause it requires more thinking : #163 |
Pulled into |
Yaaaay !!! :D |
The new custom request takes care of ".DATA", ".FILES", overloaded HTTP method, content type and content.