-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
201ccf7
commit df78858
Showing
16 changed files
with
852 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
from django.contrib import admin | ||
|
||
|
||
class VoteAdmin(admin.ModelAdmin): | ||
list_display = ('points', 'voter', 'problem', 'note') | ||
search_fields = ('voter', 'problem') | ||
|
||
# if the user has edit all problem or edit own problem perms, so curators authors and superusers | ||
def has_change_permission(self, request, obj=None): | ||
if not request.user.has_perm('judge.edit_own_problem'): | ||
return False | ||
if request.user.has_perm('judge.edit_all_problem') or obj is None: | ||
return True | ||
return obj.problem.is_editor(request.profile) | ||
|
||
def lookup_allowed(self, key, value): | ||
return super(VoteAdmin, self).lookup_allowed(key, value) or key in ('problem__code',) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Generated by Django 2.2.19 on 2021-04-19 01:20 | ||
|
||
import django.core.validators | ||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('judge', '0115_contest_scoreboard_visibility'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='profile', | ||
name='is_banned_from_voting_problem_points', | ||
field=models.BooleanField(default=False, help_text="User will not be able to vote on problems' points values.", verbose_name='banned from voting'), | ||
), | ||
migrations.CreateModel( | ||
name='ProblemPointsVote', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('points', models.FloatField(help_text='The amount of points you think this problem deserves.', validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(50)], verbose_name='points')), | ||
('note', models.TextField(blank=True, default=' ', help_text='Justification for problem points value.', max_length=2048, verbose_name='note')), | ||
('problem', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='problem_points_votes', to='judge.Problem')), | ||
('voter', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='problem_points_votes', to='judge.Profile')), | ||
], | ||
options={ | ||
'verbose_name': 'Vote', | ||
'verbose_name_plural': 'Votes', | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from django.conf import settings | ||
from django.core.validators import MaxValueValidator, MinValueValidator | ||
from django.db import models | ||
from django.db.models import CASCADE | ||
from django.utils.translation import gettext as _ | ||
|
||
from judge.models.problem import Problem | ||
from judge.models.profile import Profile | ||
|
||
|
||
class ProblemPointsVote(models.Model): | ||
points = models.FloatField( # How much this vote is worth | ||
verbose_name=_('points'), | ||
help_text=_('The amount of points you think this problem deserves.'), | ||
validators=[ | ||
MinValueValidator(settings.DMOJ_PROBLEM_MIN_USER_POINTS_VOTE), | ||
MaxValueValidator(settings.DMOJ_PROBLEM_MAX_USER_POINTS_VOTE), | ||
], | ||
) | ||
# who voted | ||
voter = models.ForeignKey(Profile, related_name='problem_points_votes', on_delete=CASCADE, db_index=True) | ||
# what problem is this vote for | ||
problem = models.ForeignKey(Problem, related_name='problem_points_votes', on_delete=CASCADE, db_index=True) | ||
note = models.TextField( # note to go along with vote | ||
verbose_name=_('note'), | ||
help_text=_('Justification for problem points value.'), | ||
max_length=2048, | ||
blank=True, | ||
default=' ', | ||
) | ||
|
||
# The name that shows up on the sidebar instead of the model class name | ||
class Meta: | ||
verbose_name = _('Vote') | ||
verbose_name_plural = _('Votes') | ||
|
||
def __str__(self): | ||
return f'{self.voter}: {self.points} for {self.problem.code} - "{self.note}"' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.