예제 #1
0
    def get():
        """
            参数:
                user_id:用户登录id
        """
        parser = reqparse.RequestParser()
        parser.add_argument('user_id', type=str, required=True, help=u'user_id必须.')

        args = parser.parse_args()

        user_id = args['user_id']

        resp_suc = success_dic().dic
        resp_fail = fail_dic().dic

        message_count = Message.query.filter(Message.receiver_id == user_id).count()
        if message_count > 1:
            messages = Message.query.filter(Message.receiver_id == user_id).all()
            for message in messages:
                db.delete(message)
                try:
                    db.commit()
                except:
                    return resp_fail
            return resp_suc
        else:
            message = Message.query.filter(Message.receiver_id == user_id).first()
            db.delete(message)
            try:
                db.commit()
            except:
                return resp_fail
            return resp_suc
예제 #2
0
def delete():
    session_token = request.cookies.get("session_token")

    user = db.query(User).filter_by(session_token=session_token).first()

    if not user:
        return render_template(
            "home.html",
            user=user,
            location=location.title(),
            temperature=temperature,
            weather=weather,
        )

    if request.method == "POST":
        if user:
            db.delete(user)
            db.commit()

        response = make_response(redirect(url_for("home")))
        response.set_cookie("session_token", "")

        return response

    return render_template(
        "profile.html",
        user=user,
        location=location.title(),
        temperature=temperature,
        weather=weather,
    )
예제 #3
0
    def get():
        """
        参数
        1.pub_id:酒吧id
        2.user_id: 登录用户id
        """
        parser = reqparse.RequestParser()
        parser.add_argument('pub_id', type=str, required=True, help=u'pub_id 必须')
        parser.add_argument('user_id', type=str, required=True, help=u'user_id 必须')

        args = parser.parse_args()

        success = success_dic().dic
        fail = fail_dic().dic

        pub_id = args['pub_id']
        user_id = args['user_id']

        collect = Collect.query.filter(Collect.user_id == user_id, Collect.pub_id == pub_id).first()
        try:
            db.delete(collect)
            db.commit()
            return success
        except:
            return fail
예제 #4
0
def delete(msg_id):
    # Get session_token
    session_token = request.cookies.get("session_token")

    # Get the user from the database
    user = db.query(User).filter_by(session_token=session_token).first()

    # Get the message using msg_id from database
    message = db.query(Message).get(int(msg_id))

    # If the user.id matchs the message.receiver
    if user.id == message.receiver:

        # Delete the message from the database
        db.delete(message)
        db.commit()

        # Send the user to the index page
        return redirect(url_for("index"))

    # Else - the message does not belong to the user
    else:

        # Send the user to the index page
        return redirect(url_for("index"))
예제 #5
0
 def delete(self, name):
     claims = get_jwt_claims()
     if not claims['is_admin']:
         return {'message': 'Admin Privilege is required'}, 401
     if db.find_item_by_name(name):
         db.delete(name)
         return {"message": "Item deleted"}
     return {'message': "Item not found"}, 401
예제 #6
0
파일: main.py 프로젝트: Kristjaan/Messenger
def profile_delete():
    session_cookie = request.cookies.get("session_cookie")
    user = db.query(User).filter_by(session_token=session_cookie).first()
    db.delete(user)
    db.commit()
    response: Response = redirect(url_for("login", logged_in=False))
    response.set_cookie('session_cookie', '', expires=0)
    return response
예제 #7
0
def delete_user(user_id):
    user = db.query(User).get(int(user_id))
    if user is None:
        return redirect(url_for("register"))
    if request.method == "GET":
        response = make_response(redirect(url_for('register')))
        db.delete(user)
        db.commit()
        return response
예제 #8
0
def deleteNotes(list_id):
    itemlist = db.query(List).get(int(list_id))
    items = db.query(Item).filter_by(lid = itemlist.id)
    for item in items:
        if not item.active:
            db.delete(item)

    db.commit()

    return redirect("/{0}".format(itemlist.id))
예제 #9
0
파일: main.py 프로젝트: Aljosa12/class18
def profile_delete_post():
    session_token = request.cookies.get("session_token")
    user = db.query(User).filter_by(session_token=session_token).first()
    if user is None:
        response = make_response(redirect(url_for("login_get")))
        return response

    db.delete(user)
    db.commit()

    return make_response(redirect(url_for("login_get")))
