예제 #1
0
파일: table.py 프로젝트: coblan/helpers
    def make_pop_edit_field(self, heads):
        """
        确定弹出框 列
        """
        if self.pop_edit_field:
            for head in heads:
                if head['name'] == self.pop_edit_field:
                    director_name = self.get_director_name()
                    #model_form = model_dc[self.model].get('fields')
                    model_form = director.get(self.get_edit_director_name())
                    form_obj = model_form(crt_user=self.crt_user)
                    #head['name'] ==self.pop_edit_field
                    head['editor'] = 'com-table-pop-fields'
                    head['fields_ctx'] = form_obj.get_head_context()
                    head['get_row'] = {
                        #'fun':'use_table_row'
                        "fun": 'get_table_row'
                        #'fun':'get_with_relat_field',
                        #'kws':{
                        #"model_name":model_to_name(TbBanner),
                        #'relat_field':'pk'
                        #}
                    }
                    head['after_save'] = {
                        #'fun':'do_nothing'
                        'fun': 'update_or_insert'
                    }
                    #head['ops']=form_obj.get_operations()
                    #head['extra_mixins']=form_obj.extra_mixins
        if self.pop_edit_fields:
            model_form = director.get(self.get_edit_director_name())
            if model_form:
                form_obj = model_form(crt_user=self.crt_user)
                fields_ctx = form_obj.get_head_context()
                for head in heads:
                    if head['name'] in self.pop_edit_fields:
                        head['editor'] = 'com-table-click'
                        head['fields_ctx'] = fields_ctx
                        head['fields_ctx'].update({
                            #'after_save':'scope.vc.par_row.car_no =scope.row.car_no; scope.vc.par_row.has_washed=scope.row.has_washed ',
                            #'init_express':'cfg.show_load(),ex.director_call(scope.vc.ctx.director_name,{pk:scope.vc.par_row.pk}).then((res)=>{cfg.hide_load();ex.vueAssign(scope.row,res.row)})',

                            #'mounted_express':'ex.vueAssign(scope.row,scope.vc.par_row)',
                            #'after_save':'ex.vueAssign( scope.vc.par_row,scope.row)',
                            'ops_loc': 'bottom',
                            # 把初始化row放到 action里面去了 [1]
                            #'mounted_express':'ex.vueAssign(scope.row,ex.copy(scope.vc.par_row))',
                        })
                        head[
                            'action'] = ''' scope.head.fields_ctx.genVc=scope.vc;
                        scope.head.fields_ctx.title=scope.row._label;
                        scope.head.fields_ctx.par_row=scope.row;
                        scope.head.fields_ctx.row = ex.copy(scope.row); // [1] 如果不是编辑par_row ,可以修改这行
                        cfg.pop_vue_com("com-form-one",scope.head.fields_ctx,{maxmin: true})'''

        return heads
예제 #2
0
 def handle(self, *args, **options):
     permit_options = director.get('permit.options')()
     depend_chain={}
     # 生成依赖dict
     for opt in permit_options:
         for dc in self.parse_item(opt):
             if dc['key'] in depend_chain:
                 raise UserWarning('%s 重复了,请检查 permit 设置'%dc['key'])
             depend_chain[dc['key']] = dc['depend']
             
     # 根据依赖dict 去修正 PermitModel的每行数据
     for pg in PermitModel.objects.all():
         ls = pg.names.split(';')
         ls = [x for x in ls if x in depend_chain]
         out_ls=[]
         last_out_len = 0
         while True:
             for pname in ls:
                 if pname in depend_chain:
                     out_ls.append(pname)
                     out_ls += depend_chain[pname]
             out_ls = list( set(out_ls) )
             ls = list( out_ls)
             if len(out_ls) == last_out_len:
                 break
             else:
                 last_out_len = len(out_ls)
         pg.names = ';'.join(out_ls)
         pg.save()
     print('更新权限依赖关系完成。')
