def get_form_layout(self): if self.org_obj: self.form_layout = (Main( Fieldset("讲师信息", 'teacher', 'course_org', css_class='unsort no_title'), Fieldset( "基本信息", 'name', 'desc', Row('learn_times', 'degree'), Row('category', 'tag'), 'youneed_know', 'teacher_tell', 'detail', ), ), Side( Fieldset("访问信息", 'fav_nums', 'click_nums', 'students', 'add_time'), ), Side( Fieldset("选择信息", 'is_banner', 'is_classics'), )) return super(NewCourseAdmin, self).get_form_layout()
def get_form_layout(self): # 判断是否是编辑页面 # if self.org_obj: self.form_layout = ( Main( Fieldset('讲师信息', 'teacher', 'course_org', css_class='unsort no_title' ), Fieldset('基本信息', 'name', 'describe', Row('learn_time', 'degree'), Row('category', 'tag'), ), ), Side( Fieldset('情况', 'students', 'fav_nums', 'click_nums', ), ), Side( Fieldset('选择', 'is_class', 'is_banner', ), ) ) return super(NewCouseAdmin, self).get_form_layout()
def get_form_layout(self): self.form_layout =( Main( Fieldset("讲师信息", "teacher","course_org", # css_class='unsort no_title' ), Fieldset("基本信息", "name","desc", Row("learn_times","degree"), Row("category","tag"), ), ), Side( Fieldset("访问信息", Row("students","fav_num","click_num") ), Fieldset("课程信息", "youneed_know","teacher_tell","is_classics" ) ), Side( Fieldset("封面信息", "image", "notice", "is_banner","is_index" ) ) ) return super(CourseAdmin, self).get_form_layout()
def get_form_layout(self): self.form_layout = (Main( Fieldset('讲师信息', 'teacher', 'course_org', css_class='unsort no_title'), Fieldset( '基本信息', 'name', 'desc', Row('degree', 'learn_times'), Row('category', 'tags'), 'notice', 'teacher_tell', 'detail', ), ), Side( Fieldset( '访问信息', 'fav_nums', 'click_nums', 'students', 'add_time', ), ), Side( Fieldset( '选择信息', 'is_banner', 'is_classics', ), )) return super(CoursesAdmin, self).get_form_layout()
def get_form_layout(self): if self.org_obj: self.form_layout = ( Main( Fieldset( '用户信息', 'username', 'password', 'email', 'sex', 'realname', #css_class='unsort no_title' ), Fieldset( '权限和组', 'groups', 'user_permissions', ), ), Side( Fieldset( '用户状态', 'is_active', 'is_staff', 'is_superuser', ), Fieldset('时间', 'joined_at', 'last_login'))) else: self.form_layout = ( Main( Fieldset( '用户信息', 'username', 'password1', 'password2', 'email', 'sex', 'realname', #css_class='unsort no_title' ), Fieldset( '权限和组', 'groups', 'user_permissions', ), ), Side( Fieldset( '用户状态', 'is_active', 'is_staff', 'is_superuser', ), Fieldset('时间', 'joined_at', 'last_login'))) return super(UserAdmin, self).get_form_layout()
class AuthorBlogAdmin(CommonSetting): exclude = ('id', 'author') list_display = ('title', 'cat', 'is_active', 'original', 'tags', 'read', 'like', 'url') search_fields = ('title', ) list_filter = ('add', 'mod') readonly_fields = ('read', 'like', 'add', 'mod', 'is_active', 'is_top', 'is_fine', "apply_active", "apply_top", "apply_fine") form_layout = (Main( Fieldset(_('基本信息'), Row('title', 'cat'), Row('cover', 'tags'), Row('music')), Fieldset(_('标记信息'), Row('apply_active', ), Row('apply_top', ), Row('apply_fine')), Fieldset( _('正文'), Row('source'), Row('content'), ), Fieldset( _('统计信息'), Row('read', 'like'), Row('add', 'mod'), ), ), Side(Fieldset(_('状态'), 'is_active', 'is_top', 'is_fine'))) def queryset(self): q = super().queryset() return q.filter(author_id=self.request.user.id) def save_models(self): """ 01.保存数据到数据库中时提取作者为当前用户 02.修复代码块bug """ if (not hasattr(self.new_obj, 'author')) or (not self.new_obj.author): self.new_obj.author = self.request.user self.new_obj.save() def has_add_permission(self): # 写文章的权限 if self.request.user.is_superuser: return True return self.request.user.is_active def has_delete_permission(self, obj=None): # 删除权限 if obj is not None: if self.request.user.is_superuser: return True if self.request.user.id == obj.author.id: return True return False def has_change_permission(self, obj=None): if obj is not None: if self.request.user.is_superuser: return True if self.request.user.id == obj.author.id: return True return False
class BlogAdmin(CommonSetting): exclude = ('id', ) list_display = ('title', "is_active", 'author', 'cat', 'original', 'read', 'like', 'url') search_fields = ('title', 'author__username', 'author__email') list_filter = ('is_active', 'add', 'mod') readonly_fields = ('read', 'like', 'add', 'mod') form_layout = (Main( Fieldset(_('基本信息'), Row('title', 'cat', 'author'), Row('cover', 'tags'), Row('music')), Fieldset( _('正文'), Row('source'), Row('content'), ), Fieldset( _('统计信息'), Row('read', 'like'), Row('add', 'mod'), ), ), Side(Fieldset(_('状态'), 'is_active', 'is_top', 'is_fine'), )) def save_models(self): """ 保存数据到数据库中时提取作者为当前用户 """ if (not hasattr(self.new_obj, 'author')) or (not self.new_obj.author): self.new_obj.author = self.request.user self.new_obj.save()
def get_form_layout(self): if self.org_obj: self.form_layout = (Main( Fieldset( _('Personal info'), Row('email'), Row('password'), ), Fieldset( '作者信息', Row('username', 'header'), Row('desc'), Row('alipay', 'wechat'), ), Fieldset( "统计信息", Row('last_login', 'date_joined', "published", "to_publish", "read", "like")), ), Side( Fieldset( _('Status'), 'is_active', 'is_staff', 'is_superuser', ), )) return super(UserAdmin, self).get_form_layout()
def get_form_layout(self): if self.org_obj: self.form_layout = (Main( Fieldset( _('Personal info'), Row('email'), Row('password'), ), Fieldset( '作者信息', Row('username', 'header'), Row('desc'), Row('alipay', 'wechat'), ), Fieldset(_('Permissions'), 'groups', 'user_permissions'), Fieldset(_('Important dates'), Row('last_login', 'date_joined')), ), Side( Fieldset( _('Status'), 'is_active', 'is_staff', 'is_superuser', ), )) return super(UserAdmin, self).get_form_layout()
def get_form_layout(self): if self.org_obj: self.form_layout = ( Main( Fieldset('', 'username', 'password', css_class='unsort no_title' ), Fieldset(_('Personal info'), Row('level', 'credit'), Row('sex', 'email'), Row('phone', ), 'address', 'signature', ), Fieldset(_('Important dates'), 'last_login', 'date_joined' ), ), Side( Fieldset(_('Status'), 'is_active', 'is_staff', 'is_superuser', ), ) ) return super(UserAdmin, self).get_form_layout()
def get_form_layout(self): if self.org_obj: # 只有在修改页面才变 self.form_layout = ( Main( # Fieldset表示一块 Fieldset('讲师信息', 'teacher', 'course_org', css_class='unsort no_title' ), Fieldset('基本信息'), 'name', 'desc', Row('learn_times', 'degree'), Row('category', 'tag'), 'you_need_know', 'teacher_tell', 'detail', ), # Side( # # 右侧的信息 # Fieldset('访问信息'), # 'fav_nums', 'click_nums', 'students', 'add_times' # ), Side( # 右侧的信息 Fieldset('选择信息'), 'is_classics', 'is_banner', 'image' ), ) return super(NewCourseAdmin, self).get_form_layout()
def get_form_layout(self): self.form_layout = ( Main( Fieldset('基础信息', 'Gmodel', Row('price', 'min_price') # css_class='unsort no_title' ), Fieldset( '备注信息', "meno", ), ), # Side( # Fieldset(_('Status'), # 'is_active', 'is_staff', 'is_superuser', # ), # ) Side( '选择项目', 'brand', 'supplier', 'type', 'unit', ), ) return super(GoodsAdmin, self).get_form_layout()
class CommunityAdmin(object): hidden_menu = True list_display = ("community_name", "group", "responsibility", "date_created") form_layout = (Main( Tab( "用户组", Inline(GroupInline), Fieldset( "用户权限组", "group", description="针对操作管线的用户管理组进行责任划分。", ), ), ), Side( Tab( "责任", Fieldset( "责任管理", "community_name", "responsibility", description="针对系统部件创建策略, 设置生效与否", ), ), ))
def get_form_layout(self): if self.org_obj: self.form_layout = ( Main( Fieldset('', 'username', 'password', css_class='unsort no_title' ), Fieldset('个人信息', Row('first_name', 'last_name'), 'email' ), # Fieldset('Permissions', # 'groups', 'user_permissions' # ), Fieldset('时间信息', 'last_login', 'date_joined' ), ), Side( Fieldset('Status', 'is_active', 'is_staff', 'is_superuser', ), ) ) return super(UserProfilesAdmin, self).get_form_layout()
def get_form_layout(self): # 修改显示布局 if self.org_obj: # 判断是否时新增,返回真则不是 self.form_layout = ( Main( # 左侧显示 Fieldset('讲师信息', 'teacher', 'course_org', css_class='unsort no_title' ), Fieldset('基本信息', 'name', 'desc', 'notice', 'youneed_know', 'teacher_tell', 'detail', Row('learn_times', 'degree'), Row('category', 'tag'), ), ), Side( # 右侧小框显示 Fieldset('访问信息', 'click_nums', 'students', 'fav_nums' ), Fieldset('是否选择', 'is_banner', 'is_classics' ), ), ) return super(NewCourseAdmin, self).get_form_layout()
def get_form_layout(self): """自定义后台字段顺序""" if self.org_obj: from xadmin.layout import Main from xadmin.layout import Fieldset from django.utils.translation import ugettext as _ from xadmin.layout import Row from xadmin.layout import Side self.form_layout = ( Main( Fieldset('', 'username', 'password', css_class='unsort no_title' ), Fieldset(_('Personal info'), 'first_name', 'last_name', 'email' ), Fieldset(_('Permissions'), 'groups', 'user_permissions' ), Fieldset(_('Important dates'), 'last_login', 'date_joined' ), ), Side( Fieldset(_('Status'), 'is_active', 'is_staff', 'is_superuser', ), ) ) # 调用UserAdmin中的Mro父集方法 return super(UserAdmin, self).get_form_layout()
def get_form_layout(self): if self.org_obj: self.form_layout = ( Main( Fieldset(_('基本信息'), 'company_name', 'company_type', 'url', 'city', 'keyword', ), Fieldset(_('联系方式'), 'qq', 'wechat', 'phone', 'address', ), Fieldset(_('意向信息'), 'sem_status', 'aike_status', ), Fieldset(_('签单信息'), 'depart', 'sales', 'amount', 'business', ), Fieldset(_('时间信息'), 'create_time', 'update_time', ), ), Side( ) ) return super(addUpByDepartAdmin, self).get_form_layout()
class WrokOrdersAdmin(object): list_display = ['org_user', 'pro_type','pro_date','is_finish'] search_fields = [] readonly_fields = ['creator'] list_filter = ['creator','is_finish','is_key_work','create_time','modified_time'] exclude = ['org_dept'] reversion_enable = True form_layout = ( Main( Fieldset('', Row('creator','org_user'), Row('pro_type', 'pro_date'), Row('pro_desc'), Row('solver', 'solve_len_time'), Row('solve_desc'), ), ), Side( Fieldset(('Status'), 'is_finish','is_key_work', ), ) ) def save_models(self): obj = self.new_obj request = self.request obj.creator = str(request.user.username) obj.save()
class UserProfileAdmin(object): list_display = ('username', 'email', 'is_staff', 'mobile', 'number', 'gender', 'birthday') search_fields = ('number', 'email', 'username', 'mobile') list_filter = ('is_staff', ) model_icon = 'fa fa-user-o' readonly_fields = ('follow_nums', 'fan_nums', 'upload_nums', 'like_nums', 'collection_nums', 'download_nums', 'add_time', 'password') relfield_style = 'fk-ajax' form_layout = (Main( Fieldset('', 'username', 'password', css_class='unsort no_title'), Fieldset( '关键信息', Row('real_name', 'p_class'), Row('email', 'mobile'), Row('qq', 'id_card'), ), Fieldset('权限', 'groups', 'user_permissions'), Fieldset('日期', 'last_login', 'date_joined'), ), Side( Fieldset('状态', 'is_active', 'is_staff', 'is_superuser', 'if_sign'), )) def get_readonly_fields(self): if self.user.is_superuser: self.readonly_fields = [] return self.readonly_fields
class ImageModelAdmin(object): list_display = ('name', 'url', 'if_active', 'cates', 'pattern', 'i_desc', 'add_time') search_fields = ('name', 'desc', 'pattern') list_filter = ('user', 'name', 'if_active', 'desc', 'pattern', 'cates', 'add_time') readonly_fields = ('add_time',) model_icon = 'fa fa-file-image-o' refresh_times = (5, 10) relfield_style = 'fk-ajax' form_layout = ( Main( Fieldset('', 'name', 'image', 'user', 'pattern', 'desc', 'cates', css_class='unsort no_title' ), ), Side( Fieldset('状态', 'if_active' ), ) ) def get_readonly_fields(self): if self.user.is_superuser: self.readonly_fields = [] return self.readonly_fields
def get_form_layout(self): if self.org_obj: self.form_layout = ( Main( Fieldset('', 'username', 'password', css_class='unsort no_title' ), Fieldset(_('Personal info'), Row('first_name', 'last_name'), 'email' ), Fieldset(_('Permissions'), 'groups', 'user_permissions' ), Fieldset(_('Important dates'), 'last_login', 'date_joined' ), ), Side( Fieldset(_('Status'), 'is_active', 'is_staff', 'is_superuser', ), ) ) return super(UserAdmin, self).get_form_layout()
class NewNewsBaseClass(object): list_filter = ['time', 'source'] list_editable = ['priority', 'hidden', 'source'] # 每页显示的数量 list_per_page = 30 # 显示缩略图 def img_data(self, obj): if obj.img and hasattr(obj.img, 'url'): if 'http' in obj.img.url: return format_html( '<img src="{0}" width="150px" height="150px"/>'.format( obj.img)) else: return format_html( '<img src="{0}" width="150px" height="150px"/>'.format( obj.img.url)) else: return '无' img_data.short_description = '新闻图片' # 显示的字段 list_display = [ 'title', 'img_data', 'go_to', 'time', 'source', 'priority', 'hidden' ] list_display_links = ['title', 'source', "time"] # 设置空值 empty_value_display = '无' # 操作选项 actions_on_top = True # 还原按钮,删除的信息可以还原 reversion_enable = True # 搜索器 search_fields = ['title', 'content'] # 设置外键位搜索格式 relfield_style = 'fk_ajax' # 跳转字段 ordering = ('-time', ) def del_imgs(self, request, queryset): queryset.update(img=None) messages.success(request, "删除图片成功") del_imgs.short_description = "删除图片" actions = [del_imgs] #内部排版 form_layout = (Main( Fieldset('基本信息', 'title', 'img', 'priority', 'time', 'label', 'source', 'author', 'hidden'), Fieldset( '新闻内容', 'content', ), ), Side(Fieldset('其它', 'url', 'comment', 'like', 'keywords'), )) readonly_fields = ('comment', 'like', 'keywords') exclude = ['url']
class AdvertisementAdmin(CommonSetting): list_display = ('ad_name', 'adtype', 'url', 'end') search_fields = ('ad_name', 'remark') list_filter = ('add', 'mod', 'end', "adtype") readonly_fields = ('add', 'mod') form_layout = (Main( Fieldset(_('广告信息'), Row('ad_name', 'add', 'end'), Row('link', 'mod'), Row('image', 'adtype')), ), Side(Fieldset(_('备注'), 'remark')))
class GroupsAdmin(object): list_display = ('name', 'add_time', 'if_show') search_fields = ('name', ) list_filter = ('name', 'add_time', 'if_show') model_icon = 'fa fa-object-group' form_layout = (Main( Fieldset('', 'name', 'add_time', css_class='unsort no_title'), ), Side(Fieldset('状态', 'if_show'), ))
class LinkAdmin(CommonSetting): list_display = ('link_name', 'is_active', 'cat', 'url') search_fields = ('link_name', 'email', 'link') list_filter = ('cat', 'is_active') readonly_fields = ('add', 'mod') form_layout = (Main( Fieldset(_('链接信息'), Row('link_name', 'cat'), Row('link', 'email'), Row('add', 'mod')), ), Side(Fieldset(_('状态'), 'is_active'), ))
class NoticeAdmin(CommonSetting): list_display = ('title', 'is_active', 'add', 'url') search_fields = ('title', ) list_filter = ('add', 'mod', 'is_active') readonly_fields = ('add', 'mod') form_layout = (Main( Fieldset(_('公告信息'), Row('title'), Row('add', 'mod'), Row('content')), ), Side(Fieldset(_('状态'), 'is_active')))
class HostAdmin(object): def open_web(self, instance): return "<a href='http://%s' target='_blank'>Open</a>" % instance.ip open_web.short_description = "Acts" open_web.allow_tags = True open_web.is_column = True list_display = ('name', 'idc', 'guarantee_date', 'service_type', 'status', 'open_web', 'description') list_display_links = ('name',) raw_id_fields = ('idc',) style_fields = {'system': "radio-inline"} search_fields = ['name', 'ip', 'description'] list_filter = ['idc', 'guarantee_date', 'status', 'brand', 'model', 'cpu', 'core_num', 'hard_disk', 'memory', 'service_type'] list_bookmarks = [{'title': "Need Guarantee", 'query': {'status__exact': 2}, 'order': ('-guarantee_date',), 'cols': ('brand', 'guarantee_date', 'service_type')}] show_detail_fields = ('idc',) list_editable = ( 'name', 'idc', 'guarantee_date', 'service_type', 'description') save_as = True aggregate_fields = {"guarantee_date": "min"} form_layout = ( Main( TabHolder( Tab('Comm Fiels', Fieldset('Company data', 'name', 'idc', description="some comm fields, required" ), Inline(MaintainLog), ), Tab('Extend Fiedls', Fieldset('Contact details', 'service_type', Row('brand', 'model'), Row('cpu', 'core_num'), Row(AppendedText( 'hard_disk', 'G'), AppendedText('memory', "G")), 'guarantee_date' ), ), ), ), Side( Fieldset('Status data', 'status', 'ssh_port', 'ip' ), ) ) inlines = [MaintainInline] reversion_enable = True
class ExpandAdmin(CommonSetting): list_display = ('key', 'value', "mod") search_fields = ('remark', 'key') list_filter = ('mod', ) ordering = ('-mod', ) readonly_fields = ('mod', ) form_layout = (Main( Fieldset(_('数据记录'), Row('key'), Row('value'), Row('mod'))), Side(Fieldset(_('备注'), 'remark')))
class CategoryAdmin(CommonSetting): list_display = ('pre_cat', 'cat', 'is_active', 'art_nums', 'add', 'mod') search_fields = ('cat', 'pre_cat') list_filter = ('add', 'mod', 'is_active') readonly_fields = ('add', 'mod') form_layout = ( Main(Fieldset(_('类别信息'), Row('pre_cat', 'cat'), Row('add', 'mod')), ), Side(Fieldset(_('状态'), 'is_active'), ), )
class ScanTaskAdmin(object): def queryset(self): qs = super(ScanTaskAdmin, self).queryset() if self.request.user.username in PREVILEGED_USER_SETS: return qs else: return qs.filter(workspace__user=self.request.user) list_display = ( 'targets', "ports", "imports_active", "scan_scheme", "date_created", ) # list_display = ('targets', "ports", "scan_scheme", "date_created", schedule) list_editable = ['imports_active', 'workspace'] fieldsets = [ # ("基本描述", {'fields': ['type', "name", "desc"] }), ('工作组', { 'fields': ['workspace'] }), ('文件导入', { 'fields': ['imports_active', 'imports'] }), ('自定义目标', { 'fields': ['targets', "ports", "udp", "domains"] }), ('选定扫描方案', { 'fields': ['scan_scheme'] }), ('执行类型', { 'fields': ['atnow', "regular", "interval", "crontab"] }), ] # wizard_form_list = fieldsets # inlines = [WorkspaceInline, ] form_layout = (Main( TabHolder( Tab( "文件添加扫描", Fieldset( "基础扫描设置", "workspace", "scan_scheme", Row("imports_active", "imports"), Row("atnow", "regular"), ), ), ), ), Side( Fieldset("自定义目标", 'targets', "ports", "udp", "domains"), ))