Beispiel #1
0
class FeedBack(db.Model):
    __tablename__ = "FeedBack"
    query_class = FeedBackQuery
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Unicode(200), nullable=False)
    email = db.Column(db.Unicode(200), nullable=False)
    description = db.Column(db.UnicodeText)
    create_time = db.Column(db.DateTime, default=datetime.now)

    def __init__(self, *args, **kwargs):
        super(FeedBack, self).__init__(*args, **kwargs)

    def __repr__(self):
        return "<%s>" % self
Beispiel #2
0
class ModuleType(db.Model):
    __tablename__ = "moduletype"
    query_class = ModuleTypeQuery
    PER_PAGE = 20
    id = db.Column(db.Integer, primary_key=True)
    parent_id = db.Column(db.Integer, default=0, nullable=False)
    name = db.Column(db.Unicode(30), unique=True, nullable=False)
    description = db.Column(db.UnicodeText)
    type_create_time = db.Column(db.DateTime, default=datetime.now)
    type_update_time = db.Column(db.DateTime, default=datetime.now)
    input_template = db.Column(db.UnicodeText, nullable=False)
    output_template = db.Column(db.UnicodeText, nullable=False)

    # level = db.Column(db.Integer, default=1, nullable=False)

    def __init__(self, *args, **kwargs):
        super(ModuleType, self).__init__(*args, **kwargs)

    def __str__(self):
        return self.name

    def __repr__(self):
        return "<%s>" % self

    @cached_property
    def json(self):
        return dict(id=self.id,
                    name=self.name,
                    description=self.description,
                    parent_id=self.parent_id,
                    input_template=self.input_template,
                    output_template=self.output_template,
                    type_create_time=str(self.type_create_time),
                    type_update_time=str(self.type_update_time))
Beispiel #3
0
class Machine(db.Model):
    OK = 1
    REALLY = 0
    PER_PAGE = 20
    __tablename__ = "machine"
    query_class = MachineQuery
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Unicode(30), unique=True, nullable=False)
    description = db.Column(db.UnicodeText)
    m_create_time = db.Column(db.DateTime, default=datetime.now)
    m_update_time = db.Column(db.DateTime, default=datetime.now)
    status = db.Column(db.Integer, default=0)
    key = db.Column(db.Unicode(100))
    username = db.Column(db.Unicode(30), nullable=False)
    password = db.Column(db.Unicode(30), nullable=False)
    url_hudson = db.Column(db.Unicode(60))
    task_count = db.Column(db.Integer, default=0)

    def __init__(self, *args, **kwargs):
        super(Machine, self).__init__(*args, **kwargs)

    def __str__(self):
        return self.name

    def __repr__(self):
        return "<%s>" % self

    @cached_property
    def json(self):
        return dict(id=self.id,
                    name=self.name,
                    description=self.description,
                    status=self.status,
                    m_create_time=str(self.m_create_time),
                    m_update_time=str(self.m_update_time),
                    username=self.username,
                    password=self.password,
                    url_hudson=self.url_hudson,
                    task_count=self.task_count,
                    key=self.key)
Beispiel #4
0
class User(db.Model):

    __tablename__ = "users"
    PER_PAGE = 20
    query_class = UserQuery

    # user roles
    MEMBER = 100
    MODERATOR = 200
    ADMIN = 300

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.Unicode(30), unique=True, nullable=False)
    email = db.Column(db.String(30), unique=True, nullable=False)
    status = db.Column(db.Boolean, default=True)
    user_create_time = db.Column(db.DateTime, default=datetime.now)
    user_update_time = db.Column(db.DateTime, default=datetime.now)
    role = db.Column(db.Integer, default=MEMBER)

    email_alerts = db.Column(db.Boolean, default=False)
    _password = db.Column("password", db.String(80))

    class Permissions(object):
        pass

    def __init__(self, *args, **kwargs):
        super(User, self).__init__(*args, **kwargs)

    def __str__(self):
        return self.username

    def __repr__(self):
        return "<%s>" % self

    @cached_property
    def permissions(self):
        return self.Permissions(self)

    def _get_password(self):
        return self._password

    def _set_password(self, password):
        self._password = generate_password_hash(password)

    password = db.synonym("_password",
                          descriptor=property(_get_password, _set_password))

    def check_password(self, password):
        if self.password is None:
            return False
        return check_password_hash(self.password, password)

    @cached_property
    def provides(self):
        needs = [RoleNeed('authenticated'), UserNeed(self.id)]

        if self.is_moderator:
            needs.append(RoleNeed('moderator'))

        if self.is_admin:
            needs.append(RoleNeed('admin'))

        return needs

    @cached_property
    def json(self):
        return dict(id=self.id,
                    name=self.username,
                    email=self.email,
                    status=self.status,
                    user_create_time=str(self.user_create_time),
                    user_update_time=str(self.user_update_time),
                    role=get_role(self.role),
                    email_alerts=self.email_alerts)

    @property
    def is_moderator(self):
        return self.role >= self.MODERATOR

    @property
    def is_admin(self):
        return self.role >= self.ADMIN

    @property
    def is_member(self):
        return self.role == self.MEMBER
