Cloned DMOJ

This commit is contained in:
thanhluong 2020-01-21 15:35:58 +09:00
parent f623974b58
commit 49dc9ff10c
513 changed files with 132349 additions and 39 deletions

22
judge/widgets/checkbox.py Normal file
View file

@ -0,0 +1,22 @@
from django import forms
from django.core.exceptions import FieldError
from django.template.loader import get_template
from django.utils.safestring import mark_safe
class CheckboxSelectMultipleWithSelectAll(forms.CheckboxSelectMultiple):
def render(self, name, value, attrs=None, renderer=None):
if 'id' not in attrs:
raise FieldError('id required')
select_all_id = attrs['id'] + '_all'
select_all_name = name + '_all'
original = super(CheckboxSelectMultipleWithSelectAll, self).render(name, value, attrs, renderer)
template = get_template('widgets/select_all.html')
return mark_safe(template.render({
'original_widget': original,
'select_all_id': select_all_id,
'select_all_name': select_all_name,
'all_selected': all(choice[0] in value for choice in self.choices) if value else False,
'empty': not self.choices,
}))