Пример #1
0
    def upload(self):
        f = upload('upfile')
        if not f : return jsonify({
                                   'url' : '', 'title' : '', 'state' : 'ERROR',
                                   })

        return jsonify({
                        'url' : f.url ,
                        'title' : f.name,
                        'state' : 'SUCCESS',
                        })
Пример #2
0
def ajax_thumbnail_file():
    try:
        f = upload("fileToUpload")
        i = Image.open(f.path)
        data = {
                "image_id" : f.id,
                "image_url" : f.url,
                "image_size" : i.size,
                }
#        i.close()
        return {"data" : data}
    except:
        app.logger.error(traceback.format_exc())
        return {"data" : {}}
Пример #3
0
def ajax_thumbnail_file():
    try:
        f = upload("fileToUpload")
        i = Image.open(f.path)
        data = {
            "image_id": f.id,
            "image_url": f.url,
            "image_size": i.size,
        }
        #        i.close()
        return {"data": data}
    except:
        app.logger.error(traceback.format_exc())
        return {"data": {}}
Пример #4
0
def save_profile():
    id = session['user_profile']["id"]
    u = connection.User.one({"id" : id})
    u.first_name = _g("first_name")
    u.last_name = _g("last_name")
    u.phone = _g("phone")
    u.birthday = _g("birthday")
    try:
        f = upload("image_url")
        u.image_url = f.id
    except:
        app.logger.error(traceback.format_exc())
    u.save()
    flash("Update the profile successfully!", MESSAGE_INFO)
    return redirect(url_for("index"))
Пример #5
0
def save_profile():
    id = session['user_profile']["id"]
    u = connection.User.one({"id": id})
    u.first_name = _g("first_name")
    u.last_name = _g("last_name")
    u.phone = _g("phone")
    u.birthday = _g("birthday")
    try:
        f = upload("image_url")
        u.image_url = f.id
    except:
        app.logger.error(traceback.format_exc())
    u.save()
    flash("Update the profile successfully!", MESSAGE_INFO)
    return redirect(url_for("index"))
Пример #6
0
def m_nurse_save():
    required_fields = ["email", "first_name", "last_name"]
    for f in required_fields:
        if not _g(f) :
            flash("The required field is not supplied !", MESSAGE_ERROR)
            return redirect(url_for("m_nurse_list"))


    action_type = _g("action_type")
    _gl = request.form.getlist
    if action_type == "NEW":
        if not _g("password") or not _g("repassword"):
            flash("The required field is not supplied !", MESSAGE_ERROR)
            return redirect(url_for("m_nurse_list"))

        if _g("password") != _g("repassword"):
            flash("The password and the confirmed password are not the same !", MESSAGE_ERROR)
            return redirect(url_for("m_nurse_list"))
        u = connection.User()
        u.id = u.getID()
        u.email = _g("email")
        u.password = _g("password")
        u.first_name = _g("first_name")
        u.last_name = _g("last_name")
        u.phone = _g("phone")
        u.birthday = _g("birthday")
        r = connection.Role.one({'active':0, 'name' : 'NURSE'})
        r.users.append(u.id)
        u.roles = [r.id]
        try:
            f = upload("image_url")
            u.image_url = f.id
        except:
            app.logger.error(traceback.format_exc())
        r.save()
        u.save()

        n = connection.NurseProfile()
        n.id = n.getID()
        n.uid = u.id
        n.desc = _g("desc")

        n.clinic = map(int, _gl("clinic"))
        for c in n.clinic: connection.Clinic.one({"id":c}).nurses.append(n.id)
        n.save()
        flash("Save the new nurse successfully!", MESSAGE_INFO)
        return redirect(url_for("m_nurse_list"))

    elif action_type == 'UPDATE':
        id = _g("id")
        if not id:
            flash("No nurse id supplied!", MESSAGE_ERROR)
            return redirect(url_for("m_doctor_list"))
        n = connection.NurseProfile.one({'id':int(id)})
        n.desc = _g("desc")
        #map the relation
        n.clinic = map(int, _gl("clinic"))
        for c in n.clinic: connection.Clinic.one({"id":c}).nurses.append(n.id)
        n.save()
        u = connection.User.one({'id' : n.uid})
        u.email = _g("email")
        u.first_name = _g("first_name")
        u.last_name = _g("last_name")
        u.phone = _g("phone")
        u.birthday = _g("birthday")
        try:
            f = upload("image_url")
            u.image_url = f.id
        except:
            app.logger.error(traceback.format_exc())
        u.save()
        flash("Save the update successfully !", MESSAGE_INFO)
        return redirect(url_for("m_nurse_list"))
    else:
        flash("No such action type !", MESSAGE_ERROR)
        return redirect(url_for("m_nurse_list"))
