Ejemplo n.º 1
0
class DevLog(models.Model):
    '''
    设备通讯日志表模型
    '''
    SN = DeviceForeignKey(verbose_name=_(u'设备'))
    OP = models.CharField(
        _(u'数据'),
        max_length=40,
        default="TRANSACT",
    )
    Object = models.CharField(_(u'对象'), max_length=80, null=True, blank=True)
    Cnt = models.IntegerField(_(u'数据记录数'), default=1, blank=True)
    ECnt = models.IntegerField(_(u'错误'), default=0, blank=True)
    OpTime = models.DateTimeField(_(u'上传时间'), default=datetime.datetime.now())

    def Device(self):
        return get_device(self.SN_id)

    @staticmethod
    def del_old():
        return ("OpTime", 30)

    def save(self, **args):
        if not self.id:
            self.OpTime = datetime.datetime.now()
        models.Model.save(self, **args)

    class dataexport(Operation):
        help_text = _(u"数据导出")  #导出
        verbose_name = _(u"导出")
        visible = False

        def action(self):
            pass

    def __unicode__(self):
        try:
            return u"%s, %s, %s" % (
                self.SN, self.OpTime.strftime('%y-%m-%d %H:%M'), self.OP)
        except:
            return u"%s, %s, %s" % (
                self.SN_id, self.OpTime.strftime('%y-%m-%d %H:%M'), self.OP)

    class Admin:
        visible = "mysite.att" in settings.INSTALLED_APPS  #暂只有考勤使用
        list_display = ('SN.alias', 'SN.sn', 'OpTime', 'OP', 'Cnt')
        query_fields = ('SN.alias', 'SN.sn', 'OP', 'Cnt')
        list_filter = ("SN", 'OpTime')
        search_fields = ["OP", "Object"]
        disabled_perms = ["change_devlog", "delete_devlog", "add_devlog"]
        hide_perms = [
            "dataexport_devlog",
        ]

    class Meta:
        app_label = 'iclock'
        verbose_name = _(u"设备通讯日志")
        verbose_name_plural = verbose_name
        db_table = 'devlog'
Ejemplo n.º 2
0
class DevLog(models.Model):
    SN = DeviceForeignKey(verbose_name=_(u'设备'))
    OP = models.CharField(_(u'数据'),max_length=40, default="TRANSACT",)
    Object = models.CharField(_(u'对象'),max_length=80, null=True, blank=True)
    Cnt = models.IntegerField(_(u'数据记录数'),default=1, blank=True)
    ECnt = models.IntegerField(_(u'错误'),default=0, blank=True)
    OpTime = models.DateTimeField(_(u'上传时间'),default=datetime.datetime.now())
    def Device(self):
        return get_device(self.SN_id)
    @staticmethod    
    def del_old(): return ("OpTime", 30)
    def save(self, **args):
        if not self.id:
            self.OpTime=datetime.datetime.now()
        models.Model.save(self, **args)
    class dataexport(Operation):
        help_text=_(u"数据导出") #导出
        verbose_name=_(u"导出")
        visible=False
        def action(self):
                pass
    
    def __unicode__(self): 
        from mysite.iclock.models.model_device import get_device
        sn_info = get_device(self.SN_id)
        
        try:
            return u"%s, %s, %s"%(sn_info, self.OpTime.strftime('%y-%m-%d %H:%M'), self.OP)
        except:
            return u"%s, %s, %s"%(self.SN_id, self.OpTime.strftime('%y-%m-%d %H:%M'), self.OP)
    def get_device_sn(self):
        from mysite.iclock.models.model_device import get_device_attr
        return get_device_attr(self.SN_id,"sn")
    
    def get_device_alias(self):
        from mysite.iclock.models.model_device import get_device_attr
        return get_device_attr(self.SN_id,"alias")
    
    class Admin:
        sort_fields = ["SN.sn","OpTime"]
        visible = get_option("DEVLOG_VISIBLE")#暂只有考勤使用
        list_display=('SN.alias','SN.sn','OpTime','OP','Cnt')
        newadded_column={
            "SN.alias":"get_device_alias",
            "SN.sn":"get_device_sn",
        }
        query_fields=('SN.sn','OP','SN.device_type')
        list_filter=("SN",'OpTime')
        search_fields = ["OP","Object"]
        disabled_perms=["change_devlog","delete_devlog","add_devlog"]
        hide_perms=["dataexport_devlog",]
    class Meta:
        app_label='iclock'
        verbose_name = _(u"设备操作日志")
        verbose_name_plural=verbose_name
        db_table = 'devlog'
