python tornado 实现类似禅道系统

读的道是悲苦之,可是本人深信不疑自己是好成功的,

run 运行文件。

from models.dataconfig import db_session,Base,create_all
from sqlalchemy import  Column,Integer,DateTime,Boolean,String,ForeignKey,desc,asc,Text
from sqlalchemy.orm import  relationship,backref
from untils.common import encrypt
import datetime
class User(Base):
    __tablename__='users'
    id=Column(Integer(),primary_key=True)
    username=Column(String(64),unique=True,index=True)
    email=Column(String(64))
    password=Column(String(64))
    last_logtime=Column(DateTime())
    status=Column(Integer())
    leves=Column(Integer())
    iphone=Column(Integer())
    Projects=relationship('Project',backref='users')
    shebei=relationship('Shebei',backref='users')
    file=relationship('FilePan',backref='users')
    banben=relationship('BanbenWrite',backref='users')
    testresult=relationship('TestResult',backref='users')
    testcase=relationship('TestCase',backref='users')
    buglog=relationship('BugLog',backref='users')
    def __repr__(self):
        return self.username
    @classmethod
    def get_by_id(cls, id):
        item = db_session.query(User).filter(User.id==id).first()
        return item
    @classmethod
    def get_by_username(cls, username):
        item = db_session.query(User).filter(User.username== username).first()
        return item
    @classmethod
    def get_count(cls):
        return db_session.query(Shebei).count()
    @classmethod
    def add_new(cls,username,password,iphone,email,leves):
        new=User(username=username,iphone=iphone,email=email,leves=leves)
        new.password=encrypt(password)
        new.status=0
        db_session.add(new)
        try:
            db_session.commit()
        except:
            db_session.rollback()
class Shebei(Base):
    __tablename__='shebeis'
    id=Column(Integer(),primary_key=True)
    shebei_id=Column(String(32),unique=True)
    shebei_name=Column(String(64))
    shebei_xitong=Column(String(64))
    shebei_xinghao=Column(String(255))
    shebei_jiage=Column(Integer())
    shebei_fapiaobianhao=Column(String(64))
    shebei_quanxian=Column(Boolean())
    shebei_jie=Column(Boolean())
    shebei_shuyu=Column(String())
    shebei_date=Column(DateTime())
    shebei_user=Column(String())
    gou_date=Column(DateTime())
    shebei_status=Column(String(16))
    she_sta=Column(Integer(),default=0)
    ruku_user=Column(Integer(),ForeignKey('users.id'))
    def __repr__(self):
        return self.shebei_name
    @classmethod
    def get_by_name(cls,name):
        item=db_session.query(Shebei).filter(Shebei.shebei_name==name).first()
        return item
    @classmethod
    def get_by_id(cls,id):
        item=db_session.query(Shebei).filter(Shebei.id==id).first()
        return item
    @classmethod
    def get_count(cls):
        return db_session.query(Shebei).count()
class TestResult(Base):
    __tablename__='testresults'
    id=Column(Integer(),primary_key=True)
    porject_id=Column(Integer(),ForeignKey('projects.id'))
    creat_time=Column(DateTime())
    bug_first=Column(Integer())
    ceshirenyuan=Column(String(255))
    is_send=Column(Boolean(),default=True)
    filepath=Column(String(64))
    status=Column(Integer(),default=0)
    user_id=Column(Integer(),ForeignKey('users.id'))
    def __repr__(self):
        return self.porject_name
    @classmethod
    def get_by_name(cls,name):
        item=db_session.query(TestResult).filter(TestResult.porject_name==name).first()
        return item
    @classmethod
    def get_by_id(cls,id):
        item=db_session.query(TestResult).filter(TestResult.id==id).first()
        return item
    @classmethod
    def get_by_user_id(cls,user_id):
        item=db_session.query(TestResult).filter(TestResult.user_id==user_id).first()
        return item
    @classmethod
    def get_count(cls):
        return db_session.query(TestResult).count()
