def clean_expires_at(self):
# Validate the expiration date
expires_at = self.cleaned_data.get("expires_at", "")
never_expires = self.cleaned_data.get("never_expires", "")
current_tz = timezone.get_current_timezone()
if never_expires:
expires_at = None
self.cleaned_data["expires_at"] = expires_at
if expires_at:
# Check if the expiration date is a past date
if timezone.localtime(timezone.now(), current_tz) > expires_at:
self.add_error('expires_at', _('The date must be on the future.'))
if not expires_at and not never_expires:
self.add_error('expires_at',
_('This field is required, unless box is set to '
'never expire.'))
return expires_at
评论列表
文章目录