Пример #7
0
def m_doctor_save():
    required_fields = ["email", "first_name", "last_name"]
    for f in required_fields:
        if not _g(f) :
            flash("The required field is not supplied !", MESSAGE_ERROR)
            return redirect(url_for("m_doctor_list"))


    action_type = _g("action_type")
    _gl = request.form.getlist #could not move it outside the function , don't know why
    if action_type == "NEW":
        if not _g("password") or not _g("repassword"):
            flash("The required field is not supplied !", MESSAGE_ERROR)
            return redirect(url_for("m_doctor_list"))

        if _g("password") != _g("repassword"):
            flash("The password and the confirmed password are not the same !", MESSAGE_ERROR)
            return redirect(url_for("m_doctor_list"))


        u = connection.User()
        u.id = u.getID()
        u.email = _g("email")
        u.password = _g("password")
        u.first_name = _g("first_name")
        u.last_name = _g("last_name")
        u.phone = _g("phone")
        u.birthday = _g("birthday")
        r = connection.Role.one({'active':0, 'name' : 'DOCTOR'})
        r.users.append(u.id)
        u.roles = [r.id]
        try:
            f = upload("image_url")
            u.image_url = f.id
        except:
            app.logger.error(traceback.format_exc())
        r.save()
        u.save()

        d = connection.DoctorProfile()
        d.id = d.getID()
        d.uid = u.id
        d.desc = _g("desc")
#        d.qty = int(_g("qty"))  if _g("qty") else 10
        #map the relation 
        d.category = map(int, _gl("category"))
        for c in d.category : connection.Category.one({'id':c}).doctors.append(d.id)
        d.clinic = map(int, _gl("clinic"))
        for c in d.clinic: connection.Clinic.one({"id":c}).doctors.append(d.id)

#        d.avaiable_day = map(int, _gl("avaiable_day"))
        for day in ["MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY", "HOLIDAY"]:
            app.logger.info(request.form.getlist("time_" + day))
            ts = [map(lambda v : ("0" + v)[-5:], t.split("|")) for t in request.form.getlist("time_" + day)]
            ts.sort(cmp = lambda a, b:cmp(a[0], b[0]))
            app.logger.info(ts)
            d.worktime_setting[day] = ts

        d.save()
        flash("Save the new doctor successfully!", MESSAGE_INFO)
        return redirect(url_for("m_doctor_list"))

    elif action_type == 'UPDATE':
        id = _g("id")
        if not id:
            flash("No doctor id supplied!", MESSAGE_ERROR)
            return redirect(url_for("m_doctor_list"))
        d = connection.DoctorProfile.one({'id':int(id)})
        d.desc = _g("desc")
        #map the relation
        d.category = map(int, _gl("category"))
        for c in d.category : connection.Category.one({'id':c}).doctors.append(d.id)
        d.clinic = map(int, _gl("clinic"))
        for c in d.clinic: connection.Clinic.one({"id":c}).doctors.append(d.id)

        for day in ["MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY", "HOLIDAY"]:
            app.logger.info(request.form.getlist("time_" + day))
            ts = [map(lambda v : ("0" + v)[-5:], t.split("|")) for t in request.form.getlist("time_" + day)]
            ts.sort(cmp = lambda a, b:cmp(a[0], b[0]))
            app.logger.info(ts)
            d.worktime_setting[day] = ts