Ejemplo n.º 3
0
class OpLog(models.Model):
    '''
    操作设备日志模型
    '''
    SN = DeviceForeignKey(db_column='SN',
                          verbose_name=_(u'设备'),
                          null=True,
                          blank=True)
    admin = models.IntegerField(_(u'设备超级管理员'),
                                null=False,
                                blank=False,
                                default=0)
    OP = models.SmallIntegerField(_(u'操作'), null=False, blank=False, default=0)
    OPTime = models.DateTimeField(_(u'时间'))
    Object = models.IntegerField(_(u'对象'), null=True, blank=True)
    Param1 = models.IntegerField(_(u'参数1'), null=True, blank=True)
    Param2 = models.IntegerField(_(u'参数2'), null=True, blank=True)
    Param3 = models.IntegerField(_(u'参数3'), null=True, blank=True)

    def Device(self):
        return get_device(self.SN_id)

    @staticmethod
    def delOld():
        return ("OPTime", 200)

    def OpName(self):
        return OpName(self.OP)

    def ObjName(self):
        if self.OP == 3:
            return AlarmName(self.Object)
        return self.Object or ""

    def __unicode__(self):
        return u"%s,%s,%s" % (self.Device(), self.OP,
                              self.OPTime.strftime("%y-%m-%d %H:%M:%S"))

    class Meta:
        app_label = 'iclock'
        verbose_name = _(u"操作设备日志")
        verbose_name_plural = verbose_name
        unique_together = (("SN", "OPTime"), )
        permissions = (('monitor_oplog', 'Transaction Monitor'), )

    class Admin:
        visible = True
        list_display = (
            'SN',
            'admin',
            'OP',
            'OPTime',
            'Object',
        )
        list_filter = ('SN', 'admin', 'OP', 'OPTime')
