7
7
8
8
from wagtail .wagtailsnippets .models import get_snippet_content_types
9
9
from wagtail .wagtailsnippets .permissions import user_can_edit_snippet_type
10
- from wagtail .wagtailsnippets .views .snippets import get_snippet_type_description , get_snippet_type_name
11
10
from wagtail .wagtailsnippets .views .snippets import get_content_type_from_url_params
11
+ from wagtail .wagtailsnippets .models import get_snippet_models
12
+
12
13
from wagtailembedder .format import embed_to_editor_html
13
14
14
15
15
16
@permission_required ('wagtailadmin.access_admin' )
16
17
def index (request ):
17
- snippet_types = [(
18
- get_snippet_type_name (content_type )[1 ],
19
- get_snippet_type_description (content_type ),
20
- content_type )
21
- for content_type in get_snippet_content_types ()
18
+ """
19
+ Fetches all human-readabe names of all snippet classes and presents them
20
+ in a list.
21
+ """
22
+ snippet_types = [
23
+ (
24
+ content_type ._meta .app_label ,
25
+ content_type ._meta .model .__name__ ,
26
+ content_type ._meta .description ,
27
+ )
28
+ for content_type in get_snippet_models ()
22
29
if user_can_edit_snippet_type (request .user , content_type )
23
30
]
24
31
return render_modal_workflow (
@@ -32,13 +39,16 @@ def index(request):
32
39
33
40
34
41
def index_objects (request , content_type_app_name , content_type_model_name ):
42
+ """
43
+ Fetch objects of related model of the given ContentType and call the template
44
+ to properly display them in a list.
45
+ """
35
46
snippet_types = get_snippet_content_types ()
36
47
for content_type in snippet_types :
37
- name = get_snippet_type_name (content_type )[0 ]
38
- if name .lower ().replace (" " , "" ) == content_type_model_name :
39
- model = content_type .model_class ()
40
- items = model .objects .all ()
41
- snippet_type_name , snippet_type_name_plural = get_snippet_type_name (content_type )
48
+ if content_type .model == content_type_model_name .lower ():
49
+ items = content_type .model_class ().objects .all ()
50
+ snippet_type_name = content_type .model_class ()._meta .verbose_name
51
+ snippet_type_name_plural = content_type .model_class ()._meta .verbose_name_plural
42
52
43
53
return render_modal_workflow (
44
54
request ,
@@ -56,6 +66,9 @@ def index_objects(request, content_type_app_name, content_type_model_name):
56
66
57
67
58
68
def choose_snippet (request , id , content_type_app_name , content_type_model_name ):
69
+ """
70
+ Choose snippet and display its representation in the Hallo.js richtext field.
71
+ """
59
72
content_type = get_content_type_from_url_params (content_type_app_name , content_type_model_name )
60
73
if not user_can_edit_snippet_type (request .user , content_type ):
61
74
raise PermissionDenied
0 commit comments