当前位置: 首页>>代码示例>>Python>>正文


Python Select.render方法代码示例

本文整理汇总了Python中django.forms.widgets.Select.render方法的典型用法代码示例。如果您正苦于以下问题:Python Select.render方法的具体用法?Python Select.render怎么用?Python Select.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.forms.widgets.Select的用法示例。


在下文中一共展示了Select.render方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render

# 需要导入模块: from django.forms.widgets import Select [as 别名]
# 或者: from django.forms.widgets.Select import render [as 别名]
 def render(self, name, value, attrs=None):
     if value is None: value = ''
     attrs = attrs or {}
     if attrs:
         self.attrs.update(attrs)
     
     output = []
     uf_val = ''
     uf_choices = [('','Estado')]+[(uf.pk,uf.uf) for uf in UF.objects.order_by('uf')]
     uf_select = Select(choices=uf_choices)
     municipio_select = Select(choices=(('','Cidades'),))
     
     if value:
         try:
             municipio = Municipio.objects.get(pk=value)
             uf_val = municipio.uf
             mun_choices = [(m.pk, m.nome) for m in Municipio.objects.filter(uf=uf_val).order_by('nome')]
             municipio_select = Select(choices=[('','Cidades')]+mun_choices)
         except Municipio.DoesNotExist:
             pass
     uf_attrs = self.attrs.copy()
     uf_attrs.update({"id":'%s_uf' % name, "onchange":"changeUF(this);"})
     select_html = uf_select.render('%s_uf' % name, uf_val, attrs=uf_attrs)
     required = False
     if 'class' in self.attrs:
         required = self.attrs['class'] == 'required'
     output.append(u'<label>*Local</label><div class="estado">%s%s</div>' % (required and ' class="required"' or '', select_html))#background:url(/media/images/flecha.gif) right no-repeat
     
     munic_attrs = self.attrs.copy()
     munic_attrs['style']="width:230px;"
     select_html = municipio_select.render(name, value, munic_attrs)
     output.append(u'<div class="cidade">%s%s</div>' % (required and ' class="required"' or '', select_html))
     return mark_safe(u'\n'.join(output))
开发者ID:veiodruida,项目名称:sonorah,代码行数:35,代码来源:widgets.py

示例2: render

# 需要导入模块: from django.forms.widgets import Select [as 别名]
# 或者: from django.forms.widgets.Select import render [as 别名]
    def render(self, name, value, attrs=None):
        try:
            y_val, m_val = value.year, value.month
        except AttributeError:
            y_val = m_val = None
            if isinstance(value, str):
                match = RE_DATE.match(value)
                if match:
                    y_val, m_val, d_val = [int(v) for v in match.groups()]

        output = []

        if 'id' in self.attrs:
            id_ = self.attrs['id']
        else:
            id_ = 'id_%s' % name

        month_choices = list(MONTHS.items())
        if not (self.required and value):
            month_choices.append(self.none_value_month)
        month_choices.sort()
        local_attrs = self.build_attrs(id=self.month_field % id_)
        s = Select(choices=month_choices)
        select_html = s.render(self.month_field % name, m_val, local_attrs)
        output.append('<div class="date-select">' + select_html + '</div>')

        year_choices = [(i, i) for i in self.years]
        if not (self.required and value):
            year_choices.insert(0, self.none_value_year)
        local_attrs['id'] = self.year_field % id_
        s = Select(choices=year_choices)
        select_html = s.render(self.year_field % name, y_val, local_attrs)
        output.append('<div class="date-select">' + select_html + '</div>')

        return mark_safe(u'\n'.join(output))
开发者ID:lm-tools,项目名称:situational,代码行数:37,代码来源:widgets.py

示例3: render

