Beispiel #1
0
 def __init__(self, filetype, format):
     self.filetype = template.Variable(filetype)
     self.format = template.Variable(format)
Beispiel #2
0
 def __init__(self, app_label, model_name, plural):
     self.app_label = template.Variable(app_label)
     self.model_name = template.Variable(model_name)
     self.plural = template.Variable(plural)
Beispiel #3
0
 def __init__(self, context_name, starts_with=None):
     self.context_name = context_name
     if starts_with:
         self.starts_with = template.Variable(starts_with)
     else:
         self.starts_with = None
Beispiel #4
0
 def __init__(self, group_name, context_name):
     self.group = template.Variable(group_name)
     self.context_name = context_name
Beispiel #5
0
 def resolve(arg):
     try:
         return template.Variable(arg).resolve(context)
     except template.VariableDoesNotExist:
         return arg
Beispiel #6
0
 def __init__(self, product_id):
     self.product_id = template.Variable(product_id)
Beispiel #7
0
def get_active_tabs(context):
    active_tabs = template.Variable(ACTIVE_TAB_NAME)
    try:
        return active_tabs.resolve(context)
    except template.VariableDoesNotExist:
        return {}
Beispiel #8
0
 def __init__(self, table):
     self.table = template.Variable(table)
Beispiel #9
0
 def render(self, context):
     iterable = template.Variable(self.iterable).resolve(context)
     num_cols = self.num_cols
     context[self.varname] = zip(
         *[chain(iterable, [None] * (num_cols - 1))] * num_cols)
     return ''
Beispiel #10
0
 def __init__(self, image_var_name, filter_spec, output_var_name=None):
     self.image_var = template.Variable(image_var_name)
     self.filter, created = Filter.objects.get_or_create(spec=filter_spec)
     self.output_var_name = output_var_name
Beispiel #11
0
 def __init__(self, nodelist, domain_var):
     self.nodelist = nodelist
     self.domain_var = template.Variable(domain_var)
Beispiel #12
0
	def __init__(self, page_range, page):
		self.page_range = template.Variable(page_range)
		self.page = template.Variable(page)
Beispiel #13
0
 def __init__(self, user, key):
     self.user = template.Variable(user)
     self.key = key
Beispiel #14
0
 def __init__(self, instancia, etiqueta, nodelist):
     self.instancia = template.Variable(instancia)
     self.etiqueta = etiqueta
     self.etiqueta = self.etiqueta.replace("\"", "")
     self.etiqueta = self.etiqueta.replace("'", "")
     self.nodelist = nodelist
Beispiel #15
0
 def __init__(self, object_data, object_show_fields, object_ex_fields):
     self.object = template.Variable(object_data)
     self.show_fields = template.Variable(object_show_fields)
     self.ex_fields = template.Variable(object_ex_fields)
Beispiel #16
0
 def __init__(self, obj, varname):
     self.obj = template.Variable(obj)
     self.varname = varname
Beispiel #17
0
 def __init__(self, object):
     self.object = template.Variable(object)
Beispiel #18
0
    def render(self, context):  # noqa: C901
        # Nodes are not threadsafe so we must store and look up our instance
        # variables in the current rendering context first
        if self not in context.render_context:
            context.render_context[self] = (
                template.Variable(self.field),
                self.attrs,
                template.Variable(self.html5_required),
            )

        field, attrs, html5_required = context.render_context[self]
        field = field.resolve(context)
        try:
            html5_required = html5_required.resolve(context)
        except template.VariableDoesNotExist:
            html5_required = False

        # If template pack has been overridden in FormHelper we can pick it from context
        template_pack = context.get("template_pack", TEMPLATE_PACK)

        # There are special django widgets that wrap actual widgets,
        # such as forms.widgets.MultiWidget, admin.widgets.RelatedFieldWidgetWrapper
        widgets = getattr(
            field.field.widget, "widgets",
            [getattr(field.field.widget, "widget", field.field.widget)])

        if isinstance(attrs, dict):
            attrs = [attrs] * len(widgets)

        converters = {}
        converters.update(getattr(settings, "CRISPY_CLASS_CONVERTERS", {}))

        for widget, attr in zip(widgets, attrs):
            class_name = widget.__class__.__name__.lower()
            class_name = converters.get(class_name, class_name)
            css_class = widget.attrs.get("class", "")
            if css_class:
                if css_class.find(class_name) == -1:
                    css_class += " %s" % class_name
            else:
                css_class = class_name

            # Added additional code for Tailwind
            if template_pack == "tailwind":
                css_container = context.get("css_container",
                                            self.default_container)
                if css_container:
                    css = " " + css_container.get_input_class(field)
                    css_class += css
                if field.errors:
                    error_border_class = css_container.error_border
                    css_class = re.sub(r"border-\S+", error_border_class,
                                       css_class)

            widget.attrs["class"] = css_class

            # HTML5 required attribute
            if html5_required and field.field.required and "required" not in widget.attrs:
                if field.field.widget.__class__.__name__ != "RadioSelect":
                    widget.attrs["required"] = "required"

            for attribute_name, attribute in attr.items():
                attribute_name = template.Variable(attribute_name).resolve(
                    context)

                if attribute_name in widget.attrs:
                    widget.attrs[attribute_name] += " " + template.Variable(
                        attribute).resolve(context)
                else:
                    widget.attrs[attribute_name] = template.Variable(
                        attribute).resolve(context)

        return str(field)
