Exemple #1
0
def api_apk():
    if request.method == "GET":
        if "ids[]" in request.args:
            ids = request.args.getlist("ids[]")
            session = db_manager.master()
            session.query(Apk).filter(
                Apk.id.in_(ids)).delete(synchronize_session=False)
            session.commit()
            session.close()
            return "ok"
        session = db_manager.slave()
        apks = session.query(Apk).order_by(
            Apk.id.desc())  # .slice(start, start + limit)
        start = int(request.args.get('start', 0))
        limit = int(request.args.get('limit', 10))
        pageindex = int(request.args.get('pageIndex', 0))
        response = {"rows": [], "results": apks.count()}
        for s in apks.slice(start, start + limit):
            row = {
                'id': s.id,
                'version_number': s.version_number,
                'version_name': s.version_name,
                'filename': s.filename,
                'description': s.description,
                'download_url': s.download_url,
                'apk_size': s.apk_size,
                'upload_time': s.upload_time.timestamp(),
            }
            response["rows"].append(row)
        return jsonify(response)
    elif request.method == "POST":
        if not request.is_json:
            return
        pjs = request.json
        session = db_manager.master()
        apk = Apk(
            version_number=pjs['version_number'],
            version_name=pjs['version_name'],
            filename=pjs['info']['filename'],
            description=pjs['description'],
            download_url=app.config['APK_DL_URL'] + pjs['info']['filename'],
            apk_size=pjs['info']['size'],
        )
        session.add(apk)
        session.commit()
        session.close()
        return jsonify({"result": "ok"})
Exemple #2
0
def api_aboutus():
    if request.method == 'POST':
        if request.is_json is False:
            # 要求Content-Type为:application/json
            return jsonify({"code": "fail", "error": "content type error!"})
        request_js = request.json
        for f in ["appid", "editer", "content"]:
            if f not in request_js:
                return jsonify({"code": "fail", "error": "data error!"})
        desc = request_js.get("desc", "")
        session = db_manager.master()
        try:
            aboutus = session.query(AboutUs).filter(
                AboutUs.appid == request_js['appid']).one()
            aboutus.appid = request_js['appid']
            aboutus.desc = desc
            aboutus.editer = request_js['editer']
            aboutus.content = request_js['content']
        except MultipleResultsFound:
            return jsonify({"code": "fail", "error": "appid fount many"})
        except NoResultFound:
            aboutus = AboutUs(
                appid=request_js['appid'],
                desc=desc,
                editer=request_js['editer'],
                content=request_js['content'],
            )
        except Exception as e:
            return jsonify({"code": "fail", "error": f"{e}"})
        session.add(aboutus)
        session.commit()
        session.close()
        return jsonify({"code": "success"})
    elif request.method == "GET":
        appid = request.args.get('appid', None)
        if appid is None:
            return jsonify({"code": "fail", "error": "data error!"})
        session = db_manager.slave()
        try:
            aboutus = session.query(AboutUs).filter(
                AboutUs.appid == appid).one()
            session.close()
        except MultipleResultsFound:
            return jsonify({"code": "fail", "error": "appid fount many"})
        except NoResultFound:
            return jsonify({"code": "fail", "error": "appid no found"})
        except Exception as e:
            return jsonify({"code": "fail", "error": f"{e}"})
        return jsonify({
            "appid": aboutus.appid,
            "desc": aboutus.desc,
            "editer": aboutus.editer,
            "edit_time": aboutus.edit_time,
            "content": aboutus.content,
        })
    else:
        return jsonify({"code": "fail", "error": "method no support!"})
def delete_message():
    msg_id = request.args.get("ids[]", None)
    if not msg_id:
        return jsonify({"code": "fail", "error": "no id"})
    try:
        session = db_manager.master()
        m = session.query(Message).filter(Message.id == int(msg_id)).delete()
        session.commit()
        session.close()
        return jsonify({"code": "delete success"})
    except Exception as e:
        print(f"{e}")
def delete_help_information():
    hi_id = request.args.get("ids[]", None)
    if not hi_id:
        return jsonify({"code": "fail", "error": "no id"})
    try:
        session = db_manager.master()
        h = session.query(HelpInformation).filter(HelpInformation.hi_id == int(hi_id)).delete()
        session.commit()
        session.close()
        return jsonify({"code": "delete success"})
    except Exception as e:
        print(f"{e}")
