本文整理汇总了Python中cms.models.Placeholder.save方法的典型用法代码示例。如果您正苦于以下问题:Python Placeholder.save方法的具体用法?Python Placeholder.save怎么用?Python Placeholder.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cms.models.Placeholder
的用法示例。
在下文中一共展示了Placeholder.save方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_05_remove_plugin_not_associated_to_page
# 需要导入模块: from cms.models import Placeholder [as 别名]
# 或者: from cms.models.Placeholder import save [as 别名]
def test_05_remove_plugin_not_associated_to_page(self):
"""
Test case for PlaceholderField
"""
page_data = self.get_new_page_data()
response = self.client.post(URL_CMS_PAGE_ADD, page_data)
page = Page.objects.all()[0]
# add a plugin
plugin_data = {
"plugin_type": "TextPlugin",
"language": settings.LANGUAGES[0][0],
"placeholder": page.placeholders.get(slot="body").pk,
}
response = self.client.post(URL_CMS_PLUGIN_ADD, plugin_data)
self.assertEquals(response.status_code, 200)
self.assertEquals(int(response.content), CMSPlugin.objects.all()[0].pk)
# there should be only 1 plugin
self.assertEquals(CMSPlugin.objects.all().count(), 1)
ph = Placeholder(slot="subplugin")
ph.save()
plugin_data = {
"plugin_type": "TextPlugin",
"language": settings.LANGUAGES[0][0],
"placeholder": ph.pk,
"parent": int(response.content),
}
response = self.client.post(URL_CMS_PLUGIN_ADD, plugin_data)
plugin_data = {"plugin_id": int(response.content)}
response = response.client.post(URL_CMS_PLUGIN_REMOVE, plugin_data)
self.assertEquals(response.status_code, 200)
示例2: test_05_remove_plugin_not_associated_to_page
# 需要导入模块: from cms.models import Placeholder [as 别名]
# 或者: from cms.models.Placeholder import save [as 别名]
def test_05_remove_plugin_not_associated_to_page(self):
"""
Test case for PlaceholderField
"""
page_data = self.get_new_page_data()
response = self.client.post(URL_CMS_PAGE_ADD, page_data)
page = Page.objects.all()[0]
# add a plugin
plugin_data = {
'plugin_type':"TextPlugin",
'language':settings.LANGUAGES[0][0],
'placeholder':page.placeholders.get(slot="body").pk,
}
response = self.client.post(URL_CMS_PLUGIN_ADD, plugin_data)
self.assertEquals(response.status_code, 200)
self.assertEquals(int(response.content), CMSPlugin.objects.all()[0].pk)
# there should be only 1 plugin
self.assertEquals(CMSPlugin.objects.all().count(), 1)
ph = Placeholder(slot="subplugin")
ph.save()
plugin_data = {
'plugin_type':"TextPlugin",
'language':settings.LANGUAGES[0][0],
'placeholder': ph.pk,
'parent': int(response.content)
}
response = self.client.post(URL_CMS_PLUGIN_ADD, plugin_data)
# no longer allowed for security reasons
self.assertEqual(response.status_code, 404)
示例3: __init__
# 需要导入模块: from cms.models import Placeholder [as 别名]
# 或者: from cms.models.Placeholder import save [as 别名]
def __init__(self, request):
super(CMSToolbar, self).__init__()
self.left_items = None
self.right_items = None
self.menus = {}
self.request = request
self.login_form = CMSToolbarLoginForm(request=request)
self.is_staff = self.request.user.is_staff
self.edit_mode = self.is_staff and self.request.session.get('cms_edit', False)
self.build_mode = self.is_staff and self.request.session.get('cms_build', False)
self.use_draft = self.is_staff and self.edit_mode or self.build_mode
self.show_toolbar = self.is_staff or self.request.session.get('cms_edit', False)
if settings.USE_I18N:
self.language = get_language_from_request(request)
else:
self.language = settings.LANGUAGE_CODE
# We need to store the current language in case the user's preferred language is different.
self.toolbar_language = self.language
if self.is_staff:
try:
user_settings = UserSettings.objects.get(user=self.request.user)
except UserSettings.DoesNotExist:
user_settings = UserSettings(language=self.language, user=self.request.user)
placeholder = Placeholder(slot="clipboard")
placeholder.save()
user_settings.clipboard = placeholder
user_settings.save()
self.toolbar_language = user_settings.language
self.clipboard = user_settings.clipboard
示例4: __init__
# 需要导入模块: from cms.models import Placeholder [as 别名]
# 或者: from cms.models.Placeholder import save [as 别名]
def __init__(self, request):
super(CMSToolbar, self).__init__()
self.right_items = []
self.left_items = []
self.populated = False
self.post_template_populated = False
self.menus = {}
self.request = request
self.login_form = CMSToolbarLoginForm(request=request)
self.is_staff = self.request.user.is_staff
self.edit_mode = self.is_staff and self.request.session.get("cms_edit", False)
self.edit_mode_url_on = get_cms_setting("CMS_TOOLBAR_URL__EDIT_ON")
self.edit_mode_url_off = get_cms_setting("CMS_TOOLBAR_URL__EDIT_OFF")
self.build_mode = self.is_staff and self.request.session.get("cms_build", False)
self.use_draft = self.is_staff and self.edit_mode or self.build_mode
self.show_toolbar = self.is_staff or self.request.session.get("cms_edit", False)
self.obj = None
self.redirect_url = None
if settings.USE_I18N:
self.language = get_language_from_request(request)
else:
self.language = settings.LANGUAGE_CODE
# We need to store the current language in case the user's preferred language is different.
self.toolbar_language = self.language
if self.is_staff:
try:
user_settings = UserSettings.objects.select_related("clipboard").get(user=self.request.user)
except UserSettings.DoesNotExist:
user_settings = UserSettings(language=self.language, user=self.request.user)
placeholder = Placeholder(slot="clipboard")
placeholder.save()
user_settings.clipboard = placeholder
user_settings.save()
if (settings.USE_I18N and user_settings.language in dict(settings.LANGUAGES)) or (
not settings.USE_I18N and user_settings.language == settings.LANGUAGE_CODE
):
self.toolbar_language = user_settings.language
else:
user_settings.language = self.language
user_settings.save()
self.clipboard = user_settings.clipboard
with force_language(self.language):
try:
self.app_name = resolve(self.request.path).app_name
except Resolver404:
self.app_name = ""
toolbars = toolbar_pool.get_toolbars()
self.toolbars = SortedDict()
app_key = ""
for key in toolbars:
app_name = ".".join(key.split(".")[:-2])
if app_name == self.app_name and len(key) > len(app_key):
app_key = key
for key in toolbars:
toolbar = toolbars[key](self.request, self, key == app_key, app_key)
self.toolbars[key] = toolbar
示例5: get_user_settings
# 需要导入模块: from cms.models import Placeholder [as 别名]
# 或者: from cms.models.Placeholder import save [as 别名]
def get_user_settings(self):
user_settings = None
if self.is_staff:
try:
user_settings = UserSettings.objects.select_related("clipboard").get(user=self.request.user)
except UserSettings.DoesNotExist:
user_settings = UserSettings(language=self.language, user=self.request.user)
placeholder = Placeholder(slot="clipboard")
placeholder.save()
user_settings.clipboard = placeholder
user_settings.save()
return user_settings
示例6: test_toolbar_switch_urls
# 需要导入模块: from cms.models import Placeholder [as 别名]
# 或者: from cms.models.Placeholder import save [as 别名]
def test_toolbar_switch_urls(self):
user = self.get_superuser()
user_settings = UserSettings(language="en", user=user)
placeholder = Placeholder(slot="clipboard")
placeholder.save()
user_settings.clipboard = placeholder
user_settings.save()
page = create_page("page", "nav_playground.html", "en", published=True)
create_title("fr", "french home", page)
publish_page(page, user, "fr")
with self.login_user_context(user):
response = self.client.get("/fr/?%s" % get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON'))
self.assertContains(response, "/fr/?%s" % get_cms_setting('CMS_TOOLBAR_URL__EDIT_OFF'), 1, 200)
response = self.client.get("/fr/?%s" % get_cms_setting('CMS_TOOLBAR_URL__EDIT_OFF'))
self.assertContains(response, "/fr/?%s" % get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON'), 1, 200)
示例7: fill_placeholder
# 需要导入模块: from cms.models import Placeholder [as 别名]
# 或者: from cms.models.Placeholder import save [as 别名]
def fill_placeholder(self, placeholder=None):
if placeholder is None:
placeholder = Placeholder(slot=u"some_slot")
placeholder.save() # a good idea, if not strictly necessary
# plugin in placeholder
plugin_1 = add_plugin(placeholder, u"TextPlugin", u"en", body=u"01")
plugin_1.save()
# IMPORTANT: plugins must be reloaded, before they can be assigned
# as a parent. Otherwise, the MPTT structure doesn't seem to rebuild
# properly.
# child of plugin_1
plugin_2 = add_plugin(placeholder, u"TextPlugin", u"en", body=u"02")
plugin_1 = self.reload(plugin_1)
plugin_2.parent = plugin_1
plugin_2.save()
return placeholder
示例8: convert
# 需要导入模块: from cms.models import Placeholder [as 别名]
# 或者: from cms.models.Placeholder import save [as 别名]
#.........这里部分代码省略.........
# loop over the fields that need converting
for field in model_values["fields"]:
print field
old_field = field["old_field"]
new_field = field["new_field"]
slot = field["slot"]
# create a summary report for this field
models_dictionary["messages"][mmodel][old_field]={}
try:
getattr(actual_model, new_field)
except AttributeError:
message = "field " + new_field + " is missing - check the model and try agin"
models_dictionary["messages"][mmodel][old_field]["Error"]=message
continue
junk_content = [] # a record of those items with nothing but <br /> in them
moved_items =[] # a record of the items we migrated to placeholders
# loop over each item in the class
for item in actual_model.objects.all():
old_field_content = getattr(item, old_field) # the old field we want to convert
# first get rid of junk content (change "<br />" to "")
if old_field_content == "<br />":
old_field_content = ""
setattr(item, old_field, "") # item.content = ""
if execute == "convert":
item.save()
# now the serious business of converting the fields
# if the item lacks a placeholder, create the placeholder and the reference to it
if old_field_content and not getattr(item, new_field, None):
# check to see if it's worth converting
if len(old_field_content) > 60:
# create the placeholder
placeholder=Placeholder(slot=slot)
if execute == "convert":
placeholder.save()
# refer to the placeholder from the item
setattr(item, new_field, placeholder)
# I copied this from one of the test files
plugin_base = CMSPlugin(
plugin_type='TextPlugin',
placeholder=placeholder,
position=1,
language=settings.LANGUAGES[0][0]) # we assume the original field was in the first language
plugin_base.insert_at(None, position='last-child', commit=False)
# create a text plugin
plugin = Text(body='')
plugin_base.set_base_attr(plugin)
plugin.body = getattr(item, old_field)
if execute == "convert":
plugin.save()
示例9: __init__
# 需要导入模块: from cms.models import Placeholder [as 别名]
# 或者: from cms.models.Placeholder import save [as 别名]
def __init__(self, request):
super(CMSToolbar, self).__init__()
self.right_items = []
self.left_items = []
self.populated = False
self.post_template_populated = False
self.menus = {}
self.request = request
self.login_form = CMSToolbarLoginForm(request=request)
self.is_staff = self.request.user.is_staff
self.edit_mode = self.is_staff and self.request.session.get('cms_edit', False)
self.edit_mode_url_on = get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON')
self.edit_mode_url_off = get_cms_setting('CMS_TOOLBAR_URL__EDIT_OFF')
self.build_mode = self.is_staff and self.request.session.get('cms_build', False)
self.use_draft = self.is_staff and self.edit_mode or self.build_mode
self.show_toolbar = self.is_staff or self.request.session.get('cms_edit', False)
self.obj = None
self.redirect_url = None
if settings.USE_I18N:
self.language = get_language_from_request(request)
else:
self.language = settings.LANGUAGE_CODE
# We need to store the current language in case the user's preferred language is different.
self.toolbar_language = self.language
if self.is_staff:
try:
user_settings = UserSettings.objects.select_related('clipboard').get(user=self.request.user)
except UserSettings.DoesNotExist:
user_settings = UserSettings(language=self.language, user=self.request.user)
placeholder = Placeholder(slot="clipboard")
placeholder.save()
user_settings.clipboard = placeholder
user_settings.save()
if (settings.USE_I18N and user_settings.language in dict(settings.LANGUAGES)) or (
not settings.USE_I18N and user_settings.language == settings.LANGUAGE_CODE):
self.toolbar_language = user_settings.language
else:
user_settings.language = self.language
user_settings.save()
self.clipboard = user_settings.clipboard
with force_language(self.language):
try:
decorator = resolve(self.request.path_info).func
try:
# If the original view is decorated we try to extract the real function
# module instead of the decorator's one
if decorator and getattr(decorator, 'func_closure', False):
# python 2
self.app_name = decorator.func_closure[0].cell_contents.__module__
elif decorator and getattr(decorator, '__closure__', False):
# python 3
self.app_name = decorator.__closure__[0].cell_contents.__module__
else:
raise AttributeError()
except (TypeError, AttributeError):
# no decorator
self.app_name = decorator.__module__
except Resolver404:
self.app_name = ""
toolbars = toolbar_pool.get_toolbars()
parts = self.app_name.split('.')
while parts:
path = '.'.join(parts)
if path in installed_apps():
self.app_name = path
break
parts.pop()
self.toolbars = SortedDict()
for key in toolbars:
toolbar = toolbars[key](self.request, self, toolbars[key].check_current_app(key, self.app_name), self.app_name)
self.toolbars[key] = toolbar