def create_comment(seatarrname):
    if request.method == 'POST':
        error = False
        if request.form['UserName'].isspace() or request.form['UserName'] == "":
            error = "Invalid UserName, Please write something for UserName..."

        elif request.form['CommentText'].isspace() or request.form['CommentText'] == "":
            error = "Invalid Comment Text, Please write something for Comment Text..."

        if error != False:
            return render_template("create_comment.html", seatarrname = seatarrname, new_CommentID = request.form['CommentID'],
                                   today = request.form['CommentDatetime'], error = error)

        new_comment = Comment(seatarrname,
                        request.form['CommentID'],
                        request.form['CommentText'],
                        request.form['CommentDatetime'],
                        request.form['UserName'])
        execute_sql(new_comment.create_new_record())

        UserName, SeatArrName, SeatArrSeq, RowNo, ColumnNo, CommentIDs = execute_sql("SELECT * FROM SavedSeatArr WHERE SeatArrName = '{}'".format(seatarrname))[0]
        edit_ssr = SavedSeatArr(UserName, SeatArrName, SeatArrSeq, RowNo, ColumnNo, CommentIDs)
        edit_ssr.set_CommentIDs(request.form['CommentID'])
        execute_sql(edit_ssr.update_record())

        return redirect(url_for("show_seatarr_by_name", seatarrname = seatarrname))
    else:
        # GET
        CommentID = execute_sql("SELECT Max(CommentID) FROM Comment")[0][0]
        new_CommentID = "{:0>6}".format(int(CommentID) + 1)
        today = "{:%Y-%m-%d}".format(date.today())

        return render_template("create_comment.html", seatarrname = seatarrname, new_CommentID = new_CommentID, today = today)
def save_seatarr():
    seatarrname = request.form.get('savedname')
    seatarrseq = request.form.get('SeatingArrangement_lst')
    RowNo = int(request.form.get('RowNo'))
    ColumnNo = int(request.form.get('ColumnNo'))

    if seatarrname != '':
        currentuser = execute_sql('SELECT * FROM CurrentUser')[0][0]
        save = SavedSeatArr(currentuser, seatarrname, seatarrseq.replace("'", '"'), RowNo, ColumnNo)
        execute_sql(save.create_new_record())
    return show_current_seating_arrangement(seatarrseq, RowNo, ColumnNo)
def delete_comment():
    comment_id = request.form.get('delete')
    comment = execute_sql("SELECT * FROM Comment WHERE CommentID = '{}'".format(comment_id))[0]
    #print(comment)
    SeatArrName, CommentID, CommentText, CommentDatetime, UserName = comment
    delete_comment = Comment(SeatArrName, CommentID, CommentText, CommentDatetime, UserName)

    # Update DB
    execute_sql(delete_comment.delete_record())

    UserName, SeatArrName, SeatArrSeq, RowNo, ColumnNo, CommentIDs = execute_sql("SELECT * FROM SavedSeatArr WHERE SeatArrName = '{}'".format(SeatArrName))[0]
    edit_ssr = SavedSeatArr(UserName, SeatArrName, SeatArrSeq, RowNo, ColumnNo, CommentIDs)
    edit_ssr.delete_CommentIDs(comment_id)
    execute_sql(edit_ssr.update_record())

    # Return to mainpage
    return redirect(url_for("show_seatarr_by_name", seatarrname = SeatArrName))
Ejemplo n.º 4
0
def create_table():
    execute_sql(Class.create_table())
    execute_sql(Student.create_table())
    execute_sql(StudentRecords.create_table())
    execute_sql(Subject.create_table())
    execute_sql(SeatingArrangement.create_table())
    execute_sql(User.create_table())
    execute_sql(CurrentUser.create_table())
    execute_sql(SavedSeatArr.create_table())
    execute_sql(Comment.create_table())
    execute_sql(UserInfo.create_table())