Beispiel #5
0
class Case(db.Model):
    __tablename__ = "cases"
    query_class = CaseQuery
    PER_PAGE = 20
    PUBLIC = 100
    PRIVATE = 300
    id = db.Column(db.Integer, primary_key=True)
    author_id = db.Column(db.Integer,
                          db.ForeignKey(User.id, ondelete='CASCADE'),
                          nullable=False)
    title = db.Column(db.Unicode(200), unique=True, nullable=False)
    description = db.Column(db.UnicodeText)
    case_create_time = db.Column(db.DateTime, default=datetime.now)
    case_update_time = db.Column(db.DateTime, default=datetime.now)
    access = db.Column(db.Integer, default=PUBLIC)
    # status = db.Column(db.Boolean, default=True)
    usecase_input = db.Column(db.UnicodeText)
    usecase_output = db.Column(db.UnicodeText)
    pre = db.Column(db.UnicodeText)
    other = db.Column(db.UnicodeText)
    module_type = db.Column(db.Integer,
                            db.ForeignKey(ModuleType.id, ondelete='CASCADE'),
                            nullable=False)
    parent_id = db.Column(db.Integer, nullable=False)
    author = db.relation(User, innerjoin=True, lazy="joined")
    casetype = db.relation(ModuleType, innerjoin=True, lazy="joined")

    class Permissions(object):

        def __init__(self, obj):
            self.obj = obj

        @cached_property
        def default(self):
            return Permission(UserNeed(self.obj.author_id)) & moderator

        @cached_property
        def view(self):
            if self.obj.access == Case.PUBLIC:
                return Permission()
            return self.default

        @cached_property
        def edit(self):
            return self.default

        @cached_property
        def delete(self):
            return self.default

    def __init__(self, *args, **kwargs):
        super(Case, self).__init__(*args, **kwargs)
        self.access = self.access or self.PUBLIC

    def __str__(self):
        return self.title

    def __repr__(self):
        return "<%s>" % self

    @cached_property
    def permissions(self):
        return self.Permissions(self)

    @cached_property
    def json(self):
        return dict(id=self.id,
                    author=self.author.username,
                    title=self.title,
                    description=self.description,
                    case_create_time=str(self.case_create_time),
                    case_update_time=str(self.case_update_time),
                    access=get_access(self.access),
                    usecase_input=self.usecase_input,
                    usecase_output=self.usecase_output,
                    casetype=self.casetype.name,
                    checkBox="<input type='checkbox' name='case' value='" + str(self.id) + "' onclick='setSelectAll();' />"
                    )
