def clean(self, *args, **kwargs):
super(NewPrivateMessageForm, self).clean(*args, **kwargs)
try:
last_pm = (PrivateMessage.objects
.filter(sender=self._author)
.order_by('-created'))[0]
except IndexError:
return self.cleaned_data
time_since = (timezone.now() - last_pm.created).total_seconds()
flood_control = utils.get_config('private_message_flood_control')
if time_since < flood_control:
raise ValidationError(
('Flood control has blocked this message from being sent, '
'you can send another PM in %(ttp)d seconds.'),
params={'ttp': flood_control - time_since},
code='FLOOD_CONTROL')
return self.cleaned_data
评论列表
文章目录