예제 #10
0
def deleteList(list_id):
    itemlist = db.query(List).get(int(list_id))
    session_token = request.cookies.get("session_token")
    user = db.query(User).filter_by(session_token=session_token).first()
    if request.method == "GET":
       return render_template("deletelist.html", itemlist=itemlist, user=user)
    if request.method == "POST":
        items = db.query(Item).filter_by(lid=itemlist.id)
        for item in items:
                db.delete(item)
        db.delete(itemlist)
        db.commit()
        return redirect(url_for("index"))
예제 #11
0
def profile_delete():
    session_token = request.cookies.get("session_token")
    user = db.query(User).filter_by(session_token=session_token).first()

    if request.method == "GET":
        if user:
            return render_template("profile_delete.html", user=user)
        else:
            return redirect(url_for("index"))
    elif request.method == "POST":
        db.delete(user)
        db.commit()
        return redirect(url_for("index"))
예제 #12
0
def delete_profile():
    if request.method == "GET":
        return render_template("delete_profile.html")
    elif request.method == "POST":
        session_token = request.cookies.get("session_token")
        user = db.query(User).filter_by(session_token=session_token).first()

        db.delete(user)
        db.commit()

        response = make_response(redirect("index"))
        response.set_cookie("session_token", "")
        return response
예제 #13
0
def profile_delete():
    token = request.cookies.get('token')
    user = db.query(User).filter_by(session_token=token).first()

    if not user:
        return redirect(url_for('login'))
    else:
        if request.method == "GET":
            return render_template("profile_delete.html")
        else:
            db.delete(user)
            db.commit()

            return render_template("deleted.html")
예제 #14
0
def receipt(user_id, receipt_id):
    user = User.query.filter_by(id=user_id).first()
    receipt = Receipt.query.filter_by(id=receipt_id).first()

    if not user or not receipt or not user == receipt.user:
        return make_response("404 coming your way", 404)

    if request.method == "GET":
        return json.dumps({"receipt" : receipt.serialize_with_items()})
    elif request.method == "DELETE":
        db.delete(receipt)
        db.commit()

        return json.dumps({})
예제 #15
0
def camera_type_delete(id):
    """
    API endpoint to delete camera type.

    :param id: camera type identifier
    :return:
    """
    camera_type = CameraType.query.get(id)
    if not camera_type:
        raise ValueError("Invalid camera type with identifier %s" % id)

    db.delete(camera_type)
    db.commit()
    return jsonify(camera_type.to_dict())
예제 #16
0
def patient(nhi):
    patient = Patient.query.filter_by(nhi=nhi).first()

    if not patient:
        return make_response("No patient with NHI " + nhi, 404)

    elif request.method == "GET":
        return jsonify(patient.serialize())

    elif request.method == "DELETE":
        db.delete(patient)
        db.commit()

        return make_response("Deleted patient: {}".format(nhi), 200)
예제 #17
0
파일: vsm.py 프로젝트: jcgharvey/vsm-svr
def patient(nhi):
    patient = Patient.query.join(Department.patients).filter(
        Department.department_name == request.cookies.get('department', 'default')).filter_by(nhi=nhi).first()

    if not patient:
        return make_response("No patient with NHI " + nhi, 404)

    elif request.method == "GET":
        return jsonify(patient.serialize())

    elif request.method == "DELETE":
        db.delete(patient)
        db.commit()

        return make_response("Deleted patient: {}".format(nhi), 200)
예제 #18
0
def profile_delete():
    session_token = request.cookies.get("session_token")

    # get user from the database based on her/his email address
    user = db.query(User).filter_by(session_token=session_token).first()

    if request.method == "GET":
        if user:  # if user is found
            return render_template("profile_delete.html", user=user)
        else:
            return redirect(url_for("index"))
    elif request.method == "POST":
        # delete the user in the database
        db.delete(user)
        db.commit()

        return redirect(url_for("index"))
예제 #19
0
def spending_category(user_id, sc_id):
  # do the validation of valid sc here
  user = User.query.filter_by(id=user_id).first()
  sc = SpendingCategory.query.filter_by(id=sc_id).first()

  if (not user) or (not sc) or (sc.user != user):
    return make_response("User or card doesn't exist or card doesn't belong to user", 404)

  if request.method == "GET":
    return json.dumps(sc.serialize())

  if request.method == "PUT":
    return spending_category_put(sc)

  if request.method == "DELETE":
    db.delete(sc)
    db.commit()

    return json.dumps({})