Ejemplo n.º 4
0
class DevCmd(CachingModel):
    '''
    服务器下发命令:服务器请求设备的命令
    '''
    SN = DeviceForeignKey(verbose_name=_(u'设备'), null=True)
    CmdOperate = models.ForeignKey(OperateCmd,
                                   verbose_name=_(u'操作任务'),
                                   null=True)
    CmdContent = models.TextField(_(u'命令内容'), max_length=2048)  #----命令字符串的内容
    CmdCommitTime = models.DateTimeField(_(u'提交时间'),
                                         default=datetime.datetime.now())
    CmdTransTime = models.DateTimeField(_(u'传送时间'), null=True, blank=True)
    CmdOverTime = models.DateTimeField(_(u'返回时间'), null=True, blank=True)
    CmdReturn = models.IntegerField(_(u'返回值'),
                                    null=True,
                                    blank=True,
                                    choices=CMDRETURN)
    CmdReturnContent = models.TextField(_(u'返回内容'), null=True, blank=True)
    CmdImmediately = models.BooleanField(_(u'是否是立即备份'), default=False)

    def device(self):
        return get_device(self.SN_id)

    class _delete(Operation):
        help_text = _(u"删除选定记录")  #删除选定的记录
        verbose_name = _(u"删除")

        def action(self):
            self.object.delete()

    def __unicode__(self):
        from base.templatetags.base_tags import fmt_shortdatetime
        try:
            return u"%s, %s" % (self.SN, fmt_shortdatetime(self.CmdCommitTime))
        except:
            return u"%s, %s" % (self.SN_id,
                                fmt_shortdatetime(self.CmdCommitTime))

    def save(self, **kargs):
        if not self.CmdCommitTime: self.CmdCommitTime = datetime.datetime.now()
        ret = models.Model.save(self, kargs)
        if self.SN and not self.CmdTransTime:
            trigger_cmd_device(self)
        return ret

    def file_url(self):
        if self.CmdContent.find("GetFile ") == 0:
            fname = self.CmdContent[8:]
        elif self.CmdContent.find("Shell ") == 0:
            fname = "shellout.txt"
        else:
            return ""
        return getUploadFileURL(self.SN.SN, self.id, fname)

    class dataexport(Operation):
        help_text = _(u"数据导出")  #导出
        verbose_name = u"导出"
        visible = False

        def action(self):
            pass

    class OpClearDevCmd(ModelOperation):
        verbose_name = _(u'''清空命令表''')
        help_text = _(u"清空服务器下发命令表。")
        tips_text = _(u"确认要清空命令表")

        def action(self):
            self.model.objects.all().delete()

    class Admin(CachingModel.Admin):
        #visible = False
        list_display = ('SN.alias', 'SN.sn', 'CmdCommitTime|fmt_shortdatetime',
                        'CmdTransTime|fmt_shortdatetime',
                        'CmdOverTime|fmt_shortdatetime', 'CmdContent',
                        'CmdReturn')
        adv_fields = ('SN.sn', 'SN.alias', 'CmdCommitTime', 'CmdTransTime',
                      'CmdOverTime', 'CmdContent', 'CmdReturn')
        search_fields = ["CmdContent"]
        list_filter = ['SN', 'CmdCommitTime', 'CmdOverTime']
        query_fields = ['SN.alias', 'SN.sn', 'CmdReturn']
        disabled_perms = ["change_devcmd", "add_devcmd", "dataexport_devcmd"
                          ]  #"dataexport_devcmd"]"delete_devcmd"

    class Meta:
        app_label = 'iclock'
        db_table = 'devcmds'
        verbose_name = _(u"服务器下发命令")
        verbose_name_plural = verbose_name
Ejemplo n.º 5
0
class Template(models.Model):
    '''
    人员指纹表模型
    '''
    id = models.AutoField(db_column='templateid', primary_key=True)
    UserID = EmpForeignKey(db_column='userid', verbose_name=u"员工")
    Template = models.TextField(_(u'指纹模板'))
    FingerID = models.SmallIntegerField(_(u'手指'), default=0, choices=FINGERIDS)
    Valid = models.SmallIntegerField(_(u'指纹类别'), default=1, choices=BOOLEANS)

    Fpversion = models.CharField(verbose_name=_(u'指纹版本'),
                                 max_length=10,
                                 null=False,
                                 blank=False,
                                 editable=False,
                                 default='9',
                                 choices=FPVERSION)

    bio_type = models.SmallIntegerField(choices=((0, _(u"指纹")), (1, _(u'人脸'))),
                                        default=0)
    SN = DeviceForeignKey(db_column='SN',
                          verbose_name=_(u'登记设备'),
                          null=True,
                          blank=True)
    UTime = models.DateTimeField(_(u'更新时间'),
                                 null=True,
                                 blank=True,
                                 editable=False)
    BITMAPPICTURE = models.TextField(null=True, editable=False)
    BITMAPPICTURE2 = models.TextField(null=True, editable=False)
    BITMAPPICTURE3 = models.TextField(null=True, editable=False)
    BITMAPPICTURE4 = models.TextField(null=True, editable=False)
    USETYPE = models.SmallIntegerField(null=True, editable=False)
    Template2 = models.TextField(_(u'指纹模板'), null=True, editable=False)
    Template3 = models.TextField(_(u'指纹模板'), null=True, editable=False)

    def __unicode__(self):
        return u"%s, %d" % (self.UserID.__unicode__(), self.FingerID)

    def template(self):
        return self.Template.decode("base64")

    def temp(self):
        #去掉BASE64编码的指纹模板中的回车
        return self.Template.replace("\n", "").replace("\r", "")

    class Admin:
        list_display = ('UserID', 'FingerID', 'Valid', 'DelTag')
        list_filter = (
            'UserID',
            'SN',
            'UTime',
        )
