• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

django_context_decorator.egg-info/H03-May-2022-8565

PKG-INFOH A D14-Apr-20193.2 KiB8565

README.rstH A D14-Apr-20192 KiB6647

django_context_decorator.pyH A D14-Apr-20191.7 KiB5137

setup.cfgH A D14-Apr-201938 53

setup.pyH A D14-Apr-20191.4 KiB4943

README.rst

1django-context-decorator
2------------------------
3
4.. image:: https://img.shields.io/travis/rixx/django-context-decorator.svg
5   :target: https://travis-ci.org/rixx/django-context-decorator
6   :alt: Continuous integration
7
8.. image:: https://img.shields.io/codecov/c/github/rixx/django-context-decorator.svg
9   :target: https://codecov.io/gh/rixx/django-context-decorator
10   :alt: Coverage
11
12.. image:: https://img.shields.io/pypi/v/django-context-decorator.svg
13   :target: https://pypi.python.org/pypi/django-context-decorator
14   :alt: PyPI
15
16``django-context-decorator`` is a Python package for Django removing the need
17to call ``super().get_context_data(**kwargs)`` in nearly every Django view.
18
19Usage
20=====
21
22.. code-block:: python
23
24   from django_context_decorator import context
25   from django.utils.functional import cached_property
26   from django.views.generic import TemplateView
27
28   class MyView(TemplateView):
29       template_name = 'path/to/template.html'
30
31       @context
32       def context_variable(self):
33           return 'context value'
34
35       @context
36       @property
37       def context_property(self):
38           return 'context property'
39
40       @context
41       @cached_property
42       def expensive_context_property(self):
43           return 'expensive context property'
44
45Now you'll have access to ``{{ context_variable }}``, ``{{ context_property }}``
46and ``{{ expensive_context_property }}`` in your template.
47
48Please note: While this package works with the ``@cached_property`` decorator,
49please make sure to add the ``@context`` decorator **above** the
50``@cached_property`` decorator.
51
52Limitations
53===========
54
55Due to the usage of ``__set_name__``, this package is limited to usage with Python 3.6+.
56
57Development
58===========
59
60All code resides in ``django_context_decorator.py``. Tests are collected by
61``pytest`` from all files starting with ``test_``. To run tests, start a
62virtual environment, install the dependencies, and run ``pytest``::
63
64    pip install django pytest pytest-cov
65    py.test --cov-report term --cov=django_context_decorator
66