├── tests
├── __init__.py
├── templates
│ ├── blank.html
│ ├── 404.html
│ └── form.html
├── urls_namespaced.py
├── forms.py
├── compat.py
├── models.py
├── test_forms.py
├── factories.py
├── settings.py
├── helpers.py
├── urls.py
├── test_ajax_mixins.py
├── views.py
├── test_access_mixins.py
└── test_other_mixins.py
├── setup.cfg
├── requirements-docs.txt
├── requirements.txt
├── MANIFEST.in
├── .gitignore
├── .coveragerc
├── conftest.py
├── braces
├── __init__.py
├── forms.py
└── views
│ ├── __init__.py
│ ├── _queries.py
│ ├── _other.py
│ ├── _ajax.py
│ ├── _forms.py
│ └── _access.py
├── CONTRIBUTORS.txt
├── .travis.yml
├── docs
├── index.rst
├── contributing.rst
├── Makefile
├── changelog.rst
├── form.rst
├── conf.py
├── access.rst
└── other.rst
├── setup.py
├── LICENSE
├── README.md
└── tox.ini
/tests/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/templates/blank.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/setup.cfg:
--------------------------------------------------------------------------------
1 | [wheel]
2 | universal = 1
3 |
--------------------------------------------------------------------------------
/requirements-docs.txt:
--------------------------------------------------------------------------------
1 | sphinx
2 | releases
3 |
--------------------------------------------------------------------------------
/tests/templates/404.html:
--------------------------------------------------------------------------------
1 |
404!!!!
2 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | factory_boy
2 | mock
3 | pytest-django
4 | pytest-cov
5 | six
6 | coverage
7 |
--------------------------------------------------------------------------------
/MANIFEST.in:
--------------------------------------------------------------------------------
1 | include README.md
2 | include LICENSE
3 | include CONTRIBUTORS.txt
4 | recursive-include braces *.py
5 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .python-version
3 | ._*
4 | *.pyc
5 | *.egg-info
6 | /docs/_build/
7 | /.coverage
8 | /.coverage.xml
9 | /htmlcov
10 | /.tox
11 | dist/
12 | .idea
13 | build/
14 |
--------------------------------------------------------------------------------
/.coveragerc:
--------------------------------------------------------------------------------
1 | # django-braces coverage config file
2 | [run]
3 | branch = true
4 |
5 | [report]
6 | omit =
7 | *site-packages*
8 | *tests*
9 | *.tox*
10 | *conftest*
11 | show_missing = True
12 |
--------------------------------------------------------------------------------
/tests/templates/form.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {% if messages %}
5 | {% for message in messages %}
6 | {{ message }}
7 | {% endfor %}
8 | {% endif %}
9 |
10 | {{ form.as_p }}
11 |
12 |
13 |
--------------------------------------------------------------------------------
/conftest.py:
--------------------------------------------------------------------------------
1 | import os
2 | from django.conf import settings
3 | from tests import settings as test_settings
4 |
5 |
6 | def pytest_configure():
7 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tests.settings')
8 | settings.configure(default_settings=test_settings)
9 |
--------------------------------------------------------------------------------
/tests/urls_namespaced.py:
--------------------------------------------------------------------------------
1 | from __future__ import absolute_import
2 |
3 | from . import views
4 | from .compat import patterns, url
5 |
6 |
7 | urlpatterns = patterns(
8 | '',
9 | # CanonicalSlugDetailMixin namespace tests
10 | url(r'^article/(?P\d+)-(?P[\w-]+)/$',
11 | views.CanonicalSlugDetailView.as_view(),
12 | name="namespaced_article"),
13 | )
14 |
--------------------------------------------------------------------------------
/tests/forms.py:
--------------------------------------------------------------------------------
1 | from __future__ import absolute_import
2 |
3 | from django import forms
4 |
5 | from braces.forms import UserKwargModelFormMixin
6 |
7 | from .models import Article
8 |
9 |
10 | class FormWithUserKwarg(UserKwargModelFormMixin, forms.Form):
11 | field1 = forms.CharField()
12 |
13 |
14 | class ArticleForm(forms.ModelForm):
15 | class Meta:
16 | model = Article
17 |
--------------------------------------------------------------------------------
/tests/compat.py:
--------------------------------------------------------------------------------
1 | try:
2 | from django.utils.encoding import force_text
3 | except ImportError:
4 | from django.utils.encoding import force_unicode as force_text
5 |
6 | try:
7 | import json
8 | except ImportError:
9 | from django.utils import simplejson as json
10 |
11 | try:
12 | from django.conf.urls import patterns, url, include
13 | except ImportError:
14 | from django.conf.urls.defaults import patterns, url, include
15 |
--------------------------------------------------------------------------------
/braces/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | django-braces mixins library
3 | ----------------------------
4 |
5 | Several mixins for making Django's generic class-based views more useful.
6 |
7 | :copyright: (c) 2013 by Kenneth Love and Chris Jones
8 | :license: BSD 3-clause. See LICENSE for more details
9 | """
10 |
11 | __title__ = 'braces'
12 | __version__ = '1.4.0'
13 | __author__ = 'Kenneth Love and Chris Jones'
14 | __license__ = 'BSD 3-clause'
15 | __copyright__ = 'Copyright 2013 Kenneth Love and Chris Jones'
16 |
--------------------------------------------------------------------------------
/braces/forms.py:
--------------------------------------------------------------------------------
1 | class UserKwargModelFormMixin(object):
2 | """
3 | Generic model form mixin for popping user out of the kwargs and
4 | attaching it to the instance.
5 |
6 | This mixin must precede forms.ModelForm/forms.Form. The form is not
7 | expecting these kwargs to be passed in, so they must be popped off before
8 | anything else is done.
9 | """
10 | def __init__(self, *args, **kwargs):
11 | self.user = kwargs.pop("user", None) # Pop the user off the
12 | # passed in kwargs.
13 | super(UserKwargModelFormMixin, self).__init__(*args, **kwargs)
14 |
--------------------------------------------------------------------------------
/CONTRIBUTORS.txt:
--------------------------------------------------------------------------------
1 | ====
2 | Team
3 | ====
4 |
5 | Project Leads
6 | =============
7 |
8 | * Kenneth Love
9 | * Chris Jones
10 |
11 | Direct Contributors
12 | ===================
13 |
14 | * Daniel Greenfeld
15 | * Drew Tempelmeyer
16 | * Baptiste Mispelon
17 | * Derek Payton
18 | * Rafal Stozek
19 | * Ethan Soergel
20 | * Piotr Kilczuk
21 | * Rodney Folz
22 | * Markus Zapke-Gründemann
23 | * Kamil Gałuszka
24 | * Danilo Bargen
25 | * Jon Bolt
26 | * Kit Sunde
27 | * Ben Cardy
28 | * Rag Sagar.V
29 |
30 | Other Contributors
31 | ==================
32 |
33 | * The entire Python and Django communities for providing us the tools and desire we to build these things.
34 |
--------------------------------------------------------------------------------
/tests/models.py:
--------------------------------------------------------------------------------
1 | from django.db import models
2 |
3 |
4 | class Article(models.Model):
5 | author = models.ForeignKey('auth.User', null=True, blank=True)
6 | title = models.CharField(max_length=30)
7 | body = models.TextField()
8 | slug = models.SlugField(blank=True)
9 |
10 |
11 | class CanonicalArticle(models.Model):
12 | author = models.ForeignKey('auth.User', null=True, blank=True)
13 | title = models.CharField(max_length=30)
14 | body = models.TextField()
15 | slug = models.SlugField(blank=True)
16 |
17 | def get_canonical_slug(self):
18 | if self.author:
19 | return "{0.author.username}-{0.slug}".format(self)
20 | return "unauthored-{0.slug}".format(self)
21 |
22 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: python
2 | services: sqlite
3 | env:
4 | - DJANGO='django>=1.4,<1.5'
5 | - DJANGO='django>=1.5,<1.6'
6 | - DJANGO='django>=1.6,<1.7'
7 | - DJANGO='django>=1.7,<1.8'
8 | python:
9 | - 3.4
10 | - 3.3
11 | - 2.7
12 | - 2.6
13 | - pypy
14 | - pypy3
15 | install:
16 | - pip install $DJANGO
17 | - python setup.py install
18 | - pip install -r requirements.txt
19 | script: py.test tests/
20 | matrix:
21 | exclude:
22 | - python: 3.3
23 | env: DJANGO='django>=1.4,<1.5'
24 | - python: 3.4
25 | env: DJANGO='django>=1.4,<1.5'
26 | - python: pypy3
27 | env: DJANGO='django>=1.4,<1.5'
28 | - python: 2.6
29 | env: DJANGO='django>=1.7,<1.8'
30 |
--------------------------------------------------------------------------------
/tests/test_forms.py:
--------------------------------------------------------------------------------
1 | from __future__ import absolute_import
2 |
3 | from django import test
4 | from django.contrib.auth.models import User
5 |
6 | from . import forms
7 |
8 |
9 | class TestUserKwargModelFormMixin(test.TestCase):
10 | """
11 | Tests for UserKwargModelFormMixin.
12 | """
13 | def test_without_user_kwarg(self):
14 | """
15 | It should be possible to create form without 'user' kwarg.
16 |
17 | In that case 'user' attribute should be set to None.
18 | """
19 | form = forms.FormWithUserKwarg()
20 | assert form.user is None
21 |
22 | def test_with_user_kwarg(self):
23 | """
24 | Form's 'user' attribute should be set to value passed as 'user'
25 | argument.
26 | """
27 | user = User(username='test')
28 | form = forms.FormWithUserKwarg(user=user)
29 | assert form.user is user
30 |
--------------------------------------------------------------------------------
/docs/index.rst:
--------------------------------------------------------------------------------
1 | .. django-braces documentation master file, created by
2 | sphinx-quickstart on Mon Apr 30 10:31:44 2012.
3 | You can adapt this file completely to your liking, but it should at least
4 | contain the root `toctree` directive.
5 |
6 | Welcome to django-braces's documentation!
7 | =========================================
8 |
9 | You can view the code of our project or fork it and add your own mixins (please, send them back to us), on `Github`_.
10 |
11 | .. toctree::
12 | :maxdepth: 2
13 |
14 | Access Mixins
15 | Form Mixins