#        visible=False

    class Meta:
        app_label = 'iclock'
        db_table = 'template'
        unique_together = (("UserID", "FingerID", "Fpversion"), )
        verbose_name = _(u"人员指纹")
        verbose_name_plural = verbose_name
Ejemplo n.º 6
0
class DevCmd(CachingModel):
    SN = DeviceForeignKey(verbose_name=_(u'设备'), null=True)
    CmdOperate = models.ForeignKey(OperateCmd,
                                   verbose_name=_(u'操作任务'),
                                   null=True)
    CmdContent = models.TextField(_(u'命令内容'), max_length=2048)
    CmdCommitTime = models.DateTimeField(_(u'提交时间'),
                                         default=datetime.datetime.now())
    CmdTransTime = models.DateTimeField(_(u'传送时间'), null=True, blank=True)
    CmdOverTime = models.DateTimeField(_(u'返回时间'), null=True, blank=True)
    CmdReturn = models.IntegerField(_(u'返回值'), null=True, blank=True)
    CmdReturnContent = models.TextField(_(u'返回内容'), null=True, blank=True)
    CmdImmediately = models.BooleanField(_(u'是否是立即备份'), default=False)

    def device(self):
        return get_device(self.SN_id)

    class _delete(Operation):
        help_text = _(u"删除选定记录")  #删除选定的记录
        verbose_name = _(u"删除")

        def action(self):
            self.object.delete()

    def __unicode__(self):
        from base.templatetags.base_tags import fmt_shortdatetime
        from mysite.iclock.models.model_device import get_device
        try:
            return u"%s, %s" % (get_device(self.SN_id), self.CmdCommitTime)
        except:
            return u"%s, %s" % (self.SN_id, self.CmdCommitTime)