def delete_saved_seatingarr():
    delete = request.form.get('delete')
    print('delete', delete)
    seatarrname = delete
    username = execute_sql('SELECT * FROM CurrentUser')[0][0]
    seatarr_details = execute_sql("SELECT * FROM SavedSeatArr WHERE UserName == '{}' AND SeatArrName == '{}'".format(username, seatarrname))[0]
    UserName, SeatArrName , SeatArrSeq, RowNo, ColumnNo, CommentIDs = seatarr_details
    seatarr = SavedSeatArr(UserName,SeatArrName, SeatArrSeq, RowNo, ColumnNo, CommentIDs)

    #Delete SavedSeatArr object
    execute_sql(seatarr.delete_record())

    #Delete Comments linked to the SavedSeatArr
    if CommentIDs != '':
        for commentid in CommentIDs.split(','):
            comment_details = execute_sql('SELECT * FROM Comment WHERE CommentID = "{}"'.format(commentid))[0]
            SeatArrName, CommentID, CommentText, CommentDatetime, UserName = comment_details
            comment = Comment(SeatArrName, CommentID, CommentText, CommentDatetime, UserName)
            execute_sql(comment.delete_record())

    return show_saved_seatingarr()
def show_seatarr_by_name(seatarrname):
    seatarr = execute_sql("SELECT * FROM SavedSeatArr WHERE SeatArrName = '{}'".format(seatarrname))[0]
    #print(seatarr)
    UserName, SeatArrName, SeatArrSeq, RowNo, ColumnNo, CommentIDs = seatarr
    seatarr_oop = SavedSeatArr(UserName, SeatArrName, SeatArrSeq, RowNo, ColumnNo)
    ClassSize = len(SeatArrSeq.split(","))
    comments = execute_sql("SELECT * FROM Comment WHERE SeatArrName = '{}'".format(seatarrname))  # SQL ReadF
    # print(comments)
    comments_oop = list(map(lambda t: Comment(t[0], t[1], t[2], t[3], t[4]), comments))
    # print(comments_oop)
    # process to find SeatingArrangement_lst
    #print(SeatArrSeq)
    seatarrseq = SeatArrSeq.split(',')
    SeatingArrangement_lst = []
    pair = []
    for i in seatarrseq:
        i = i.replace("'", '"').strip('"[]"')
        index = 0
        for x in i:
            if x.isalpha():
                break
            else:
                index += 1
        i = i[index:]
        pair.append(i)
        if len(pair) == 2:
            SeatingArrangement_lst.append(pair)
            pair = []
    if len(pair) == 1:
        SeatingArrangement_lst.append(pair)

    #print("SeatingArrangement_lst",SeatingArrangement_lst)

    count = 0
    temp, result = [], []

    for row in range(RowNo):
        for column in range(ColumnNo):
            if count < ClassSize:
                temp.append(SeatingArrangement_lst[row * ColumnNo + column])
                if len(SeatingArrangement_lst[row * ColumnNo + column]) == 2:
                    count += 2
                if len(SeatingArrangement_lst[row * ColumnNo + column]) == 1:
                    count += 1
        result.append(temp)
        temp = []

    return render_template("show_seatarr_by_name.html", seatarrname=seatarrname, comments=comments_oop, SeatingArrangement_lst = result, RowNoRange = range(RowNo), ColumnNoRange = range(ColumnNo), ColumnNo = ColumnNo, ClassSize = ClassSize)
def edit_saved_seatingarr(): #only can rename
    newname = request.form.get('newname')
    replace = True
    if len(newname.split(',')) == 2:
        newname, seatarrname = newname.split(',')
        replace = False
    else:
        newname, seatarrname, replace = newname.split(',')
        replace = True

    username = execute_sql('SELECT * FROM CurrentUser')[0][0]
    if replace == True: #will have to delete all the comments and seating arrangement of the one that will be replaced
        replace_seatarrs = execute_sql("SELECT * FROM SavedSeatArr WHERE UserName == '{}' AND SeatArrName == '{}'".format(username, newname))[0]
        UserName, SeatArrName, SeatArrSeq, RowNo, ColumnNo, CommentIDs = replace_seatarrs
        replace_seatarr = SavedSeatArr(UserName, SeatArrName, SeatArrSeq, RowNo, ColumnNo, CommentIDs)
        #delete SavedSeatArr obj
        execute_sql(replace_seatarr.delete_record())
        #delete_SavedSeatArr_obj
        for commentid in CommentIDs.split(','):
            replace_comments = execute_sql("SELECT * FROM Comment WHERE CommentID == '{}'".format(commentid))[0]
            SeatArrName, CommentID, CommentText, CommentDatetime, UserName = replace_comments
            replace_comment = Comment(SeatArrName, CommentID, CommentText, CommentDatetime, UserName)
            execute_sql(replace_comment.delete_record())

    seatarr_details = execute_sql("SELECT * FROM SavedSeatArr WHERE UserName == '{}' AND SeatArrName == '{}'".format(username, seatarrname))[0]
    #print(seatarr_details)
    UserName, SeatArrName , SeatArrSeq, RowNo, ColumnNo, CommentIDs = seatarr_details
    seatarr = SavedSeatArr(UserName,SeatArrName, SeatArrSeq, RowNo, ColumnNo, CommentIDs)
    seatarr.set_SeatArrName(newname)
    #Update SavedSeatArr
    execute_sql('''UPDATE SavedSeatArr SET\nUserName = '******', SeatArrName = "{}", SeatArrSeq = '{}', RowNo = '{}', ColumnNo = '{}', CommentIDs = '{}'\nWHERE \nUserName = '******' and SeatArrName = "{}"'''.format(UserName, newname, SeatArrSeq, RowNo, ColumnNo, CommentIDs, UserName, seatarrname))

    #Update Comment
    if CommentIDs != '':
        for commentid in CommentIDs.split(','):
            print(execute_sql('SELECT * FROM Comment WHERE CommentID = "{}"'.format(commentid)))
            comment_details = execute_sql('SELECT * FROM Comment WHERE CommentID = "{}"'.format(commentid))[0]
            SeatArrName, CommentID, CommentText, CommentDatetime, UserName = comment_details
            comment = Comment(SeatArrName, CommentID, CommentText, CommentDatetime, UserName)
            comment.set_SeatArrName(newname)
            execute_sql(comment.update_record())

    return show_saved_seatingarr()
