-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
34 lines (21 loc) · 774 Bytes
/
utils.py
File metadata and controls
34 lines (21 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from model_comments.forms import CommentForm
def get_subsubclasses_for(klass):
subclasses = []
for cls in klass.__subclasses__():
subclasses.append(cls)
if len(cls.__subclasses__()) > 0:
subclasses.extend(get_subsubclasses_for(cls))
return subclasses
def get_form_class_for_object(obj):
# Find subclasses of CommentForm and see which one we should display
#print get_subsubclasses_for(CommentForm)
for cls in get_subsubclasses_for(CommentForm):
# Instantiate class
f = cls(obj)
try:
if f.is_form_for_object(obj):
return cls
except NotImplementedError:
pass
# If no form, revert to default form
return CommentForm