-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question status #136
base: master
Are you sure you want to change the base?
Question status #136
Changes from all commits
257f12a
f9c9ce0
72b27f5
67a18f6
29e90ff
b43c17b
c193793
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,15 @@ class Meta: | |
database = db | ||
|
||
|
||
class QuestionStatus(Model): | ||
question = ForeignKeyField(Question) | ||
user = TextField() | ||
status = TextField() | ||
|
||
class Meta: | ||
database = db | ||
|
||
|
||
class ContestProblems(Model): | ||
contest = ForeignKeyField(Contest, backref="questions") | ||
question = ForeignKeyField(Question) | ||
|
@@ -76,7 +85,7 @@ class Meta: | |
|
||
|
||
db.connect() | ||
db.create_tables([User, Session, Submission, ContestProblems, Contest, Question]) | ||
db.create_tables([User, Session, Submission, ContestProblems, Contest, Question, QuestionStatus]) | ||
|
||
|
||
def login_required(function): | ||
|
@@ -236,9 +245,16 @@ def question(code, number): | |
.dicts() | ||
.get() | ||
) | ||
return bottle.template( | ||
"question.html", question_number=number, contest=code, question=statement | ||
) | ||
user = Session.get(Session.token == bottle.request.get_cookie("s_id")).user | ||
question_status = QuestionStatus.select().where((QuestionStatus.question == number) & (QuestionStatus.user == user)) | ||
if question_status.count() == 0: | ||
return bottle.template( | ||
"question.html", question_number=number, contest=code, question=statement, question_status='Not Submitted' | ||
) | ||
else: | ||
return bottle.template( | ||
"question.html", question_number=number, contest=code, question=statement, question_status='Submitted' | ||
) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be better to directly return the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can also avoid the if-else block by using something like:
|
||
|
||
@app.get("/contest/<code>") | ||
|
@@ -399,6 +415,12 @@ def file_upload(code, number): | |
) | ||
except Exception as e: | ||
bottle.abort(500, str(e)) | ||
try: | ||
QuestionStatus.get_or_create( | ||
question=number, user=user, status='Attempted' | ||
) | ||
except Exception as e: | ||
bottle.abort(500, str(e)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be better to merge the two try catch blocks into one. |
||
if not ans: | ||
return "Wrong Answer!!" | ||
else: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add an index for the database here.