Beispiel #6
0
class Code(db.Model):
    __tablename__ = "code"
    query_class = CodeQuery
    PER_PAGE = 20
    id = db.Column(db.Integer, primary_key=True)
    author_id = db.Column(db.Integer,
                          db.ForeignKey(User.id, ondelete='CASCADE'),
                          nullable=False)
    name = db.Column(db.Unicode(200), unique=True, nullable=False)
    description = db.Column(db.UnicodeText)
    code_create_time = db.Column(db.DateTime, default=datetime.now)
    code_update_time = db.Column(db.DateTime, default=datetime.now)
    related_module = db.Column(db.Integer,
                               db.ForeignKey(ModuleType.id,
                                             ondelete='CASCADE'),
                               nullable=False)
    parent_id = db.Column(db.Integer, nullable=False)
    relatedmodule = db.relation(ModuleType, innerjoin=True, lazy="joined")
    path = db.Column(db.UnicodeText, nullable=False)
    # forder_name = db.Column(db.Unicode(200), nullable=False)
    author = db.relation(User, innerjoin=True, lazy="joined")

    class Permissions(object):
        def __init__(self, obj):
            self.obj = obj

        @cached_property
        def default(self):
            return Permission(UserNeed(self.obj.author_id)) & moderator

        @cached_property
        def edit(self):
            return self.default

        @cached_property
        def delete(self):
            return self.default

    def __init__(self, *args, **kwargs):
        super(Code, self).__init__(*args, **kwargs)

    def __str__(self):
        return self.name

    def __repr__(self):
        return "<%s>" % self

    @cached_property
    def permissions(self):
        return self.Permissions(self)

    @cached_property
    def json(self):
        return dict(id=self.id,
                    name=self.author.username,
                    title=self.name,
                    description=self.description,
                    code_create_time=str(self.code_create_time),
                    code_update_time=str(self.code_update_time),
                    path=self.path,
                    codetype=self.relatedmodule.name,
                    checkBox="<input type='checkbox' name='code' value='" +
                    str(self.id) + "' onclick='setSelectCodeAll();' />")

    @cached_property
    def attach_path(self):
        result = []
        if self.path:
            result = self.path.split(";").remove('')
        return result
Beispiel #7
0
class Taskcount(db.Model):
    PASS = 0
    FAIL = 1
    PER_PAGE = 20
    __tablename__ = "task_count"
    query_class = TaskcountQuery
    id = db.Column(db.Integer, primary_key=True)
    task_id = db.Column(db.Integer, db.ForeignKey(Task.id, ondelete='CASCADE'), nullable=False)
    case_all = db.Column(db.Integer)
    case_pass = db.Column(db.Integer)
    case_fail = db.Column(db.Integer)
    result = db.Column(db.Integer, default=0)
    result_path = db.Column(db.String(150))
    fail_case = db.Column(db.UnicodeText)
    start_time = db.Column(db.DateTime, default=datetime.now)
    stop_time = db.Column(db.DateTime, default=datetime.now)
    timing = db.Column(db.UnicodeText, default=0)
    other = db.Column(db.UnicodeText)
    build_id = db.Column(db.Integer)
    next = db.Column(db.Integer, default=0, nullable=False)
    task = db.relation(Task, innerjoin=True, lazy="joined")

    def __init__(self, *args, **kwargs):
        super(Taskcount, self).__init__(*args, **kwargs)

    @cached_property
    def json(self):
        return dict(id=self.id,
                    task_id=self.task_id,
                    case_all=self.case_all,
                    case_pass=self.case_pass,
                    case_fail=self.case_fail,
                    result=self.result,
                    result_path=self.result_path,
                    fail_case=self.fail_case,
                    start_time=str(self.start_time),
                    stop_time=str(self.stop_time),
                    timing=self.timing,
                    build_id=self.build_id,
                    next=self.next,
                    other=self.other)