def delete_protocol():
    p_id = request.args.get("ids[]", None)
    if not p_id:
        return jsonify({"code": "fail", "error": "no id"})
    try:
        session = db_manager.master()
        p = session.query(Protocol).filter(
            Protocol.protocol_id == int(p_id)).delete()
        session.commit()
        session.close()
        return jsonify({"code": "delete success"})
    except Exception as e:
        print(f"{e}")
Exemple #6
0
def delete_feedback():
    feedback_id = request.args.get("ids[]", None)
    if not feedback_id:
        return jsonify({"code": "fail", "error": "no id"})
    try:
        session = db_manager.master()
        f = session.query(Feedback).filter(
            Feedback.feedback_id == int(feedback_id)).delete()
        session.commit()
        session.close()
        return jsonify({"code": "delete success"})
    except Exception as e:
        print(f"{e}")
def add_help_information():
    try:
        question = request.args.get("question", None)
        answer = request.args.get("answer", "")
        if question:
            session = db_manager.master()
            h = HelpInformation(question=question, answer=answer, edit_time=datetime.datetime.now())
            session.add(h)
            session.commit()
            return jsonify({"code": "success"})
        else:
            return jsonify({"code": "fail"})
    except Exception as e:
        print(f"{e}")
Exemple #8
0
def add_newest_feedback(*args, **kwargs):
    try:
        feedback_name = kwargs.get("feedback_name", None)
        feedback_content = kwargs.get("feedback_content", "")
        if feedback_name or feedback_content:
            session = db_manager.master()
            f = Feedback(feedback_name=feedback_name, feedback_content=feedback_content,
                         edit_time=datetime.datetime.now())
            session.add(f)
            session.commit()
            return {"code": "success", "message": "feedback success"}
        else:
            return {"code": "fail", "error": "no feedback_name or no feedback_content"}
    except Exception as e:
        return {"code": "fail", "error": f"{e}"}
def add_protocol():
    try:
        protocol_name = request.args.get("protocol_name", None)
        protocol_content = request.args.get("protocol_content", "")
        if protocol_name:
            session = db_manager.master()
            p = Protocol(protocol_name=protocol_name,
                         protocol_content=protocol_content,
                         edit_time=datetime.datetime.now())
            session.add(p)
            session.commit()
            return jsonify({"code": "success"})
        else:
            return jsonify({"code": "fail"})
    except Exception as e:
        print(f"{e}")
Exemple #10
0
def add_feedback():
    try:
        feedback_name = request.args.get("feedback_name", None)
        feedback_content = request.args.get("feedback_content", "")
        if feedback_name:
            session = db_manager.master()
            f = Feedback(feedback_name=feedback_name,
                         feedback_content=feedback_content,
                         edit_time=datetime.datetime.now())
            session.add(f)
            session.commit()
            return jsonify({"code": "success"})
        else:
            return jsonify({"code": "fail"})
    except Exception as e:
        print(f"{e}")
def update_message():
    id = request.args.get("id", None)
    msg_name = request.args.get("msg_name", None)
    msg_content = request.args.get("msg_content", "")
    if not id or not msg_name:
        return jsonify({"code": "fail", "error": "no id or msg_name"})
    try:
        session = db_manager.master()
        m = session.query(Message).filter(Message.id == id).one()
        m.msg_name = msg_name
        m.msg_content = msg_content
        session.add(m)
        session.commit()
        session.close()
        return jsonify({"code": "success"})
    except Exception as e:
        print(f"{e}")
def update_protocol():
    id = request.args.get("id", None)
    protocol_name = request.args.get("protocol_name", None)
    protocol_content = request.args.get("protocol_content", "")
    if not id or not protocol_name:
        return jsonify({"code": "fail", "error": "no id or msg_name"})
    try:
        session = db_manager.master()
        p = session.query(Protocol).filter(Protocol.id == id).one()
        p.protocol_name = protocol_name
        p.protocol_content = protocol_content
        session.add(p)
        session.commit()
        session.close()
        return jsonify({"code": "success"})
    except Exception as e:
        print(f"{e}")
