Reusable, generic mixins for Django

Overview

django-braces

Mixins for Django's class-based views.

Latest Travis CI status PyPI version

Documentation

Read The Docs

Installation

Install from PyPI with pip: pip install django-braces

Building the Docs

  1. Install docs requirements: pip install -r requirements-docs.txt.
  2. cd docs.
  3. make html.
  4. Open _build/index.html in your browser.

Contributing

See our contribution guide

Add yourself to CONTRIBUTORS.txt if you want.

All development dependencies are available in requirements.txt file.

To run the test suite, please install tox and as many Python interpreters as you'd like to test against. Currently we test against 2.7, 3.6, 3.7, and 3.8. We recommend using asdf to install various Python versions.

Once tox and Python(s) are installed, you can execute the entire suite by running just the tox command.

Change Log

Changelog on Read The Docs

Supported Django Versions

Our policy is that django-braces officially supports, and is tested on, all versions that Django officially supports. You are free to use django-braces with any version of Django you wish (so long as it has class-based views) but no support will be promised.

Comments
  • Login required without exception, permission required with

    Login required without exception, permission required with

    I require the functionality to create a view that redirects to the login page if the user is not logged in, but raises an exception if they are but do not have the correct permissions. In vanilla Django, I'd do the following:

    @login_required
    @permission_required('my_permission', raise_exception=True)
    def my_view(request):
        pass
    

    Doing this using the LoginRequiredMixin and the PermissionRequiredMixin is impossible, as they both use the same raise_exception class-level variable.

    This would apply to the MultiplePermissionsRequiredMixin also.

    opened by benbacardi 15
  • PermissionRequiredMixin doesn't allow custom permissions/object permissions

    PermissionRequiredMixin doesn't allow custom permissions/object permissions

    The PermissionRequiredMixin does not allow for checking custom object permissions provided by libraries like django object permissions or django-guardian.

    I was thinking of updating it to be similar to https://github.com/lukaszb/django-guardian/blob/master/guardian/mixins.py#L52

    Except stripping out the parts where it does object specific actions or guardian specific things, and allow overriding to implement said functionality.

    opened by chancez 15
  • Potential mixin contributions - sortable-listview & spreadsheet-response

    Potential mixin contributions - sortable-listview & spreadsheet-response

    Hi lovely django-braces people, hope this is the right place for this, I wasn't sure how best to reach you otherwise. Am a huge fan of braces, use it a lot.

    I have two mixins which I'm wondering whether you might be interested in. If so, I'd be delighted to do the work to get them fit for braces, they already have some tests, but not python 3 etc..

    django-spreadsheetresponsemixin - https://github.com/birdsarah/django-spreadsheetresponsemixin Renders views that have a queryset e.g. a ListView, into an excel spreadsheet or a CSV. Takes headers from model or you can customize them. Can specify fields and order columns by doing so. Maybe you don't want to rely on additional libraries, so maybe just the CSV portion would be interesting.

    django-sortable-listview - https://github.com/aptivate/django-sortable-listview Like OrderableListMixin but takes things a bit further, for example, if you're already sorted in one direction it'll provide context data so that the next sort can be in the opposite direction. Obviously, would be happy to pull out specific features and add them to the existing OrderableListMixin.

    Thanks in advance for your thoughts.

    opened by birdsarah 14
  • redirect_unauthenticated_users will cause raise_exception to be ignored

    redirect_unauthenticated_users will cause raise_exception to be ignored

    When chaining LoginRequiredMixin and another AccessMixin, setting raise_exception = True and redirect_unauthenticated_users = True doesn't seem to do the right thing.

    opened by cornmander 12
  • Adding OwnerOrPermissionRequiredMixin

    Adding OwnerOrPermissionRequiredMixin

    I have made a mixin that checks if the user is regarded as owner for an object, if not it checks if the user has the given permission. Nice to have for Django's UpdateView or DeleteView. Tests and docs are updated :)

    opened by erlingbo 12
  • Added a cache mixin [builds on #159]

    Added a cache mixin [builds on #159]

    Picking up on work done by @omerzimp in #159. Addressing concerns in #159 and adding tests. Last modified times must now also be timezone-aware datetimes.

    Edit: Todos:

    • [x] Initial documentation
    • [x] Support for conditional retrieval (see the condition mixin)
    • [x] ~~Consider sha1'ing the response from get_etag(), and rename to get_etag_data()~~ No, a separate ETag class could provide better functionality, but that's probably out of scope for now.
    • [x] Add support for Cache-Control: private/public
    • [x] Finalise documentation
    opened by adamcharnock 10
  • Django 1.4 - braces tag 1.4.0 error

    Django 1.4 - braces tag 1.4.0 error

    The doc on github says that works but is not working.

    1.4.x will be the last version to officially support Django 1.4.x

    Django 1.4.1-final, 0

    ImportError at /admin/xxxxx
    cannot import name force_text
    
    opened by alexsilva 9
  • OwnerRequiredMixin

    OwnerRequiredMixin

    What about adding an OwnerRequiredMixin to work with the DetailView, UpdateView and DeleteView views.

    Something like ...

    class OwnerRequiredMixin(object):
    
        def dispatch(self, request, *args, **kwargs):
            self.object = self.get_object()
    
            if request.user != self.object.user:
                raise PermissionDenied
    
            return super(OwnerRequiredMixin, self).dispatch(request, *args, **kwargs)
    
    opened by epicserve 9
  • Customizable LoginRequiredMixin

    Customizable LoginRequiredMixin

    The LoginRequiredMixin was lacking the ability to customize login_url, redirect field, or redirect path per view because it was using a decorator. Since these things need to change based on instance, we are using the redirect_to_login view directly instead of the login_required decorator, and we are adding methods and properties which allow us to micro-manage the view instances.

    opened by foxbunny 9
  • TBD: access mixins: support for custom exceptions

    TBD: access mixins: support for custom exceptions

    I wanted to use a custom exception with SuperuserRequiredMixin (Http404) and added support for it.

    raise_exception can now be True, False, a custom exception or a callable (that should return a response).

    I have then factored the no-permission handling into a separate function, and moved redirect_unauthenticated_users to the base mixin.

    This does not include any documentation changes yet, because I wanted to gather feedback on it first.

    E.g., I am not sure if handle_no_permission should fall back to raising an exception for any non-HTTP-response (not isinstance(ret, (HttpResponse, StreamingHttpResponse))).

    opened by blueyed 8
  • Add PrepareMixin

    Add PrepareMixin

    I've added here a mixin we use intermittently when the normal flow of a class-based view becomes awkward. It allows you to place permission and/or existence checking earlier in the process in a more reusable way, especially useful when dealing with permissions of related objects. It also allows you to do more than just 404 if permissions are different which is hard to do from within a normal integration point (e.g. get_object). Hopefully my documentation makes sense!

    Personally I find this updated dispatch method a much cleaner way to do checking early in a view compared to messing around in the dispatch method, mainly as args, kwargs, request are all set already. Perhaps some of the other mixins here could be made cleaner using this, I've not looked too closely.

    I'm open to changes of terminology if you think the naming is unclear.

    opened by mjtamlyn 8
  • docs: Fix a few typos

    docs: Fix a few typos

    There are small typos in:

    • docs/other.rst
    • tests/test_access_mixins.py

    Fixes:

    • Should read respond rather than responsed.
    • Should read passing rather than passsing.

    Semi-automated pull request generated by https://github.com/timgates42/meticulous/blob/master/docs/NOTE.md

    opened by timgates42 1
  • Django 4 ajax

    Django 4 ajax

    need change:

    class AjaxResponseMixin(object): def dispatch(self, request, *args, **kwargs): request_method = request.method.lower()

        if request.is_ajax and request_method in self.http_method_names:
    

    here modify: if request.headers.get('x-requested-with') == 'XMLHttpRequest' and request_method in self.http_method_names:

    its work now

    opened by jonaqp 2
  • Cleaner approach to `HeaderMixin`

    Cleaner approach to `HeaderMixin`

    satisfying

    This PR introduces a backwards-compatible change to the HeaderMixin. Our existing method works but feels kind of heavy-handed. This approach is more in-line with Django's design, IMO, and doesn't feel as blunt.

    Unfortunately, it only works if render_to_response is ultimately called, so I had to leave in the old approach as well. Maybe we should split it up into a new mixin?

    opened by kennethlove 1
  • Look at refactoring tests

    Look at refactoring tests

    Our tests seem a little overly complicated. We should make sure they're as easy to write as possible.

    Maybe we should have a "how to write a test" guide

    opened by kennethlove 0
Releases(v1.15.0)
  • v1.15.0(Nov 5, 2021)

    • Updates and fixes from https://github.com/brack3t/django-braces/pull/265
    • Typo fixes from https://github.com/brack3t/django-braces/pull/269 and https://github.com/brack3t/django-braces/pull/262
    • Formatted project with black
    • Dropped explicit support for Python versions before 3.7 and non-LTS versions of Django
    Source code(tar.gz)
    Source code(zip)
  • v1.14.0(Dec 30, 2019)

  • v1.13.0(Dec 23, 2019)

  • v1.12.0(Dec 23, 2019)

  • v1.11.0(Dec 23, 2019)

  • v1.10.0(Dec 23, 2019)

  • 1.9.0(May 31, 2016)

    • [Feature] #203: Use Django’s supplied version of six to remove an external dependency.
    • [Bug] #161: Fixed redirect loop for users without proper groups for MultipleGroupRequiredMixin and GroupRequiredMixin.
    • [Bug] #181: Fixed redirect loops based on user permissions.
    • [Bug] #196: Refactor how users without permissions are handled.
    • [Bug] #208: Fixed errors from combining certain access mixins.
    • [Support]: Added note to docs about Python and Django versions used in tests.
    • [Support] #192: Added example for OrderableListView.
    • [Support] #201: Fixed typo in SuccessURLRedirectListMixin.
    • [Support] #202: Fixed typo in PermissionsRequiredMixin and MultiplePermissionsRequiredMixin.
    • [Support] #209: Fixed link to Django documentation for user_passes_test decorator.
    Source code(tar.gz)
    Source code(zip)
  • v1.8.0(Apr 17, 2015)

    • #145 Allow custom exceptions to be raised by all AccessMixins.
    • #171 New SSLRequiredMixin. Redirect http -> https.
    • #138 New RecentLoginRequiredMixin to require user sessions to have a given freshness.
    • #164 Use resolve_url to handle LOGIN_REDIRECT_URLs in settings.py that are just URL names.
    • #130 New attribute on JSONResponseMixin to allow setting a custom JSON encoder class.
    • #131 New attribute on LoginRequiredMixin so it's possible to redirect unauthenticated users while using AccessMixin-derived mixins instead of throwing an exception.
    Source code(tar.gz)
    Source code(zip)
  • v1.4.0(Mar 4, 2014)

    • Split views.py out into multiple files since it was approaching 1000 LoC.
    • SetHeadlineMixin now accepts headline with ugettext_lazy()-wrapped strings.
    • Fixed a bug where JSONResponseMixin would override the content_type of Django's TemplateView in Django 1.6.
    • Fixed bug in PermissionRequiredMixin where if PermissionRequiredMixin.no_permissions_fail returned a false-y value, the user lacking the permission would pass instead of being denied access.
    • Added doc for how to contribute.
    • Added MessageMixin to allow easier access to Django's contrib.messages messages. FormValidMessageMixin and FormInvalidMessageMixin were updated to use it.
    • Fixed bug in CanonicalSlugDetailMixin to allow it to use custom URL kwargs.
    • Fixed bug in GroupRequiredMixin where superusers were blocked by lack of group memberships.
    • Fixed bug in GroupRequiredMixin which now correctly checks for group membership against a list.
    • Added new StaticContextMixin mixin which lets you pass in static_context as a property of the view.
    • Added new AnonymousRequiredMixin which redirects authenticated users to another view.
    • Added new AllVerbsMixin which allows a single method to response to all HTTP verbs.
    • Provided JSONRequestResponseMixin as a mirror of JsonRequestResponseMixin because we're not PHP.
    • FormValidMessageMixin, FormInvalidMessageMixin, and FormMessagesMixin all allow ugettext_lazy-wrapped strings.
    • Extended PermissionRequiredMixin and MultiplePermissionsRequiredMixin to accept django-guardian-style custom/object permissions.
    Source code(tar.gz)
    Source code(zip)
  • v1.3.1(Jan 5, 2014)

  • v1.3.0(Jan 4, 2014)

    • Removed CreateAndRedirectToEditView mixin. It was marked for deprecation and removal since 1.0.
    • Added JsonRequestAndResponseMixin mixin which attempts to parse requests as JSON.
    • Added CanonicalSlugDetailMixin mixin which allows for the specification of a canonical slug on a DetailView to help with SEO by redirecting on non-canonical requests.
    • Added UserPassesTestMixin mixin to replicate the behavior of Django's @user_passes_test decorator.
    • Some fixes for CanonicalSlugDetailMixin.
    • AccessMixin now has a runtime-overridable login_url attribute.
    • Fixed problem with GroupRequiredMixin that made it not actually work.
    • All tests pass for Django versions 1.4 through 1.6 and Python versions 2.6, 2.7, and 3.3 (Django 1.4 and 1.5 not tested with Python 3.3).
    • Tests and documentation changes for all of the above.
    Source code(tar.gz)
    Source code(zip)
  • v1.2.2(Aug 7, 2013)

  • v1.2.1(Jul 28, 2013)

  • v1.2.0(Jul 27, 2013)

    • FormValidMessageMixin which provides a messages message when the processed form is valid.
    • FormInvalidMessageMixin which provides a messages message when the processed form is invalid.
    • FormMessagesMixin which provides the functionality of both of the above mixins.
    • GroupRequiredMixin which is a new access-level mixin which requires that a user be part of a specified group to access a view.
    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Jul 18, 2013)

    1.1.0 Release

    • JSONResponseMixin.render_json_response method updated to accept a status code.
    • JSONResponseMixin added json_dumps_kwargs attribute & get method to pass args to the json encoder.
    • New OrderableListMixin allows ordering of list views by GET params.
    • Tests updated to test against latest stable Django release (1.5.1)
    • Small fixes and additions to documentation.
    Source code(tar.gz)
    Source code(zip)
Twitter Bootstrap for Django Form - A simple Django template tag to work with Bootstrap

Twitter Bootstrap for Django Form - A simple Django template tag to work with Bootstrap

tzangms 557 Oct 19, 2022
A simple trivia quizzz web app made using django

Trivia Quizzz A simple trivia quizzz web app made using django Demo http://triviaquizzz.herokuapp.com/ & https://triviaquiz.redcrypt.xyz Features Goog

Rachit Khurana 2 Feb 10, 2022
Django React - Purity Dashboard (Open-Source) | AppSeed

Django React Purity Dashboard Start your Development with an Innovative Admin Template for Chakra UI and React. Purity UI Dashboard is built with over

App Generator 19 Sep 19, 2022
GeoDjango provides geospatial extensions to the Django web dev framework

Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. All documentation is in the "docs" directo

Paul Smith 20 Sep 20, 2022
Source code for Django for Beginners 3.2

The official source code for https://djangoforbeginners.com/. Available as an ebook or in Paperback. If you have the 3.1 version, please refer to this

William Vincent 10 Jan 03, 2023
Radically simplified static file serving for Python web apps

WhiteNoise Radically simplified static file serving for Python web apps With a couple of lines of config WhiteNoise allows your web app to serve its o

Dave Evans 2.1k Dec 15, 2022
Exploit Discord's cache system to remote upload payloads on Discord users machines

Exploit Discord's cache system to hide payloads PoC Remote upload embedded payload from image using EOF to Discord users machines through cache. Depen

cs 169 Dec 20, 2022
This is raw connection between redis server and django python app

Django_Redis This repository contains the code for this blogpost. Running the Application Clone the repository git clone https://github.com/xxl4tomxu9

Tom Xu 1 Sep 15, 2022
A multiprocessing distributed task queue for Django

A multiprocessing distributed task queue for Django Features Multiprocessing worker pool Asynchronous tasks Scheduled, cron and repeated tasks Signed

Ilan Steemers 1.7k Jan 03, 2023
A standalone package to scrape financial data from listed Vietnamese companies via Vietstock

Scrape Financial Data of Vietnamese Listed Companies - Version 2 A standalone package to scrape financial data from listed Vietnamese companies via Vi

Viet Anh (Vincent) Tran 45 Nov 16, 2022
Twitter-clone using Django (DRF) + VueJS

Twitter Clone work in progress 🚧 A Twitter clone project Table Of Contents About the Project Built With Getting Started Running project License Autho

Ahmad Alwi 8 Sep 08, 2022
📝 Sticky Notes in Django admin

django-admin-sticky-notes Share notes between superusers. Installation Install via pip: pip install django_admin_sticky_notes Put django_admin_sticky_

Dariusz Choruży 7 Oct 06, 2021
Bootstrap 4 integration with Django.

django-bootstrap 4 Bootstrap 4 integration for Django. Goal The goal of this project is to seamlessly blend Django and Bootstrap 4. Requirements Pytho

Zostera B.V. 980 Dec 29, 2022
A simple app that provides django integration for RQ (Redis Queue)

Django-RQ Django integration with RQ, a Redis based Python queuing library. Django-RQ is a simple app that allows you to configure your queues in djan

RQ 1.6k Jan 06, 2023
Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly.

Cookiecutter Django Powered by Cookiecutter, Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly. Documentati

Daniel Feldroy 10k Dec 31, 2022
A simple porfolio with Django, Bootstrap and Sqlite3

Django Portofolio Example this is a basic portfolio in dark mode Installation git clone https://github.com/FaztWeb/django-portfolio-simple.git cd djan

Fazt Web 16 Sep 26, 2022
Displaying objects on maps in the Django views and administration site.

DjangoAdminGeomap library The free, open-source DjangoAdminGeomap library is designed to display objects on the map in the Django views and admin site

Vitaly Bogomolov 31 Dec 28, 2022
PicoStyle - Advance market place website written in django

Advance market place website written in django :) Online fashion store for whole

AminAli Mazarian 26 Sep 10, 2022
This is django-import-export module that exports data into many formats

django-import-export This is django-import-export module which exports data into many formats, you can implement this in your admin panel. - Dehydrat

Shivam Rohilla 3 Jun 03, 2021
Probably the best abstract model / admin for your tree based stuff.

django-treenode Probably the best abstract model / admin for your tree based stuff. Features Fast - get ancestors, children, descendants, parent, root

Fabio Caccamo 360 Jan 05, 2023