Ejemplo n.º 1
0
class DeletePmachineForm(ModelForm):
    ip = forms.GenericIPAddressField(
        label=u'IP地址',
        widget=BootstrapUneditableInput(),
    )
    cpu = forms.CharField(
        label=u'CPU核心数',
        widget=BootstrapUneditableInput(),
    )
    disk = forms.CharField(
        label=u'硬盘大小',
        widget=BootstrapUneditableInput(),
    )
    memory = forms.CharField(
        label=u'内存大小',
        widget=BootstrapUneditableInput(),
    )
    maxvm = forms.IntegerField(
        label=u'可产虚机数',
        widget=BootstrapUneditableInput(),
    )

    class Meta:
        model = Pmachine
        fields = ['ip', 'cpu', 'disk', 'memory', 'maxvm']
Ejemplo n.º 2
0
class DeleteVimageForm(ModelForm):
    img_url = forms.CharField(
        required=True,
        label=u'虚机镜像地址(http)',
        error_messages={'required': u'请输入虚机镜像的下载地址'},
        widget=BootstrapUneditableInput(),
    )

    class Meta:
        model = Vimage
        fields = ['img_url']
Ejemplo n.º 3
0
def test_form(request):
    layout = request.GET.get('layout')
    if not layout:
        layout = 'vertical'
    if request.method == 'POST':
        form = TestForm(request.POST)
        form.is_valid()
    else:
        form = TestForm()
    form.fields['title'].widget = BootstrapUneditableInput()
    return render_to_response('form.html', RequestContext(request, {
        'form': form,
        'layout': layout,
    }))
Ejemplo n.º 4
0
def home_form(request):
    messages.success(request, 'Successfully loaded a form?')
    layout = request.GET.get('layout')
    if not layout:
        layout = 'vertical'
    if request.method == 'POST':
        form = HomeForm(request.POST)
        form.is_valid()
    else:
        form = HomeForm()
    form.fields['title'].widget = BootstrapUneditableInput()
    return render_to_response(
        'form.html', RequestContext(request, {
            'form': form,
            'layout': layout,
        }))
Ejemplo n.º 5
0
class TestForm(forms.Form):
    date = forms.DateField(widget=BootstrapDateInput(), )
    title = forms.CharField(
        max_length=100,
        help_text=u'This is the standard text input',
    )
    disabled = forms.CharField(
        max_length=100,
        help_text=u'I am disabled',
        widget=forms.TextInput(attrs={
            'disabled': 'disabled',
            'placeholder': 'I am disabled',
        }))
    uneditable = forms.CharField(
        max_length=100,
        help_text=u'I am uneditable and you cannot enable me with JS',
        initial=u'Uneditable',
        widget=BootstrapUneditableInput())
    content = forms.ChoiceField(
        choices=(
            ("text", "Plain text"),
            ("html", "HTML"),
        ),
        help_text=u'Pick your choice',
    )
    email = forms.EmailField()
    like = forms.BooleanField(required=False)
    fruits = forms.MultipleChoiceField(
        widget=forms.CheckboxSelectMultiple,
        choices=(
            ("apple", "Apple"),
            ("pear", "Pear"),
        ),
        help_text=u'As you can see, multiple checkboxes work too',
    )
    veggies = forms.MultipleChoiceField(
        widget=forms.CheckboxSelectMultiple(attrs={
            'inline': True,
        }),
        choices=(
            ("broccoli", "Broccoli"),
            ("carrots", "Carrots"),
            ("turnips", "Turnips"),
        ),
        help_text=u'And can be inline',
    )
    color = forms.ChoiceField(
        widget=forms.RadioSelect,
        choices=(
            ("#f00", "red"),
            ("#0f0", "green"),
            ("#00f", "blue"),
        ),
        help_text=u'And we have <i>radiosets</i>',
    )
    prepended = forms.CharField(
        max_length=100,
        help_text=u'I am prepended by a P',
        widget=BootstrapTextInput(prepend='P'),
    )

    def clean(self):
        cleaned_data = super(TestForm, self).clean()
        raise forms.ValidationError(
            "This error was added to show the non field errors styling.")
        return cleaned_data