# 需要导入模块: from django.forms.widgets import Select [as 别名]
# 或者: from django.forms.widgets.Select import render [as 别名]
	def render(self, name, value, attrs=None):
		try:
			hour_val, minute_val = value.hour, value.minute
		except AttributeError:
			hour_val = minute_val = None
			if isinstance(value, basestring):
				match = RE_TIME.match(value)
				if match:
					hour_val, minute_val = [int(v) for v in match.groups()]

		output = []

		if 'id' in self.attrs:
			id_ = self.attrs['id']
		else:
			id_ = 'id_%s' % name

		hour_choices = [(i, '%02d' % i) for i in range(0, 24)]
		if not (self.required and value):
			hour_choices.append(self.none_value)
		s = Select(choices=hour_choices)
		select_html = s.render(self.hour_field % name, hour_val)
		output.append(select_html)

		output.append(':')

		minute_choices = [(i, '%02d' % i) for i in range(0, 60)]
		if not (self.required and value):
			minute_choices.append(self.none_value)
		s = Select(choices=minute_choices)
		select_html = s.render(self.minute_field % name, minute_val)
		output.append(select_html)

		return mark_safe(u'\n'.join(output))
开发者ID:CodeMontage,项目名称:myrobogals,代码行数:36,代码来源:utils.py

示例4: render

# 需要导入模块: from django.forms.widgets import Select [as 别名]
# 或者: from django.forms.widgets.Select import render [as 别名]
	def render(self, name, value, attrs=None):
		try:
			year_val, month_val = value.year, value.month
		except AttributeError:
			year_val = month_val = None
			if isinstance(value, basestring):
				match = RE_DATE.match(value)
				if match:
					year_val, month_val, day_val = [int(v) for v in match.groups()]

		output = []

		if 'id' in self.attrs:
			id_ = self.attrs['id']
		else:
			id_ = 'id_%s' % name

		local_attrs = self.build_attrs(id=self.month_field % id_)
		month_choices = MONTHS.items()
		month_choices.insert(0, self.none_value)
		#month_choices.sort()
		s = Select(choices=month_choices)
		select_html = s.render(self.month_field % name, month_val, local_attrs)
		output.append(select_html)

		year_choices = [(i, i) for i in self.years]
		year_choices.insert(0, self.none_value)
		local_attrs['id'] = self.year_field % id_
		s = Select(choices=year_choices)
		select_html = s.render(self.year_field % name, year_val, local_attrs)
		output.append(select_html)

		return mark_safe(u'\n'.join(output))
开发者ID:Trannosaur,项目名称:myrobogals,代码行数:35,代码来源:views.py

示例5: render

# 需要导入模块: from django.forms.widgets import Select [as 别名]
# 或者: from django.forms.widgets.Select import render [as 别名]
 def render(self, name, value, attrs=None):
     if value is None: value = ''
     attrs = attrs or {}
     if attrs:
         self.attrs.update(attrs)
     
     output = []
     uf_val = ''
     uf_choices = [('','--')]+[(uf.pk,uf.uf) for uf in UF.objects.order_by('uf')]
     uf_select = Select(choices=uf_choices)
     municipio_select = Select(choices=(('','--'),))
     
     if value:
         try:
             municipio = Municipio.objects.get(pk=value)
             uf_val = municipio.uf
             mun_choices = [(m.pk, m.nome) for m in Municipio.objects.filter(uf=uf_val).order_by('nome')]
             municipio_select = Select(choices=[('','- Selecione -')]+mun_choices)
         except Municipio.DoesNotExist:
             pass
     uf_attrs = self.attrs.copy()
     uf_attrs.update({"id":'%s_uf' % name, "onchange":"changeUF(this);"})
     select_html = uf_select.render('%s_uf' % name, uf_val, attrs=uf_attrs)
     required = False
     if 'class' in self.attrs:
         required = self.attrs['class'] == 'required'
     output.append(u'<div class="field"><label%s>UF</label><br />%s</div>' % (required and ' class="required"' or '', select_html))
     
     munic_attrs = self.attrs.copy()
     munic_attrs['style']="width:250px;"
     select_html = municipio_select.render(name, value, munic_attrs)
     output.append(u'<div class="field"><label%s>Município</label><br />%s</div>' % (required and ' class="required"' or '', select_html))
     return mark_safe(u'\n'.join(output))
