當前位置: 首頁>>代碼示例>>Python>>正文


Python forms.CharField方法代碼示例

本文整理匯總了Python中django.forms.CharField方法的典型用法代碼示例。如果您正苦於以下問題:Python forms.CharField方法的具體用法?Python forms.CharField怎麽用?Python forms.CharField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.forms的用法示例。


在下文中一共展示了forms.CharField方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: new_student

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import CharField [as 別名]
def new_student(request, userid):
    person = get_object_or_404(Person, find_userid_or_emplid(userid))
    semester = Semester.next_starting()
    semesterconfig = SemesterConfig.get_config(request.units, semester)
    student = get_object_or_404(Person, find_userid_or_emplid(userid))
    initial = {'person': student.emplid, 'start_date': semesterconfig.start_date(), 'end_date': semesterconfig.end_date(), 'hours': 80 }
    scholarship_choices, hiring_faculty_choices, unit_choices, project_choices, account_choices, program_choices = \
        _appointment_defaults(request.units, emplid=student.emplid)
    gss = GradStudent.objects.filter(person=student)
    if gss:
        gradstudent = gss[0]
        initial['sin'] = gradstudent.person.sin()
    
    raform = RAForm(initial=initial)
    raform.fields['person'] = forms.CharField(widget=forms.HiddenInput())
    raform.fields['scholarship'].choices = scholarship_choices
    raform.fields['hiring_faculty'].choices = hiring_faculty_choices
    raform.fields['unit'].choices = unit_choices
    raform.fields['project'].choices = project_choices
    raform.fields['account'].choices = account_choices
    raform.fields['program'].choices = program_choices
    return render(request, 'ra/new.html', { 'raform': raform, 'person': person })

#Edit RA Appointment 
開發者ID:sfu-fas,項目名稱:coursys,代碼行數:26,代碼來源:views.py

示例2: make_entry_field

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import CharField [as 別名]
def make_entry_field(self, fieldsubmission=None):
        self.min_length = 0
        self.max_length = 0

        if self.config['min_length'] and int(self.config['min_length']) > 0:
            self.min_length = int(self.config['min_length'])
        if self.config['max_length'] and int(self.config['max_length']) > 0:
            self.max_length = int(self.config['max_length'])

        c = forms.CharField(required=self.config['required'],
            widget=forms.Textarea(attrs={'cols': '60', 'rows': self.config.get('rows', '3')}),
            label=self.config['label'],
            help_text=self.config['help_text'],
            min_length=self.min_length,
            max_length=self.max_length)

        if fieldsubmission:
            c.initial = fieldsubmission.data['info']

        return c 
開發者ID:sfu-fas,項目名稱:coursys,代碼行數:22,代碼來源:text.py

示例3: add_extra_questions

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import CharField [as 別名]
def add_extra_questions(self, event):
        if 'extra_questions' in event.config and len(event.config['extra_questions']) > 0:
            extra_fields = []
            for question in event.config['extra_questions']:
                extra_fields.append(question)
                if 'extra_questions' in self.instance.config and question in self.instance.config['extra_questions']:
                    self.fields[question] = \
                        forms.CharField(label=question,widget=forms.Textarea,
                                        initial=self.instance.config['extra_questions'][question])
                else:
                    self.fields[question] = forms.CharField(label=question, widget=forms.Textarea)
            # We want to move the extra questions *before* the waivers, for neatness' sake.
            field_list = (self._meta.fields)
            # We got the original list of fields, add our extra questions in the spot before two before last.
            field_list[len(field_list) - 2:len(field_list) - 2] = extra_fields
            # Re-order the fields to that list.
            self.order_fields(field_list) 
開發者ID:sfu-fas,項目名稱:coursys,代碼行數:19,代碼來源:forms.py

示例4: test_extra_fields

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import CharField [as 別名]
def test_extra_fields(self):

        class FooModelService(ModelService):
            two = forms.CharField()

            class Meta:
                model = FooModel
                fields = '__all__'

            def process(self):
                pass

        f = FooModelService()

        field_names = list(six.iterkeys(f.fields))
        self.assertEqual(2, len(field_names))
        self.assertEqual('one', field_names[0])
        self.assertEqual('two', field_names[1]) 
開發者ID:mixxorz,項目名稱:django-service-objects,代碼行數:20,代碼來源:test_services.py

