Exemplo n.º 1
0
    def getAll(self, params, page, limit):

        whereStr = " 1=1 "
        limitStr = ""

        if ("jobName" in params.keys()):
            whereStr = whereStr + " and jobName=\'" + params["jobName"] + "\'"

        if ("jobParams" in params.keys()):
            whereStr = whereStr + " and jobParams=\'" + params[
                "jobParams"] + "\'"

        if ("jobDesc" in params.keys()):
            whereStr = whereStr + " and jobDesc=\'" + params["jobDesc"] + "\'"

        if ((page != None) and (limit != None)):
            limitStr = " order by id desc limit " + str(
                (int(page) - 1) * int(limit)) + " , " + str(limit)

        sqlStr = whereStr + limitStr
        try:
            jobDescs = dbSession.query(JobDesc).filter(text(sqlStr)).all()
            jobsDescTotal = dbSession.query(func.count(JobDesc.id)).filter(
                text(whereStr)).all()
            results = self.getResult(jobDescs, totalTmps=jobsDescTotal)
            dbSession.commit()
        except Exception as e:
            dbSession.rollback()
            app.logger.info("ERROR:ServiceJobDesc.getAll():" +
                            e.args.__str__())

        return results
Exemplo n.º 2
0
 def wrapper(self, *args, **kwargs):
     try:
         result = func(self, *args, **kwargs)
         dbSession.commit()
         return result
     except Exception as e:
         dbSession.rollback()
         raise e
Exemplo n.º 3
0
 def deleteJob(self, jobId):
     try:
         dbSession.query(CronJob).filter(CronJob.jobId == jobId).delete()
         dbSession.commit()
     except Exception as e:
         dbSession.rollback()
         app.logger.info("ERROR:ServiceJob.deleteJob():" +
                         e.args.__str__() + jobId)
Exemplo n.º 4
0
 def saveReport(self, report):
     try:
         dbSession.add(report)
         dbSession.commit()
         return 1
     except Exception as e:
         dbSession.rollback()
         app.logger.info(e.args.__str__())
         return 0
Exemplo n.º 5
0
    def getByJobId(self, jobId):
        job = None
        try:
            job = dbSession.query(CronJob).filter(
                CronJob.jobId == jobId).first()
            dbSession.commit()

        except Exception as e:
            dbSession.rollback()
            app.logger.info("ERROR:ServiceJob.getByJobId():" +
                            e.args.__str__() + ":" + jobId)

        return job
Exemplo n.º 6
0
def delete_center():
    """Elimina un centro de manera definitiva"""
    try:
        center_id = request.args['object_id']
        center_name = Center.get_by_id(center_id).name
        if Center.delete_by_id(center_id):
            dbSession.commit()
            flash("el Centro {} ha sido borrado".format(center_name), "info")
    except BadRequestKeyError:
        flash("ERROR: id Centro no recibido", "danger")
    except NoResultFound as e:
        flash(e, 'danger')
    finally:
        return redirect(url_for('center_index'))
Exemplo n.º 7
0
def create():
    """ Da de alta un centro en la base de datos."""
    form = CreateCenterForm()
    app.logger.info(form.data)
    if form.validate():
        center = Center()
        form.populate_obj(center)
        center.protocol = request.files['protocol'].read()
        dbSession.add(center)
        dbSession.commit()
    if form.errors:
        display_errors(form.errors)
        return redirect(url_for("center_new"))
    return redirect(url_for("center_index", page=1))
Exemplo n.º 8
0
 def delete(self, id):
     """
     根据id删除用户
     :param id:
     :return:
     """
     dbSession.query(User).filter_by(id=id).delete()
     return dbSession.commit()
Exemplo n.º 9
0
def update_center(object_id):
    """ edita los atributos del centro con los datos obtenidos del formulario """
    form = CreateCenterForm(request.form)
    if form.validate():
        try:
            center = Center.get_by_id(object_id)
        except NoResultFound as e:
            flash(e, 'danger')
            return redirect(url_for("center_index"))
        form.populate_obj(center)
        center.protocol = request.files['protocol'].read()
        dbSession.commit()
    elif form.errors:
        display_errors(form.errors)
        flash("Error al validar formulario", "danger")
        return update_center_form(object_id)
    flash("se guardaron los cambios", "info")
    return redirect(url_for("center_index"))
Exemplo n.º 10
0
 def update(email, updated_time):
     """
     更新更新时间
     :param email:
     :param updated_time:
     :return:
     """
     dbSession.query(User).filter_by(email=email).update({'updated_time': updated_time})
     return dbSession.commit()
Exemplo n.º 11
0
 def add(index, uuid, imgString):
     """
     增加分片数据
     :param index:
     :param uuid:
     :param imgString:
     :return:
     """
     data = ImgShard(index=index, uuid=uuid, imgString=imgString)
     dbSession.add(data)
     return dbSession.commit()
Exemplo n.º 12
0
 def add(self, data, type=1, level=1):
     """
     添加
     :param data:
     :param type:
     :param level:
     :return:
     """
     data_dict = {
         'data': data,
         'type': type,
         'level': level,
         'create_time': int(time.time())
     }
     try:
         log = HotLog(**data_dict)
         dbSession.add(log)
         dbSession.flush()
         id = log.id
         dbSession.commit()
         return id
     except Exception as e:
         dbSession.rollback()
         return 0
Exemplo n.º 13
0
 def putJob(self, job):
     try:
         dbSession.add(job)
         dbSession.commit()
     except Exception as e:
         app.logger.info("ERROR:ServiceJob.putJob():" + e.args.__str__())