示例#1
0
def find():

    if "_id" in request.args == False:
        return "malformed request"

    dbManager = DBManager()
    requestDict = {"_id": ObjectId(request.args["_id"])}
    returnValue = dbManager.find("Users", requestDict)
    return str(returnValue)
示例#2
0
def delete():

    if "_id" in request.args == False:
        return "malformed request"

    dbManager = DBManager()
    requestDict = {"_id": ObjectId(request.args["_id"])}
    returnValue = dbManager.delete("Users", requestDict)
    return str(returnValue.deleted_count)
示例#3
0
def update():
    print("updating")

    if checkUserDict(request.args) == False:
        print "malformed request"
        return "malformed request"
    print("updating")
    dbManager = DBManager()
    requestDict = request.args
    returnValue = dbManager.update("Users", requestDict)
    return str(returnValue.modified_count)
示例#4
0
def create():
    requestDict = {}

    if checkUserDict(request.args) == False:
        return "malformed requessst"

    for key in request.args.keys():
        requestDict[key] = request.args[key]
    dbManager = DBManager()
    returnValue = dbManager.insert("Users", requestDict)
    return str(returnValue.inserted_id)
示例#5
0
def list():
    returnObject = []
    dbManager = DBManager()
    returnValue = dbManager.findAll("Users")
    for record in returnValue:
        recordDict = {}
        for key in record.keys():
            if key == "_id":
                recordDict[key] = str(ObjectId(record[key]))
            else:
                recordDict[key] = record[key]
        returnObject.append(recordDict)

    jsonList = json.dumps(returnObject)
    return jsonList
示例#6
0
class ListView:
    def __init__(self, tableName):
        self.tableName = tableName
        self.dbManager = DBManager()

    def getHTML(self):
        HTMLString = ""
        HTMLString += "<h2>Backend</h2>"
        HTMLString += "<table style=\"width:50%\">"
        HTMLString += "<tr>"
        HTMLString += "<th> Name </th>"
        HTMLString += "<th> Surname </th>"
        HTMLString += "<th> Age </th>"
        HTMLString += "<th> Actions </th>"
        HTMLString += "</tr>"
        resultDict = self.dbManager.findAll(self.tableName)
        for result in resultDict:
            HTMLString += "<tr><form action=\"/operation\">"
            HTMLString += "<input name=\"_id\" type=\"hidden\" value =" + str(
                result["_id"]) + ">"
            HTMLString += "<td><input name=\"name\" type=\"text\" value =" + result[
                "name"] + "></td>"
            HTMLString += "<td><input name=\"surname\" type=\"text\" value =" + result[
                "surname"] + "></td>"
            HTMLString += "<td><input name=\"age\" type=\"text\" value =" + str(
                result["age"]) + "></td>"
            HTMLString += "<td><input name = \"action\" type=\"submit\" value =\"Update\">"
            HTMLString += "<input name = \"action\" type=\"submit\" value =\"Delete\"></td>"
            HTMLString += "</form></tr>"

        HTMLString += "<tr><form action=\"/operation\">"
        HTMLString += "<td><input name=\"name\" type=\"text\"></td>"
        HTMLString += "<td><input name=\"surname\" type=\"text\"></td>"
        HTMLString += "<td><input name=\"age\" type=\"text\"></td>"
        HTMLString += "<td colspan=\"2\"><input name = \"action\" type=\"submit\" value =\"Create\" style=\"width:100%\"></td>"
        HTMLString += "</form></tr>"
        HTMLString += "</table>"
        return HTMLString
示例#7
0
 def __init__(self, tableName):
     self.tableName = tableName
     self.dbManager = DBManager()