Skip to content

Commit 36c1359

Browse files
committed
working on new django examples code
1 parent 6814e9a commit 36c1359

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
title: django.core.exceptions ImproperlyConfigured Examples
2+
category: page
3+
slug: django-core-exceptions-improperlyconfigured
4+
sortorder: 50030
5+
toc: False
6+
sidebartitle: django.core.exceptions ImproperlyConfigured
7+
meta: Python code examples for the ImproperlyConfigured exception class provided by the Django codebase.
8+
9+
10+
# django.core.exceptions ImproperlyConfigured Examples
11+
[ImproperlyConfigured](https://github.com/django/django/blob/master/django/core/exceptions.py)
12+
is a class within the [Django](/django.html) project that is thrown
13+
when there is a mistake in an application's settings. The exception
14+
can also be thrown by a developer when building a library for project
15+
that will be used with Django.
16+
17+
18+
## Example 1 from django-object-tools
19+
[django-object-tools](https://github.com/praekelt/django-object-tools)
20+
is a code library to make it easier to create new
21+
[Django admin](https://docs.djangoproject.com/en/dev/ref/contrib/admin/)
22+
object tools. The project's code provided as open source under the
23+
[BSD 3-Clause "New" or "Revised" License](https://github.com/praekelt/django-object-tools/blob/develop/LICENSE).
24+
25+
[**django-object-tools / object_tools / validation.py**](https://github.com/praekelt/django-object-tools/blob/develop/object_tools/validation.py)
26+
27+
```python
28+
from __future__ import unicode_literals
29+
30+
~~from django.core.exceptions import ImproperlyConfigured
31+
32+
__all__ = ['validate']
33+
34+
35+
def validate(tool_class, model_class):
36+
"""
37+
Does basic ObjectTool option validation.
38+
"""
39+
if not hasattr(tool_class, 'name'):
40+
~~ raise ImproperlyConfigured("No 'name' attribute found for tool %s." % (
41+
~~ tool_class.__name__
42+
))
43+
44+
if not hasattr(tool_class, 'label'):
45+
~~ raise ImproperlyConfigured("No 'label' attribute found for tool %s." % (
46+
~~ tool_class.__name__
47+
))
48+
49+
if not hasattr(tool_class, 'view'):
50+
~~ raise NotImplementedError("No 'view' method found for tool %s." % (
51+
~~ tool_class.__name__
52+
))
53+
```

0 commit comments

Comments
 (0)