本文整理汇总了Python中media_tree.admin.utils.get_request_attr函数的典型用法代码示例。如果您正苦于以下问题:Python get_request_attr函数的具体用法?Python get_request_attr怎么用?Python get_request_attr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_request_attr函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: admin_preview
def admin_preview(self, node, icons_only=False):
request = get_current_request()
template = 'admin/media_tree/filenode/includes/preview.html'
thumbnail_backend = get_media_backend(handles_media_types=(node.media_type,), supports_thumbnails=True)
if not thumbnail_backend:
icons_only = True
template = 'media_tree/filenode/includes/icon.html'
# TODO SPLIT preview.html in two: one that doesn't need media backend!
context = {
'node': node,
'preview_file': node.get_icon_file() if icons_only else node.get_preview_file(),
'class': 'collapsed' if node.is_folder() else '',
}
if not icons_only:
thumb_size_key = get_request_attr(request, 'thumbnail_size') or 'default'
context['thumbnail_size'] = app_settings.MEDIA_TREE_ADMIN_THUMBNAIL_SIZES[thumb_size_key]
thumb = thumbnail_backend.get_thumbnail(context['preview_file'], {'size': context['thumbnail_size']})
context['thumb'] = thumb
preview = render_to_string(template, context)
if node.is_folder():
preview += render_to_string(template, {
'node': node,
'preview_file': node.get_preview_file(default_name='_folder_expanded'),
'class': 'expanded'
})
return preview
示例2: save_model
def save_model(self, request, obj, form, change):
"""
Given a model instance save it to the database.
"""
if not change:
if not obj.node_type:
obj.node_type = get_request_attr(request, 'save_node_type', None)
super(FileNodeAdmin, self).save_model(request, obj, form, change)
示例3: get_form
def get_form(self, request, *args, **kwargs):
if get_request_attr(request, 'save_node_type', None) == FileNode.FOLDER:
self.form = FolderForm
else:
self.form = FileForm
self.fieldsets = self.form.Meta.fieldsets
form = super(FileNodeAdmin, self).get_form(request, *args, **kwargs)
return form
示例4: get_results
def get_results(self, request):
""" Temporarily decreases the `level` attribute of all search results
in order to prevent indendation when displaying them. """
super(FileNodeChangeList, self).get_results(request)
try:
reduce_levels = abs(int(get_request_attr(
request, 'reduce_levels', 0)))
except TypeError:
reduce_levels = 0
is_filtered = self.is_filtered(request)
if is_filtered or reduce_levels:
for item in self.result_list:
item.prevent_save()
item.actual_level = item.level
if is_filtered:
item.reduce_levels = item.level
item.level = 0
else:
item.reduce_levels = reduce_levels
item.level = max(0, item.level - reduce_levels)
示例5: admin_preview
def admin_preview(self, node, icons_only=False):
request = get_current_request()
template = 'admin/media_tree/filenode/includes/preview.html'
if not get_media_backend():
icons_only = True
template = 'media_tree/filenode/includes/icon.html'
# TODO SPLIT preview.html in two: one that doesn't need media backend!
thumb_size_key = get_request_attr(request, 'thumbnail_size') or 'default'
preview = render_to_string(template, {
'node': node,
'preview_file': node.get_icon_file() if icons_only else node.get_preview_file(),
'class': 'collapsed' if node.is_folder() else '',
'thumbnail_size': app_settings.MEDIA_TREE_ADMIN_THUMBNAIL_SIZES[thumb_size_key]
})
if node.is_folder():
preview += render_to_string(template, {
'node': node,
'preview_file': node.get_preview_file(default_name='_folder_expanded'),
'class': 'expanded'
})
return preview
示例6: get_parent_folder
def get_parent_folder(self, request):
return get_request_attr(request, 'parent_folder', None)
示例7: save_model
def save_model(self, request, obj, form, change):
if not change:
if not obj.node_type:
obj.node_type = get_request_attr(request, 'save_node_type', None)
obj.attach_user(request.user, change)
super(FileNodeAdmin, self).save_model(request, obj, form, change)