class BanbenWrite(Base):
    __tablename__='banbens'
    id=Column(Integer(),primary_key=True)
    porject_id=Column(Integer(),ForeignKey('projects.id'))
    creat_time=Column(DateTime(),default=datetime.datetime.now())
    banbenhao=Column(String(32))
    is_xian=Column(Boolean(),default=False)
    is_test=Column(Boolean(),default=False)
    status=Column(Integer())
    user_id=Column(Integer(),ForeignKey('users.id'))
    bugadmin=relationship('BugAdmin',backref='banbens')
    def __repr__(self):
        return self.banbenhao
    @classmethod
    def get_by_name(cls,name):
        item=db_session.query(BanbenWrite).filter(BanbenWrite.porject_name==name).first()
        return item
    @classmethod
    def get_by_id(cls,id):
        item=db_session.query(BanbenWrite).filter(BanbenWrite.id==id).first()
        return item
    @classmethod
    def get_by_user_id(cls,user_id):
        item=db_session.query(BanbenWrite).filter(BanbenWrite.user_id==user_id).first()
        return item
    @classmethod
    def get_count(cls):
        return db_session.query(BanbenWrite).count()
class FilePan(Base):
    __tablename__='files'
    id=Column(Integer(),primary_key=True)
    file_fenlei=Column(String(64))
    file_name=Column(String(64))
    down_count=Column(Integer(),default=0)
    creat_time=Column(DateTime(),default=datetime.datetime.now())
    status=Column(Integer(),default=0)
    down_url=Column(String(64))
    is_tui=Column(Boolean(),default=False)
    user_id=Column(Integer(),ForeignKey('users.id'))
    def __repr__(self):
        return self.file_name
    @classmethod
    def get_by_file_name(cls,name):
        item=db_session.query(FilePan).filter(FilePan.file_name==name).first()
        return item
    @classmethod
    def get_by_id(cls,id):
        item=db_session.query(FilePan).filter(FilePan.id==id).first()
        return item
    @classmethod
    def get_by_user_id(cls,user_id):
        item=db_session.query(FilePan).filter(FilePan.user_id==user_id).first()
        return item
    @classmethod
    def get_count(cls):
        return db_session.query(FilePan).count()
class BugAdmin(Base):
    __tablename__='bugadmins'
    id=Column(Integer(),primary_key=True)
    porject_id=Column(Integer(),ForeignKey('projects.id'))
    bugname=Column(String(64))
    bugdengji=Column(String(64))
    bugtime=Column(DateTime(),default=datetime.datetime.now())
    bug_miaoshu=Column(String(255))
    ban_id=Column(Integer(),ForeignKey('banbens.id'))
    fujian=Column(String(64))
    is_que=Column(Boolean())
    bug_status=Column(String(64))
    bug_jiejuefangan=Column(String(64))
    bug_send=Column(String(64))
    status=Column(Integer(),default=0)
    bug_log=relationship('BugLog',backref='bugadmins')
    user_id=Column(Integer(),ForeignKey('users.id'))
    def __repr__(self):
        return self.bugname
    @classmethod
    def get_by_bugname(cls,bugname):
        item=db_session.query(BugAdmin).filter(BugAdmin.bugname==bugname).first()
        return item
    @classmethod
    def get_by_id(cls,id):
        item=db_session.query(BugAdmin).filter(BugAdmin.id==id).first()
        return item
    @classmethod
    def get_by_porject_name(cls,porject_name):
        item=db_session.query(BugAdmin).filter(BugAdmin.porject_name==porject_name).first()
        return item
    @classmethod
    def get_count(cls):
        return db_session.query(BugAdmin).count()
class TestCase(Base):
    __tablename__='testcases'
    id=Column(Integer(),primary_key=True)
    porject_id=Column(Integer(),ForeignKey('projects.id'))
    casename=Column(String(64))
    case_qianzhi=Column(String())
    case_buzhou=Column(String())
    case_yuqi=Column(String())
    status=Column(Integer(),default=0)
    case_crea_time=Column(DateTime(),default=datetime.datetime.now())
    user_id=Column(Integer(),ForeignKey('users.id'))
    def __repr__(self):
        return self.casename
    @classmethod
    def get_by_project_name(Cls,project_name):
        item=db_session.query(TestCase).filter(TestCase.project_name==project_name).first()
        return item
    @classmethod
    def get_by_casename(Cls,casename):
        item=db_session.query(TestCase).filter(TestCase.casename==casename).first()
        return item
    @classmethod
    def get_by_id(cls,id):
        item=db_session.query(TestCase).filter(TestCase.id==id).first()
        return item
    @classmethod
    def get_count(cls):
        return db_session.query(TestCase).count()
