from __future__ import absolute_import
from collections import OrderedDict
from django.core.exceptions import PermissionDenied, ObjectDoesNotExist
from django.core.paginator import InvalidPage, Paginator
from django.core.urlresolvers import NoReverseMatch
from django.db import models
from django.http import HttpResponseRedirect
from django.template.response import SimpleTemplateResponse, TemplateResponse
from django.utils import six
from django.utils.encoding import force_text, smart_text
from django.utils.html import escape, conditional_escape
from django.utils.safestring import mark_safe
from django.utils.text import capfirst
from django.utils.translation import ugettext as _
from xadmin.util import lookup_field, display_for_field, label_for_field, boolean_icon
from .base import ModelAdminView, filter_hook, inclusion_tag, csrf_protect_m
# List settings
ALL_VAR = 'all'
ORDER_VAR = 'o'
PAGE_VAR = 'p'
TO_FIELD_VAR = 't'
COL_LIST_VAR = '_cols'
ERROR_FLAG = 'e'
DOT = '.'
# Text to display within change-list table cells if the value is blank.
EMPTY_CHANGELIST_VALUE = _('Null')
class FakeMethodField(object):
"""
This class used when a column is an model function, wrap function as a fake field to display in select columns.
"""
def __init__(self, name, verbose_name):
# Initial comm field attrs
self.name = name
self.verbose_name = verbose_name
self.primary_key = False
class ResultRow(dict):
pass
class ResultItem(object):
def __init__(self, field_name, row):
self.classes = []
self.text = ' '
self.wraps = []
self.tag = 'td'
self.tag_attrs = []
self.allow_tags = False
self.btns = []
self.menus = []
self.is_display_link = False
self.row = row
self.field_name = field_name
self.field = None
self.attr = None
self.value = None
@property
def label(self):
text = mark_safe(
self.text) if self.allow_tags else conditional_escape(self.text)
if force_text(text) == '':
text = mark_safe(' ')
for wrap in self.wraps:
text = mark_safe(wrap % text)
return text
@property
def tagattrs(self):
return mark_safe(
'%s%s' % ((self.tag_attrs and ' '.join(self.tag_attrs) or ''),
(self.classes and (' class="%s"' % ' '.join(self.classes)) or '')))
class ResultHeader(ResultItem):
def __init__(self, field_name, row):
super(ResultHeader, self).__init__(field_name, row)
self.tag = 'th'
self.tag_attrs = ['scope="col"']
self.sortable = False
self.allow_tags = True
self.sorted = False
self.ascending = None
self.sort_priority = None
self.url_primary = None
self.url_remove = None
self.url_toggle = None
class ListAdminView(ModelAdminView):
"""
Display models objects view. this class has ordering and simple filter features.
"""
list_display = ('__str__',)
list_display_links = ()
list_display_links_details = False
list_select_related = None
list_per_page = 50
list_max_show_all = 200
list_exclude = ()
search_fields = ()
paginator_class = Paginator
ordering = None
# Change list templates
object_list_template = None
def init_request(self, *args, **kwargs):
if not self.has_view_permission():
raise PermissionDenied
request = self.request
request.session['LIST_QUERY'] = (self.model_info, self.request.META['QUERY_STRING'])
self.pk_attname = self.opts.pk.attname
self.lookup_opts = self.opts
self.list_display = self.get_list_display()
self.list_display_links = self.get_list_display_links()
# Get page number parameters from the query string.
try:
self.page_num = int(request.GET.get(PAGE_VAR, 0))
except ValueError:
self.page_num = 0
# Get params from request
self.show_all = ALL_VAR in request.GET
self.to_field = request.GET.get(TO_FIELD_VAR)
self.params = dict(request.GET.items())
if PAGE_VAR in self.params:
del self.params[PAGE_VAR]
if ERROR_FLAG in self.params:
del self.params[ERROR_FLAG]
@filter_hook
def get_list_display(self):
"""
Return a sequence containing the fields to be displayed on the list.
"""
self.base_list_display = (COL_LIST_VAR in self.request.GET and self.request.GET[COL_LIST_VAR] != "" and \
self.request.GET[COL_LIST_VAR].split('.')) or self.list_display
return list(self.base_list_display)
@filter_hook
def get_list_display_links(self):
"""
Return a sequence containing the fields to be displayed as links
on the changelist. The list_display parameter is the list of fields
returned by get_list_display().
"""
if self.list_display_links or not self.list_display:
return self.list_display_links
else:
# Use only the first item in list_display as link
return list(self.list_display)[:1]
def make_result_list(self):
# Get search parameters from the query string.
self.base_queryset = self.queryset()
self.list_queryset = self.get_list_queryset()
self.ordering_field_columns = self.get_ordering_field_columns()
self.paginator = self.get_paginator()
# Get the number of objects, with admin filters applied.
self.result_count = self.paginator.count
self.can_show_all = self.result_count <= self.list_max_show_all
self.multi_page = self.result_count > self.list_per_page
# Get the list of objects to display on this page.
if (self.show_all and self.can_show_all) or not self.multi_page:
self.result_list = self.list_queryset._clone()
else:
try:
self.result_list = self.paginator.page(
self.page_num + 1).object_list
except InvalidPage:
if ERROR_FLAG in self.request.GET.keys():
return SimpleTemplateResponse('xadmin/views/invalid_setup.html', {
'title': _('Database error'),
})
return HttpResponseRedirect(self.request.path + '?' + ERROR_FLAG + '=1')
self.has_more = self.result_count > (
self.list_per_page * self.page_num + len(self.result_list))
@filter_hook
def get_result_list(self):
return self.make_result_list()
@filter_hook
def post_result_list(self):
return self.make_result_list()
@filter_hook
def get_list_queryset(self):
"""
Get model queryset. The query has been filted and ordered.
"""
# First, get queryset from base class.
queryset = self.queryset()
# Use select_related() if one of the list_display options is a field
# with a relationship and the provided queryset doesn't already have
# select_related defined.
if not queryset.query.select_related:
if self.list_select_related:
queryset = queryset.select_related()
elif self.list_select_related is None:
related_fields = []
for field_name in self.list_display:
try:
field = self.opts.get_field(field_name)
except models.FieldDoesNotExist:
pass
else:
if isinstance(field.rel, models.ManyToOneRel):
related_fields.append(field_name)
if related_fields:
queryset = queryset.select_related(*related_fields)
else:
pass
# Then, set queryset ordering.
queryset = query
没有合适的资源?快使用搜索试试~ 我知道了~
基于django的后台管理.zip
共374个文件
js:134个
html:85个
py:75个
需积分: 5 0 下载量 12 浏览量
2024-04-26
16:35:55
上传
评论
收藏 1.11MB ZIP 举报
温馨提示
django Django是一个高级的Python Web框架,可以快速开发安全和可维护的网站。由经验丰富的开发者构建,Django负责处理网站开发中麻烦的部分,可以专注于编写应用程序,而无需重新开发。它是免费和开源的,有活跃繁荣的社区,丰富的文档,以及很多免费和付费的解决方案。 [8]2019年12月2日,Django 3. 0发布 Django是高水准的Python编程语言驱动的一个开源模型.视图,控制器风格的Web应用程序框架,它起源于开源社区。使用这种架构,程序员可以方便、快捷地创建高品质、易维护、数据库驱动的应用程序。这也正是OpenStack的Horizon组件采用这种架构进行设计的主要原因。另外,在Dj ango框架中,还包含许多功能强大的第三方插件,使得Django具有较强的可扩展性 [2]。Django 项目源自一个在线新闻 Web 站点,于 2005 年以开源的形式被释放出来。Django 框架的核心组件有: 1. 2. 用于创建模型的对象关系映射; 3. 为最终用户设计较好的管理界面; 4. URL 设计; 5. 设计者友好的模板语言; 6. 缓存系统。
资源推荐
资源详情
资源评论
收起资源包目录
基于django的后台管理.zip (374个子文件)
config 335B
bootstrap.css 123KB
bootstrap.min.css 100KB
font-awesome.css 21KB
bootstrap-theme.css 19KB
select2.css 19KB
font-awesome.min.css 17KB
bootstrap-theme.min.css 17KB
selectize.bootstrap2.css 15KB
selectize.default.css 11KB
selectize.legacy.css 11KB
selectize.bootstrap3.css 10KB
datepicker.css 10KB
selectize.css 8KB
xadmin.main.css 8KB
xadmin.responsive.css 4KB
bootstrap-modal.css 4KB
xadmin.form.css 4KB
bootstrap-clockpicker.css 4KB
bootstrap-image-gallery.css 3KB
bootstrap-clockpicker.min.css 3KB
bootstrap-timepicker.css 3KB
bootstrap-image-gallery.min.css 2KB
bootstrap-timepicker.min.css 2KB
xadmin.widget.select-transfer.css 2KB
bootstrap-xadmin.css 2KB
xadmin.mobile.css 1KB
snap.css 1KB
xadmin.plugin.formset.css 1KB
xadmin.widget.editable.css 1KB
xadmin.page.dashboard.css 790B
xadmin.plugin.importexport.css 321B
xadmin.plugin.quickfilter.css 248B
xadmin.plugins.css 175B
xadmin.plugin.aggregation.css 95B
bootstrap-multiselect.css 0B
fontawesome-webfont.eot 37KB
glyphicons-halflings-regular.eot 20KB
loading.gif 4KB
select2-spinner.gif 2KB
ajax-loader.gif 2KB
.gitignore 1KB
model_list.html 5KB
base_site.html 4KB
import.html 3KB
date.html 3KB
login.html 3KB
model_list.top_toolbar.exports.html 3KB
model_list.top_toolbar.importexport.export.html 3KB
number.html 3KB
model_delete_selected_confirm.html 2KB
model_history.html 2KB
sitemenu_default.html 2KB
change_password.html 2KB
model_list.nav_menu.bookmarks.html 2KB
base.html 2KB
revision_diff.html 2KB
accordion.html 2KB
model_delete_confirm.html 2KB
thumbnails.html 2KB
submit_line.html 2KB
batch_change_form.html 2KB
tabular.html 2KB
base.html 2KB
tab.html 2KB
base.html 2KB
form.html 2KB
sitemenu_accordion.html 1KB
form.html 1KB
model_list.results_bottom.actions.html 1KB
recover_list.html 1KB
transfer.html 1KB
comm.top.setlang.html 1KB
model_detail.html 1KB
model_form.submit_line.wizard.html 1KB
fk_search.html 1KB
stacked.html 1KB
model_form.html 1KB
revision_form.html 1KB
confirm.html 1KB
export_action.html 1KB
input_group.html 1KB
comm.top.topnav.html 1KB
recover_form.html 1KB
dashboard.html 1KB
char.html 928B
addform.html 895B
model_dashboard.html 883B
logged_out.html 855B
list.html 828B
model_list.top_toolbar.refresh.html 793B
model_list.results_top.charts.html 780B
chart.html 726B
model_list.nav_menu.filters.html 675B
model_form.before_fieldsets.wizard.html 669B
model_list.nav_form.search_form.html 660B
complete.html 641B
checklist.html 621B
quickfilter.html 614B
done.html 600B
共 374 条
- 1
- 2
- 3
- 4
资源评论
生瓜蛋子
- 粉丝: 3927
- 资源: 7441
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 白色简洁风格的优雅创意设计模板下载.zip
- 白色简洁风格的娱乐APP应用整站网站源码下载.zip
- 白色简洁风格的园艺修整整站网站源码下载.zip
- 白色简洁风格的远足旅行机构整站网站源码下载.zip
- 白色简洁风格的杂志列表展示源码下载.rar
- 白色简洁风格的运动会员信息登记源码下载.zip
- 白色简洁风格的运动品牌商城网站模板下载.zip
- 白色简洁风格的杂志主题网页CSS模板下载.zip
- 白色简洁风格的照相摄影源码下载.zip
- 白色简洁风格的照片浏览切换源码下载.rar
- 白色简洁风格的纸竹BLOG网页源码下载.zip
- 白色简洁风格的制造工厂建设整站网站源码下载.zip
- 白色简洁风格的重型汽车销售企业网站源码下载.zip
- 《1+X移动互联网应用开发初级》01-解析.docx
- 大学生党建系统:用户体验与功能优化
- JAVA源码+SpringBoot+vue+mysql+信息学科平台+数据库+指导文档
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功