Skip to main content

Common utiltiies and dependencies for the modern Django project

Project description

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Description: # djx
Common utilities and dependencies for the modern Django project.

## database

Helpers for parsing database connection strings into Django-compatible database configuration. Uses `dj-database-url`.

### parse(url)

Parse the given database URL.

## environment

Helpers for pulling in environment variables.

### get_string(key, default=None)

Return an environment variable as a string, defaulting to the given
value if the environment variable is undefined.

### get_boolean(key, default)

Return an environment variable as a boolean, defaulting to the given
value if the environment variable is undefined.

### get_int(key)

Return an environment variable as an integer, defaulting to the given
value if the environment variable is undefined.

## static

Helpers for working with static files. Uses `dj-static`.

### Cling

Wrap a WSGI application to support static file serving:

```
from djx.static import Cling
application = Cling(get_wsgi_application())
```

## urls

Helpers for dynamically loading urls.

### load_urls(file, namespace=True)

Find submodules of the given file with valid url patterns and concatenate them into a list of patterns.
Only submodules with a `urls` module that contains a `urlpatterns` symbol will be considered.
If the `urls` module exists but cannot be imported, an exception is raised.

If `namespace` is set to `True` (the default), the urls will be exposed under the prefix of the submodule name.
If `namespace` is set to a function, this function will be called with the submodule name,
and the output will be used as the prefix.
If `namespace` is set to a string, this string will be used as the prefix.
If `namespace` is set to `False`, the urls will not be namespaced.

For example, if your project includes an "api" submodule with a `urls.py` file that defines url patterns
for your API and a separate "admin" submodule with a `urls.py` file that defines url patterns for admins,
you can automatically import these patterns with the following one-liner in the project `urls.py` file:

```
from djx.urls import load_urls
urlpatterns = load_urls(__file__)
```

Assuming admin/urls.py includes the urls "users" and "groups" and api/urls.py includes the urls "users" and "events",
the above call would produce the following urlpatterns:

```
/admin/groups/
/admin/users/
/api/events/
/api/users/
```

If you were to pass `namespace=lambda x: '/foo/' + x`, you would get the following patterns:

```
/foo/admin/events/
/foo/admin/groups/
/foo/api/events/
/foo/api/users/
```

However, if you were to pass `namespace='foo'`, you would get the following patterns:

```
/foo/events/
/foo/groups/
/foo/users/
```

Note that "/foo/users/" becomes ambiguous in this scenario; for this reason,
passing in string or False values to `namespace` should be done with caution.

### get_host(url)

Returns the network host for a given URL.

Platform: UNKNOWN

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djx-0.0.4.tar.gz (4.5 kB view hashes)

Uploaded Source

Built Distribution

djx-0.0.4-py2-none-any.whl (24.1 MB view hashes)

Uploaded Python 2

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page