开发者ID:Vieceli,项目名称:django-municipios,代码行数:35,代码来源:widgets.py

示例6: render

# 需要导入模块: from django.forms.widgets import Select [as 别名]
# 或者: from django.forms.widgets.Select import render [as 别名]
    def render(self, name, value, attrs=None):
        try:
            year_val, month_val, day_val = value.year, value.month, value.day
        except AttributeError:
            year_val = month_val = day_val = None
            if isinstance(value, basestring):
                match = RE_DATE.match(value)
                if match:
                    year_val, month_val, day_val = [int(v) for v in match.groups()]

        output = []

        if "id" in self.attrs:
            id_ = self.attrs["id"]
        else:
            id_ = "id_%s" % name

        month_choices = MONTHS.items()
        if not (self.required and value):
            month_choices.append(self.none_value_month)
        month_choices.sort()
        local_attrs = self.build_attrs(id=self.month_field % id_)
        s = Select(choices=month_choices)

        if self.attrs_month is not None:
            local_attrs.update({"class": self.attrs_month})

        select_html = s.render(self.month_field % name, month_val, local_attrs)
        output.append(select_html)

        day_choices = [(i, i) for i in range(1, 32)]
        if not (self.required and value):
            day_choices.insert(0, self.none_value_day)
        local_attrs["id"] = self.day_field % id_
        if self.attrs_day is not None:
            local_attrs.update({"class": self.attrs_day})

        s = Select(choices=day_choices)
        select_html = s.render(self.day_field % name, day_val, local_attrs)
        output.append(select_html)

        year_choices = [(i, i) for i in self.years]
        if not (self.required and value):
            year_choices.insert(0, self.none_value_year)
        local_attrs["id"] = self.year_field % id_

        if self.attrs_year is not None:
            local_attrs.update({"class": self.attrs_year})

        s = Select(choices=year_choices)
        select_html = s.render(self.year_field % name, year_val, local_attrs)
        output.append(select_html)

        return mark_safe(u"\n".join(output))
开发者ID:braskin,项目名称:pd,代码行数:56,代码来源:widgets.py

示例7: render

# 需要导入模块: from django.forms.widgets import Select [as 别名]
# 或者: from django.forms.widgets.Select import render [as 别名]
    def render(self, name, value, attrs=None):
        try:
            year_val, month_val = value.year, value.month
        except AttributeError:
            year_val = month_val = None

            if isinstance(value, basestring):
                match = RE_DATE.match(value)

                if match:
                    year_val, month_val, day_val = [int(v) for v in match.groups()]

        output = []

        if 'id' in self.attrs:
            id_ = self.attrs['id']
        else:
            id_ = 'id_%s' % name

        # month_choices = MONTHS.items()
        month_choices = []

        for month in MONTHS:
            month_choices.append(
                (month, '{} - {}'.format(month, MONTHS[month][0:]))
            )

        if not (self.required and value):
            month_choices.append(self.none_value)

        month_choices.sort()

        local_attrs = self.build_attrs(id=self.month_field % id_)
        local_attrs['style'] = 'width: 130px;'

        s = Select(choices=month_choices)
        select_html = s.render(self.month_field % name, month_val, local_attrs)
        output.append(select_html)

        output.append('&nbsp;')

        year_choices = [(i, i) for i in self.years]

        if not (self.required and value):
            year_choices.insert(0, self.none_value)

        local_attrs['id'] = self.year_field % id_
        local_attrs['style'] = 'width: 90px;'
        s = Select(choices=year_choices)
        select_html = s.render(self.year_field % name, year_val, local_attrs)
        output.append(select_html)

        return mark_safe(u'\n'.join(output))
开发者ID:stabora,项目名称:cochera,代码行数:55,代码来源:widgets.py