예제 #20
0
def delete_message_info(sender_id, receiver_id):
    """
    删除
    """
    message_count = Message.query.filter(or_(and_(Message.sender_id == sender_id, Message.receiver_id == receiver_id, Message.delete_id == 0),and_(Message.sender_id == receiver_id, Message.receiver_id == sender_id, Message.delete_id == 0))).count()
    if message_count > 1:
        message = Message.query.filter(or_(and_(Message.sender_id == sender_id, Message.receiver_id == receiver_id),and_(Message.sender_id == receiver_id, Message.receiver_id == sender_id))).all()
        for m in message:
            m.delete_id = receiver_id
            try:
                db.commit()
            except:
                return False
        return True
    elif message_count == 1:
        message = Message.query.filter(or_(and_(Message.sender_id == sender_id, Message.receiver_id == receiver_id),and_(Message.sender_id == receiver_id, Message.receiver_id == sender_id))).first()
        message.delete_id = receiver_id
        try:
            db.commit()
        except:
            return False
        return True
    else:
        message_count = Message.query.filter(or_(and_(Message.sender_id == sender_id, Message.receiver_id == receiver_id),and_(Message.sender_id == receiver_id, Message.receiver_id == sender_id))).count()
        if message_count > 1:
            message = Message.query.filter(or_(and_(Message.sender_id == sender_id, Message.receiver_id == receiver_id),and_(Message.sender_id == receiver_id, Message.receiver_id == sender_id))).all()
            for m in message:
                db.delete(m)
                try:
                    db.commit()
                except:
                    return False
            return True
        else:
            message = Message.query.filter(or_(and_(Message.sender_id == sender_id, Message.receiver_id == receiver_id),and_(Message.sender_id == receiver_id, Message.receiver_id == sender_id))).first()
            db.delete(message)
            try:
                db.commit()
            except:
                return False
            return True
예제 #21
0
def contact_delete(contact_id):
    github = OAuth2Session(os.environ.get("GITHUB_CLIENT_ID"),
                           token=json.loads(
                               request.cookies.get("oauth_token")))
    github_profile_data = github.get("https://api.github.com/user").json()

    contact = db.query(Contact).get(int(contact_id))  # query by id

    if request.method == "GET":
        if contact:  # if contact is found
            return render_template("contact_delete.html",
                                   contact=contact,
                                   github_profile_data=github_profile_data)
        else:
            return redirect(url_for("my_contacts"))

    elif request.method == "POST":
        # delete the contact in the database
        db.delete(contact)
        db.commit()

        return redirect(url_for("success"))
예제 #22
0
def smartcard(user_id):
	user = User.query.filter_by(id=user_id).first()
	if not user:
		return make_response("USER " + str(user_id) + " DOESN'T EXIST", 404)

	if request.method == "GET":
		if user.smartcard:
			return json.dumps(user.smartcard.serialize())
		else:
			return json.dumps({})

	elif request.method == "POST":
		return new_smartcard(user)

	elif request.method == "PUT":
		return update_smartcard_status(user.smartcard)

	elif request.method == "DELETE":
		sc = user.smartcard
		db.delete(sc)
		db.commit()

		return json.dumps({})
예제 #23
0
def create_db(csvFilePath):
    jsonFilePath = 'questions.json'
    data = []
    with open(csvFilePath) as csvFile:
        csvReader = csv.DictReader(csvFile)
        for rows in csvReader:
            data.append(rows)
    with open(jsonFilePath, 'w+') as jsonFile:
        jsonFile.write(json.dumps(data, indent=4))
    with open(jsonFilePath, "r") as read_file:
        data = json.load(read_file)
        for entry in data:
            # print('Looking: ', entry['test'])
            test_object = db.query(Test).filter_by(title=entry['test']).first()
            # print('Found: ', test_object)
            if test_object == None:
                test = Test(title=entry['test'])
                db.add(test)
                test_object = test
            new_question = Question(title=entry['title'],
                                    a1=entry['a1'],
                                    a2=entry['a2'],
                                    a3=entry['a3'],
                                    correct=entry['correct'],
                                    test_id=test_object.id)
            # case the question exists
            question_object = db.query(Question).filter_by(
                title=entry['title']).first()
            if question_object != None:
                # print('Found duplicate ', question_object)
                db.delete(question_object)
                db.commit()
                db.add(new_question)
            # case the question does not exists
            else:
                db.add(new_question)
            db.commit()