#        d.avaiable_day = map(int, _gl("avaiable_day"))
        d.save()
        u = connection.User.one({'id' : d.uid})
        u.email = _g("email")
        u.first_name = _g("first_name")
        u.last_name = _g("last_name")
        u.phone = _g("phone")
        u.birthday = _g("birthday")
        try:
            f = upload("image_url")
            u.image_url = f.id
        except:
            app.logger.error(traceback.format_exc())
        u.save()

        flash("Save the update successfully !", MESSAGE_INFO)
        return redirect(url_for("m_doctor_list"))
    else:
        flash("No such action type !", MESSAGE_ERROR)
        return redirect(url_for("m_doctor_list"))
Пример #8
0
def m_nurse_save():
    required_fields = ["email", "first_name", "last_name"]
    for f in required_fields:
        if not _g(f):
            flash("The required field is not supplied !", MESSAGE_ERROR)
            return redirect(url_for("m_nurse_list"))

    action_type = _g("action_type")
    _gl = request.form.getlist
    if action_type == "NEW":
        if not _g("password") or not _g("repassword"):
            flash("The required field is not supplied !", MESSAGE_ERROR)
            return redirect(url_for("m_nurse_list"))

        if _g("password") != _g("repassword"):
            flash("The password and the confirmed password are not the same !",
                  MESSAGE_ERROR)
            return redirect(url_for("m_nurse_list"))
        u = connection.User()
        u.id = u.getID()
        u.email = _g("email")
        u.password = _g("password")
        u.first_name = _g("first_name")
        u.last_name = _g("last_name")
        u.phone = _g("phone")
        u.birthday = _g("birthday")
        r = connection.Role.one({'active': 0, 'name': 'NURSE'})
        r.users.append(u.id)
        u.roles = [r.id]
        try:
            f = upload("image_url")
            u.image_url = f.id
        except:
            app.logger.error(traceback.format_exc())
        r.save()
        u.save()

        n = connection.NurseProfile()
        n.id = n.getID()
        n.uid = u.id
        n.desc = _g("desc")

        n.clinic = map(int, _gl("clinic"))
        for c in n.clinic:
            connection.Clinic.one({"id": c}).nurses.append(n.id)
        n.save()
        flash("Save the new nurse successfully!", MESSAGE_INFO)
        return redirect(url_for("m_nurse_list"))

    elif action_type == 'UPDATE':
        id = _g("id")
        if not id:
            flash("No nurse id supplied!", MESSAGE_ERROR)
            return redirect(url_for("m_doctor_list"))
        n = connection.NurseProfile.one({'id': int(id)})
        n.desc = _g("desc")
        #map the relation
        n.clinic = map(int, _gl("clinic"))
        for c in n.clinic:
            connection.Clinic.one({"id": c}).nurses.append(n.id)
        n.save()
        u = connection.User.one({'id': n.uid})
        u.email = _g("email")
        u.first_name = _g("first_name")
        u.last_name = _g("last_name")
        u.phone = _g("phone")
        u.birthday = _g("birthday")
        try:
            f = upload("image_url")
            u.image_url = f.id
        except:
            app.logger.error(traceback.format_exc())
        u.save()
        flash("Save the update successfully !", MESSAGE_INFO)
        return redirect(url_for("m_nurse_list"))
    else:
        flash("No such action type !", MESSAGE_ERROR)
        return redirect(url_for("m_nurse_list"))