示例8: render

# 需要导入模块: from django.forms.widgets import Select [as 别名]
# 或者: from django.forms.widgets.Select import render [as 别名]
    def render(self, name, value, attrs=None):
        if value is None:
            value = ''
        attrs = attrs or {}
        if attrs:
            self.attrs.update(attrs)

        output = []
        uf_val = ''
        uf_choices = [('', '--')] + list(self.mun_cls.objects.values_list('uf__id_ibge', 'uf_sigla').distinct().order_by('uf_sigla'))
        uf_select = Select(choices=uf_choices)
        municipio_select = Select(choices=(('', '--'),))

        if value:
            try:
                municipio = self.mun_cls.objects.get(pk=value)
                uf_val = municipio.uf.pk
                mun_choices = [(m.pk, m.nome) for m in self.mun_cls.objects.filter(uf=uf_val).order_by('nome')]
                municipio_select = Select(choices=[('', '- Selecione -')] + mun_choices)
            except self.mun_cls.DoesNotExist:
                pass
        uf_attrs = self.attrs.copy()
        uf_attrs.update(
            {
                "id": '%s_uf' % name,
                "onchange": "changeUF(this);",
                "data-app_label": self.app_label,
                "data-object_name": self.object_name,
            }
        )
        select_html = uf_select.render('%s_uf' % name, uf_val, attrs=uf_attrs)
        required = False
        if 'class' in self.attrs:
            required = self.attrs['class']
        # output.append(u'<div class="field"><label%s>UF</label><br />%s</div>' % (required and ' class="required"' or '', select_html))
        template_uf = get_template('municipios/uf_field.html')
        context_uf = {'label_class': required, 'wselect': select_html}
        output.append(template_uf.render(context_uf))

        munic_attrs = self.attrs.copy()
        munic_attrs['style'] = "width:250px;"
        select_html = municipio_select.render(name, value, munic_attrs)
        # output.append(u'<div class="field"><label%s>Município</label><br />%s</div>' % (required and ' class="required"' or '', select_html))
        template_mun = get_template('municipios/municipio_field.html')
        context_mun = {'label_class': required, 'wselect': select_html}
        output.append(template_mun.render(context_mun))

        return mark_safe(u'\n'.join(output))
开发者ID:znc-sistemas,项目名称:django-municipios,代码行数:50,代码来源:widgets.py

示例9: render

# 需要导入模块: from django.forms.widgets import Select [as 别名]
# 或者: from django.forms.widgets.Select import render [as 别名]
    def render(self, name, value, attrs=None):
        try:
            year_val, month_val, day_val, hour_val, min_val = value.year, value.month, value.day, value.hour, value.minute
        except AttributeError:
            year_val = month_val = day_val = hour_val = min_val = None
            if isinstance(value, basestring):
                match = RE_DATE.match(value)
                if match:
                    year_val, month_val, day_val, hour_val, min_val, throw_away_seconds  = [int(v) for v in match.groups()]

        date_val = "%04s-%02s-%02s" % (year_val,month_val, day_val)

        output = []

        if 'id' in self.attrs:
            id_ = self.attrs['id']
        else:
            id_ = 'id_%s' % name

        output.append("<span id=\"%s_humanreadable\"></span>" % (name))


        output.append("<input type=\"hidden\" name=\"%s\" id=\"%s\" value=\"%s\" onchange=\"updateCalendar(this);\">" % ((self.date_field % name), (self.date_field % name), date_val))

		
        output.append("<span id=\"%s_showcalendar\"><img src=\"/static/calendar.png\" alt=\"Calendar\"></span>&nbsp;&nbsp;&nbsp;" % (name));
        output.append("""<script>Event.observe(window, 'load', function(event) {  Calendar.setup({dateField : '%s',triggerElement : '%s_showcalendar'})});</script>""" % ((self.date_field % name), name))
        output.append("""<script>Event.observe(window, 'load', function(event) {  updateCalendar($(\"%s\")); });</script>""" % ((self.date_field % name)))

        hour_choices = [(i, i) for i in range(0, 23)]
        #if not (self.required and value):
        #    hour_choices.insert(0, self.none_value)
        local_attrs = self.build_attrs(id=self.hour_field % id_)
        s = Select(choices=hour_choices)
        select_html = s.render(self.hour_field % name, hour_val, local_attrs)
        output.append(select_html)

        output.append(":");

        min_choices = [(i, i) for i in range(0, 59)]
        #if not (self.required and value):
        #    hour_choices.insert(0, self.none_value)
        local_attrs['id'] = self.min_field % id_
        s = Select(choices=min_choices)
        select_html = s.render(self.min_field % name, min_val, local_attrs)
        output.append(select_html)

        return mark_safe(u'\n'.join(output))
