GithubHelp home page GithubHelp logo

alir3z4 / django-crequest Goto Github PK

View Code? Open in Web Editor NEW
60.0 60.0 10.0 23 KB

django-crequest - Taking care of current request in silent way.

Home Page: http://pypi.python.org/pypi/django-crequest

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%
authentication django

django-crequest's People

Contributors

alir3z4 avatar asergeant01 avatar coredumperror avatar richardroyal 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  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  avatar  avatar  avatar

django-crequest's Issues

Python 2 Support

The 2018.5.1 release will cause exception in python 2.

Downloading https://files.pythonhosted.org/packages/ac/36/80fc1d95cea52f5ff1cc3bbf338c8e1a18388b5b75b0c316f62afdf69e89/django-crequest-2018.5.1.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-hzETvf/django-crequest/setup.py", line 9, in <module>
        license=open('LICENSE', encoding='utf-8').read(),
    TypeError: 'encoding' is an invalid keyword argument for this function

Sometimes request objects are missing

django 1.11.1
python 2.7
django-crequest 2016.3.16

If used with the new MIDDLEWARE setting (instead of the old MIDDLEWARE_CLASSES one) there is some scenario things don't work properly.

I'm using wagtail (a CMS open source based on django). Wagtail has a SiteMiddleware that sets a site attribute onto the request object containing the current site. This middleware comes after the CrequestMiddleware.

Only when rendering a template in wagtail's preview mode, I get a None site (previously setted with the right value). A method object used in the template accesses the request object as usually request = CrequestMiddleware.get_request() where then i see request.site is None. This doesn't happen if I switch back to the MIDDLEWARE_CLASSES setting.

Internal Server Error: /cms/admin/pages/39/edit/preview/
Traceback (most recent call last):
  File "C:\...\Lib\site-packages\django\core\handlers\exception.py", line 41, in inner
    response = get_response(request)
  File "C:\...\Lib\site-packages\django\core\handlers\base.py", line 217, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\...\Lib\site-packages\django\core\handlers\base.py", line 215, in _get_response
    response = response.render()
  File "C:\...\Lib\site-packages\django\template\response.py", line 107, in render
    self.content = self.rendered_content
  File "C:\...\Lib\site-packages\django\template\response.py", line 84, in rendered_content
    content = template.render(context, self._request)
  File "C:\...\Lib\site-packages\django\template\backends\django.py", line 66, in render
    return self.template.render(context)
  File "C:\...\Lib\site-packages\django\template\base.py", line 207, in render
    return self._render(context)
  File "C:\...\Lib\site-packages\django\test\utils.py", line 107, in instrumented_test_render
    return self.nodelist.render(context)
  File "C:\...\Lib\site-packages\django\template\base.py", line 990, in render
    bit = node.render_annotated(context)
  File "C:\...\Lib\site-packages\django\template\base.py", line 957, in render_annotated
    return self.render(context)
  File "C:\...\Lib\site-packages\django\template\loader_tags.py", line 177, in render
    return compiled_parent._render(context)
  File "C:\...\Lib\site-packages\django\test\utils.py", line 107, in instrumented_test_render
    return self.nodelist.render(context)
  File "C:\...\Lib\site-packages\django\template\base.py", line 990, in render
    bit = node.render_annotated(context)
  File "C:\...\Lib\site-packages\django\template\base.py", line 957, in render_annotated
    return self.render(context)
  File "C:\...\Lib\site-packages\django\template\loader_tags.py", line 177, in render
    return compiled_parent._render(context)
  File "C:\...\Lib\site-packages\django\test\utils.py", line 107, in instrumented_test_render
    return self.nodelist.render(context)
  File "C:\...\Lib\site-packages\django\template\base.py", line 990, in render
    bit = node.render_annotated(context)
  File "C:\...\Lib\site-packages\django\template\base.py", line 957, in render_annotated
    return self.render(context)
  File "C:\...\Lib\site-packages\django\template\loader_tags.py", line 72, in render
    result = block.nodelist.render(context)
  File "C:\...\Lib\site-packages\django\template\base.py", line 990, in render
    bit = node.render_annotated(context)
  File "C:\...\Lib\site-packages\django\template\base.py", line 957, in render_annotated
    return self.render(context)
  File "C:\...\Lib\site-packages\django\template\loader_tags.py", line 216, in render
    return template.render(context)
  File "C:\...\Lib\site-packages\django\template\base.py", line 209, in render
    return self._render(context)
  File "C:\...\Lib\site-packages\django\test\utils.py", line 107, in instrumented_test_render
    return self.nodelist.render(context)
  File "C:\...\Lib\site-packages\django\template\base.py", line 990, in render
    bit = node.render_annotated(context)
  File "C:\...\Lib\site-packages\django\template\base.py", line 957, in render_annotated
    return self.render(context)
  File "C:\...\Lib\site-packages\django\template\defaulttags.py", line 166, in render
    values = self.sequence.resolve(context, True)
  File "C:\...\Lib\site-packages\django\template\base.py", line 708, in resolve
    obj = self.var.resolve(context)
  File "C:\...\Lib\site-packages\django\template\base.py", line 849, in resolve
    value = self._resolve_lookup(context)
  File "C:\...\Lib\site-packages\django\template\base.py", line 890, in _resolve_lookup
    current = getattr(current, bit)
  File "C:\...\Lib\site-packages\django\utils\functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\tron\eclipse_workspace\mydjangobase\mydjangobase_HEAD\my_cms\models_base.py", line 565, in csspages_css
    csspages = self.get_basepage.csspages_css
  File "C:\...\Lib\site-packages\django\utils\functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\tron\eclipse_workspace\mydjangobase\mydjangobase_HEAD\my_cms\models_base.py", line 527, in get_basepage
    return self._get_basepages[0]
  File "C:\...\Lib\site-packages\django\utils\functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\tron\eclipse_workspace\mydjangobase\mydjangobase_HEAD\my_cms\models_base.py", line 504, in _get_basepages
    basepages.append(SiteSettings.for_site(request.site).fk_basepage or BasePage())
AttributeError: 'NoneType' object has no attribute 'site'
[08/May/2017 17:31:40] "GET /cms/admin/pages/39/edit/preview/ HTTP/1.1" 500 240362

A new PyPI release?

Could you make a new release for PyPI, please? That encoding error that you fixed 5 months ago is necessary to make this module work in Python 3, which my team needs.

We're installing the package directly from here for now, but it'd be very nice to be able to install from an official PyPI build.

Thanks!

process_exception() should not delete the request when using MIDDLEWARE.

I just discovered today that CrequestMiddleware.process_response() should not be deleting the request, due to how exceptions are now handled by the MIDDLEWARE setting. Rather than process_exception() being called instead of process_response() when an exception occurs, it gets called before and in addition to process_response().

I discovered this because I have code that attempts to retrieve the current request when a 404 page is rendered, and it was crashing because the request object had already been deleted by the time the 404.html template was rendered.

Careful reading of the new MIDDLEWARE docs shows that process_response() is always called (unless an earlier middleware returns a response, which short-circuits the middleware chain). This means it's safe to not delete the request in process_exception(), which then allows the request to be retrieved while rendering an error page.

However, I'm fairly sure this isn't true up to Django 1.9, or in any newer Django site that uses MIDDLEWARE_CLASSES instead of MIDDLEWARE. So the right fix here would be to check for MIDDLEWARE in process_exception(), and to just pass if it's defined.

Is the maintainer of this module still watching this issue queue and/or interested in this module? If not, I'd be happy to take over maintainership.

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.