#        try:
#            return u"%s, %s" % (self.SN, fmt_shortdatetime(self.CmdCommitTime))
#        except:
#            return u"%s, %s" % (self.SN_id, fmt_shortdatetime(self.CmdCommitTime))

    def save(self, **kargs):
        is_new = False
        if not self.pk:
            is_new = True
        if not self.CmdCommitTime:
            self.CmdCommitTime = datetime.datetime.now()

        ret = models.Model.save(self, kargs)

        if is_new and self.SN and self.SN.device_type in [
                DEVICE_TIME_RECORDER, DEVICE_POS_SERVER
        ]:  #新增
            #更新缓存中该设备的最后一条命令
            set_last_save_cmd_pk(self.SN_id, self.pk)

        #加入判断  仅门禁
        if self.SN and self.SN.device_type == DEVICE_ACCESS_CONTROL_PANEL and not self.CmdTransTime:
            trigger_cmd_device(self)
        return ret

    def file_url(self):
        if self.CmdContent.find("GetFile ") == 0:
            fname = self.CmdContent[8:]
        elif self.CmdContent.find("Shell ") == 0:
            fname = "shellout.txt"
        else:
            return ""
        return getUploadFileURL(self.SN.SN, self.id, fname)

    class dataexport(Operation):
        help_text = _(u"数据导出")  #导出
        verbose_name = u"导出"
        visible = False

        def action(self):
            pass

    class OpClearDevCmd(ModelOperation):
        verbose_name = _(u'''清空命令表''')
        help_text = _(u"清空服务器下发命令表。")
        tips_text = _(u"确认要清空命令表")

        def action(self):
            self.model.objects.all().delete()

    #修正命令长度过长导致浏览器崩溃的bug,只保留前200个字符
    def get_cmdcontent(self):
        content = self.CmdContent[0:200]
        if len(content) == 200:
            return content + '...'
        return content

    def get_device_sn(self):
        from mysite.iclock.models.model_device import get_device_attr
        return get_device_attr(self.SN_id, "sn")

    def get_device_alias(self):
        from mysite.iclock.models.model_device import get_device_attr
        return get_device_attr(self.SN_id, "alias")

    class Admin(CachingModel.Admin):
        visible = get_option("ATT") or get_option("IACCESS") or get_option(
            "POS_IC")
        #sort_fields = ["SN.sn","CmdCommitTime","CmdTransTime","CmdOverTime"]
        #list_display=('SN.alias','SN.sn','CmdCommitTime|fmt_shortdatetime','CmdTransTime|fmt_shortdatetime','CmdOverTime|fmt_shortdatetime','get_cmdcontent','CmdReturn')
        list_display = ('SN.alias', 'SN.sn', 'CmdCommitTime', 'CmdTransTime',
                        'CmdOverTime', 'get_cmdcontent', 'CmdReturn')
        newadded_column = {
            "SN.alias": "get_device_alias",
            "SN.sn": "get_device_sn",
        }
        adv_fields = ('SN.sn', 'SN.alias', 'CmdCommitTime', 'CmdTransTime',
                      'CmdOverTime', 'CmdContent', 'CmdReturn')
        search_fields = ["CmdContent"]
        list_filter = ['SN', 'CmdCommitTime', 'CmdOverTime']
        query_fields = [
            'SN.sn',
            'CmdReturn',
            'SN.device_type',
        ]
        disabled_perms = ["change_devcmd", "add_devcmd", "dataexport_devcmd"
                          ]  #"dataexport_devcmd"]"delete_devcmd"

    class Meta:
        app_label = 'iclock'
        db_table = 'devcmds'
        verbose_name = _(u"服务器下发命令")
        verbose_name_plural = verbose_name