Exemple #13
0
def update_feedback():
    id = request.args.get("id", None)
    feedback_name = request.args.get("feedback_name", None)
    feedback_content = request.args.get("feedback_content", "")
    if not id or not feedback_name:
        return jsonify({"code": "fail", "error": "no id or feedback_name"})
    try:
        session = db_manager.master()
        f = session.query(Feedback).filter(Feedback.feedback_id == id).one()
        f.feedback_name = feedback_name
        f.feedback_content = feedback_content
        session.add(f)
        session.commit()
        session.close()
        return jsonify({"code": "success"})
    except Exception as e:
        print(f"{e}")
def update_help_information():
    id = request.args.get("id", None)
    question = request.args.get("question", None)
    answer = request.args.get("answer", "")
    if not id or not question:
        return jsonify({"code": "fail", "error": "no id or question"})
    try:
        session = db_manager.master()
        h = session.query(HelpInformation).filter(HelpInformation.hi_id == id).one()
        h.question = question
        h.answer = answer
        session.add(h)
        session.commit()
        session.close()
        return jsonify({"code": "success"})
    except Exception as e:
        print(f"{e}")
def add_message():
    try:
        msg_name = request.args.get("msg_name", None)
        msg_content = request.args.get("msg_content", "")
        if msg_name:
            session = db_manager.master()
            m = Message(msg_name=msg_name,
                        msg_content=msg_content,
                        edit_time=datetime.datetime.now())
            session.add(m)
            session.commit()
            return jsonify({
                "code": "success",
                "hasError": True,
                "error": "新增成功!"
            })
        else:
            return jsonify({
                "code": "fail",
                "hasError": True,
                "error": "新增失败!"
            })
    except Exception as e:
        print(f"{e}")
Exemple #16
0
def api_slideshow():
    if request.method == 'POST':
        if not request.is_json:
            return
        pjs = request.json
        session = db_manager.master()
        if 'isNew' in pjs:
            slideshow = SlideShow(slide_show_name=pjs['slide_show_name'],
                                  description=pjs['description'],
                                  images=pjs['pics'])
            session.add(slideshow)
            session.commit()
            session.close()
            return jsonify({"result": "ok"})
        else:
            try:
                slideshow = session.query(SlideShow).filter(
                    SlideShow.id == pjs['id']).one()
                if "containspics" in pjs and pjs['containspics'] == "yes":
                    slideshow.images = pjs['pics']
                slideshow.description = pjs['description']
                slideshow.slide_show_name = pjs['slide_show_name']
            except MultipleResultsFound:
                return jsonify({"result": "appid fount many"})
            except NoResultFound:
                slideshow = SlideShow(slide_show_name=pjs['slide_show_name'],
                                      description=pjs['description'],
                                      images=pjs['pics'])
                session.add(slideshow)
            except Exception as e:
                return jsonify({"result": f"{e}"})
            session.commit()
            session.close()
            return jsonify({"result": "ok"})
    elif request.method == 'GET':
        # http://localhost:7000/main/api/slideshow/?start=0&limit=30&pageIndex=0&_=1547524941956
        if "ids[]" in request.args:
            ids = request.args.getlist("ids[]")
            session = db_manager.master()
            session.query(SlideShow).filter(
                SlideShow.id.in_(ids)).delete(synchronize_session=False)
            session.commit()
            session.close()
            return "ok"
        else:
            session = db_manager.slave()
            slideshow = session.query(SlideShow).order_by(
                SlideShow.id.desc())  # .slice(start, start + limit)
            session.close()
            start = int(request.args.get('start', 0))
            limit = int(request.args.get('limit', 10))
            pageindex = int(request.args.get('pageIndex', 0))
            response = {"rows": [], "results": slideshow.count()}
            for s in slideshow.slice(start, start + limit):
                row = {
                    'id': s.id,
                    'slide_show_name': s.slide_show_name,
                    'description': s.description,
                    'edit_time': s.edit_time.timestamp(),
                    'images_num': len(s.images),
                    'images': s.images
                }
                response["rows"].append(row)
            return jsonify(response)