示例#1
0
文件: main.py 项目: yaqwsx/quickPoll
def deleteChoice(roomId, widgetId):
    room, widget, choice = validateForChoice(request, roomId, widgetId, None)
    if room is None or widget is None:
        return
    widget.addChoice(Choice(""))
    dbFun.updateRoom(db, room)
    updateRoomLayout(room)
    return roomOverview(room)
示例#2
0
文件: main.py 项目: yaqwsx/quickPoll
def createRoom():
    username = request.environ["AUTH_USER"]
    if not isTeacher(username):
        return
    room = roomSuite.addRoom(author=username)
    dbFun.updateRoom(db, room)
    updateRoomsOverview()
    return room.id
示例#3
0
文件: main.py 项目: yaqwsx/quickPoll
def deleteChoice(roomId, widgetId, choiceId, value):
    room, widget, choice = validateForChoice(request, roomId, widgetId, choiceId)
    if room is None or widget is None or choice is None:
        return
    choice.text = value
    dbFun.updateRoom(db, room)
    updateRoomLayout(room)
    return roomOverview(room)
示例#4
0
文件: main.py 项目: yaqwsx/quickPoll
def deleteChoice(roomId, widgetId, choicesIds):
    room, widget, choice = validateForChoice(request, roomId, widgetId, None)
    if room is None or widget is None:
        return
    if len(choicesIds) != len(widget.choices) or any([ch.id not in choicesIds for ch in widget.choices]):
        return

    widget.reorderChoices(choicesIds)
    dbFun.updateRoom(db, room)
    updateRoomLayout(room)
    return roomOverview(room)
示例#5
0
文件: main.py 项目: yaqwsx/quickPoll
def changeRoomPropertyHandler(request, roomId, propertyName, propertyValue):
    username = request.environ["AUTH_USER"]
    if not isTeacher(username):
        return
    if not roomSuite.hasRoom(roomId):
        return
    room = roomSuite.getRoom(roomId)
    setattr(room, propertyName, propertyValue)
    dbFun.updateRoom(db, room)
    updateRoomLayout(room)
    return roomOverview(room)
示例#6
0
文件: main.py 项目: yaqwsx/quickPoll
def deleteWidget(roomId, widgetId):
    username = request.environ["AUTH_USER"]
    if not isTeacher(username):
        return
    if not roomSuite.hasRoom(roomId):
        return
    room = roomSuite.getRoom(roomId)
    room.deleteWidget(widgetId)
    dbFun.updateRoom(db, room)
    updateRoomLayout(room)
    return roomOverview(room)
示例#7
0
文件: main.py 项目: yaqwsx/quickPoll
def reorderWidgets(roomId, widgetsId):
    username = request.environ["AUTH_USER"]
    if not isTeacher(username):
        return
    if not roomSuite.hasRoom(roomId):
        return
    room = roomSuite.getRoom(roomId)
    if len(widgetsId) != len(room.widgets) or any([w.id not in widgetsId for w in room.widgets]):
        return

    room.reorderWidgets(widgetsId)
    dbFun.updateRoom(db, room)
    updateRoomLayout(room)
    return roomOverview(room)
示例#8
0
文件: main.py 项目: yaqwsx/quickPoll
def cloneRoom(roomId):
    username = request.environ["AUTH_USER"]
    if not isTeacher(username):
        return
    if not roomSuite.hasRoom(roomId):
        return
    room = roomSuite.getRoom(roomId)

    newRoom = Room(None, room.name + " (klon)", username, room.description)
    for widget in room.widgets:
        newRoom.addWidget(deepcopy(widget))
    roomSuite.addExistingRoom(newRoom)
    dbFun.updateRoom(db, newRoom)

    updateRoomsOverview()
示例#9
0
文件: main.py 项目: yaqwsx/quickPoll
def addWidget(roomId, type):
    username = request.environ["AUTH_USER"]
    if not isTeacher(username):
        return
    if not roomSuite.hasRoom(roomId):
        return
    room = roomSuite.getRoom(roomId)

    if type == "text":
        room.addWidget(TextWidget("Nová textová otázka"))
    elif type == "choice":
        room.addWidget(ChoiceWidget("Nová výběrová otázka", False, []))
    else:
        return
    dbFun.updateRoom(db, room)
    updateRoomLayout(room)
    return roomOverview(room)
示例#10
0
文件: main.py 项目: yaqwsx/quickPoll
    w2.description = "Neboj se být upřímný v tomto volitelném popisku otázky"

    w3 = room.addWidget(ChoiceWidget("Zadej možnost v multiple-choice widgetu", True, [
        Choice("Možnost 1"),
        Choice("Možnost 2"),
        Choice("Možnost 3"),
    ]))
    w3.visible = True
    return room

roomSuite = RoomSuite()
for room in dbFun.loadRooms(db):
    roomSuite.addExistingRoom(room)
if not roomSuite.hasRoom("demo"):
    r = addDemoRoom(roomSuite)
    dbFun.updateRoom(db, r)

def isTeacher(username):
    try:
        cursor = db.cursor()
        cursor.execute("SELECT COUNT(*) FROM teachers WHERE login = %s", [username])
        result = cursor.fetchone()
        return result[0] > 0
    except Exception as e:
        db.rollback()
        print("Warning, DB query failed", file=sys.stderr)
        return False

@socketio.on("disconnect")
def disconnect():
    def onLeave(room):