Ejemplo n.º 7
0
class Transaction(models.Model):
        UserID = EmpPoPForeignKey(db_column='userid', verbose_name=_(u"人员"))
        TTime = models.DateTimeField(_(u'考勤时间'), db_column='checktime')
        State = models.CharField(_(u'考勤状态'), db_column='checktype', max_length=5, default='I', choices=ATTSTATES)
        Verify = models.IntegerField(_(u'验证方式'), db_column='verifycode', default=0, choices=VERIFYS)    #---签卡类型
        SN = DeviceForeignKey(db_column='SN', verbose_name=_(u'设备'), null=True, blank=True)
        sensorid = models.CharField(db_column='sensorid', verbose_name=u'Sensor ID', null=True, blank=True, max_length=5, editable=False)
        WorkCode = models.CharField(_(u'工作代码'), max_length=20, null=True, blank=True)
        Reserved = models.CharField(_(u'保留'), max_length=20, null=True, blank=True)
        sn_name = models.CharField(_(u'序列号'), max_length=40, null=True, blank=True)
        def limit_transaction_to(self,query_set,user): 
            from mysite.iclock.iutils import userDeptList,userAreaList
            deptids = userDeptList(user)
            if not deptids:
                return query_set
            deptids = [ int(dept.pk) for dept in deptids ]
            return query_set.filter(UserID__DeptID__in=deptids)
        def employee(self): #cached employee
                try:
                        return Employee.objByID(self.UserID_id)
                except:
                        return None
        def Time(self):
                if self.TTime.microsecond>500000:
                        self.TTime=self.TTime+datetime.timedelta(0,0,1000000-self.TTime.microsecond)
                return self.TTime
        def StrTime(self):
                return self.Time().strftime('%Y/%m%d/%H%M%S')
        @staticmethod        
        def delOld(): return ("TTime", 365)
        def Device(self):
                return get_device(self.sn_name)
        def get_img_url(self, default=None):
                device=self.Device()
                emp=self.employee()
                if device and emp:
                        try:
                                pin=int(emp.PIN)
                        except:
                                pin=emp.PIN
                        fname="%s.jpg"%(self.StrTime())
                        imgUrl=getUploadFileName(device.SN, pin, fname)
                        if os.path.exists(imgUrl):
                                return getUploadFileURL(device.SN, pin, fname)
                return default
        def get_thumbnail_url(self, default=None):
                device=self.Device()
                emp=self.employee()
                if device and emp:
                        try:
                                pin=int(emp.PIN)
                        except:
                                pin=emp.PIN
                        fname="%s.jpg"%(self.StrTime())
                        imgUrl=getUploadFileName("thumbnail/"+device.SN, pin, fname)
                        #print imgUrl
                        if not os.path.exists(imgUrl):
                                imgUrlOrg=getUploadFileName(device.SN, pin, fname)
                                if not os.path.exists(imgUrlOrg):
                                        #print imgUrlOrg, "is not exists"
                                        return default
                                if not createThumbnail(imgUrlOrg, imgUrl):
                                        #print imgUrl, "create fail."
                                        return default
                        return getUploadFileURL("thumbnail/"+device.SN, pin, fname)
                #print "device, emp", device, emp
                return default
        def __unicode__(self):
                return self.UserID.__unicode__()+', '+self.TTime.strftime("%y-%m-%d %H:%M:%S")
                
        @staticmethod
        def myData(user):
                if user.username=='employee': #employee user
                        return Transaction.objects.filter(UserID=request.employee)
                return Transaction.objects.filter(UserID__DeptID__in=userDeptList(user))
        
        def get_attpic(self):            
            from dbapp.file_handler import get_model_filename
            dt=self.TTime.strftime("%Y%m%d%H%M%S")
            pin=""
            pin= int(self.UserID.PIN)
            sn=self.sn_name

            t=get_model_filename(Transaction,            
            "%s/%s/%s" % (sn, dt[:4], dt[4:8])+"/"+ str(pin)+"_"+ dt[8:] + ".jpg",
            "picture")[1]
            return t
        
        def get_emppic(self):
            return self.UserID.photo            
        
        class dataexport(Operation):
                help_text=_(u"数据导出") #导出
                verbose_name=_(u"导出")
                visible=False
                def action(self):
                        pass
        
        class Meta:
                app_label='iclock'
                verbose_name = _(u"原始记录表")
                verbose_name_plural = verbose_name
                db_table = 'checkinout'
                unique_together = (("UserID", "TTime"),)
                permissions = (
                                ('clearObsoleteData_transaction','Clear Obsolete Data'),
                                )
        class Admin:
                default_give_perms=["contenttypes.can_AttCalculate"]
                sort_fields=["UserID.PIN","TTime"]
                app_menu="att"
                menu_group = 'att'
                visible = "mysite.att" in settings.INSTALLED_APPS#暂只有考勤使用
                read_only=True
                api_fields=('UserID.PIN','UserID.EName','TTime','State','sn_name')
                list_display=('UserID_id','UserID.PIN','UserID.EName','TTime','State','sn_name','get_attpic','get_emppic')
                photo_path_tran="get_attpic"
                photo_path="get_emppic"
                hide_fields=('UserID_id','get_attpic')
                list_filter = ('UserID','TTime','State','Verify','SN')
                query_fields=['UserID__PIN','UserID__EName','sn_name']
                search_fields=('TTime',)
                menu_index=4
                disabled_perms=["add_transaction",'change_transaction','delete_transaction','clearObsoleteData_transaction']
                layout_types=["table","photo"]