예제 #24
0
파일: vsm.py 프로젝트: jcgharvey/vsm-svr
def vital_info(nhi, vital_info_id):
    vitalinfo = VitalInfo.query.filter_by(
        patient_nhi=nhi, vital_info_id=vital_info_id).first()

    if not vitalinfo:
        return make_response("No vitalinfo for patient {} with id {}".format(nhi, vital_info_id))

    elif request.method == "GET":
        return jsonify(vitalinfo.serialize())

    elif request.method == "POST":
        vitalinfo_data = json.loads(request.data)
        vitalinfo = VitalInfo(**vitalinfo_data)
        vitalinfo.vital_info_id = vital_info_id
        vitalinfo = db.merge(vitalinfo)
        db.commit()

        return jsonify(vitalinfo.serialize())

    elif request.method == "DELETE":
        db.delete(vitalinfo)
        db.commit()

        return make_response("Deleted vitalinfo: {} from patient: {}".format(vital_info_id, nhi), 200)
예제 #25
0
def checkin(nhi, checkin_id):
    checkin = CheckIn.query.filter_by(
        patient_nhi=nhi, checkin_id=checkin_id).first()

    if not checkin:
        return make_response("No checkin for patient {} with id {}".format(nhi, checkin_id))

    elif request.method == "GET":
        return jsonify(checkin.serialize())

    elif request.method == "POST":
        checkin_data = json.loads(request.data)
        checkin = CheckIn(**checkin_data)
        checkin.checkin_id = checkin_id
        checkin = db.merge(checkin)
        db.commit()

        return jsonify(checkin.serialize())

    elif request.method == "DELETE":
        db.delete(checkin)
        db.commit()

        return make_response("Deleted checkin: {} from patient: {}".format(checkin_id, nhi), 200)
예제 #26
0
def patient_appointment(nhi, appointment_id):
    appointment = Appointment.query.filter_by(
        patient_nhi=nhi, appointment_id=appointment_id).first()

    if not appointment:
        return make_response("No appointment for patient {} with id {}".format(nhi, appointment_id))

    elif request.method == "GET":
        return jsonify(appointment.serialize())

    elif request.method == "POST":
        appointment_data = json.loads(request.data)
        appointment = Appointment(**appointment_data)
        appointment.appointment_id = appointment_id
        appointment = db.merge(appointment)
        db.commit()

        return jsonify(appointment.serialize())

    elif request.method == "DELETE":
        db.delete(appointment)
        db.commit()

        return make_response("Deleted appointment: {} from patient: {}".format(appointment_id, nhi), 200)
예제 #27
0
    def get():
        """
        所需参数
            user_id: 必传,登录用户的id
            pub_id: 必传,用户点击收藏的当前酒吧的id
        """
        parser = reqparse.RequestParser()
        parser.add_argument('user_id', type=str, required=True, help=u'用户登录user_id必须。')
        parser.add_argument('pub_id', type=str, required=True, help=u'当前酒吧pub_id必须。')

        args = parser.parse_args()
        user_id = args['user_id']
        pub_id = args['pub_id']
        resp_suc = {}
        # 先判断用户是否已经收藏此酒吧
        check_collect = Collect.query.filter(Collect.user_id == user_id, Collect.pub_id == pub_id).count()
        if check_collect >= 1:
            c = Collect.query.filter(Collect.user_id == user_id, Collect.pub_id == pub_id).first()
            db.delete(c)
            db.commit()
            resp_suc['message'] = 'success'
            resp_suc['status'] = 0
        else:
            collect = Collect(user_id=user_id, pub_id=pub_id)
            db.add(collect)
            try:
                db.commit()
            except:
                pass
            user_info = UserInfo.query.filter(UserInfo.user_id == user_id).first()
            user_info.add_credit('pub')
            user_info.add_reputation('pub')
            db.commit()
            resp_suc['message'] = 'success'
            resp_suc['status'] = 0
        return resp_suc
예제 #28
0
def delete_all_smartcards():
	for sc in Smartcard.query.all():
		db.delete(sc)

	db.commit()
	return ""
예제 #29
0
def crypto_delete(crypto_code):
    crypto = db.query(Cryptocurrency).filter_by(code=crypto_code).first()

    db.delete(crypto)
    db.commit()
    return redirect(url_for("portfolio"))
 def delete(self, twit_id):
     twt = Twits.query.filter_by(twit_id=twit_id).first()
     db.delete(twt)
     db.session.commit()
     return Twits.query.order_by(Twits.created_at.desc()).all()
 def delete(self, image_id):
     result = Images.query.filter_by(image_id=image_id).first()
     db.delete(result)
     db.session.commit()
     return Images.query.order_by(Images.created_at.desc()).all()
예제 #32
0
파일: main.py 프로젝트: Giessrigl/shadowrun
def delete(char_char_name):
    chars = db.query(Character).filter_by(char_name=char_char_name).first()
    db.delete(chars)
    db.commit()
    return redirect(url_for("characters"))