Skip to content

Commit

Permalink
Clean up i18n in __str__
Browse files Browse the repository at this point in the history
  • Loading branch information
int-y1 committed Apr 30, 2022
1 parent 8b29591 commit e910ab7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion judge/models/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def get_absolute_url(self):
return '%s#comment-%d' % (self.link, self.id)

def __str__(self):
return '%(page)s by %(user)s' % {'page': self.page, 'user': self.author.user.username}
return _('%(comment_id)s by %(user)s') % {'comment_id': self.page, 'user': self.author.user.username}

# Only use this when queried with
# .prefetch_related(Prefetch('votes', queryset=CommentVote.objects.filter(voter_id=profile_id)))
Expand Down
10 changes: 6 additions & 4 deletions judge/models/contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.urls import reverse
from django.utils import timezone
from django.utils.functional import cached_property
from django.utils.translation import gettext, gettext_lazy as _
from django.utils.translation import gettext_lazy as _
from jsonfield import JSONField
from lupa import LuaRuntime
from moss import MOSS_LANG_C, MOSS_LANG_CC, MOSS_LANG_JAVA, MOSS_LANG_PYTHON
Expand Down Expand Up @@ -565,10 +565,12 @@ def time_remaining(self):

def __str__(self):
if self.spectate:
return gettext('%s spectating in %s') % (self.user.username, self.contest.name)
return _('%(user)s spectating in %(contest)s') % {'user': self.user.username, 'contest': self.contest.name}
if self.virtual:
return gettext('%s in %s, v%d') % (self.user.username, self.contest.name, self.virtual)
return gettext('%s in %s') % (self.user.username, self.contest.name)
return _('%(user)s in %(contest)s, v%(id)d') % {
'user': self.user.username, 'contest': self.contest.name, 'id': self.virtual
}
return _('%(user)s in %(contest)s') % {'user': self.user.username, 'contest': self.contest.name}

class Meta:
verbose_name = _('contest participation')
Expand Down
4 changes: 2 additions & 2 deletions judge/models/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def get_visible_classes(cls, user):
return cls.objects.filter(contest__organizations__admins=user.profile) | cls.objects.filter(admins=user.profile)

def __str__(self):
return f'{self.name} in {self.organization.name}'
return _('%(class)s in %(organization)s') % {'class': self.name, 'organization': self.organization.name}

def get_absolute_url(self):
return reverse('class_home', args=self._url_args)
Expand Down Expand Up @@ -345,7 +345,7 @@ def webauthn_user(self):
)

def __str__(self):
return f'WebAuthn credential: {self.name}'
return _('WebAuthn credential: %(name)s') % {'name': self.name}

class Meta:
verbose_name = _('WebAuthn credential')
Expand Down
6 changes: 4 additions & 2 deletions judge/models/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ def contest_key(self):
return self.contest_object.key

def __str__(self):
return 'Submission %d of %s by %s' % (self.id, self.problem, self.user.user.username)
return _('Submission %(id)d of %(problem)s by %(user)s') % {
'id': self.id, 'problem': self.problem, 'user': self.user.user.username
}

def get_absolute_url(self):
return reverse('submission_status', args=(self.id,))
Expand Down Expand Up @@ -238,7 +240,7 @@ class SubmissionSource(models.Model):
source = models.TextField(verbose_name=_('source code'), max_length=65536)

def __str__(self):
return 'Source of %s' % self.submission
return _('Source of submission %(id)d') % {'id': self.submission.id}

class Meta:
verbose_name = _('submission source')
Expand Down

0 comments on commit e910ab7

Please # to comment.