2
2
from copy import deepcopy
3
3
from distutils .version import LooseVersion
4
4
from urllib2 import unquote
5
+ from cms .utils .conf import get_cms_setting
5
6
6
7
import django
7
8
from django .conf import settings
@@ -73,7 +74,7 @@ def get_prepopulated_fields(self, request):
73
74
74
75
75
76
def contribute_fieldsets (cls ):
76
- if settings . CMS_MENU_TITLE_OVERWRITE :
77
+ if get_cms_setting ( 'MENU_TITLE_OVERWRITE' ) :
77
78
general_fields = [('title' , 'menu_title' )]
78
79
else :
79
80
general_fields = ['title' ]
@@ -83,19 +84,19 @@ def contribute_fieldsets(cls):
83
84
template_fields = ['template' ]
84
85
hidden_fields = ['site' , 'parent' ]
85
86
seo_fields = []
86
- if settings . CMS_SOFTROOT :
87
+ if get_cms_setting ( 'SOFTROOT' ) :
87
88
advanced_fields .append ('soft_root' )
88
- if settings . CMS_SHOW_START_DATE and settings . CMS_SHOW_END_DATE :
89
+ if get_cms_setting ( 'SHOW_START_DATE' ) and get_cms_setting ( 'SHOW_END_DATE' ) :
89
90
general_fields .append (('publication_date' , 'publication_end_date' ))
90
- elif settings . CMS_SHOW_START_DATE :
91
+ elif get_cms_setting ( 'SHOW_START_DATE' ) :
91
92
general_fields .append ('publication_date' )
92
- elif settings . CMS_SHOW_END_DATE :
93
+ elif get_cms_setting ( 'SHOW_END_DATE' ) :
93
94
general_fields .append ('publication_end_date' )
94
- if settings . CMS_SEO_FIELDS :
95
+ if get_cms_setting ( 'SEO_FIELDS' ) :
95
96
seo_fields = ['page_title' , 'meta_description' , 'meta_keywords' ]
96
- if not settings . CMS_URL_OVERWRITE :
97
+ if not get_cms_setting ( 'URL_OVERWRITE' ) :
97
98
advanced_fields .remove ("overwrite_url" )
98
- if not settings . CMS_REDIRECTS :
99
+ if not get_cms_setting ( 'REDIRECTS' ) :
99
100
advanced_fields .remove ('redirect' )
100
101
if menu_pool .get_menus_by_attribute ("cms_enabled" , True ):
101
102
advanced_fields .append ("navigation_extenders" )
@@ -122,7 +123,7 @@ def contribute_fieldsets(cls):
122
123
}),
123
124
]
124
125
125
- if settings . CMS_SEO_FIELDS :
126
+ if get_cms_setting ( 'SEO_FIELDS' ) :
126
127
fieldsets .append ((_ ("SEO Settings" ), {
127
128
'fields' : seo_fields ,
128
129
'classes' : ('collapse' ,),
@@ -138,7 +139,7 @@ def contribute_fieldsets(cls):
138
139
139
140
def contribute_list_filter (cls ):
140
141
list_filter = ['published' , 'in_navigation' , 'template' , 'changed_by' ]
141
- if settings . CMS_SOFTROOT :
142
+ if get_cms_setting ( 'SOFTROOT' ) :
142
143
list_filter .append ('soft_root' )
143
144
setattr (cls , 'list_filter' , list_filter )
144
145
@@ -303,7 +304,7 @@ def get_fieldsets(self, request, obj=None):
303
304
advanced = given_fieldsets .pop (3 )
304
305
if obj .has_advanced_settings_permission (request ):
305
306
given_fieldsets .append (advanced )
306
- if settings . CMS_SEO_FIELDS :
307
+ if get_cms_setting ( 'SEO_FIELDS' ) :
307
308
seo = given_fieldsets .pop (3 )
308
309
given_fieldsets .append (seo )
309
310
else : # new page
@@ -329,7 +330,7 @@ def get_form(self, request, obj=None, **kwargs):
329
330
elif 'published' in self .exclude :
330
331
self .exclude .remove ('published' )
331
332
332
- if not settings . CMS_SOFTROOT and 'soft_root' in self .exclude :
333
+ if not get_cms_setting ( 'SOFTROOT' ) and 'soft_root' in self .exclude :
333
334
self .exclude .remove ('soft_root' )
334
335
335
336
form = super (PageAdmin , self ).get_form (request , obj , ** kwargs )
@@ -358,9 +359,9 @@ def get_form(self, request, obj=None, **kwargs):
358
359
form .base_fields ['overwrite_url' ].initial = title_obj .path
359
360
else :
360
361
form .base_fields ['overwrite_url' ].initial = ""
361
- if settings . CMS_TEMPLATES :
362
+ if get_cms_setting ( 'TEMPLATES' ) :
362
363
selected_template = get_template_from_request (request , obj )
363
- template_choices = list (settings . CMS_TEMPLATES )
364
+ template_choices = list (get_cms_setting ( 'TEMPLATES' ) )
364
365
form .base_fields ['template' ].choices = template_choices
365
366
form .base_fields ['template' ].initial = force_unicode (selected_template )
366
367
@@ -439,18 +440,18 @@ def get_form(self, request, obj=None, **kwargs):
439
440
form .base_fields [name ].initial = u''
440
441
form .base_fields ['parent' ].initial = request .GET .get ('target' , None )
441
442
form .base_fields ['site' ].initial = request .session .get ('cms_admin_site' , None )
442
- form .base_fields ['template' ].initial = settings . CMS_TEMPLATES [0 ][0 ]
443
+ form .base_fields ['template' ].initial = get_cms_setting ( 'TEMPLATES' ) [0 ][0 ]
443
444
444
445
return form
445
446
446
447
def get_inline_instances (self , request ):
447
448
inlines = super (PageAdmin , self ).get_inline_instances (request )
448
- if settings . CMS_PERMISSION and hasattr (self , '_current_page' )\
449
+ if get_cms_setting ( 'PERMISSION' ) and hasattr (self , '_current_page' )\
449
450
and self ._current_page :
450
451
filtered_inlines = []
451
452
for inline in inlines :
452
- if isinstance (inline , PagePermissionInlineAdmin )\
453
- and not isinstance (inline , ViewRestrictionInlineAdmin ):
453
+ if ( isinstance (inline , PagePermissionInlineAdmin )
454
+ and not isinstance (inline , ViewRestrictionInlineAdmin )) :
454
455
if "recover" in request .path or "history" in request .path :
455
456
# do not display permissions in recover mode
456
457
continue
@@ -486,7 +487,7 @@ def change_view(self, request, object_id, extra_context=None):
486
487
context = {
487
488
'placeholders' : self .get_fieldset_placeholders (selected_template ),
488
489
'page' : obj ,
489
- 'CMS_PERMISSION' : settings . CMS_PERMISSION ,
490
+ 'CMS_PERMISSION' : get_cms_setting ( 'PERMISSION' ) ,
490
491
'ADMIN_MEDIA_URL' : settings .STATIC_URL ,
491
492
'can_change' : obj .has_change_permission (request ),
492
493
'can_change_permissions' : obj .has_change_permissions_permission (request ),
@@ -553,7 +554,7 @@ def has_add_permission(self, request):
553
554
"""
554
555
Return true if the current user has permission to add a new page.
555
556
"""
556
- if settings . CMS_PERMISSION :
557
+ if get_cms_setting ( 'PERMISSION' ) :
557
558
return permissions .has_page_add_permission (request )
558
559
return super (PageAdmin , self ).has_add_permission (request )
559
560
@@ -562,7 +563,7 @@ def has_change_permission(self, request, obj=None):
562
563
Return true if the current user has permission on the page.
563
564
Return the string 'All' if the user has all rights.
564
565
"""
565
- if settings . CMS_PERMISSION :
566
+ if get_cms_setting ( 'PERMISSION' ) :
566
567
if obj :
567
568
return obj .has_change_permission (request )
568
569
else :
@@ -575,7 +576,7 @@ def has_delete_permission(self, request, obj=None):
575
576
Django model instance. If CMS_PERMISSION are in use also takes look to
576
577
object permissions.
577
578
"""
578
- if settings . CMS_PERMISSION and obj is not None :
579
+ if get_cms_setting ( 'PERMISSION' ) and obj is not None :
579
580
return obj .has_delete_permission (request )
580
581
return super (PageAdmin , self ).has_delete_permission (request , obj )
581
582
@@ -644,10 +645,10 @@ def changelist_view(self, request, extra_context=None):
644
645
'has_add_permission' : self .has_add_permission (request ),
645
646
'root_path' : reverse ('admin:index' ),
646
647
'app_label' : app_label ,
647
- 'CMS_MEDIA_URL' : settings . CMS_MEDIA_URL ,
648
- 'CMS_SHOW_END_DATE' : settings . CMS_SHOW_END_DATE ,
649
- 'softroot' : settings . CMS_SOFTROOT ,
650
- 'CMS_PERMISSION' : settings . CMS_PERMISSION ,
648
+ 'CMS_MEDIA_URL' : get_cms_setting ( 'MEDIA_URL' ) ,
649
+ 'CMS_SHOW_END_DATE' : get_cms_setting ( 'SHOW_END_DATE' ) ,
650
+ 'softroot' : get_cms_setting ( 'SOFTROOT' ) ,
651
+ 'CMS_PERMISSION' : get_cms_setting ( 'PERMISSION' ) ,
651
652
'DEBUG' : settings .DEBUG ,
652
653
'site_languages' : languages ,
653
654
'open_menu_trees' : open_menu_trees ,
@@ -712,7 +713,7 @@ def change_template(self, request, object_id):
712
713
return HttpResponseForbidden (_ ("You do not have permission to change the template" ))
713
714
714
715
to_template = request .POST .get ("template" , None )
715
- if to_template not in dict (settings . CMS_TEMPLATES ):
716
+ if to_template not in dict (get_cms_setting ( 'TEMPLATES' ) ):
716
717
return HttpResponseBadRequest (_ ("Template not valid" ))
717
718
718
719
page .template = to_template
@@ -1170,7 +1171,7 @@ def add_plugin(self, request):
1170
1171
reversion .revision .comment = _ (u"%(plugin_name)s plugin added to %(placeholder)s" ) % {
1171
1172
'plugin_name' : plugin_name , 'placeholder' : placeholder }
1172
1173
1173
- return HttpResponse (str (plugin .pk ))
1174
+ return HttpResponse (str (plugin .pk ), content_type = 'text/plain' )
1174
1175
1175
1176
@require_POST
1176
1177
@create_on_success
@@ -1270,7 +1271,7 @@ def edit_plugin(self, request, plugin_id):
1270
1271
if request .POST .get ("_cancel" , False ):
1271
1272
# cancel button was clicked
1272
1273
context = {
1273
- 'CMS_MEDIA_URL' : settings . CMS_MEDIA_URL ,
1274
+ 'CMS_MEDIA_URL' : get_cms_setting ( 'MEDIA_URL' ) ,
1274
1275
'plugin' : cms_plugin ,
1275
1276
'is_popup' : True ,
1276
1277
'name' : unicode (cms_plugin ),
@@ -1317,7 +1318,7 @@ def edit_plugin(self, request, plugin_id):
1317
1318
saved_object = plugin_admin .saved_object
1318
1319
1319
1320
context = {
1320
- 'CMS_MEDIA_URL' : settings . CMS_MEDIA_URL ,
1321
+ 'CMS_MEDIA_URL' : get_cms_setting ( 'MEDIA_URL' ) ,
1321
1322
'plugin' : saved_object ,
1322
1323
'is_popup' : True ,
1323
1324
'name' : unicode (saved_object ),
0 commit comments