Debian Codegraph @

README.rst

raw
1 ====================
2 django-organizations
3 ====================
4
5 .. start-table
6
7 .. list-table::
8 :stub-columns: 1
9
10 * - Summary
11 - Groups and multi-user account management
12 * - Author
13 - Ben Lopatin (http://benlopatin.com)
14 * - Status
15 - |docs| |version| |wheel| |supported-versions| |supported-implementations|
16
17 .. |docs| image:: https://readthedocs.org/projects/django-organizations/badge/?style=flat
18 :target: https://readthedocs.org/projects/django-organizations
19 :alt: Documentation Status
20
21 .. |version| image:: https://img.shields.io/pypi/v/django-organizations.svg?style=flat
22 :alt: PyPI Package latest release
23 :target: https://pypi.python.org/pypi/django-organizations
24
25 .. |wheel| image:: https://img.shields.io/pypi/wheel/django-organizations.svg?style=flat
26 :alt: PyPI Wheel
27 :target: https://pypi.python.org/pypi/django-organizations
28
29 .. |supported-versions| image:: https://img.shields.io/pypi/pyversions/django-organizations.svg?style=flat
30 :alt: Supported versions
31 :target: https://pypi.python.org/pypi/django-organizations
32
33 .. |supported-implementations| image:: https://img.shields.io/pypi/implementation/django-organizations.svg?style=flat
34 :alt: Supported implementations
35 :target: https://pypi.python.org/pypi/django-organizations
36
37
38 .. end-table
39
40
41 Separate individual user identity from accounts and subscriptions. Django
42 Organizations adds user-managed, multi-user groups to your Django project. Use
43 Django Organizations whether your site needs organizations that function like
44 social groups or multi-user account objects to provide account and subscription
45 functionality beyond the individual user.
46
47 * Works with your existing user model, whether
48 `django.contrib.auth` or a custom model. No additional user
49 or authentication functionality required.
50 * Users can be belong to and own more than one organization (account, group)
51 * Invitation and registration functionality works out of the box for many
52 situations and can be extended as need to fit specific requirements.
53 * Start with the base models or use your own for greater customization.
54
55 Documentation is on `Read the Docs
56 <http://django-organizations.readthedocs.org/en/latest/index.html>`_
57
58
59 Development & Contributing
60 ==========================
61
62 **The master branch represents version 2 development. For updates related to 1.x
63 versions of django-organizations pull requests should be made against the
64 [`version-1.x` branch](tree/version-1.x).**
65
66 Development is on-going. To-do items have been moved to the wiki for the time
67 being.
68
69 The basic functionality should not need much extending. Current dev priorities
70 for me and contributors should include:
71
72 * Improving the tests and test coverage (ideally moving them back out of the
73 main module and executable using the setup.py file)
74 * Improving the backends and backends concept so that additional invitation and
75 registration backends can be used
76 * Documentation
77 * Ensuring all application text is translatable
78
79 Please use the project's issues tracker to report bugs, doc updates, or other
80 requests/suggestions.
81
82 Targets & testing
83 -----------------
84
85 The codebase is targeted and tested against:
86
87 * Django 3.2.x against Python 3.8, 3.9, 3.10
88 * Django 4.1.x against Python 3.8, 3.9, 3.10, 3.11
89 * Django 4.2.x against Python 3.8, 3.9, 3.10, 3.11
90
91 To run the tests against all target environments, install `tox
92 <https://testrun.org/tox/latest/>`_ and then execute the command::
93
94 tox
95
96 Fast testing
97 ------------
98
99 Testing each change on all the environments takes some time, you may
100 want to test faster and avoid slowing down development by using pytest
101 against your current environment::
102
103 pip install -r requirements-test.txt
104 py.test
105
106 Supply the ``-x`` option for **failfast** mode::
107
108 py.test -x
109
110 Submitting
111 ----------
112
113 These submission guidelines will make it more likely your submissions will be
114 reviewed and make it into the project:
115
116 * Ensure they match the project goals and are sufficiently generalized
117 * Please try to follow `Django coding style
118 <https://docs.djangoproject.com/en/stable/internals/contributing/writing-code/coding-style/>`_.
119 The code base style isn't all up to par, but I'd like it to move in that
120 direction
121 * Also please try to include `good commit log messages
122 <http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html>`_.
123 * Pull requests should include an amount of code and commits that are
124 reasonable to review, are **logically grouped**, and based off clean feature
125 branches.
126
127 Code contributions are expected to pass in all target environments, and
128 pull requests should be made from branches with passing builds on `GitHub Actions <https://github.com/bennylope/django-organizations/actions/workflows/test.yml>`_.
129
130 Project goals
131 -------------
132
133 django-organizations should be backend agnostic:
134
135 1. Authentication agnostic
136 2. Registration agnostic
137 3. Invitation agnostic
138 4. User messaging agnostic
139
140 Etc.
141
142 Installing
143 ==========
144
145 First add the application to your Python path. The easiest way is to use
146 `pip`::
147
148 pip install django-organizations
149
150 Check the `Release History tab <https://pypi.org/project/django-organizations/#history>`_ on
151 the PyPI package page for pre-release versions. These can be downloaded by specifying the version.
152
153 You can also install by downloading the source and running::
154
155 $ python setup.py install
156
157 By default you will need to install `django-extensions` or comparable libraries
158 if you plan on adding Django Organizations as an installed app to your Django
159 project. See below on configuring.
160
161 Configuring
162 -----------
163
164 Make sure you have `django.contrib.auth` installed, and add the `organizations`
165 application to your `INSTALLED_APPS` list:
166
167 .. code-block:: python
168
169 INSTALLED_APPS = (
170 ...
171 'django.contrib.auth',
172 'organizations',
173 )
174
175 Then ensure that your project URL conf is updated. You should hook in the
176 main application URL conf as well as your chosen invitation backend URLs:
177
178 .. code-block:: python
179
180 from organizations.backends import invitation_backend
181
182 urlpatterns = [
183 ...
184 url(r'^accounts/', include('organizations.urls')),
185 url(r'^invitations/', include(invitation_backend().get_urls())),
186 ]
187
188 Auto slug field
189 ~~~~~~~~~~~~~~~
190
191 The standard way of using Django Organizations is to use it as an installed app
192 in your Django project. Django Organizations will need to use an auto slug
193 field which are not included. By default it will try to import these from
194 django-extensions, but you can configure your own in settings. The default:
195
196 .. code-block:: python
197
198 ORGS_SLUGFIELD = 'django_extensions.db.fields.AutoSlugField'
199
200 Alternative:
201
202 .. code-block:: python
203
204 ORGS_SLUGFIELD = 'autoslug.fields.AutoSlugField'
205
206 Previous versions allowed you to specify an `ORGS_TIMESTAMPED_MODEL` path. This
207 is now ignored and the functionality satisfied by a vendored solution. A
208 warning will be given but this *should not* have any effect on your code.
209
210 - `django-extensions <http://django-extensions.readthedocs.org/en/latest/>`_
211 - `Django AutoSlug <https://github.com/justinmayer/django-autoslug/>`_
212 - `django-slugger <https://gitlab.com/dspechnikov/django-slugger/>`_
213
214 Registration & invitation backends
215 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
216
217 You can specify a different invitation backend in your project settings, and
218 the `invitation_backend` function will provide the URLs defined by that
219 backend:
220
221 .. code-block:: python
222
223 INVITATION_BACKEND = 'myapp.backends.MyInvitationBackend'
224
225
226 Usage Overview
227 ==============
228
229 For most use cases it should be sufficient to include the app views directly
230 using the default URL conf file. You can customize their functionality or
231 access controls by extending the base views.
232
233 There are three models:
234
235 * **Organization** The group object. This is what you would associate your own
236 app's functionality with, e.g. subscriptions, repositories, projects, etc.
237 * **OrganizationUser** A custom `through` model for the ManyToMany relationship
238 between the `Organization` model and the `User` model. It stores additional
239 information about the user specific to the organization and provides a
240 convenient link for organization ownership.
241 * **OrganizationOwner** The user with rights over the life and death of the
242 organization. This is a one to one relationship with the `OrganizationUser`
243 model. This allows `User` objects to own multiple organizations and makes it
244 easy to enforce ownership from within the organization's membership.
245
246 The underlying organizations API is simple:
247
248 .. code-block:: python
249
250 >>> from organizations.utils import create_organization
251 >>> chris = User.objects.get(username="chris")
252 >>> soundgarden = create_organization(chris, "Soundgarden", org_user_defaults={'is_admin': True})
253 >>> soundgarden.is_member(chris)
254 True
255 >>> soundgarden.is_admin(chris)
256 True
257 >>> soundgarden.owner.organization_user
258 <OrganizationUser: Chris Cornell>
259 >>> soundgarden.owner.organization_user.user
260 >>> <User: chris>
261 >>> audioslave = create_organization(chris, "Audioslave")
262 >>> tom = User.objects.get(username="tom")
263 >>> audioslave.add_user(tom, is_admin=True)
264 <OrganizationUser: Tom Morello>
265
266 Custom models
267 -------------
268
269 Django-organizations can act as a base library (not installed in your project)
270 and used to create unique organization model sets using custom tables. See the
271 `Cooking with Django Organizations
272 <http://django-organizations.readthedocs.org/en/latest/cookbook.html#advanced-customization>`_
273 section in the documentation for advice on proceeding.
274
275 License
276 =======
277
278 Anyone is free to use or modify this software under the terms of the BSD
279 license.
280
281 Sponsors
282 ========
283
284 `Muster <https://www.muster.com/home?utm_source=github&campaign=opensource>`_ is building precision advocacy software to impact policy through grassroots action.
285
286 .. image:: https://www.muster.com/hs-fs/hubfs/muster_logo-2.png?width=600&name=muster_logo-2.png
287 :target: https://www.muster.com/home?utm_source=github&campaign=opensource
288 :width: 400
289 :alt: Alternative text
290