Beispiel #8
0
class Task(db.Model):
    __tablename__ = "task"
    query_class = TaskQuery
    PUBLIC = 100
    PRIVATE = 300
    PER_PAGE = 20
    id = db.Column(db.Integer, primary_key=True)
    author_id = db.Column(db.Integer,
                          db.ForeignKey(User.id, ondelete='CASCADE'),
                          nullable=True)
    moduletype_id = db.Column(db.Integer,
                              db.ForeignKey(ModuleType.id, ondelete='CASCADE'),
                              nullable=True)
    parent_id = db.Column(db.Integer, nullable=False)
    name = db.Column(db.Unicode(200), unique=True, nullable=False)
    case = db.relationship("Case", secondary="task_case", backref=db.backref("task", lazy='dynamic'), order_by=Case.id)
    code = db.relationship("Code", secondary="task_code", backref=db.backref("task", lazy='dynamic'))
    machine_id = db.Column(db.Integer, db.ForeignKey(Machine.id, ondelete='CASCADE'), nullable=False)
    access = db.Column(db.Integer, default=PUBLIC)
    hudson = db.Column(db.Integer, default=None)
    task_excute_times = db.Column(db.Integer, default=0)
    description = db.Column(db.UnicodeText)
    command = db.Column(db.UnicodeText, nullable=False)
    runtime = db.Column(db.UnicodeText)
    timing = db.Column(db.UnicodeText, default=0)
    svn = db.Column(db.UnicodeText, nullable=False)
    email = db.Column(db.UnicodeText, nullable=False)
    email_topic = db.Column(db.UnicodeText, nullable=False)
    other = db.Column(db.UnicodeText)
    task_create_time = db.Column(db.DateTime, default=datetime.now)
    task_update_time = db.Column(db.DateTime, default=datetime.now)
    author = db.relation(User, innerjoin=True, lazy="joined")
    moduletype = db.relation(ModuleType, innerjoin=True, lazy="joined")
    machine = db.relation(Machine, innerjoin=True, lazy="joined")

    class Permissions(object):

        def __init__(self, obj):
            self.obj = obj

        @cached_property
        def default(self):
            return Permission(UserNeed(self.obj.author_id)) & moderator

        @cached_property
        def view(self):
            if self.obj.access == Task.PUBLIC:
                return Permission()
            return self.default

        @cached_property
        def run(self):
            if self.obj.access == Task.PUBLIC:
                return Permission()
            return self.default

        @cached_property
        def edit(self):
            return self.default

        @cached_property
        def delete(self):
            return self.default

    def __init__(self, *args, **kwargs):
        super(Task, self).__init__(*args, **kwargs)
        self.access = self.access or self.PUBLIC

    @staticmethod
    def count_task(self):
        print self.task

    @cached_property
    def permissions(self):
        return self.Permissions(self)

    @cached_property
    def attach_task_url(self):
        result = []
        if self.task_path:
            result = self.task_path.split(";").remove('')
        return result

    @cached_property
    def attach_code_url(self):
        result = []
        if self.code_path:
            result = self.code_path.split(";").remove('')
        return result

    @cached_property
    def attach_other_url(self):
        result = []
        if self.other_path:
            result = self.other_path.split(";").remove('')
        return result

    @cached_property
    def json(self):
        return dict(id=self.id,
                    author=self.author.username,
                    name=self.name,
                    description=self.description,
                    hudson=get_hudson(self.hudson),
                    times=self.task_excute_times,
                    command=self.command,
                    runtime=self.runtime,
                    timing=self.timing,
                    svn=self.svn,
                    email=self.email,
                    email_topic=self.email_topic,
                    other=self.other,
                    case=str([i.title for i in self.case]),
                    code=str([i.name for i in self.code]),
                    task_create_time=str(self.task_create_time),
                    task_update_time=str(self.task_update_time),
                    access=get_access(self.access),
                    tasktype=self.moduletype.name,
                    machine=self.machine.name)
Beispiel #9
0
"""
from datetime import datetime
from werkzeug import cached_property
from sqlalchemy import event, DDL
from flask.ext.sqlalchemy import BaseQuery
from flask.ext.principal import Permission, UserNeed
from izppy.permissions import moderator
from izppy.models.cases import Case
from izppy.models.admin import ModuleType, Machine
from izppy.models.codes import Code
from izppy.models.users import User
from izppy.extensions import db
from izppy.helpers import get_access, get_hudson

task_case = db.Table('task_case',
                     db.Column('cases_id', db.Integer, db.ForeignKey('cases.id')),
                     db.Column('task_id', db.Integer, db.ForeignKey('task.id'))
                     )
task_code = db.Table('task_code',
                     db.Column('code_id', db.Integer, db.ForeignKey('code.id')),
                     db.Column('task_id', db.Integer, db.ForeignKey('task.id'))
                     )
"""
task_machine = db.Table('task_machine',
                        db.Column('machine_id', db.Integer, db.ForeignKey('machine.id')),
                        db.Column('task_id', db.Integer, db.ForeignKey('task.id'))
)
"""


class TaskQuery(BaseQuery):