Source code for oioioi.ipauthsync.models
from django.core.exceptions import ValidationError
from django.db import models
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from oioioi.base.utils.deps import check_django_app_dependencies
from oioioi.contests.date_registration import date_registry
from oioioi.contests.models import Contest
from oioioi.ipdnsauth.models import IpToUser
from oioioi.participants.models import Region
check_django_app_dependencies(__name__, ['oioioi.participants', 'oioioi.ipdnsauth'])
[docs]class IpAuthSyncConfigManager(models.Manager):
[docs] def get_active(self, timestamp):
return self.get_queryset().filter(
start_date__lte=timestamp, end_date__gte=timestamp, enabled=True
)
@date_registry.register(
'start_date', name_generator=(lambda obj: _("Enable IP authentication sync"))
)
@date_registry.register(
'end_date', name_generator=(lambda obj: _("Disable IP authentication sync"))
)
[docs]class IpAuthSyncConfig(models.Model):
[docs] def __str__(self):
return u'%s (%s): %s - %s' % (
self.contest,
u'enabled' if self.enabled else u'disabled',
self.start_date,
self.end_date,
)
[docs] def clean(self):
if self.start_date > self.end_date:
raise ValidationError(_("The start date should precede the end date"))