PyJaipur / PyJudge

Simple Programming Contest hosting software
MIT License
17 stars 29 forks source link

Database #102

Closed theSage21 closed 5 years ago

theSage21 commented 5 years ago

Our system needs a database system since if we restart the server right now, all attempt information is lost. The simplest system is to use the shelve system provided by python. This would store the data you update on the disk so that the server can be restarted and no information is lost.

You would need to store whatever gets lost whenever the server is restarted, for example the attempt history.

rishabhKalakoti commented 5 years ago

If i write the following code,

    submission_record = shelve.open("submission_record.db")
    if not u_name in submission_record.keys():
        submission_record[u_name] = list()
    submission_record[u_name].append(
        Submission(question=number, time=time, output=uploaded, is_correct=ans)
    )
    print(len(submission_record[u_name]))
    submission_record.close()

0 is printed on the terminal when the function executes. It does not append to the list. But u_name is being added to keys.


Solution: https://stackoverflow.com/questions/30149628/python-append-to-list-owned-by-an-instance-stored-in-shelved-dictionary