示例5: test_model_init_params

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import CharField [as 別名]
def test_model_init_params(self):
        """Model __init__ gets all fields as params."""
        lines = []
        docstrings._add_model_fields_as_params(self.app, SimpleModel, lines)
        self.assertEqual(
            lines,
            [
                ":param id: Id",
                ":type id: AutoField",
                ":param user: User",
                ":type user: ForeignKey to :class:`~django.contrib.auth.models.User`",
                ":param user2: User2",
                ":type user2: ForeignKey to"
                " :class:`~sphinxcontrib_django.tests.test_docstrings.User2`",
                ":param user3: User3",
                ":type user3: ForeignKey to :class:`~django.contrib.auth.models.User`",
                ":param dummy_field: Dummy field",
                ":type dummy_field: CharField",
            ],
        ) 
開發者ID:edoburu,項目名稱:sphinxcontrib-django,代碼行數:22,代碼來源:test_docstrings.py

示例6: test_add_form_fields

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import CharField [as 別名]
def test_add_form_fields(self):
        """Form fields should be mentioned."""
        lines = []
        docstrings._add_form_fields(SimpleForm, lines)
        self.assertEqual(
            lines,
            [
                "**Form fields:**",
                "",
                "* ``user``: User (:class:`~django.forms.models.ModelChoiceField`)",
                "* ``user2``: User2 (:class:`~django.forms.models.ModelChoiceField`)",
                "* ``user3``: User3 (:class:`~django.forms.models.ModelChoiceField`)",
                "* ``test1``: Test1 (:class:`~django.forms.fields.CharField`)",
                "* ``test2``: Test2 (:class:`~django.forms.fields.CharField`)",
            ],
        ) 
開發者ID:edoburu,項目名稱:sphinxcontrib-django,代碼行數:18,代碼來源:test_docstrings.py

示例7: get_field_kind

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import CharField [as 別名]
def get_field_kind(field):
  if field['kind'] == 'string':
    return forms.CharField(max_length=255, required=False)
  elif field['kind'] == 'email':
    return forms.EmailField(max_length=255, required=False)
  elif field['kind'] == 'integer':
    return forms.IntegerField(required=False)
  elif field['kind'] == 'boolean':
    return forms.BooleanField(required=False)
  elif field['kind'] == 'text':
    return forms.CharField(widget=forms.Textarea(), required=False)
  elif field['kind'] == 'choice':
    return forms.ChoiceField(choices=map(lambda c: (c,c), field['choices']))
  elif field['kind'] == 'timezones':
    return TimezoneField()
  elif field['kind'] == 'authentication':
    return SwitchField('user', 'service', required=True)
  elif field['kind'] == 'json':
    return JsonField(required=False)
  elif field['kind'] == 'integer_list':
    return CommaSeparatedIntegerField(required=False)
  elif field['kind'] == 'string_list':
    return CommaSeparatedCharField(required=False)
  else:
    return forms.CharField(max_length=255, required=False) 
開發者ID:google,項目名稱:starthinker,代碼行數:27,代碼來源:forms_json.py

示例8: __init__

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import CharField [as 別名]
def __init__(self, *args, **kwargs):
        fields = []
        defaults = {"widget": self.widget, "max_length": kwargs.pop("max_length", None)}
        self.locales = kwargs.pop("locales", settings.LANGUAGES)
        self.one_required = kwargs.get("required", True)
        require_all_fields = kwargs.pop("require_all_fields", False)
        kwargs["required"] = False
        kwargs["widget"] = kwargs["widget"](
            locales=self.locales, field=self, **kwargs.pop("widget_kwargs", {})
        )
        defaults.update(**kwargs)
        for lngcode, _ in self.locales:
            defaults["label"] = "%s (%s)" % (defaults.get("label"), lngcode)
            field = forms.CharField(**defaults)
            field.locale = lngcode
            fields.append(field)
        super().__init__(fields=fields, require_all_fields=False, *args, **kwargs)
        self.require_all_fields = require_all_fields 
開發者ID:pythonitalia,項目名稱:pycon,代碼行數:20,代碼來源:forms.py

示例9: test_formfield_callback

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import CharField [as 別名]
def test_formfield_callback(self):

        def formfield_for_dbfield(db_field, **kwargs):
            # a particularly stupid formfield_callback that just uses Textarea for everything
            return CharField(widget=Textarea, **kwargs)

        class BandFormWithFFC(ClusterForm):
            formfield_callback = formfield_for_dbfield

            class Meta:
                model = Band
                fields = ['name']

        form = BandFormWithFFC()
        self.assertEqual(Textarea, type(form['name'].field.widget))
        self.assertEqual(Textarea, type(form.formsets['members'].forms[0]['name'].field.widget)) 
開發者ID:wagtail,項目名稱:django-modelcluster,代碼行數:18,代碼來源:test_cluster_form.py