Ejemplo n.º 8
0
class DevCmdBak(CachingModel):
    SN = DeviceForeignKey(verbose_name=_(u'设备'), null=True)
    CmdOperate = models.ForeignKey(OperateCmd, verbose_name = _(u'操作任务'), null=True)
    CmdContent = models.TextField(_(u'命令内容'),max_length=2048)
    CmdCommitTime = models.DateTimeField(_(u'提交时间'),default=datetime.datetime.now())
    CmdTransTime = models.DateTimeField(_(u'传送时间'),null=True, blank=True)
    CmdOverTime = models.DateTimeField(_(u'返回时间'),null=True, blank=True)
    CmdReturn = models.IntegerField(_(u'返回值'), null=True, blank=True,choices=CMDRETURN)
    CmdReturnContent = models.TextField(_(u'返回内容'), null=True, blank=True)
    CmdImmediately=models.BooleanField(_(u'是否是立即备份'), default=False)
    
    def device(self):
        return get_device(self.SN_id)
    
    class _delete(Operation):
        help_text=_(u"删除选定记录") #删除选定的记录
        verbose_name=_(u"删除")
        def action(self):
                self.object.delete()
    
    def __unicode__(self): 
        from base.templatetags.base_tags import fmt_shortdatetime
        from mysite.iclock.models.model_device import get_device
        try:
            return u"%s, %s" % (get_device(self.SN_id), self.CmdCommitTime)
        except:
            return u"%s, %s" % (self.SN_id, self.CmdCommitTime)
    
    def save(self, **kargs):
        if not self.CmdCommitTime: 
            self.CmdCommitTime=datetime.datetime.now()
            
        ret = models.Model.save(self, kargs)
    
    def file_url(self):
        if self.CmdContent.find("GetFile ")==0:
            fname=self.CmdContent[8:]
        elif self.CmdContent.find("Shell ")==0:
            fname="shellout.txt"
        else:
            return ""
        return getUploadFileURL(self.SN.SN, self.id, fname)
    class dataexport(Operation):
        help_text=_(u"数据导出") #导出
        verbose_name=u"导出"
        visible=False
        def action(self):
                pass

    class OpClearDevCmd(ModelOperation):
        verbose_name = _(u'''清空失败命令''')
        help_text = _(u"清空服务器失败命令")
        tips_text =  _(u"确认要清空失败命令")
        def action(self):
            self.model.objects.all().delete()

    #修正命令长度过长导致浏览器崩溃的bug,只保留前200个字符
    def get_cmdcontent(self):
        content = self.CmdContent[0:200]
        if len(content) == 200:
            return content+'...'
        return content
    def get_device_sn(self):
        from mysite.iclock.models.model_device import get_device_attr
        return get_device_attr(self.SN_id,"sn")
    
    def get_device_alias(self):
        from mysite.iclock.models.model_device import get_device_attr
        return get_device_attr(self.SN_id,"alias")
    
    class Admin(CachingModel.Admin):
        sort_fields = ["SN.sn","CmdCommitTime","CmdTransTime","CmdOverTime"]
        list_display=('SN.alias','SN.sn','CmdCommitTime','CmdTransTime','CmdOverTime','get_cmdcontent','CmdReturn')
        adv_fields=('SN.sn', 'SN.alias','CmdCommitTime','CmdTransTime','CmdOverTime','CmdContent','CmdReturn')
        newadded_column={
            "SN.alias":"get_device_alias",
            "SN.sn":"get_device_sn",
        }
        search_fields = ["CmdContent"]
        list_filter =['SN', 'CmdCommitTime', 'CmdOverTime']
        query_fields=['SN.alias', 'SN.sn', 'CmdReturn','SN.device_type']
        disabled_perms = ["change_devcmdbak", "add_devcmdbak", "dataexport_devcmdbak"]
        visible = get_option("DECMDBAk_VISIBLE")
   
    class Meta:
        app_label='iclock'
        db_table = 'devcmds_bak'
        verbose_name = _(u"失败命令查询")
        verbose_name_plural=verbose_name