예제 #3
0
def del_rows(rows):
    for row in rows:
        fields_cls = director.get(row.get('_director_name'))
        fields_obj = fields_cls(row)
        fields_obj.del_form()
    rows_only_pk = [{'pk': x['pk']} for x in rows]
    return rows_only_pk
예제 #4
0
파일: ajax.py 프로젝트: coblan/helpers
def del_rows(rows, user):
    for row in rows:
        fields_cls = director.get(row.get('_director_name'))
        #model = name_to_model(row.get('_class'))
        #fields_cls = model_dc.get(model).get('fields')
        fields_obj = fields_cls(row, crt_user=user)
        fields_obj.del_form()
    rows_only_pk = [{'pk': x['pk']} for x in rows]
    return rows_only_pk
예제 #5
0
def search_delete_related(rows):
    out_ls = []
    for row in rows:
        fields_cls = director.get(row['_director_name'])
        fields_obj = fields_cls(dc=row)
        inst = fields_obj.instance
        ls = delete_related_query(inst)
        if ls:
            out_ls.append({'str': str(inst), 'related': ls})
    return out_ls
예제 #6
0
파일: ajax.py 프로젝트: coblan/helpers
def get_excel(director_name, search_args, user):
    table_cls = director.get(director_name)
    table_obj = table_cls.gen_from_search_args(search_args, user)
    wb = table_obj.get_excel()
    fl_name = director_name.replace('.', '_')
    now = datetime.now().strftime('%Y_%m_%d_%H_%M_%S')
    fl_name = '%s_%s.xlsx' % (fl_name, now)

    wb.save(filename=os.path.join(settings.MEDIA_ROOT, 'gen_files', fl_name))
    return {
        'file_url': '/media/gen_files/%s' % fl_name,
    }
예제 #7
0
def permit_save_model(user, row, **kw):
    for k in row:  # convert model instance to pk for normal validation
        if isinstance(row[k], models.Model):
            row[k] = row[k].pk

    fields_cls = director.get(row['_director_name'])
    if not fields_cls:
        raise ObjectDoesNotExist('director:%s not exist' %
                                 row['_director_name'])
    fields_obj = fields_cls(dc=row, crt_user=user, **kw)
    if fields_obj.is_valid():
        #with transaction.atomic():  # 现在 transaction 由外部请求参数控制,因为有可能有不可逆转的情况,
        #                              例如在save_form里面调用了三方api,在本地保存了api返回情况。这是即便是本地报错,也不能回退。
        fields_obj.save_form()
        return fields_obj
    else:
        raise ValidationError(fields_obj.get_errors())
예제 #8
0
파일: table.py 프로젝트: coblan/helpers
    def getExtraHead(self):

        if self.button_edit:
            model_form = director.get(self.get_edit_director_name())
            if model_form:
                form_obj = model_form(crt_user=self.crt_user)
                fields_ctx = form_obj.get_head_context()
                return [{
                    'name': '_op',
                    'label': '操作',
                    'editor': 'com-table-button-click',
                    'button_label': '编辑',
                    'fields_ctx': fields_ctx,
                    'click_express': pop_edit_current_row(),
                }]

        return []
예제 #9
0
파일: ajax.py 프로젝트: coblan/helpers
def director_call(director_name, kws={}):
    #directorEnt= director_views.get(director_name)
    #if not directorEnt:
    #directorEnt = director.get(director_name)
    #rt= directorEnt(**kws)
    #if isinstance(rt,ModelFields):
    #return rt.get_row()
    #else:
    #return rt
    directorEnt = director_views.get(director_name)
    if not directorEnt:
        directorEnt = director.get(director_name)
    if inspect.isfunction(directorEnt):
        rt = directorEnt(**kws)
    else:
        # directorEnt is class
        obj = directorEnt(**kws)
        if hasattr(obj, 'get_data_context'):
            rt = obj.get_data_context()
        else:
            rt = obj.get_context()
    return rt
예제 #10
0
파일: ajax.py 프로젝트: coblan/helpers
def get_rows(director_name, search_args, user):
    table_cls = director.get(director_name)
    #model = name_to_model(model_name)
    #table_cls = model_dc[model].get('table')
    table_obj = table_cls.gen_from_search_args(search_args, user)
    return table_obj.get_data_context()
