Skip to content
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

Add problem points vote functionality #1645

Merged
merged 5 commits into from
Dec 20, 2022
Merged

Conversation

lakshy-gupta
Copy link

No description provided.

@codecov-commenter
Copy link

codecov-commenter commented Apr 19, 2021

Codecov Report

Base: 46.44% // Head: 46.64% // Increases project coverage by +0.20% 🎉

Coverage data is based on head (2506f09) compared to base (97f2c45).
Patch coverage: 66.27% of modified lines in pull request are covered.

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     
Impacted Files Coverage Δ
dmoj/urls.py 89.47% <ø> (ø)
judge/admin/profile.py 62.22% <ø> (ø)
judge/models/__init__.py 100.00% <ø> (ø)
judge/models/submission.py 88.81% <ø> (ø)
judge/views/problem.py 24.14% <26.98%> (-0.26%) ⬇️
judge/admin/problem.py 56.64% <61.90%> (+0.15%) ⬆️
judge/models/problem.py 90.85% <91.17%> (+0.03%) ⬆️
dmoj/settings.py 97.72% <100.00%> (+0.03%) ⬆️
judge/admin/__init__.py 100.00% <100.00%> (ø)
judge/forms.py 46.03% <100.00%> (+1.46%) ⬆️
... and 3 more

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.
📢 Do you have feedback about the report comment? Let us know in this issue.

@kiritofeng
Copy link
Member

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.

@lakshy-gupta
Copy link
Author

I've squashed the commits and fixed the rebase issue, this pull request should be ready for review.

judge/views/problem.py Outdated Show resolved Hide resolved
judge/views/problem.py Outdated Show resolved Hide resolved
judge/views/problem.py Outdated Show resolved Hide resolved
judge/views/problem.py Outdated Show resolved Hide resolved
@ehhthing
Copy link
Member

Could you upload screenshots for how this looks on both desktop and mobile?

judge/admin/vote.py Outdated Show resolved Hide resolved
judge/models/problem_points_vote.py Outdated Show resolved Hide resolved
judge/models/problem_points_vote.py Outdated Show resolved Hide resolved
judge/models/problem_points_vote.py Outdated Show resolved Hide resolved
judge/models/profile.py Outdated Show resolved Hide resolved
templates/problem/problem.html Outdated Show resolved Hide resolved
judge/admin/__init__.py Outdated Show resolved Hide resolved
judge/views/problem.py Outdated Show resolved Hide resolved
judge/views/problem.py Outdated Show resolved Hide resolved
templates/voting-stats.html Outdated Show resolved Hide resolved
judge/models/profile.py Outdated Show resolved Hide resolved
judge/views/problem.py Outdated Show resolved Hide resolved
judge/views/problem.py Outdated Show resolved Hide resolved
templates/lightbox.html Outdated Show resolved Hide resolved
templates/problem/problem.html Outdated Show resolved Hide resolved
judge/admin/vote.py Outdated Show resolved Hide resolved
judge/admin/vote.py Outdated Show resolved Hide resolved
judge/admin/vote.py Outdated Show resolved Hide resolved
judge/views/problem.py Outdated Show resolved Hide resolved
templates/voting-stats.html Outdated Show resolved Hide resolved
templates/voting-stats.html Outdated Show resolved Hide resolved
Copy link
Contributor

@fluix-dev fluix-dev left a 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.

judge/views/problem.py Outdated Show resolved Hide resolved
judge/models/problem.py Outdated Show resolved Hide resolved
judge/models/problem.py Outdated Show resolved Hide resolved
judge/models/problem.py Outdated Show resolved Hide resolved
judge/models/problem.py Outdated Show resolved Hide resolved
templates/problem/voting-controls.html Outdated Show resolved Hide resolved
templates/problem/voting-controls.html Outdated Show resolved Hide resolved
templates/problem/voting-stats.html Outdated Show resolved Hide resolved
templates/problem/voting-stats.html Outdated Show resolved Hide resolved
judge/admin/vote.py Outdated Show resolved Hide resolved
judge/models/problem.py Outdated Show resolved Hide resolved
judge/models/problem.py Outdated Show resolved Hide resolved
@lakshy-gupta lakshy-gupta force-pushed the master branch 3 times, most recently from 2750beb to 85ef913 Compare July 27, 2021 19:32
@lakshy-gupta
Copy link
Author

We updated the request, it should be ready for another round of code review.

dmoj/urls.py Outdated Show resolved Hide resolved
judge/admin/vote.py Outdated Show resolved Hide resolved
judge/models/problem.py Outdated Show resolved Hide resolved
judge/models/problem.py Outdated Show resolved Hide resolved
judge/models/problem.py Outdated Show resolved Hide resolved
templates/problem/voting-stats.html Outdated Show resolved Hide resolved
templates/problem/voting-controls.html Outdated Show resolved Hide resolved
templates/problem/voting-stats.html Outdated Show resolved Hide resolved
templates/problem/voting-stats.html Outdated Show resolved Hide resolved
templates/problem/voting-stats.html Outdated Show resolved Hide resolved
templates/problem/voting-controls.html Outdated Show resolved Hide resolved
templates/problem/voting-controls.html Outdated Show resolved Hide resolved
Copy link
Member

@Ninjaclasher Ninjaclasher left a 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?

judge/migrations/0122_add_voting_functionality.py Outdated Show resolved Hide resolved
judge/views/problem.py Outdated Show resolved Hide resolved
judge/views/problem.py Outdated Show resolved Hide resolved
judge/views/problem.py Outdated Show resolved Hide resolved
templates/admin/judge/problem/change_form.html Outdated Show resolved Hide resolved
templates/problem/voting-controls.html Outdated Show resolved Hide resolved
templates/problem/voting-stats.html Outdated Show resolved Hide resolved
judge/models/problem.py Outdated Show resolved Hide resolved
judge/views/problem.py Outdated Show resolved Hide resolved
margin-right: 0.5em;
}

#problem-vote-form textarea {
Copy link
Member

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?

Copy link
Contributor

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

Copy link
Contributor

@int-y1 int-y1 Dec 11, 2022

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



class ProblemPointsVoteAdmin(admin.ModelAdmin):
list_display = ('points', 'voter', 'problem', 'vote_time')
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

},
error: function (data) {
if (data.message !== undefined) {
alert(interpolate(gettext('Unable to cast vote: %s'), [data.message]));
Copy link
Contributor

@int-y1 int-y1 Oct 28, 2022

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]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

$.featherlight.close();
},
error: function (data) {
alert(interpolate(gettext('Unable to delete vote: %s'), [data.message]));
Copy link
Contributor

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

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


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] : '');
Copy link
Contributor

@int-y1 int-y1 Oct 28, 2022

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@int-y1
Copy link
Contributor

int-y1 commented Dec 12, 2022

All previous comments have been addressed.

int-y1 added a commit to int-y1/online-judge that referenced this pull request Dec 19, 2022
class Migration(migrations.Migration):

dependencies = [
('judge', '0132_no_self_vote'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update

Copy link
Contributor

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()
Copy link
Member

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.

Comment on lines +102 to +106
def can_view(self):
return self >= VotePermission.VIEW

def can_vote(self):
return self >= VotePermission.VOTE
Copy link
Member

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>
Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Member

@kiritofeng kiritofeng left a 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

@quantum5 quantum5 merged commit 7f62071 into DMOJ:master Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.