我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用django.forms.NumberInput()。
def __init__(self, world, *args, **kwargs): super(Blueprinttradeform, self).__init__(*args, **kwargs) offerchoices = [] blueprints = world.blueprints.all() len(blueprints) amounts = [] for tier in v.shipindices[2:]: query = blueprints.filter(model=tier) if len(query) > 0: for blueprint in query: if blueprint.amount not in amounts: amounts.append(blueprint.amount) offerchoices.append((blueprint.pk, blueprint.__str__())) self.fields['offer'] = forms.ChoiceField(choices=offerchoices) self.fields['offer_amount'] = forms.IntegerField(min_value=1, label="Amount", widget=forms.NumberInput( attrs={'size':'10'})) self.fields['amount'] = forms.IntegerField(min_value=1, widget=forms.NumberInput( attrs={'size':'10'})) self.fields['amount'] = forms.IntegerField(min_value=1, widget=forms.NumberInput( attrs={'size':'10'})) self.fields['amount'] = forms.IntegerField(min_value=1, widget=forms.NumberInput( attrs={'size':'10'}))
def __init__(self, world, *args, **kwargs): super(Aidform, self).__init__(*args, **kwargs) reslist = ( ('budget', 'GEU'), ('warpfuel', 'Warpfuel'), ('duranium', 'Duranium'), ('tritanium', 'Tritanium'), ('adamantium', 'Adamantium') ) choicelist = [] for field in reslist: if world.__dict__[field[0]] > 0: #if resource count > 0 choicelist.append(field) #this gives is hella dynamic forms #django loves tuples, so for resource in choicelist: max_number = world.__dict__[resource[0]] self.fields[resource[0]] = forms.IntegerField(widget=forms.NumberInput( attrs={'size':'10'}), label="%s: " % resource[1], min_value=0, max_value=max_number)
def __init__(self, *args, **kwargs): workshop = kwargs.pop('workshop') discount_code = kwargs.pop('discount_code') super().__init__(*args, **kwargs) self.rate_set = workshop.filter_rates(discount_code) for rate in self.rate_set: self.fields[rate.name] = forms.IntegerField( initial=0, min_value=0, max_value=rate.capacity - rate.ticket_count, widget=forms.NumberInput(attrs={'class': 'form-control'}) ) for rate in workshop.sold_out_rates.all(): self.fields[rate.name] = forms.IntegerField( initial=0, min_value=0, disabled=True, widget=forms.NumberInput(attrs={'class': 'form-control'}) )
def __init__(self, world, *args, **kwargs): super(Shiptradeform, self).__init__(*args, **kwargs) fleets = fleet.objects.filter(Q(sector=world.sector)|Q(sector='hangar'), world=world, controller=world) choices = [] for tier in v.shipindices: for f in fleets: if f.__dict__[tier] > 0: choices.append((tier, tier.replace('_', ' ').capitalize())) break exclusionlist = [] for f in fleets: if f.power() == 0: exclusionlist.append(f.pk) for f in exclusionlist: fleets = fleets.exclude(pk=f) choices = tuple(choices) self.fields['offer'] = forms.ChoiceField(choices=choices, label="Ship type") self.fields['fleet'] = forms.ModelChoiceField(queryset=fleets, label="From") self.fields['offer_amount'] = forms.IntegerField(min_value=1, label="Amount", widget=forms.NumberInput( attrs={'size':'10'})) self.fields['request'] = forms.ChoiceField(choices=RESOURCE_CHOICES) self.fields['request_amount'] = forms.IntegerField(min_value=1, widget=forms.NumberInput( attrs={'size':'10'})) self.fields['amount'] = forms.IntegerField(min_value=1, widget=forms.NumberInput( attrs={'size':'10'})) #request = forms.ChoiceField(choices=RESOURCE_CHOICES) #request_amount = forms.IntegerField(min_value=1) #amount = forms.IntegerField(min_value=1)
def __init__(self, world, *args, **kwargs): super(Resourcetradeform, self).__init__(*args, **kwargs) offerchoices = [] for item in RESOURCE_CHOICES: if world.__dict__[item[0]] > 0: offerchoices.append(item) self.fields['offer'] = forms.ChoiceField(choices=offerchoices) self.fields['offer_amount'] = forms.IntegerField(min_value=1, widget=forms.NumberInput( attrs={'size':'10'}))
def __init__(self, trade, *args, **kwargs): super(Accepttradeform, self).__init__(*args, **kwargs) self.fields['amount'] = forms.IntegerField(min_value=1, max_value=trade.amount, widget=forms.NumberInput( attrs={'size':'2'}))
def base_eval_assignment(request, evalassignment, i, url_action, url_cancel): """ Generate/Postprocess a form to evaluate an assigment """ error = '' EvalquestionFormSet =\ modelformset_factory(Evalquestion, extra=0, fields=['grade', 'comments'], widgets={'grade': forms.NumberInput(attrs={'min': 0, 'max': 2}), 'comments': forms.Textarea(attrs={'cols': 80, 'rows': 10})}) qs = Evalquestion.objects.filter(evalassignment=evalassignment).\ order_by('question') if request.method == 'POST' and (evalassignment.assignment.assignmentype. deadline_grading >= timezone.now() or evalassignment.is_supereval): formset = EvalquestionFormSet(request.POST, queryset=qs) if formset.is_valid(): formset.save() # if evaluation is modified, evaluation grade is reset evalassignment.grade_evaluation = 0 evalassignment.is_questions_graded =\ (None not in [q.grade for q in evalassignment.evalquestion_set.all()]) evalassignment.save() # set evalassignment.grade_assignment if question coeff exist log = tasks.compute_grade_evalassignment(evalassignment.id) logger.error(log) return None else: formset = EvalquestionFormSet(queryset=qs) if evalassignment.assignment.assignmentype.\ deadline_grading < timezone.now(): error = 'Too late to grade or to modify your grading...' assignmentype = evalassignment.assignment.assignmentype if assignmentype.questions_statement: list_questions = [ '%s: %s' % (j + 1, s) for j, s in enumerate(assignmentype.questions_statement)] else: list_questions = [j for j in range(1, assignmentype.nb_questions + 1)] context = {'formset': zip(formset, list_questions), 'formset_management_form': formset.management_form, 'title': assignmentype.title, 'i': i, 'evalassignment_name': 'assign_%s_%s' % (assignmentype.title.replace(" ", ""), i), 'description': assignmentype.description, 'evalassignment_id': evalassignment.id, 'deadline': assignmentype.deadline_grading, 'error': error, 'url_action': url_action, 'url_cancel': url_cancel} return context