-
Notifications
You must be signed in to change notification settings - Fork 391
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add problem points vote functionality #1645
Conversation
Codecov ReportBase: 46.44% // Head: 46.64% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #1645 +/- ##
==========================================
+ Coverage 46.44% 46.64% +0.20%
==========================================
Files 236 237 +1
Lines 13072 13229 +157
==========================================
+ Hits 6071 6171 +100
- Misses 7001 7058 +57
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Can you please read this tutorial on how to rebase and this one on rewriting git history so we can review the relevant changes without having to cross-reference what we already have in master. |
df78858
to
5fdf25b
Compare
I've squashed the commits and fixed the rebase issue, this pull request should be ready for review. |
Could you upload screenshots for how this looks on both desktop and mobile? |
572a1e1
to
047ea40
Compare
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.
Also Mostly just nits, based the existing code I've looked at:
- Please leave a space after your
//
comments in JS. - Capitalize the first letter of your comments as you would a sentence.
- If it's a full sentence, add a period.
- There's quite a few unnecessary comments, I've pointed out a few, please follow through with the rest.
- Configure your editor to add newlines to the end of your files (you can see it as the ⛔ on GitHub)
- Put commas between function parameters in JS.
2750beb
to
85ef913
Compare
We updated the request, it should be ready for another round of code review. |
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.
Otherwise LGTM. Could you post some screenshots?
3931912
to
9e862fc
Compare
42c261f
to
3636788
Compare
margin-right: 0.5em; | ||
} | ||
|
||
#problem-vote-form textarea { |
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.
Is there a reason we have both an id and a class for problem-vote-form
?
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.
Lack of imagination. It's probably ok to rename:
class="problem-vote-form"
->class="problem-vote-container"
.problem-vote-form
->.problem-vote-container
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.
done, .problem-vote-form
was renamed to .problem-vote-container
judge/admin/problem.py
Outdated
|
||
|
||
class ProblemPointsVoteAdmin(admin.ModelAdmin): | ||
list_display = ('points', 'voter', 'problem', 'vote_time') |
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.
Make problem
link to the problem. See CommentAdmin.linked_page
for a code example.
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.
done
resources/problem-vote.js
Outdated
}, | ||
error: function (data) { | ||
if (data.message !== undefined) { | ||
alert(interpolate(gettext('Unable to cast vote: %s'), [data.message])); |
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.
data.message !== undefined
-> 'message' in data.responseJSON
(and I think you can move var errors
upwards to simplify things)
[data.message]
-> [data.responseJSON.message]
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.
done
resources/problem-vote.js
Outdated
$.featherlight.close(); | ||
}, | ||
error: function (data) { | ||
alert(interpolate(gettext('Unable to delete vote: %s'), [data.message])); |
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.
data.message
-> data.responseJSON.message
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.
Is this necessary? The earlier code didn't use responseJSON
when looking up points
.
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.
Yes, the error path no longer alerts. I think it's because DeleteProblemVote.post
returns a JsonResponse
.
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.
done
resources/problem-vote.js
Outdated
|
||
var errors = data.responseJSON; | ||
$('#points-error').text(typeof errors === 'object' && 'points' in errors ? errors.points[0] : ''); | ||
$('#note-error').text(typeof errors === 'object' && 'note' in errors ? errors.note[0] : ''); |
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.
I guess typeof errors === 'object'
is always true, so this condition can be simplified.
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.
done
2be6f9c
to
9d0a910
Compare
All previous comments have been addressed. |
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('judge', '0132_no_self_vote'), |
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.
Please update
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.
done
@@ -434,6 +447,32 @@ def save(self, *args, **kwargs): | |||
|
|||
save.alters_data = True | |||
|
|||
def is_solved_by(self, user): | |||
# Return true if a full AC submission to the problem from the user exists. | |||
return self.submission_set.filter(user=user.profile, result='AC', points__gte=F('problem__points')).exists() |
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.
This is going to have issues with 9999/10000 in a 5 point problem or something, but I couldn't be bothered to care.
def can_view(self): | ||
return self >= VotePermission.VIEW | ||
|
||
def can_vote(self): | ||
return self >= VotePermission.VOTE |
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.
If I cared I'd ask for this to be @property
, but this has dragged on for long enough.
href="{% url 'admin:judge_submission_changelist' %}?problem__code={{ original.code }}"> | ||
<i class="fa fa-lg fa-search-plus"></i> | ||
<span class="text">{% trans "View submissions" %}</span> | ||
<span class="text">{{ _('View submissions') }}</span> |
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.
Why this change? I can't even remember if this is a Django template or Jinja2.
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.
Consistency with the rest of /templates
. The only uses of {% trans "Foo" %}
are in /templates/admin
.
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.
Yeah that would be because templates/admin
are rendered as Django and not Jinja2. I am surprised this even works.
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.
It's yolo time
No description provided.