예제 #11
0
파일: ajax.py 프로젝트: coblan/helpers
def get_row(director_name, pk=None, user=None, **kws):
    fields_cls = director.get(director_name)
    fields_obj = fields_cls(pk=pk, crt_user=user, **kws)
    return fields_obj.get_row()
예제 #12
0
def get_rows(director_name, search_args={}, user=None):
    table_cls = director.get(director_name)
    table_obj = table_cls.gen_from_search_args(search_args, user)
    return table_obj.get_data_context()
예제 #13
0
def del_rows(row):
    fields_cls = director.get(row.get('_director_name'))
    fields_obj = fields_cls(row)
    fields_obj.del_form()
예제 #14
0
def director_element_call(director_name, attr_name, kws):
    dcls = director.get(director_name)
    obj = dcls()
    return getattr(obj, attr_name)(**kws)
예제 #15
0
def get_context(director_name):
    dcls = director.get(director_name)
    return dcls().get_context()
예제 #16
0
파일: table.py 프로젝트: coblan/helpers
    def get_operations(self):
        director_name = self.get_director_name()
        #model_form = model_dc[self.model].get('fields')

        refresh_action = {
            'name': 'refresh',
            'editor': 'com-btn',
            'label': _('刷新'),
            'class': 'com-btn-refresh-btn',
            'icon': 'el-icon-refresh',
            'css': '.com-btn-refresh-btn{float:right}',
            'type': 'success',
            'plain': True,
            'visible': self.filters == RowFilter
            and self.search in [RowSearch],
            'action': 'scope.ps.search()'
        }

        fieldCls = director.get(director_name + '.edit')
        if not fieldCls:
            return [refresh_action]
        fieldobj = fieldCls(crt_user=self.crt_user)
        fields_ctx = fieldobj.get_head_context()
        fields_ctx.update({'ops_loc': 'bottom'})
        return [
            {
                'name': 'add_new',
                #'editor':'com-op-btn',
                #'icon': 'fa-plus',
                #'class':'btn btn-primary btn-sm',
                'editor': 'com-btn',
                'click_express':
                'scope.head.fields_ctx.genVc=scope.vc;scope.ps.add_new(scope.head)',
                'icon': 'el-icon-plus',
                'type': 'primary',
                'label': _('创建'),
                'pre_set': '',  # 预先设置的字段,一般用于com-tab-table下的创建
                'fields_ctx': fields_ctx,
                'visible': self.permit.can_add(),
            },
            #{'name':'save_changed_rows','editor':'com-op-btn','label':'保存',
            #'class':'btn btn-info btn-sm',
            #'show': 'scope.changed','hide':'!changed','icon':'fa-save', 'visible': self.permit.can_edit()},
            #{'name':'delete_selected',
            #'editor':'com-op-btn',
            #'label':'删除',
            #'style': 'color:red',
            #'icon': 'fa-times',
            #'disabled':'!scope.ps.has_select',
            #'visible': self.permit.can_del(),},
            {
                'name': 'delete_selected',
                'editor': 'com-btn',
                'label': _('删除'),
                'click_express':
                '''cfg.show_load();ex.director_call("d.delete_query_related",{rows:scope.ps.selected}).then((resp)=>{
                     cfg.hide_load();
                     if(resp.length>0){
                         cfg.pop_vue_com("com-pan-delete-query-message",{msg_list:resp,genStore:scope.ps,title:"删除关联确认"})
                     }else{
                        scope.ps.delete_selected()
                     }
                    
                 });  ''',
                # if(scope.ps.check_selected(scope.head)){scope.ps.delete_selected()}
                #'style': 'color:red',
                #'icon': 'fa-times',
                'type': 'danger',
                #'plain':True,
                'icon': 'el-icon-delete',
                'row_match': 'many_row',
                'disabled': '!scope.ps.has_select',
                'visible': self.permit.can_del() and self.allow_delete,
            },
            refresh_action,
        ]