Ejemplo n.º 8
0
def read_file(file_name):
    with open(file_name) as f:
        line = f.readline()
        line = f.readline()
        while line:
            lst = line.split(';')
            ClassName = lst[0]
            TotalStudents = lst[1]
            StudentRegNo = lst[2]
            StudentName = lst[3]
            StudentGender = lst[4]
            StudentSubjectCombi = lst[5]
            SubjectName = lst[6]
            Description = lst[7]
            SubjectGrade = lst[8]
            SeatArrName = lst[9]
            CommentIDs = lst[10]
            CommentID = lst[11]
            CommentText = lst[12]
            CommentDatetime = lst[13][:-1]  #because of "\n" at the back
            c1 = Class(ClassName, TotalStudents)
            st1 = Student(StudentName,
                          StudentRegNo,
                          ClassName,
                          StudentSubjectCombi,
                          StudentGender,
                          AllSubjectGrades='')
            sr1 = StudentRecords(StudentName, SubjectGrade, SubjectName)
            sb1 = Subject(SubjectName, Description)
            sa1 = SeatingArrangement(StudentName,
                                     CannotSeatNextTo='',
                                     SeatInFront=False,
                                     WeakSubjects='',
                                     StrongSubjects='',
                                     ClassLst='',
                                     SeatByGrades='',
                                     RowNo=0,
                                     ColumnNo=0)
            user1 = User(UserName='******', Password='')
            currentuser1 = CurrentUser(UserName='******')
            comment = Comment(SeatArrName,
                              int(CommentID),
                              CommentText,
                              CommentDatetime,
                              UserName="******")
            ssr1 = SavedSeatArr(UserName='******',
                                SeatArrName=SeatArrName,
                                SeatArrSeq="",
                                RowNo=0,
                                ColumnNo=0,
                                CommentIDs=CommentIDs)
            #TODO Username does not have to be class specific as CP will add in student info by themselves, most important is to do a back-end  validation to check if username is taken alr or not
            #TODO set user to an example user first, by right upon creating an account on login, user info will be created and added into User table
            #TODO set current user to nth by default until someone logins, then current user will become that username, must always reset current user
            execute_sql(c1.create_new_record())
            execute_sql(st1.create_new_record())
            execute_sql(sr1.create_new_record())
            execute_sql(sb1.create_new_record())
            execute_sql(sa1.create_new_record())
            execute_sql(user1.create_new_record())
            execute_sql(currentuser1.create_new_record())
            execute_sql(comment.create_new_record())
            execute_sql(ssr1.create_new_record())
            line = f.readline()
    f.close()
def search_filter():
    seatarr = execute_sql('SELECT * FROM SavedSeatArr')  # SQL Read
    # print(seatarr)
    seatarr_oop = list(map(lambda t: SavedSeatArr(t[0], t[1], t[2], t[3], t[4], t[5]), seatarr))
    # print(seatarr_oop)
    return render_template("search_filter.html", seatarr=seatarr_oop)