{"id":17004151,"url":"https://github.com/zerc/django-vest","last_synced_at":"2025-04-12T07:04:23.890Z","repository":{"id":33661997,"uuid":"37314585","full_name":"zerc/django-vest","owner":"zerc","description":"Extension of the default template system to make templates inheritance more flexible.","archived":false,"fork":false,"pushed_at":"2022-12-26T19:44:15.000Z","size":46,"stargazers_count":3,"open_issues_count":5,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-04T18:07:39.001Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zerc.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-12T09:49:49.000Z","updated_at":"2024-01-17T18:11:25.000Z","dependencies_parsed_at":"2023-01-15T01:56:53.407Z","dependency_job_id":null,"html_url":"https://github.com/zerc/django-vest","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zerc%2Fdjango-vest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zerc%2Fdjango-vest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zerc%2Fdjango-vest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zerc%2Fdjango-vest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zerc","download_url":"https://codeload.github.com/zerc/django-vest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239359589,"owners_count":19625667,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T04:42:51.224Z","updated_at":"2025-02-21T01:31:26.792Z","avatar_url":"https://github.com/zerc.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"django-vest\n===========\n\n.. image:: https://img.shields.io/pypi/v/django-vest.svg\n    :target: https://pypi.python.org/pypi/django-vest\n    :alt: Latest PyPI version\n\n.. image:: https://travis-ci.org/zerc/django-vest.svg?branch=master\n    :target: https://travis-ci.org/zerc/django-vest\n    :alt: Build status\n\nExtension of default template system what makes inheritance more flexible through add themes.\n\nUsage\n-----\nImagine that you have several sites on different hosts. They differ by visually and functionally a bit. ``django-vest`` provides the way to use the same code base in such kind of situations.\n\nIt allows splitting templates into ``themes`` - for one per site. Also, it provides the extended inheritance between these themes through `DEFAULT_THEME` keyword. Using this keyword in templates we can override each template. For example:\n\n.. code:: html\n\n    {% extends 'DEFAULT_THEME/index.html' %}\n    {% block page_title %}Dark theme{% endblock %}\n\n``django-vest`` has several ways to split a logic according to ``CURRENT_THEME`` in views. Assume that you have some ``form`` class which is different for each theme. Then your code may look like:\n\n\n.. code:: python\n\n    # forms.py\n    from django_vest.decorators import themeble\n\n    @themeble(name='Form', themes=('dark_theme',))\n    class DarkThemeForm(object):\n        ''' Some kind of logic/fields for dark_theme form\n        '''\n        name = 'DarkThemeForm'\n\n\n    @themeble(name='Form')\n    class DefaultForm(object):\n        ''' Default logic/fields for all themes\n        '''\n        name = 'Default form'\n\n\n    # views.py\n    from .forms import Form\n\n\nIn example above ``Form`` class will be an alias for DarkThemeForm if ``settings.CURRENT_THEME == 'dark_theme'``, otherwise it is ``DefaultForm``.\n\nYou can use ``only_for`` decorator to restrict access to particular view according to value of ``CURRENT_THEME``:\n\n.. code:: python\n\n    # views.py\n    from django.http import Http404\n    from django.views.generic.base import TemplateView\n\n    from django_vest import only_for\n\n    @only_for('black_theme')\n    def my_view(request):\n        ...\n\n    # Redirect for special page\n    dark_theme_page = only_for('dark_theme', redirect_to='restict_access')(\n        TemplateView.as_view(template_name='dark_theme_page.html'))\n\n    # Raise Http404 when user trying to open page with invalid theme\n    dark_theme_page_not_found = \\\n        only_for('dark_theme', raise_error=Http404)(\n            TemplateView.as_view(template_name='dark_theme_page.html'))\n\n\n**Extends of default templates**\n\nVersion 0.1.3 has a new template loader ``django_vest.templates_loaders.AppsLoader`` and new keyword ``DJANGO_ORIGIN``.\n\nNow you can override default django admin template without copy\u0026pasting of whole origin file.\n\nExample:\n\nFile: ``templates/main_theme/admin/change_list.html``\n\n.. code:: html\n\n    {% extends \"DJANGO_ORIGIN/admin/change_list.html\" %}\n    {% load i18n admin_urls admin_static admin_list %}\n\n    {% block breadcrumbs %}\n      \u003cdiv\u003eTemplate has been overridden\u003c/div\u003e\n      {{ block.super }}\n    {% endblock %}\n\n\nInstallation\n------------\n\n.. code:: bash\n\n    $ pip install django_vest\n\nAdd next setting options to your ``settings.py``:\n\n.. code:: python\n\n    TEMPLATE_LOADERS = (\n        'django_vest.templates_loaders.Loader',\n        'django_vest.templates_loaders.AppsLoader',\n    )\n\n    DEFAULT_THEME = 'main_theme'\n\n    # Unique for each host\n    CURRENT_THEME = 'dark_theme'\n\nOr you can set the OS environment:\n\n.. code:: bash\n\n    export DJANGO_VEST_CURRENT_THEME=dark_theme\n\nYou can specify a list of backends for getting settings. Default is:\n\n.. code:: python\n\n    VEST_SETTINGS_BACKENDS_LIST = (\n        'django_vest.config.backends.simple',\n        'django_vest.config.backends.env'\n    )\n\n* django_vest.config.backends.simple - getting settings about theme from project`s settings file.\n* django_vest.config.backends.env - from os envirom\n\nThen you need to update a structure of your templates like this:\n\n.. code:: bash\n\n    exampleproject/templates/\n    | - dark_theme\n        | - index.html\n    | - main_theme\n        | - index.html\n\n**IMPORTANT**: theme folder must ends with *_theme* suffix (example: my_super_mega_theme)\n\nOther config backends (Experimental)\n------------------------------------\nDjango-vest have are several other backends like:\n\n``django_vest.config.backends.database``. If you have some singleton model to store settings of your site you can use ``django_vest.fields.VestField`` to store value of  ``CURRENT_THEME`` in database.\n\nTo activate this feature you have to do next:\n\n* Add ``django_vest.fields.VestField`` to your settings model and do migrate.\n* Add ``django_vest.config.backends.database`` backend to the top of ``VEST_SETTINGS_BACKENDS_LIST`` setting. Example:\n\n.. code:: python\n\n    VEST_SETTINGS_BACKENDS_LIST = (\n        'django_vest.config.backends.database',\n        'django_vest.config.backends.simple',\n        'django_vest.config.backends.env',\n    )\n\n\nContributing\n------------\n\n1. Fork the `django-vest` repo on GitHub.\n2. Clone your fork locally:\n\n.. code:: bash\n\n    $ git clone git@github.com:your_name_here/django-vest.git\n\n3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:\n\n.. code:: bash\n\n    $ mkvirtualenv django-vest\n    $ cd django-vest/\n    $ python setup.py develop\n\n4. Create a branch for local development:\n\n.. code:: bash\n\n    $ git checkout -b name-of-your-bugfix-or-feature\n\n   Now you can make your changes locally.\n\n5. When you're done making changes, check that your changes pass the tests, including testing other Python versions with tox:\n\n.. code:: bash\n\n    $ make test-all\n\n6. Commit your changes and push your branch to GitHub:\n\n.. code:: bash\n\n    $ git add .\n    $ git commit -m \"Your detailed description of your changes.\"\n    $ git push origin name-of-your-bugfix-or-feature\n\n7. Submit a pull request through the GitHub website.\n\n\nLicence \u0026 Authors\n-------------------\nThe MIT License (MIT)\n\nCopyright (c) 2015 `Vladimir Savin \u003czero13cool@yandex.ru\u003e`_.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzerc%2Fdjango-vest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzerc%2Fdjango-vest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzerc%2Fdjango-vest/lists"}