开发者ID:jarofgreen,项目名称:MyJobSeek,代码行数:50,代码来源:widgets.py

示例10: head_index_box

# 需要导入模块: from django.forms.widgets import Select [as 别名]
# 或者: from django.forms.widgets.Select import render [as 别名]
 def head_index_box(self):
     from django.forms.widgets import Select
     choices = [(0, 'Unknown')]
     for i, daughter in enumerate(self.expansion.rule[1:-1].split()[1:]):
         choices.append((i+1, str(i+1) + ': ' + daughter))
     s = Select(choices=choices)
     return s.render('expansion-'+str(self.expansion.id) + '-headindex',
             self.head_index)
开发者ID:matt-gardner,项目名称:head-rule-checking,代码行数:10,代码来源:models.py

示例11: change_template_widget

# 需要导入模块: from django.forms.widgets import Select [as 别名]
# 或者: from django.forms.widgets.Select import render [as 别名]
    def change_template_widget(self):
        change_template_options = sorted(get_templates(self.obj.__class__), key=lambda x: x[1])

        widget = Select(attrs={
            'id': 'id_template_name',
        }, choices=change_template_options)

        return widget.render(name='template_name', value=self.layout._meta.template)
开发者ID:blancltd,项目名称:django-glitter,代码行数:10,代码来源:page.py

示例12: render

# 需要导入模块: from django.forms.widgets import Select [as 别名]
# 或者: from django.forms.widgets.Select import render [as 别名]
    def render(self, name, value, attrs=None):
        try:
            year_val, month_val = value.year, value.month
        except AttributeError:
            year_val = month_val = None
            if isinstance(value, basestring):
                match = RE_DATE.match(value)
                if match:
                    year_val, month_val, day_val = [int(v) for v in match.groups()]

        output = []

        if 'id' in self.attrs:
            id_ = self.attrs['id']
        else:
            id_ = 'id_%s' % name

        month_choices = MONTHS.items()
        if not (self.required and value):
            month_choices.append(self.none_value)
        month_choices.sort()
        build_attrs = {
            'id': self.month_field % id_
        }
        local_attrs = self.build_attrs(build_attrs)
        s = Select(choices=month_choices)
        select_html = s.render(self.month_field % name, month_val, local_attrs)
        output.append(select_html)

        year_choices = [(i, i) for i in self.years]
        if not (self.required and value):
            year_choices.insert(0, self.none_value)
        local_attrs['id'] = self.year_field % id_
        s = Select(choices=year_choices)
        select_html = s.render(self.year_field % name, year_val, local_attrs)
        output.append(select_html)

        # Hidden widget for custom datefield
        s = HiddenInput()
        output.append(s.render('date_mozillian', None))

        return mark_safe(u'\n'.join(output))
开发者ID:akatsoulas,项目名称:mozillians,代码行数:44,代码来源:widgets.py

示例13: create_select

