def gen_displayed_div(self): """ Generate HTML code for the div that contains displayed tags """ if self.gen_select: self.html += render_field(self.bound, *self.args, **self.kwargs) self.field.widget = TextInput(attrs={ 'name': 'mbf_' + self.name, 'placeholder': self.field.empty_label }) self.replace_input = render_field(self.bound, *self.args, **self.kwargs) if not self.gen_select: self.html += self.replace_input
def bootstrap_date_field(field, **kwargs): calendar_group_wrapper = """ <div class="bfh-datepicker" data-format="d.m.y"> <div class="input-group bfh-datepicker-toggle" data-toggle="bfh-datepicker"> %s<span class="input-group-addon btn"><i class="glyphicon glyphicon-calendar"></i></span> </div> <div class="bfh-datepicker-calendar"> <table class="calendar table table-bordered"> <thead> <tr class="months-header"> <th class="month" colspan="4"> <a class="previous" href="#"><i class="glyphicon glyphicon-chevron-left"></i></a> <span></span> <a class="next" href="#"><i class="glyphicon glyphicon-chevron-right"></i></a> </th> <th class="year" colspan="3"> <a class="previous" href="#"><i class="glyphicon glyphicon-chevron-left"></i></a> <span></span> <a class="next" href="#"><i class="glyphicon glyphicon-chevron-right"></i></a> </th> </tr> <tr class="days-header"> </tr> </thead> <tbody> </tbody> </table> </div> </div> """ kwargs['input_wrapper'] = calendar_group_wrapper return render_field(field, **kwargs)
def _render_formset_form(form): '''Renders a formset form within the style setting headers above.''' output = r''' <tr> <td> <div class='form-group' style="margin-bottom: 0px;"> <div class='form-inline'> ''' for field in form: # Delegate the hard bits to django-bootstrap3 field renderer field_str = render_field( field, form_group_class='modal-formset-field', field_class='hide' if field.name == 'DELETE' else '', show_label=False, show_help=False, size='small') output += field_str output += r''' </div> </div> </td> <td style='vertical-align: middle;'> </td> </tr> ''' return output
def render_fields(self): rendered_fields = [] for field in self.form: if isinstance(field.field, InlineFormFieldMixIn): fields = [sub_field for sub_field in field] else: fields = [field] for sub_field in fields: rendered_fields.append( render_field( sub_field, layout=self.layout, form_group_class=self.form_group_class, field_class=self.field_class, label_class=self.label_class, show_help=self.show_help, exclude=self.exclude, set_required=self.set_required, size=self.size, horizontal_label_class=self.horizontal_label_class, horizontal_field_class=self.horizontal_field_class, )) return '\n'.join(rendered_fields)
def render_fieldset(self, fieldset): output = [] output.append('<fieldset>') output.append('<legend>{}</legend>'.format(fieldset.legend)) for field in fieldset: output.append(render_field( field, layout=self.layout, form_group_class=self.form_group_class, field_class=self.field_class, label_class=self.label_class, show_label=self.show_label, show_help=self.show_help, exclude=self.exclude, set_required=self.set_required, set_disabled=self.set_disabled, size=self.size, horizontal_label_class=self.horizontal_label_class, horizontal_field_class=self.horizontal_field_class, )) output.append('</fieldset>') return '\n'.join(output)
def render_fieldset(self, fieldset): output = [] if fieldset.classes: output.append('<fieldset class="{}">'.format(fieldset.classes)) else: output.append('<fieldset>') output.append('<legend>{}</legend>'.format(fieldset.legend)) if fieldset.description: output.append('<p>{}</p>'.format(fieldset.description)) for field in fieldset: output.append( render_field( field, layout=self.layout, form_group_class=self.form_group_class, field_class=self.field_class, label_class=self.label_class, show_label=self.show_label, show_help=self.show_help, exclude=self.exclude, size=self.size, horizontal_label_class=self.horizontal_label_class, horizontal_field_class=self.horizontal_field_class, )) output.append('</fieldset>') return '\n'.join(output)
def render_fields(self): rendered_fields = [] for field in self.form: if isinstance(field.field, InlineFormFieldMixIn): fields = [sub_field for sub_field in field] else: fields = [field] for sub_field in fields: rendered_fields.append(render_field( sub_field, layout=self.layout, form_group_class=self.form_group_class, field_class=self.field_class, label_class=self.label_class, show_help=self.show_help, exclude=self.exclude, set_required=self.set_required, size=self.size, horizontal_label_class=self.horizontal_label_class, horizontal_field_class=self.horizontal_field_class, )) return '\n'.join(rendered_fields)
def bootstrap_datetime_field(field, **kwargs): wrapper = """ <div class='input-group date' name='bootstrap_datetimepicker'> %s<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span> </span> </div> """ kwargs['input_wrapper'] = wrapper return render_field(field, **kwargs)
def bootstrap_inline_checkbox_stars_field(*args, **kwargs): kwargs.update({ 'form_group_class': 'form-group stars', 'show_label': True, }) return render_field(*args, **kwargs).replace( '<div class="radio">', '<div class="radio-inline">').replace( 'class="" id="id_rating_', 'class="glyphicon glyphicon-star-empty" id="id_rating_')
def _bs_ability_score_field(*args, **kwargs): """ Wrapper around bootstrap_field with ability score arguments. """ # if "form_group_class" in kwargs: # kwargs["form_group_class"] = "col-sm-2 col-xs-4 value-block"\ # + kwargs["form_group_class"] # else: # kwargs["form_group_class"] = "col-sm-2 col-xs-4 value-block" kwargs["form_group_class"] = "col-sm-2 col-xs-4 value-block" +\ " ability-score-block" kwargs["addon_after"] = " " kwargs["layout"] = "ability_scores" return render_field(*args, **kwargs)
def render_fields(self): rendered_fields = [] instance = getattr(self.form, 'instance', None) for field in self.form: rendered_fields.append(render_field( field, layout=self.layout, form_group_class=self.form_group_class, field_class=self.field_class, label_class=self.label_class, show_help=self.show_help, exclude=self.exclude, set_required=self.set_required, value_displayer=getattr(instance, 'get_%s_display' % field.name, field.value) or '' if instance else None )) return '\n'.join(rendered_fields)
def __render_field(self, field): return render_field(field, layout=self.layout, form_group_class=self.form_group_class, field_class=self.field_class, label_class=self.label_class, show_label=False, show_help=self.show_help, exclude=self.exclude, set_required=self.set_required, set_disabled=self.set_disabled, size=self.size, horizontal_label_class=self.horizontal_label_class, horizontal_field_class=self.horizontal_field_class, error_css_class=self.error_css_class, required_css_class=self.required_css_class, bound_css_class=self.bound_css_class)
def render_fields(self): rendered_fields = [] instance = getattr(self.form, 'instance', None) for field in self.form: rendered_fields.append( render_field( field, layout=self.layout, form_group_class=self.form_group_class, field_class=self.field_class, label_class=self.label_class, show_help=self.show_help, exclude=self.exclude, set_required=self.set_required, value_displayer=getattr(instance, 'get_%s_display' % field.name, field.value) or '' if instance else None)) return '\n'.join(rendered_fields)
def render(self): """ HTML code for the fully rendered form with all the necessary form """ for name, field in self.form.fields.items(): if name not in self.exclude: if name in self.fields and name not in self.hidden_fields: mbf_field = MBFField( name, field, field.get_bound_field(self.form, name), self.choices.get(name, None), self.engine.get(name, None), self.match_func.get(name, None), self.update_on.get(name, None), self.gen_select.get(name, True), *self.args, **self.kwargs) self.html += mbf_field.render() else: self.html += render_field( field.get_bound_field(self.form, name), *self.args, **self.kwargs) return mark_safe(self.html)
def bootstrap_inline_checkbox_stars_field(*args, **kwargs): kwargs.update({ 'form_group_class': 'form-group stars', 'show_label': True, }) return render_field(*args, **kwargs).replace('<div class="radio">', '<div class="radio-inline">').replace('class="" id="id_rating_', 'class="glyphicon glyphicon-star-empty" id="id_rating_')