Пример #9
0
def m_doctor_save():
    required_fields = ["email", "first_name", "last_name"]
    for f in required_fields:
        if not _g(f):
            flash("The required field is not supplied !", MESSAGE_ERROR)
            return redirect(url_for("m_doctor_list"))

    action_type = _g("action_type")
    _gl = request.form.getlist  #could not move it outside the function , don't know why
    if action_type == "NEW":
        if not _g("password") or not _g("repassword"):
            flash("The required field is not supplied !", MESSAGE_ERROR)
            return redirect(url_for("m_doctor_list"))

        if _g("password") != _g("repassword"):
            flash("The password and the confirmed password are not the same !",
                  MESSAGE_ERROR)
            return redirect(url_for("m_doctor_list"))

        u = connection.User()
        u.id = u.getID()
        u.email = _g("email")
        u.password = _g("password")
        u.first_name = _g("first_name")
        u.last_name = _g("last_name")
        u.phone = _g("phone")
        u.birthday = _g("birthday")
        r = connection.Role.one({'active': 0, 'name': 'DOCTOR'})
        r.users.append(u.id)
        u.roles = [r.id]
        try:
            f = upload("image_url")
            u.image_url = f.id
        except:
            app.logger.error(traceback.format_exc())
        r.save()
        u.save()

        d = connection.DoctorProfile()
        d.id = d.getID()
        d.uid = u.id
        d.desc = _g("desc")
        #        d.qty = int(_g("qty"))  if _g("qty") else 10
        #map the relation
        d.category = map(int, _gl("category"))
        for c in d.category:
            connection.Category.one({'id': c}).doctors.append(d.id)
        d.clinic = map(int, _gl("clinic"))
        for c in d.clinic:
            connection.Clinic.one({"id": c}).doctors.append(d.id)

        #        d.avaiable_day = map(int, _gl("avaiable_day"))
        for day in [
                "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY",
                "SATURDAY", "SUNDAY", "HOLIDAY"
        ]:
            app.logger.info(request.form.getlist("time_" + day))
            ts = [
                map(lambda v: ("0" + v)[-5:], t.split("|"))
                for t in request.form.getlist("time_" + day)
            ]
            ts.sort(cmp=lambda a, b: cmp(a[0], b[0]))
            app.logger.info(ts)
            d.worktime_setting[day] = ts

        d.save()
        flash("Save the new doctor successfully!", MESSAGE_INFO)
        return redirect(url_for("m_doctor_list"))

    elif action_type == 'UPDATE':
        id = _g("id")
        if not id:
            flash("No doctor id supplied!", MESSAGE_ERROR)
            return redirect(url_for("m_doctor_list"))
        d = connection.DoctorProfile.one({'id': int(id)})
        d.desc = _g("desc")
        #map the relation
        d.category = map(int, _gl("category"))
        for c in d.category:
            connection.Category.one({'id': c}).doctors.append(d.id)
        d.clinic = map(int, _gl("clinic"))
        for c in d.clinic:
            connection.Clinic.one({"id": c}).doctors.append(d.id)

        for day in [
                "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY",
                "SATURDAY", "SUNDAY", "HOLIDAY"
        ]:
            app.logger.info(request.form.getlist("time_" + day))
            ts = [
                map(lambda v: ("0" + v)[-5:], t.split("|"))
                for t in request.form.getlist("time_" + day)
            ]
            ts.sort(cmp=lambda a, b: cmp(a[0], b[0]))
            app.logger.info(ts)
            d.worktime_setting[day] = ts


#        d.avaiable_day = map(int, _gl("avaiable_day"))
        d.save()
        u = connection.User.one({'id': d.uid})
        u.email = _g("email")
        u.first_name = _g("first_name")
        u.last_name = _g("last_name")
        u.phone = _g("phone")
        u.birthday = _g("birthday")
        try:
            f = upload("image_url")
            u.image_url = f.id
        except:
            app.logger.error(traceback.format_exc())
        u.save()

        flash("Save the update successfully !", MESSAGE_INFO)
        return redirect(url_for("m_doctor_list"))
    else:
        flash("No such action type !", MESSAGE_ERROR)
        return redirect(url_for("m_doctor_list"))