# 需要导入模块: from django.forms.widgets import Select [as 别名]
# 或者: from django.forms.widgets.Select import render [as 别名]
 def create_select(self, name, field, value, val, choices):
     if 'id' in self.attrs:
         id_ = self.attrs['id']
     else:
         id_ = 'id_%s' % name
     if not (self.required and value):
         choices.insert(0, self.none_value)
     local_attrs = self.build_attrs(id=field % id_)
     s = Select(choices=choices)
     select_html = s.render(field % name, val, local_attrs)
     return select_html
开发者ID:BGCX261,项目名称:zkwiki-hg-to-git,代码行数:13,代码来源:widgets.py

示例14: render

# 需要导入模块: from django.forms.widgets import Select [as 别名]
# 或者: from django.forms.widgets.Select import render [as 别名]
    def render(self, name, value, attrs=None):
        try:
            year_val, month_val, day_val = value.get_year(), value.get_month(empty_allowed=True), value.get_day(empty_allowed=True)
        except AttributeError:
            year_val, month_val, day_val = None, None, None

        output = []

        if 'id' in self.attrs:
            id_ = self.attrs['id']
        else:
            id_ = 'id_%s' % name

        local_attrs = self.build_attrs(id=self.year_field % id_)
        year_choices = [(i, i) for i in self.years]
        year_choices.reverse()
        if not self.required:
            year_choices = [(0,'(year)')] + year_choices
        s = Select(choices=year_choices)
        select_html = s.render(self.year_field % name, year_val, local_attrs)
        output.append(select_html)

        month_choices = list(MONTHS.items())
        month_choices.append(self.none_value)
        month_choices.sort()
        local_attrs['id'] = self.month_field % id_

        s = Select(choices=month_choices)
        select_html = s.render(self.month_field % name, month_val, local_attrs)
        output.append(select_html)


        day_choices = [(i, i) for i in range(1, 32)]
        day_choices.insert(0, self.none_value)
        local_attrs['id'] = self.day_field % id_

        s = Select(choices=day_choices)
        select_html = s.render(self.day_field % name, day_val, local_attrs)
        output.append(select_html)

        return mark_safe(u'\n'.join(output))
开发者ID:JordanReiter,项目名称:django-flexibledatefield,代码行数:43,代码来源:fields.py

示例15: rappel

# 需要导入模块: from django.forms.widgets import Select [as 别名]
# 或者: from django.forms.widgets.Select import render [as 别名]
def rappel(modeladmin, request, queryset):

    opts = modeladmin.model._meta
    app_label = opts.app_label

    if request.POST.get('post'):

        today = datetime.date.today()
        lastyear = today - datetime.timedelta(days=365)

        modele_id = request.POST.get('modele')
        rappelmodele = RappelModele.objects.get(pk=modele_id)

        rappel = Rappel()
        rappel.user_creation = request.user
        rappel.date_cible = lastyear
        rappel.date_limite = today + datetime.timedelta(days=30)
        rappel.sujet = rappelmodele.sujet
        rappel.contenu = rappelmodele.contenu
        rappel.save()

        for chercheur in queryset:
            rappeluser = RappelUser()
            rappeluser.rappel = rappel
            rappeluser.user = chercheur.user
            rappeluser.save()

        n = queryset.count()

        if n == 1:
            message = u"1 rappel a été envoyé."
        else:
            message = u"%(count)d rappels ont été envoyés." % {"count": n}

        modeladmin.message_user(request, message)

        return None

    select = Select(choices=RappelModele.objects.values_list('id', 'nom'))

    context = {
        "title": _("Are you sure?"),
        "queryset": queryset,
        "templateselect": select.render("modele", ''),
        "app_label": app_label,
        "opts": opts,
        "action_checkbox_name": helpers.ACTION_CHECKBOX_NAME,
    }

    return render_to_response("admin/rappels/chercheurrappel/rappel_selected_confirmation.html",
        context, context_instance=template.RequestContext(request))
开发者ID:auf,项目名称:www_savoirsenpartage_auf_org,代码行数:53,代码来源:actions.py


注:本文中的django.forms.widgets.Select.render方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。