Beispiel #19
0
 def __init__(self, name, namespace=None):
     if namespace is None:
         namespace = DEFAULT_NAMESPACE
     self.namespace = template.Variable(namespace)
     self.name = template.Variable(name)
Beispiel #20
0
 def __init__(self, integration):
     self.integration = template.Variable(integration)
Beispiel #21
0
 def __init__(self, nodelist_true, nodelist_false, obj_var):
     self.nodelist_true, self.nodelist_false = nodelist_true, nodelist_false
     self.obj_var = template.Variable(obj_var)
Beispiel #22
0
 def __init__(self, var_name):
     self.var_name = var_name
     self.username = template.Variable(var_name)
Beispiel #23
0
 def __init__(self, object, varname):
     """
     The class constructor
     """
     self.object = template.Variable(object)
     self.varname = varname
 def __init__(self, target, parser, expression, var_name):
     self.target = target
     self.expression = template.Variable(expression)
     self.var_name = var_name
     self.parser = parser
Beispiel #25
0
 def __init__(self, time):
     self.time = template.Variable(time)
 def __init__(self, user, var_name, rel):
     self.user = template.Variable(user)
     self.var_name = var_name
     self.rel = rel
Beispiel #27
0
 def __init__(self):
     self.for_first = template.Variable('forloop.first')
     self.for_last = template.Variable('forloop.last')
Beispiel #28
0
 def __init__(self, email):
     self.email = template.Variable(email)
Beispiel #29
0
 def __init__(self, vobj, vadditional=None):
     self.vobj = template.Variable(vobj)
     self.vadditional = vadditional
Beispiel #30
0
    def get_render(self, context):
        """
        Returns a `Context` object with all the necessary stuff for rendering the form

        :param context: `django.template.Context` variable holding the context for the node

        `self.form` and `self.helper` are resolved into real Python objects resolving them
        from the `context`. The `actual_form` can be a form or a formset. If it's a formset
        `is_formset` is set to True. If the helper has a layout we use it, for rendering the
        form or the formset's forms.
        """
        # Nodes are not thread safe in multithreaded environments
        # https://docs.djangoproject.com/en/dev/howto/custom-template-tags/#thread-safety-considerations
        if self not in context.render_context:
            context.render_context[self] = (
                template.Variable(self.form),
                template.Variable(self.helper) if self.helper else None
            )
        form, helper = context.render_context[self]

        actual_form = form.resolve(context)
        if self.helper is not None:
            helper = helper.resolve(context)
        else:
            # If the user names the helper within the form `helper` (standard), we use it
            # This allows us to have simplified tag syntax: {% crispy form %}
            helper = FormHelper() if not hasattr(actual_form, 'helper') else actual_form.helper

        # use template_pack from helper, if defined
        try:
            if helper.template_pack:
                self.template_pack = helper.template_pack
        except AttributeError:
            pass

        self.actual_helper = helper

        # We get the response dictionary
        is_formset = isinstance(actual_form, BaseFormSet)
        response_dict = self.get_response_dict(helper, context, is_formset)
        node_context = context.__copy__()
        node_context.update(response_dict)
        final_context = node_context.__copy__()

        # If we have a helper's layout we use it, for the form or the formset's forms
        if helper and helper.layout:
            if not is_formset:
                actual_form.form_html = helper.render_layout(actual_form, node_context, template_pack=self.template_pack)
            else:
                forloop = ForLoopSimulator(actual_form)
                helper.render_hidden_fields = True
                for form in actual_form:
                    node_context.update({'forloop': forloop})
                    node_context.update({'formset_form': form})
                    form.form_html = helper.render_layout(form, node_context, template_pack=self.template_pack)
                    forloop.iterate()

        if is_formset:
            final_context['formset'] = actual_form
        else:
            final_context['form'] = actual_form

        return final_context