class BugLog(Base):
    __tablename__='buglogs'
    id=Column(Integer(),primary_key=True)
    bug_id=Column(Integer(),ForeignKey('bugadmins.id'))
    caozuo=Column(String())
    caozuo_time=Column(DateTime())
    user_id=Column(Integer(),ForeignKey('users.id'))
    def __repr__(self):
        return self.caozuo
    @classmethod
    def get_by_id(Cls,id):
        item=db_session.query(BugLog).filter(BugLog.id==id).first()
        return item
    @classmethod
    def get_by_user_id(Cls,user_id):
        item=db_session.query(BugLog).filter(BugLog.user_id==user_id).first()
        return item
    @classmethod
    def get_by_bug_id(Cls,bug_id):
        item=db_session.query(BugLog).filter(BugLog.bug_id==bug_id).first()
        return item
class Project(Base):
    __tablename__='projects'
    id=Column(Integer(),primary_key=True)
    name=Column(String(64))
    user_id=Column(Integer(),ForeignKey('users.id'))
    bug_log=relationship('BugAdmin',backref='projects')
    banben=relationship('BanbenWrite',backref='projects')
    testresult=relationship('TestResult',backref='projects')
    testcase=relationship('TestCase',backref='projects')
    def __repr__(self):
        return self.name
    @classmethod
    def get_by_id(cls,id):
        item=db_session.query(Project).filter(Project.id==id).first()
        return item 
    @classmethod
    def get_by_name(cls,name):
        item=db_session.query(Project).filter(Project.name==name).first()
        return item

sqlite 1

实在当开发的经过中,也赶上了广大绊脚石,比如下载一直兑现不佳,比如分页,也是参考别人的兑现之,

handlsers 存放类似flask的views

大题是这么的概貌,那么将到这么些的时候,我会举行要求分析,

进过两完美之开销,已经形成了成熟的,

源码已经开源道github

import xlrd,xlwt
from xlutils.copy import copy
def datacel(filepath):
    file=xlrd.open_workbook(filepath)
    me=file.sheets()[0]
    nrows=me.nrows
    porject_id_list=[]
    casename_list=[]
    case_qianzhi_list=[]
    case_buzhou_list=[]
    case_yuqi_list=[]
    for i in range(1,nrows):
        porject_id_list.append(me.cell(i,0).value)
        casename_list.append(me.cell(i,2).value)
        case_qianzhi_list.append(me.cell(i,3).value)
        case_buzhou_list.append(me.cell(i,4).value)
        case_yuqi_list.append(me.cell(i,1).value)
    return porject_id_list,casename_list,case_qianzhi_list,case_buzhou_list,case_yuqi_list

背景:目前市场上暴发不少bug管理工具,不过各类暴发各类的表征,最红,最盛行的尽管是禅道,一个偶然的空子接触到了python
,学到tornado后,就想着去怎么去用到实处,后来发现自己公司之除禅道就记录bug没有啊好为此之工具了。

models存数据库相关的,

class Pagination:
    def __init__(self, current_page, all_item):
        try:
            page = int(current_page)
        except:
            page = 1
        if page < 1:
            page = 1
        all_pager, c = divmod(all_item, 10)
        if int(c) > 0:
            all_pager += 1
        self.current_page = page
        self.all_pager = all_pager
    @property
    def start(self):
        return (self.current_page - 1) * 10
    @property
    def end(self):
        return self.current_page * 10
    def string_pager(self, base_url="/index/"):
        if self.current_page == 1:
            prev = '<li><a href="javascript:void(0);">上一页</a></li>'
        else:
            prev = '<li><a href="%s%s">上一页</a></li>' % (base_url, self.current_page - 1,)
        if self.current_page == self.all_pager:
            nex = '<li><a href="javascript:void(0);">下一页</a></li>'
        else:
            nex = '<li><a href="%s%s">下一页</a></li>' % (base_url, self.current_page + 1,)
        last = '<li><a href="%s%s">尾页</a></li>' % (base_url, self.all_pager,)
        str_page = "".join((prev,nex,last))
        return str_page

