def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request', None)
super(MatchCreationForm, self).__init__(*args, **kwargs)
self.helper = BaseFormHelper()
self.champions = []
champions = (models.Champion.objects
.filter(deleted=False, status='ready')
.select_related('author'))
if (settings.STECHEC_FIGHT_ONLY_OWN_CHAMPIONS and not
self.request.user.is_staff):
champions = champions.filter(author=self.request.user)
for i in range(1, settings.STECHEC_NPLAYERS + 1):
f = forms.ModelChoiceField(label="Champion %d" % i,
queryset=champions,
widget=forms.Select(attrs={'class': 'select2'}))
self.fields['champion_%d' % i] = f
self.helper.append_field('champion_%d' % i)
self.champions.append(f)
if settings.STECHEC_USE_MAPS:
self.fields['map'] = forms.ChoiceField(required=True,
widget=MapSelect(attrs={'class': 'mapselect select2'}),
label="Carte utilisée")
all_maps = models.Map.objects.select_related('author').order_by('author__username', 'name')
self.fields['map'].choices = [
('Officielles', [(map.id, map) for map in all_maps if map.official])
] + [
(author, [(map.id, map) for map in maps])
for author, maps in groupby(
(map for map in all_maps if not map.official),
lambda map: map.author
)
]
self.helper.append_field('map')
self.helper.append_submit("Lancer le match")
评论列表
文章目录