Example #1
0
    def validate_title(self, field):
        case = Case.query.filter(db.and_(
                                 Case.title.like(field.data),
                                 db.not_(Case.id == self.case.id))).first()

        if case:
            raise ValidationError(gettext(u"用例名已经存在"))
Example #2
0
    def validate_username(self, field):
        user = User.query.filter(db.and_(
                                 User.username.like(field.data),
                                 db.not_(User.id == self.user.id))).first()

        if user:
            raise ValidationError(gettext(u"用户名已经存在"))
Example #3
0
 def search(self, keywords, user=None):
     criteria = []
     if user and user.is_moderator:
         for keyword in keywords.split():
             keyword = '%' + keyword + '%'
             criteria.append(db.or_(Case.title.ilike(keyword),
                             Case.description.ilike(keyword),
                             Case.id.ilike(keyword)))
     else:
         for keyword in keywords.split():
             keyword = '%' + keyword + '%'
             criteria.append(db.or_(db.and_(db.or_(Case.title.ilike(keyword),
                                                   Case.description.ilike(keyword),
                                                   Case.id.ilike(keyword)),
                                            Case.access == Case.PUBLIC),
                                    db.and_(db.or_(Case.title.ilike(keyword),
                                                   Case.description.ilike(keyword),
                                                   Case.id.ilike(keyword)),
                                            Case.author_id == user.id)))
     q = reduce(db.and_, criteria)
     return self.filter(q).distinct().order_by(Case.id.desc())
Example #4
0
 def validate_name(self, field):
     code = Code.query.filter(
         db.and_(Code.name.like(field.data),
                 db.not_(Code.id == self.code.id))).first()
     if code:
         raise ValidationError(gettext(u"名称已经存在"))
Example #5
0
 def validate_name(self, field):
     task = Task.query.filter(
         db.and_(Task.name.like(field.data),
                 db.not_(Task.id == self.task.id))).first()
     if task:
         raise ValidationError(gettext(u"名称已经被使用"))
Example #6
0
 def validate_email(self, field):
     user = User.query.filter(db.and_(
                              User.email.like(field.data),
                              db.not_(User.id == self.user.id))).first()
     if user:
         raise ValidationError(gettext(u"邮箱地址已经存在"))
Example #7
0
 def validate_name(self, field):
     task = Task.query.filter(db.and_(Task.name.like(field.data),
                                      db.not_(Task.id == self.task.id))).first()
     if task:
         raise ValidationError(gettext(u"名称已经被使用"))
Example #8
0
 def validate_name(self, field):
     code = Code.query.filter(db.and_(
                              Code.name.like(field.data),
                              db.not_(Code.id == self.code.id))).first()
     if code:
         raise ValidationError(gettext(u"名称已经存在"))
Example #9
0
 def validate_name(self, field):
     moduleType = ModuleType.query.filter(db.and_(
                                          ModuleType.name.like(field.data),
                                          db.not_(ModuleType.id == self.moduleType.id))).first()
     if moduleType:
         raise ValidationError(gettext(u"模块名已经存在"))
Example #10
0
 def validate_name(self, field):
     machine = Machine.query.filter(db.and_(
                                    Machine.name.like(field.data),
                                    db.not_(Machine.id == self.machine.id))).first()
     if machine:
         raise ValidationError(gettext(u"机器名已经存在"))
Example #11
0
 def validate_name(self, field):
     moduleType = ModuleType.query.filter(
         db.and_(ModuleType.name.like(field.data),
                 db.not_(ModuleType.id == self.moduleType.id))).first()
     if moduleType:
         raise ValidationError(gettext(u"模块名已经存在"))
Example #12
0
 def validate_name(self, field):
     machine = Machine.query.filter(
         db.and_(Machine.name.like(field.data),
                 db.not_(Machine.id == self.machine.id))).first()
     if machine:
         raise ValidationError(gettext(u"机器名已经存在"))