# by luffycity.com from stark.service.stark import site, ModelStark from .models import * site.register(School) class UserConfig(ModelStark): list_display = ["name", "email", "depart"] site.register(UserInfo, UserConfig) class ClassConfig(ModelStark): def display_classname(self, obj=None, header=False): if header: return "班级名称" class_name = "%s(%s)" % (obj.course.name, str(obj.semester)) return class_name list_display = [display_classname, "tutor", "teachers"] site.register(ClassList, ClassConfig) from django.utils.safestring import mark_safe from django.conf.urls import url
'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', 'stark.apps.StarkConfig', 'api.apps.ApiConfig', ] - 使用 - 在指定app中,创建stark.py - 注册想要增删改查的类 stark.py from stark.service.stark import site from api import models site.register(models.BusinessUnit) - 配置路由 from django.conf.urls import url,include from django.contrib import admin from stark.service.stark import site urlpatterns = [ ... url(r'^stark/',site.urls), ] 小总结:stark帮助用户快速完成增伤改查 - 拷贝stark组件到项目中 - 注册stark app (在自定义app的上方) - from stark.service.stark import site,StarkConfig from api import models
#!/usr/bin/env python3 from stark.service.stark import site from api import models from api.handler.idc import IDCConfig from api.handler.server import ServerConfig site.register(models.IDC, IDCConfig) site.register(models.Server, ServerConfig)
from stark.service.stark import site from crm import models from crm.stark_config.UserInfoStark import UserInfoStark from crm.stark_config.DepartmentStark import DepartmentStark from crm.stark_config.CustomerStark import PersonalCustomerStark from crm.stark_config.ProductStark import ProductStark from crm.stark_config.ConsultantRecordStark import PersonalConsultantRecordStark from crm.stark_config.PaymentRecordStark import PaymentRecordStark, AuditPaymentStark from crm.stark_config.ProductParameterStark import ProductParameterStark from crm.stark_config.ProcedureStark import ProcedureStark from crm.stark_config.WorkShopStark import WorkShopStark from crm.stark_config.ProductAuditStark import ProductAuditStark from crm.stark_config.OrderStark import OrderStark, CheckOrderStark, CustomerOrderStark site.register(models.UserInfo, UserInfoStark) site.register(models.DepartMent, DepartmentStark) site.register(models.Customer, PersonalCustomerStark, 'per') # site.register(models.Customer,CustomerStark) site.register(models.Product, ProductStark) site.register(models.ConsultantRecord, PersonalConsultantRecordStark, 'per') # site.register(models.ConsultantRecord,ConsultantRecordStark) # site.register(models.PaymentRecord,PersonalPaymentRecordStark,'per') site.register(models.Order, CustomerOrderStark) site.register(models.ProductParameter, ProductParameterStark) site.register(models.Procedure, ProcedureStark) site.register(models.ProductAudit, ProductAuditStark) site.register(models.WorkShop, WorkShopStark) # site.register(models.ProductAudit,ProductAuditStark) # site.register(models.Order,PersonOrderStark,'per') site.register(models.Order, OrderStark)
def get_time_format(self,request): time_unit = request.GET.get('timeunit') if time_unit is None: time_unit = 'D' if time_unit == 'D': time_format = {'inserttime': "DATE_FORMAT(inserttime,'%%Y-%%m-%%d')"} elif time_unit == 'H': time_format = {'inserttime': "DATE_FORMAT(inserttime,'%%Y-%%m-%%d %%H')"} elif time_unit == 'm': time_format = {'inserttime': "DATE_FORMAT(inserttime,'%%Y-%%m')"} elif time_unit == 'Y': time_format = {'inserttime': "DATE_FORMAT(inserttime,'%%Y')"} return time_format def src_pic(self,pd): pass site.register(Count_data,Count_dataConfig) class Colum_Count(Count_dataConfig): '''月流量''' def business(self): list_column = self.list_filter_column list_column1 = [] for i in list_column: list_column1.append(i.filed) return list_column1 def text_func(self, option): return option.field def value_func(self, option): return option.colum_nu def colum_monitor(self,qs_dataframe,bussiness): qs_dataframe['Monitor'] = qs_dataframe['Monitor']//1000000
] extra = self.extra_url() if extra: urlpatterns.extend(extra) return urlpatterns def get_list_display(self): val = [] val.extend(self.list_display) val.append(StarkConfig.display_edit_del('edit')) return val site.register(models.BusinessUnit, BusinessUnitConfig) class IDCConfig(StarkConfig): # 展示的字段 list_display = ['id', 'name', 'floor'] # 排序 order_by = ['-id'] # 搜索 search_list = ['name', 'floor'] site.register(models.IDC, IDCConfig) from stark.forms.forms import StarkModelForm from stark.forms.widgets import DatePickerInput
"permissions__pk").distinct() per_id_list = [item[0] for item in per_id_list] return render(request, "permission_distribute.html", locals()) def extra_url(self): l = [ url(r"distribute/", self.permission_distribute), url(r"per_data/", self.per_data), ] return l list_display = ['title', "type", 'url', "code", "pid"] model_form_class = PermissionModelForm class RoleModelForm(forms.ModelForm): class Meta: model = Role exclude = [ "permissions", ] class RoleConfig(ModelStark): model_form_class = RoleModelForm site.register(Role, RoleConfig) site.register(Permission, PermissionConfig)
#! /usr/bin/env python3 # coding:utf-8 # author:zhangjiaqi<*****@*****.**> # Date:2018-09-21 from stark.service.stark import site, ModelConfig from rbac import models site.register(models.Users) site.register(models.Role) site.register(models.Permissions) site.register(models.PermissionGroup) if __name__ == '__main__': pass
from stark.service.stark import site from Django_apps.web.views.survey_forms import TableSettingsConfig, DetailsOfFilling from school.models import TableSettings, TableInfo from Django_apps.web.views.student import StudentInfo, StudentConfig, SchoolStudentConfig from Django_apps.web.views.teacher import TeacherInfoConfig, SchoolTeacherConfig from teacher.models import TeacherInfo from Django_apps.web.views.school import SchoolInfoConfig from school.models import SchoolInfo from stark.service.stark import site from Django_apps.weixinApp.models import Emblem from Django_apps.web.views.wechat_applet.emblem import EmblemHandler site.register(Emblem, EmblemHandler) site.register(TeacherInfo, stark_config=TeacherInfoConfig) site.register(TeacherInfo, stark_config=SchoolTeacherConfig, prev='school') site.register(SchoolInfo, SchoolInfoConfig) # site.register(models.UserInfo, UserInfoConfig) site.register(StudentInfo, StudentConfig) site.register(StudentInfo, SchoolStudentConfig, prev='school') site.register(TableSettings, TableSettingsConfig) site.register(TableInfo, DetailsOfFilling)
from stark.service.stark import site, ModelStark from .models import * class AuthorForm(ModelStark): list_filter = ['name'] site.register(Author, AuthorForm) site.register(AuthorDetail) class PublishForm(ModelStark): list_filter = ['name'] site.register(Publish, PublishForm) from django.forms import ModelForm # #########自己有就用自己的,自己没有就用父类的########### class BookModelForm(ModelForm): class Meta: model = Book # 这块就可以定死了,因为就是给的Book表 fields = '__all__' labels = { "title": "书籍名称", "price": "价格", "publishDate": "出版日期",
from web.config.kubernetes_stark_config.k8singress import K8sIngress_list_Config from web.config.kubernetes_stark_config.k8singress_admin import K8sIngress_list_Config_Admin from web.config.user_stark_config.userprofile_list import UserProfile_list_Config from web.config.user_stark_config.admininfo_list import AdminInfo_list_Config from web.config.user_stark_config.usergroup_list import UserGroup_list_Config from web.config.user_stark_config.businessunit_list import BusinessUnit_list_Config from web.config.log_stark_config.serverrecord_list import ServerRecord_list_Config # from web.config.tag_list import Tag_list_Config from web.config.selfconfig import SelfConfig_list_Config site.register(model_class=models.UserProfile, stark_config=UserProfile_list_Config) # 用户信息表 site.register(model_class=models.AdminInfo, stark_config=AdminInfo_list_Config) # 用户账号表 site.register(model_class=models.UserGroup, stark_config=UserGroup_list_Config) # 用户组 site.register(model_class=models.BusinessUnit, stark_config=BusinessUnit_list_Config) # 业务线 # site.register(model_class=models.Tag, stark_config=Tag_list_Config) # 资产标签 site.register(model_class=models.Server, stark_config=Server_list_Config) # 主机Server表 site.register(model_class=models.Memory, stark_config=Memory_list_Config) # 内存表 site.register(model_class=models.Disk, stark_config=Disk_list_Config) # 磁盘信息 site.register(model_class=models.Cpu, stark_config=Cpu_list_Config) # Cpu信息 site.register(model_class=models.Network, stark_config=Network_list_Config) # 网络信息 site.register(model_class=models.ServerRecord, stark_config=ServerRecord_list_Config) # 资产变更记录 site.register(model_class=models.SelfConfig, stark_config=SelfConfig_list_Config) # 自用配置文件 site.register(model_class=models.K8sConfigmap, stark_config=K8sConfigmap_list_Config) # k8s configmap文件内容
from stark.service.stark import site, ModelStark from app01.models import * site.register(User) site.register(Role) class PermmissionConfig(ModelStark): list_display = ["title", "url"] list_display_links = ["title"] site.register(Permmission, PermmissionConfig)
from app01.models import User, Role, Permmission from django.shortcuts import HttpResponse, render, redirect from django.conf.urls import url from stark.service.stark import site, ModelStark site.register(User) site.register(Role) class Permission_conf(ModelStark): list_display = ['title', 'url'] list_display_links = ['title'] site.register(Permmission) ##### from app01.models import * site.register(UserInfo) site.register(Department) site.register(Course) # 学校自定制类: class SchoolConfig(ModelStark): list_display = ['title'] site.register(School, SchoolConfig) # 自定制班级类 class ClassConfig(ModelStark):
# -*- coding:utf-8 -*- __author__ = 'Qiushi Huang' from stark.service.stark import site, ModelStark from .models import * class UserConfig(ModelStark): list_display = ["name", "roles"] site.register(User, UserConfig) class RoleConfig(ModelStark): list_display = ["title", "permissions"] site.register(Role, RoleConfig) class PermissionConfig(ModelStark): list_display = ["id", "title", "url", "group", "action"] site.register(Permission, PermissionConfig) site.register(PermissionGroup)
from stark.service.stark import site,ModelStark from .models import * site.register(User) site.register(Role) class PerConfig(ModelStark): list_display = ["id","title","url","group","action"] site.register(Permission, PerConfig) site.register(PermissionGroup)
#-*- coding:utf-8 -*- from app01 import models from stark.service.stark import site, StarkConfig site.register(models.User)
# /usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2018/11/10 14:47 # @Author : TrueNewBee from stark.service.stark import site, ModelStark from app01.models import * site.register(CourseCategory) site.register(CourseSubCategory) site.register(DegreeCourse) site.register(Teacher) site.register(Scholarship) site.register(Course) site.register(CourseDetail) site.register(OftenAskedQuestion) site.register(CourseOutline) site.register(CourseChapter) site.register(CourseSection) site.register(Homework) site.register(PricePolicy) site.register(ArticleSource) site.register(Article) site.register(Collection) site.register(Comment) site.register(Account) site.register(UserAuthToken)
from crm.config.customer import CustomerConfig, PublicCustomerConfig, PrivateCustomerConfig from crm.config.consult_record import ConsultRecordConfig, PriConsultRecordConfig from crm.config.student import StudentConfig from crm.config.course_record import CourseRecordConfig from crm.config.study_record import StudyRecordConfig from crm.permission.base import RbacPermission class DepartmentConfig(StarkConfig): list_display = [ 'id', 'title', StarkConfig.display_edit, StarkConfig.display_del ] site.register(models.Department, DepartmentConfig) class UserInfoConfig(StarkConfig): def display_detail(self, row=None, header=False): if header: return '查看详细' return mark_safe('<a href="%s">%s</a>' % ( reverse('stark:crm_userinfo_detail', kwargs={'pk': row.id}), row.name, )) list_display = [ display_detail, get_choice_text('gender', '性别'), # display_gender函数:self, row=None, header=False
def display_course(self, obj=None, header=False): if header: return "咨询课程" temp = [] for course in obj.course.all(): s = "<a href='/stark/crm/customer/cancel_course/%s/%s' style='border:1px solid #369;padding:3px 6px'><span>%s</span></a> " % ( obj.pk, course.pk, course.name,) temp.append(s) return mark_safe("".join(temp)) list_display = ["name", display_gender, display_course, "consultant", ] def cancel_course(self, request, customer_id, course_id): print(customer_id, course_id) obj = Customer.objects.filter(pk=customer_id).first() obj.course.remove(course_id) return redirect(self.get_list_url()) # 父类给出的添加额外url的接口 def extra_url(self): temp = [] temp.append(url(r"cancel_course/(\d+)/(\d+)", self.cancel_course)) return temp # 有配置类的models注册 site.register(UserInfo, UserConfig) site.register(ClassList, ClassConfig) site.register(Customer, CusotmerConfig) # 没有配置类的models直接注册 site.register(Course)
list_filter = [ Option('storage', is_multi=True), Option('pos', is_multi=True), Option('cls', is_multi=True), ] search_list = ['name'] #批量删除 action_list = [ StarkConfig.multi_delete, ] site.register(models.Material, MaterialCofig) class PosConfig(StarkConfig): list_display = [ 'id', 'name', ] def get_urls(self): urlpatterns = [ url(r'^list/$', self.wrapper(self.changelist_view), name=self.get_list_url_name), url(r'^add/$', self.wrapper(self.add_view),
# 注册功能 from app01 import models from stark.service.stark import site, ModelStark from django.utils.safestring import mark_safe class BookConfig(ModelStark): list_display = ['title', 'price', 'publish'] site.register(models.Book, BookConfig) site.register(models.Publish) site.register(models.Author) site.register(models.AuthorDetail)
def multi_delete(self, request): pk_list = request.POST.getlist('pk') models.BusinessUnit.objects.filter(id__in=pk_list).delete() # 无返回值,返回当前页面,并删除你选中的数据 from django.shortcuts import redirect # 有返回值,删除数据,并返回你自定义的一个页面 return redirect('http://www.baidu.com') multi_delete.text = '批量操作' # 必须这样写,因为用的别人的插件 action_list = [ multi_delete, ] # 显示批量操作的按钮,不写就不显示 site.register(models.BusinessUnit, BusinessUnitConfig) # idc机房 class IDCConfig(StarkConfig): list_display = [ 'name', 'floor', ] search_list = ['name', 'floor'] site.register(models.IDC, IDCConfig) # 硬盘
from stark.service.stark import site, ModelStark from .models import UserInfo, Book from django.forms import ModelForm class UserConfig(ModelStark): list_display = ['nid', 'name', 'age'] list_display_links = ['name'] search_fields = ['name', 'age'] actions = [] list_filter = ['name', 'age'] class BookFormDemo(ModelForm): class Meta: model = Book fields = '__all__' class BookConfig(ModelStark): list_display = ['title', 'publish', 'price'] model_form = BookFormDemo list_filter = ['publish', 'price'] site.register(UserInfo, UserConfig) site.register(Book, BookConfig) print('register', site._registry)
@desc: ''' from stark.service.stark import site, ModelStark from .models import * from django.utils.safestring import mark_safe from django.forms import ModelForm class UserConfig(ModelStark): list_display = ['name', 'username'] site.register(UserInfo, UserConfig) site.register(Department) class UserModelForm(ModelForm): class Meta: model = User fields = ['name', 'username', 'depart', 'keyStatus'] class UsrConfig(ModelStark): def displsy_key(self, obj=None, header=False): if header: return "密钥下载" s = "<a href='http://www.baidu.com'>%s</a>" % (obj.keyPath) return mark_safe(s)
# by luffycity.com from stark.service.stark import site, DeFaultConfigClass from .models import * site.register(User) site.register(Role) class PerConfig(DeFaultConfigClass): list_display = ["id", "title", "url", "group", "action"] site.register(Permission, PerConfig) site.register(PermissionGroup)
return HttpResponse('输入网址有误') def add_view(self, request): if request.method == 'POST': re_type = request.POST.get('re_type') if re_type == 'scrapy_selenium': pass else: start_url = request.POST.get('start_url') rehis_zero.lpush('sunkey', start_url) cookie = request.POST.get('cookie') domain = urlparse(start_url).netloc url_heade = domain + ':' + 'header' print(cookie) rehis_zero.hset(url_heade, 'cookie', cookie) start_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) Reptile_reg.objects.create(domain=domain, url=start_url, FirstReptile=start_time) # Reptile_reg.save() return redirect('/stark/business_func/reptile_reg/list/') return render(request, 'business_func/reptile_add.html') def text_details(self, request, pk, sd): print(pk, sd) return HttpResponse('这是text详情') site.register(Reptile_reg, Reptle)
# Author: harry.cai # DATE: 2018/9/16 from stark.service.stark import site, StarkConfig, Option from crm.views.school import SchoolHandler from crm.views.depart import DepartmentHandler from crm.views.userinfo import UserInfoHandler from crm.views.course import CourseHandler from crm.views.consult_record import ConsultRecordHandler from crm.views.class_list import ClassListHandler from crm.views.private_customer import * from crm.views.public_customer import * site.register(models.School, SchoolHandler) site.register(models.Department, DepartmentHandler) site.register(models.UserInfo, UserInfoHandler) site.register(models.Course, CourseHandler) site.register(models.ClassList, ClassListHandler) site.register(models.Customer, PublicCustomerHandler, prev='pub') site.register(models.Customer, PrivateCustomerHandler, prev='priv') site.register(models.ConsultRecord, ConsultRecordHandler)
from stark.service.stark import site, ModelStark from django.urls import reverse from .models import * from django.utils.safestring import mark_safe from django.forms import ModelForm from django.forms import widgets as wid class BookModelForm(ModelForm): class Meta: model = Book fields = "__all__" labels = {"title": "书籍名称", "price": "价格"} class BookConfig(ModelStark): list_display = ["title", "price", "publishDate"] modelform_class = BookModelForm site.register(Book, BookConfig) site.register(Publish) site.register(Author) site.register(AuthorDetail)
class UserinfoConfig(StarkConfig): order_by = ['-id'] # 调用排序的函数,倒序生成数据 list_display = [ 'id', 'title', StarkConfig.display_edit, StarkConfig.display_del ] # 使用定制的钩子函数 # def get_list_display(self): # return ['id', 'title', StarkConfig.display_edit, StarkConfig.display_del] # 关键字搜索项,我可以按照id搜索,也能按照title搜索 search_list = ['id', 'title'] site.register(models.UserInfo, UserinfoConfig) class DepartModelForm(forms.ModelForm): class Meta: model = models.Depart fields = "__all__" def clean_name(self): return self.cleaned_data['name'] class DistinctNameOption(Option): def get_queryset(self, _field, model_class, query_dict): return Row( model_class.objects.filter(
def multi_delete(self, request): pk_list = request.POST.getlist('pk') models.Role.objects.filter(id__in=pk_list).delete() # 无返回值,返回当前页面 from django.shortcuts import redirect # 有返回值 # return HttpResponse("ok") multi_delete.text = 'multi_delete' action_list = [ multi_delete, ] site.register(models.User, userconfig) class roleconfig(StarkConfig): def display_role(self, row=None, header=False): if header: return "Role" s = [] for r in row.permissions.all(): print(r) s.append("<a href='#' style='padding:3px 6px'>%s</a>" % (r.title)) return mark_safe(" ".join(s)) list_display = [ StarkConfig.display_checkbox, "id",
class UserInfoConfig(ModelStark): list_display = ["name", "age", "gender", "depart"] class ConsultRecordConfig(ModelStark): def filter_date(self, obj=None, is_header=False): if is_header: return "跟进日期" return obj.date.strftime("%Y-%m-%d") list_display = ["customer", "note", "consultant", filter_date] site.register(Campuses) site.register(Department) site.register(Customer, CustomerConfig) site.register(UserInfo, UserInfoConfig) site.register(ConsultRecord, ConsultRecordConfig) site.register(Enrollment) site.register(Student) site.register(StudentStudyRecord) site.register(ClassStudyRecord) site.register(ClassStudyRecord) # class HostConfig(ModelStark): # list_display = ["name","IP","dist","room"] # list_filter = ["room"] # search_fields = ["name"]
patch_delete.info = '批量删除' def patch_init(self, request, data): pass patch_init.info = '批量初始化' actions = [patch_delete, patch_init] list_filter = ['publish', 'author'] # 自定义url 这里仅仅是一个示例,无具体意义 def extra_urls(self): temp=[] temp.append( url("score/(\d+)",self.score_view) ) return temp site.register(models.Book, Bookconfig) class Publishconfig(ModelStark): list_display = ['nid', 'name', 'city'] site.register(models.Publish, Publishconfig) site.register(models.Author) site.register(models.AuthorDetail)