示例10: build_default_field

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import CharField [as 別名]
def build_default_field(self, field, model):
        choices = getattr(field, "choices", None)
        if choices:
            return forms.ChoiceField(
                required=False,
                label=_("Default value"),
                choices=[(None, "-----------")] + list(choices),
            )
        if not (model is Member and field.name == "number"):
            if isinstance(field, models.CharField):
                return forms.CharField(required=False, label=_("Default value"))
            elif isinstance(field, models.DecimalField):
                return forms.DecimalField(
                    required=False,
                    label=_("Default value"),
                    max_digits=field.max_digits,
                    decimal_places=field.decimal_places,
                )
            elif isinstance(field, models.DateField):
                return forms.CharField(required=False, label=_("Other/fixed date")) 
開發者ID:byro,項目名稱:byro,代碼行數:22,代碼來源:registration.py

示例11: __init__

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import CharField [as 別名]
def __init__(self, *args, **kwargs):
        active = kwargs.pop('active', None)
        request = kwargs.pop('request', None)
        super(AdminUserForm, self).__init__(*args, **kwargs)

        if not kwargs.get('instance', None):
            self.fields['is_active'].initial = True

        if active == 'add':
            self.fields['password_1'] = forms.CharField(widget=forms.PasswordInput, label="Password")
            self.fields['password_2'] = forms.CharField(widget=forms.PasswordInput, label="Repeat password")

        if request and not request.user.is_admin:
            self.fields.pop('is_staff', None)
            self.fields.pop('is_admin', None)

        if request and not request.user.is_superuser:
            self.fields.pop('is_superuser') 
開發者ID:BirkbeckCTP,項目名稱:janeway,代碼行數:20,代碼來源:forms.py

示例12: __init__

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import CharField [as 別名]
def __init__(self, *args, **kwargs):
        components = kwargs.get('components')
        del(kwargs['components'])
        super(GsxComponentForm, self).__init__(*args, **kwargs)

        if len(components):
            components = json.loads(components)
            for k, v in components.items():
                self.fields[k] = forms.CharField(label=k, required=True, initial=v) 
開發者ID:fpsw,項目名稱:Servo,代碼行數:11,代碼來源:repairs.py

示例13: __init__

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import CharField [as 別名]
def __init__(self, *args, **kwargs):
        fields = (
            forms.CharField(label=_('place')),
            forms.DecimalField(label=_('Latitude')),
            forms.DecimalField(label=_('Longitude')),
        )
        if 'initial' in kwargs:
            kwargs['initial'] = Places(*kwargs['initial'].split(','))
        self.widget = PlacesWidget()
        super(PlacesField, self).__init__(fields, **kwargs) 
開發者ID:oscarmcm,項目名稱:django-places,代碼行數:12,代碼來源:forms.py

示例14: setUp

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import CharField [as 別名]
def setUp(self):
        class MockForm(forms.Form):
            text_field = forms.CharField()
            date_field = forms.DateField()
        self.form_class = MockForm
        self.form = self.form_class() 
開發者ID:dulacp,項目名稱:django-accounting,代碼行數:8,代碼來源:template_tags_tests.py

示例15: __init__

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import CharField [as 別名]
def __init__(self, event=None, *args, **kwargs):
        super(DonationEntryForm, self).__init__(*args, **kwargs)
        minDonationAmount = (
            event.minimumdonation if event is not None else Decimal('1.00')
        )
        self.fields['amount'] = forms.DecimalField(
            decimal_places=2,
            min_value=minDonationAmount,
            max_value=Decimal('100000'),
            label='Donation Amount (min ${0})'.format(minDonationAmount),
            widget=tracker.widgets.NumberInput(
                attrs={
                    'id': 'iDonationAmount',
                    'min': str(minDonationAmount),
                    'step': '0.01',
                }
            ),
            required=True,
        )
        self.fields['comment'] = forms.CharField(widget=forms.Textarea, required=False)
        self.fields['requestedvisibility'] = forms.ChoiceField(
            initial='CURR',
            choices=models.Donation._meta.get_field('requestedvisibility').choices,
            label='Name Visibility',
        )
        self.fields['requestedalias'] = forms.CharField(
            max_length=32, label='Preferred Alias', required=False
        )
        self.fields['requestedemail'] = forms.EmailField(
            max_length=128, label='Preferred Email', required=False
        )
        self.fields['requestedsolicitemail'] = forms.ChoiceField(
            initial='CURR',
            choices=models.Donation._meta.get_field('requestedsolicitemail').choices,
            label='Charity Email Opt In',
        ) 
開發者ID:GamesDoneQuick,項目名稱:donation-tracker,代碼行數:38,代碼來源:forms.py


注:本文中的django.forms.CharField方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。