clokep / django-render-block

Render the content of a specific block tag from a Django template.
ISC License
241 stars 23 forks source link

Support for RequestContext during block rendering #15

Closed vintage closed 5 years ago

vintage commented 6 years ago

The current implementation hard-codes use of the Context instance, but lots of apps are using RequestContext instead - https://docs.djangoproject.com/en/2.0/ref/templates/api/#django.template.RequestContext

Refactor context creation to take into account, that both classes are supported by using Django built-in method called make_context.

clokep commented 6 years ago

@vintage I think what you're saying is that if you pass a RequestContext to render_block_to_string it gets rewritten to be a Context instances instead of a RequestContext. Is that accurate?

I've been unable to find any documentation for make_context, am I missing it somewhere?

Any thoughts on adding a test for this?

vintage commented 6 years ago

@clokep That's exactly the case, as right now it's not possible to pass RequestContext down to the block rendering (which I need to accomplish in current project). I've removed the use of make_context as indeed it's not documented anywhere in the official docs - replaced it with more understandable approach, as well with unit test to see how its working.

For some reason the newly added test is failing on Travis (works locally), any ideas?

vintage commented 6 years ago

I've managed to fix the breaking test, but there is still some problem with the Travis itself Error creating virtualenv. Note that some special characters - https://github.com/pytest-dev/pytest/issues/2779

clokep commented 6 years ago

I'll try to fix the issue with travis in a separate branch.

vintage commented 6 years ago

Hey, got any news about this one?

hugokernel commented 5 years ago

Hi, Thx @vintage for the PR. @clokep, could you plan to merge this PR ?

clokep commented 5 years ago

Sorry for the extreme delay on this. Overall it looks reasonable. I left a couple of comments, but can always make these changes myself if necessary. Do you know if Jinja has any similar concept to this?

clokep commented 5 years ago

Also it would be great if we could update the README with some examples / API changes and the changelog too!

vintage commented 5 years ago

@clokep AFAIK Jinja do not provide any concept near the Django RequestContext. I've also updated the README about the new optional parameter.

clokep commented 5 years ago

Thanks for this improvement! I'll probably try to do a couple minor things before releasing. 👍

clokep commented 5 years ago

@vintage FYI I just pushed version 0.6 with this change in it!

vintage commented 5 years ago

@clokep Awesome, great to hear that <3

hugokernel commented 5 years ago

Thx guys !