事实上这么现在公共模块完毕了,其实现在可动手去开勾画咱俩的代码了,重要的代码,还有静态界面,因为前后端都是我好,我的前端其实如故从网上搜索来之模板,

选料用了sqlalchemy,往日用过flask的sqlalchemy感觉是

 

除此以外我提供vip指点,python自动化,python学习方面,python做测试出方面,我还会合提供指引,vip终身有效,现价1500,联系qq:952943386,稍后会更新qq群,喜欢的对象可来,本人也是起一个免知晓吗是python到现行亦可做东西,从15之2k至17之10k+都是辛酸泪,可以同我们齐声共勉,提供思路,能够吃你运动的双重远,我啊是由白纸一张一步步走来,如若你是新毕业的生是邪适合您,可以吃你点,不过我能开的固然是带来您,可是自不是培训班,没有提供就业之机会,我只是会当有机会的时吃您推荐,学无止境,此时或自己只得使你有的测试,提供职业指引,我恐怕后会带来吃您重新多。

以上传文件之当儿,原来存放于该地,结果为,下载处理不佳,于是乎选取了七牛,需要到七牛的官网去登记自己之账号

 这是数据库相关的,

来探自家的需文档

urls url地址映射

template存放模板

 那么自己来开计划自己之多少,其实我之数据模型也是一波三折的。

from tornado.web import RequestHandler
from models.model_py import User
class BaseHandler(RequestHandler):
    @property
    def db(self):
        return self.application.db
    def get_current_user(self):
        user_id = self.get_secure_cookie('user_id')
        if not user_id:
            return None
        return User.get_by_id(int(user_id))

分页公共模块

https://github.com/liwanlei/tornado\_guanli

需什么的数据库,
数据模型之间的关系,即使现在尚是暴发为数不少地点是描摹很的还无进展查找效果的安,不过我深信不疑,有了今天夫demo

static存放静态

言语:python3 第三库房 :tornado,qiniu(用于出口存储文件),数据库用sqlite

 解析Excel,重要用于上污染测试用例

我是一个大专生,也是一个口努力到今日。

from qiniu import Auth,put_file,etag,urlsafe_base64_encode
import qiniu.config
access_key='uVxowDUcYx641ivtUb111WBEI4112L3D117JHNM_AOtskRh4'
secret_key='PdXU9XrXTLtp1N21bhU1Frm1FDZqE1qhjkEaE9d1xVLZ5C'
def sendfile(key,file):
    q=Auth(access_key,secret_key)
    bucket_name='leilei22'
    token = q.upload_token(bucket_name, key)
    ret, info = put_file(token, key, file)
    me= ret['hash']
    f=etag(file)
    if me==f:
        assert_t=True
    else:
        assert_t=False
    return assert_t

这就是说我起来来统筹下自己重要会组织

untils存放公共库

sqlite,setting 配置文件

why  use
tornado?很多个人数其实会这样问我,我感觉tornado可以兑现异步,虽然现在代码还不曾使异步,我发依旧杀不错的框架,值得学习,现在众多公司都于于是,个人感觉这是一个正确的,值得咱们我们去学学之框架。

 

 1 数据库配置相关的
 2 
 3 from sqlalchemy import  create_engine
 4 from  sqlalchemy.orm import  scoped_session,sessionmaker
 5 from sqlalchemy.ext.declarative import  declarative_base
 6 engine=create_engine('sqlite:///shebei.db',convert_unicode=True)
 7 Base=declarative_base()
 8 db_session=scoped_session(sessionmaker(bind=engine))
 9 def create_all():
10     Base.metadata.create_all(engine)
11 def drop_all():
12     Base.metadata.drop_all(engine)

 

 

sqlite 2

 基础之类集成了RequestHandler的类,,举行了有简单易行的自定义,然后继续可以用这些,

   如今楼主加班 喽,
好久没有改进自己之博客了,哎,一言难尽,废话我就是背着了,来开上花。

网站地图xml地图