Creates attribute dicts for the switchable theme form
962785
def get_switched_form_field_attrs(self, prefix, input_type, name):
        
        attributes = {'class': 'switched', 'data-switch-on': prefix + 'field'}
        attributes['data-' + prefix + 'field-' + input_type] = name
        return attributes
70407
def _generate_dom_attrs(attrs, allow_no_value=True):
    
    for attr in iterate_items(attrs):
        if isinstance(attr, basestring):
            attr = (attr, True)
        key, value = attr
        if value is None:
            continue
        if value is True and not allow_no_value:
            value = key  # E.g. <option checked="true" />
        if value is True:
            yield True  # E.g. <option checked />
        else:
            yield '%s="%s"' % (key, value.replace('"', '\\"'))
627885
def put_attributes(self, attrs):
        
        assert(isinstance(attrs, dict)), "Argument must be a dict of key->values to save"
        for prop_name in attrs:
            value = attrs[prop_name]
            prop = self.find_property(prop_name)
            assert(prop), "Property not found: %s" % prop_name
            self._manager.set_property(prop, self, prop_name, value)
        self.reload()
        return self
407343
def set_attributes(d, elm):
    """"""
    for key in d:
        elm.setAttribute(key, d[key])
740983
def resource_attributes(resource, options = {})
      atts = {}
      name = resource_name(resource, options)
      atts[:name] = name unless name.empty?
      atts.merge!(normal_attributes(resource, options))
      atts.merge!(block_attributes(resource))
      atts
    end
806531
def create_form_data(self, **kwargs):
        """"""
        # Get the specified keyword arguments.
        children = kwargs.get('children', [])
        sort_order = kwargs.get('sort_order', None)
        solr_response = kwargs.get('solr_response', None)
        superuser = kwargs.get('superuser', False)
        # Get the vocabularies to pull the qualifiers from.
        vocabularies = self.get_vocabularies()
        # Loop through all UNTL elements in the Python object.
        for element in children:
            # Add children that are missing from the form.
            element.children = add_missing_children(
                element.contained_children,
                element.children,
            )
            # Add the form attribute to the element.
            element.add_form(
                vocabularies=vocabularies,
                qualifier=element.qualifier,
                content=element.content,
                superuser=superuser,
            )
            # Element can contain children.
            if element.form.has_children:
                # If the parent has a qualifier,
                # create a representative form element for the parent.
                if getattr(element.form, 'qualifier_name', False):
                    add_parent = PARENT_FORM[element.form.qualifier_name](
                        content=element.qualifier,
                    )
                    # Add the parent to the list of child elements.
                    element.children.append(add_parent)
                # Sort the elements by the index of child sort.
                element.children.sort(
                    key=lambda obj: element.form.child_sort.index(obj.tag)
                )
                # Loop through the element's children (if it has any).
                for child in element.children:
                    # Add the form attribute to the element.
                    child.add_form(
                        vocabularies=vocabularies,
                        qualifier=child.qualifier,
                        content=child.content,
                        parent_tag=element.tag,
                        superuser=superuser,
                    )
        element_group_dict = {}
        # Group related objects together.
        for element in children:
            # Make meta-hidden its own group.
            if element.form.name == 'meta' and element.qualifier == 'hidden':
                element_group_dict['hidden'] = [element]
            # Element is not meta-hidden.
            else:
                # Make sure the dictionary key exists.
                if element.form.name not in element_group_dict:
                    element_group_dict[element.form.name] = []
                element_group_dict[element.form.name].append(element)
        # If the hidden meta element doesn't exist, add it to its own group.
        if 'hidden' not in element_group_dict:
            hidden_element = PYUNTL_DISPATCH['meta'](
                qualifier='hidden',
                content='False')
            hidden_element.add_form(
                vocabularies=vocabularies,
                qualifier=hidden_element.qualifier,
                content=hidden_element.content,
                superuser=superuser,
            )
            element_group_dict['hidden'] = [hidden_element]
        # Create a list of group object elements.
        element_list = self.create_form_groupings(
            vocabularies,
            solr_response,
            element_group_dict,
            sort_order,
        )
        # Return the list of UNTL elements with form data added.
        return element_list
884285
def update_attributes(self, **original_kwargs):
        
        def update_attrs(layout_object):
            kwargs = original_kwargs.copy()
            if hasattr(layout_object, 'attrs'):
                if 'css_class' in kwargs:
                    if 'class' in layout_object.attrs:
                        layout_object.attrs['class'] += " %s" % kwargs.pop('css_class')
                    else:
                        layout_object.attrs['class'] = kwargs.pop('css_class')
                layout_object.attrs.update(kwargs)

        self.map(update_attrs)
401452
def post2pydict(post, ignore_list):
    """"""
    root_element = PYUNTL_DISPATCH['metadata']()
    untl_form_dict = {}
    # Turn the posted data into usable data
    # (otherwise the value lists get messed up).
    form_post = dict(post.copy())
    # Loop through all the field lists.
    for key, value_list in form_post.items():
        if key not in ignore_list:
            # Split the key into the element_tag (ex. title)
            # and element attribute (ex. qualifier, content).
            (element_tag, element_attribute) = key.split('-', 1)
            if element_tag not in untl_form_dict:
                untl_form_dict[element_tag] = ()
            # Add the value list to the dictionary.
            untl_form_dict[element_tag] += (element_attribute, value_list),

    for element_tag, attribute_tuple in untl_form_dict.items():
        # Get the count of attributes/content in the element tuple.
        attribute_count = len(attribute_tuple)
        # Get the count of the first attribute's values.
        value_count = len(attribute_tuple[0][1])
        # Check to see that all attribute/content values align numerically.
        for i in range(0, attribute_count):
            if not len(attribute_tuple[i][1]) == value_count:
                raise PyuntlException('Field values did not match up '
                                      'numerically for %s' % (element_tag))
        # Create a value loop to get all values from the tuple.
        for i in range(0, value_count):
            untl_element = None
            content = ''
            qualifier = ''
            child_list = []
            # Loop through the attributes.
            # attribute_tuple[j][0] represents the attribute/content name.
            # attribute_tuple[j][1][i] represents the
            # current attribute/content value.
            for j in range(0, attribute_count):
                if attribute_tuple[j][0] == 'content':
                    content = unicode(attribute_tuple[j][1][i])
                elif attribute_tuple[j][0] == 'qualifier':
                    qualifier = attribute_tuple[j][1][i]
                # Create a child UNTL element from the data.
                else:
                    # If the child has content, append it to the child list.
                    if attribute_tuple[j][1][i] != '':
                        child_tag = attribute_tuple[j][0]
                        # Check if the child is the attribute of the element.
                        if child_tag in PARENT_FORM:
                            qualifier = attribute_tuple[j][1][i]
                        # Else, the child is a normal child of the element.
                        else:
                            child_list.append(
                                PYUNTL_DISPATCH[attribute_tuple[j][0]](
                                    content=attribute_tuple[j][1][i]
                                )
                            )
            # Create the UNTL element.
            if content != '' and qualifier != '':
                untl_element = PYUNTL_DISPATCH[element_tag](content=content,
                                                            qualifier=qualifier)
            elif content != '':
                untl_element = PYUNTL_DISPATCH[element_tag](content=content)
            elif qualifier != '':
                untl_element = PYUNTL_DISPATCH[element_tag](qualifier=qualifier)
            # This element only has children elements.
            elif len(child_list) > 0:
                untl_element = PYUNTL_DISPATCH[element_tag]()
            # If the element has children, add them.
            if len(child_list) > 0 and untl_element is not None:
                for child in child_list:
                    untl_element.add_child(child)
            # Add the UNTL element to the root element.
            if untl_element is not None:
                root_element.add_child(untl_element)
    return root_element.create_element_dict()
527529
function(attrs) {
      var options = {};
      for(var key in attrs) {
        if (key.match(/^\$/) || key.match(/^ng[A-Z]/)) {
          void(0);
        } else {
          options[key] = attrs[key];
        }
      }
      return options;
    }
480629
def set_attributes(self, **attributes_dict):
        
        for attr_name, attr_value in attributes_dict.items():
            self.set_attr(attr_name, attr_value)
        return self
386214
def build_attrs(self, *args, **kwargs):
        """"""
        attrs = super(HeavySelect2Mixin, self).build_attrs(*args, **kwargs)

        # encrypt instance Id
        self.widget_id = signing.dumps(id(self))

        attrs['data-field_id'] = self.widget_id
        attrs.setdefault('data-ajax--url', self.get_url())
        attrs.setdefault('data-ajax--cache', "true")
        attrs.setdefault('data-ajax--type', "GET")
        attrs.setdefault('data-minimum-input-length', 2)
        if self.dependent_fields:
            attrs.setdefault('data-select2-dependent-fields', " ".join(self.dependent_fields))

        attrs['class'] += ' django-select2-heavy'
        return attrs
127608
def attributes(*attributes)
      attributes.each do |attr|
        raise ArgumentError.new("You cannot use #{attr} as an attribute name since it is a reserved method name of Xapian::Document") if reserved_method_name?(attr)
        @attributes_hash[attr] = {}
        @type_map[attr] = :string
        self.index attr
      end
    end
1142013
def get_attributes(self):
        
        items = {}
        items['form_method'] = self.form_method.strip()
        items['form_tag'] = self.form_tag
        items['form_style'] = self.form_style.strip()
        
        if self.form_action:
            items['form_action'] = self.form_action.strip()
        if self.form_id:
            items['id'] = self.form_id.strip()
        if self.form_class:
            items['class'] = self.form_class.strip()
        if self.inputs:
            items['inputs'] = self.inputs
        if self.form_error_title:
            items['form_error_title'] = self.form_error_title.strip()
        if self.formset_error_title:
            items['formset_error_title'] = self.formset_error_title.strip()
        return items
338704
def get_attributes(self, template_pack=TEMPLATE_PACK):
        
        items = {
            'form_method': self.form_method.strip(),
            'form_tag': self.form_tag,
            'form_style': self.form_style.strip(),
            'form_show_errors': self.form_show_errors,
            'help_text_inline': self.help_text_inline,
            'error_text_inline': self.error_text_inline,
            'html5_required': self.html5_required,
            'form_show_labels': self.form_show_labels,
            'disable_csrf': self.disable_csrf,
            'label_class': self.label_class,
            'field_class': self.field_class,
            'include_media': self.include_media
        }
        
        if template_pack == 'bootstrap4':
            bootstrap_size_match = re.findall('col-(xl|lg|md|sm)-(\d+)', self.label_class)
            if bootstrap_size_match:
                if template_pack == 'bootstrap4':
                    offset_pattern = 'offset-%s-%s'
                else:
                    offset_pattern = 'col-%s-offset-%s'
                items['bootstrap_checkbox_offsets'] = [offset_pattern % m for m in bootstrap_size_match]
        else:
            bootstrap_size_match = re.findall('col-(lg|md|sm|xs)-(\d+)', self.label_class)
            if bootstrap_size_match:
                if template_pack == 'bootstrap4':
                    offset_pattern = 'offset-%s-%s'
                else:
                    offset_pattern = 'col-%s-offset-%s'
                items['bootstrap_checkbox_offsets'] = [offset_pattern % m for m in bootstrap_size_match]

        items['attrs'] = {}
        if self.attrs:
            items['attrs'] = self.attrs.copy()
        if self.form_action:
            items['attrs']['action'] = self.form_action.strip()
        if self.form_id:
            items['attrs']['id'] = self.form_id.strip()
        if self.form_class:
            # uni_form TEMPLATE PACK has a uniForm class by default
            if template_pack == 'uni_form':
                items['attrs']['class'] = "uniForm %s" % self.form_class.strip()
            else:
                items['attrs']['class'] = self.form_class.strip()
        else:
            if template_pack == 'uni_form':
                items['attrs']['class'] = self.attrs.get('class', '') + " uniForm"
        if self.form_group_wrapper_class:
            items['attrs']['form_group_wrapper_class'] = self.form_group_wrapper_class

        items['flat_attrs'] = flatatt(items['attrs'])

        if self.inputs:
            items['inputs'] = self.inputs
        if self.form_error_title:
            items['form_error_title'] = self.form_error_title.strip()
        if self.formset_error_title:
            items['formset_error_title'] = self.formset_error_title.strip()

        for attribute_name, value in self.__dict__.items():
            if attribute_name not in items and attribute_name not in ['layout', 'inputs'] and not attribute_name.startswith('_'):
                items[attribute_name] = value

        return items
438996
def get_edit_form(obj, field_names, data=None, files=None):
    

    # Map these form fields to their types defined in the forms app so
    # we can make use of their custom widgets.
    from yacms.forms import fields
    widget_overrides = {
        forms.DateField: fields.DATE,
        forms.DateTimeField: fields.DATE_TIME,
        forms.EmailField: fields.EMAIL,
    }

    class EditForm(forms.ModelForm):
        """
        In-line editing form for editing a single model field.
        """

        app = forms.CharField(widget=forms.HiddenInput)
        model = forms.CharField(widget=forms.HiddenInput)
        id = forms.CharField(widget=forms.HiddenInput)
        fields = forms.CharField(widget=forms.HiddenInput)

        class Meta:
            model = obj.__class__
            fields = field_names.split(",")

        def __init__(self, *args, **kwargs):
            super(EditForm, self).__init__(*args, **kwargs)
            self.uuid = str(uuid4())
            for f in self.fields.keys():
                field_class = self.fields[f].__class__
                try:
                    widget = fields.WIDGETS[widget_overrides[field_class]]
                except KeyError:
                    pass
                else:
                    self.fields[f].widget = widget()
                css_class = self.fields[f].widget.attrs.get("class", "")
                css_class += " " + field_class.__name__.lower()
                self.fields[f].widget.attrs["class"] = css_class
                self.fields[f].widget.attrs["id"] = "%s-%s" % (f, self.uuid)
                if settings.FORMS_USE_HTML5 and self.fields[f].required:
                    self.fields[f].widget.attrs["required"] = ""

    initial = {"app": obj._meta.app_label, "id": obj.id,
               "fields": field_names, "model": obj._meta.object_name.lower()}
    return EditForm(instance=obj, initial=initial, data=data, files=files)
954664
function renderAttribute(attribute, mode) {

    var daList;
    var daItems;
    var formGroup;
    var label;
    var inputDiv;
    var input;
    var helpTextDiv;
    var sz;
    var button;
    var select;
    var textNode;
    var inputGroupDiv;
    var inputGroupSpan;
    var inputGroupButton;
    var inputGroupDropDownMenu;
    var initSwitchery;
    var items;
    var j;
    var validating;

    /**
     * Create formGroup container and label
     */

    formGroup = addEle(panel.panelForm, 'div', 'form-group');
    addEle(formGroup, 'label', 'col-sm-3 control-label').innerHTML = attribute.label;

    /**
     * Create inputDiv - set with of input based on size of field
     */
    sz = '1';
    if (attribute.size > 2) sz = '2';
    if (attribute.size > 5) sz = '3';
    if (attribute.size > 10) sz = '4';
    if (attribute.size > 20) sz = '5';
    if (attribute.size > 25) sz = '6';
    if (attribute.size > 30) sz = '7';
    if (attribute.size > 40) sz = '8';
    if (attribute.size > 50) sz = '9';
    if (attribute.type == 'Number') sz = '3';
    if (attribute.type == 'Date') sz = '3';
    if (attribute.type == 'Boolean') sz = '3';
    inputDiv = addEle(formGroup, 'div', 'col-sm-' + sz);

    /**
     * Render based on type
     */
    switch (mode + attribute.type) {

      case 'ViewBoolean':
        input = addEle(inputDiv, 'input', 'js-switch');
        input.setAttribute("type", "checkbox");
        if (attribute.value)
          input.setAttribute("checked", "true");

        initSwitchery = new Switchery(input, {
          //color: window.getComputedStyle(panel.panelTitle, null).getPropertyValue('color'),
          color: '#5bc0de', // todo based on panel theme
          secondaryColor: '#dfdfdf',
          className: 'switchery',
          disabled: true,
          disabledOpacity: 0.5,
          speed: '0.1s'
        });
        $(input).on('change', function () {
          attribute.value = input.checked;
        });
        break;

      case 'EditBoolean':
        input = addEle(inputDiv, 'input', 'js-switch');
        input.setAttribute("type", "checkbox");
        if (attribute.value)
          input.setAttribute("checked", "true");

        initSwitchery = new Switchery(input, {
          //color: window.getComputedStyle(panel.panelTitle, null).getPropertyValue('color'),
          color: '#5bc0de', // todo based on panel theme
          secondaryColor: '#dfdfdf',
          className: 'switchery',
          disabled: false,
          disabledOpacity: 0.5,
          speed: '0.1s'
        });
        $(input).on('change', function () {
          attribute.value = input.checked;
        });
        break;

      case 'EditDate':
        inputGroupDiv = addEle(inputDiv, 'div', 'input-group date');
        input = addEle(inputGroupDiv, 'input', 'form-control');
        if (attribute.placeHolder)
          input.setAttribute("placeHolder", attribute.placeHolder);
        if (attribute.value)
          input.value = (1 + attribute.value.getMonth()) + '/' + attribute.value.getDate() + '/' + attribute.value.getFullYear();
        inputGroupSpan = addEle(inputGroupDiv, 'span', 'input-group-addon');
        inputGroupSpan.innerHTML = '<i class="fa fa-calendar"></i>';
        $(inputGroupDiv).datepicker({
          autoclose: true,
          todayBtn: true,
          todayHighlight: true,
          showOnFocus: false
        }).on('hide', function (e) {
          validateInput();
          e.preventDefault();
        });
        panel.listeners.push(inputGroupDiv); // so we can avoid leakage on deleting panel
        break;

      case 'EditNumber':
        input = addEle(inputDiv, 'input', 'form-control');
        if (attribute.placeHolder)
          input.setAttribute("placeHolder", attribute.placeHolder);
        input.setAttribute("type", "number");
        input.setAttribute("maxlength", attribute.size);
        input.setAttribute("value", attribute.value ? attribute.value : 0);
        break;

      case 'EditString':
        if (attribute.quickPick) {
          inputGroupDiv = addEle(inputDiv, 'div', 'input-group');
          input = addEle(inputGroupDiv, 'input', 'form-control');
        } else {
          input = addEle(inputDiv, 'input', 'form-control');
        }
        if (attribute.placeHolder)
          input.setAttribute("placeHolder", attribute.placeHolder);
        input.setAttribute("type", attribute.hint.password ? "password" : "text");
        input.setAttribute("maxlength", attribute.size);
        if (attribute.value)
          input.setAttribute("value", attribute.value);
        if (attribute.quickPick) {
          inputGroupSpan = addEle(inputGroupDiv, 'span', 'input-group-btn');
          inputGroupButton = addEle(inputGroupSpan, 'button', 'btn btn-default dropdown-toggle');
          inputGroupButton.type = 'button';
          inputGroupButton.setAttribute('data-toggle', 'dropdown');
          inputGroupButton.innerHTML = '<span class="caret"></span>';
          daItems = attribute.quickPick;
          daList = '';
          for (j = 0; j < daItems.length; j++) {
            daList += '<li><a href="#">' + daItems[j] + '</a></li>';
          }
          inputGroupDropDownMenu = addEle(inputGroupSpan, 'ul', 'dropdown-menu pull-right');
          inputGroupDropDownMenu.innerHTML = daList;
          $(inputGroupDropDownMenu).click(function (e) {
            input.value = e.originalEvent.srcElement.innerText;
            validateInput();
            e.preventDefault();
          });
          panel.listeners.push(inputGroupDropDownMenu); // so we can avoid leakage on deleting panel
        }
        break;

      case 'ViewDate':
        input = addEle(inputDiv, 'p', 'form-control-static');
        if (attribute.value)
          input.innerHTML = (1 + attribute.value.getMonth()) + '/' + attribute.value.getDate() + '/' + attribute.value.getFullYear();

        break;

      default: // View
        input = addEle(inputDiv, 'p', 'form-control-static');
        input.innerHTML = attribute.value;

    }

    /**
     * When focus lost on attribute - validate it
     */
    var validateInput = function (event) {
      switch (attribute.type) {
        case 'Date':
          attribute.value = (input.value === '') ? null : attribute.coerce(input.value);
          if (attribute.value != null) {
            var mm = attribute.value.getMonth() + 1;
            var dd = attribute.value.getDate();
            var yyyy = attribute.value.getFullYear();
            if (mm < 10) mm = '0' + mm;
            if (dd < 10) dd = '0' + dd;
            input.value = mm + '/' + dd + '/' + yyyy;
          } else {
            input.value = '';
          }
          break;
        default:
          attribute.value = (input.value === '') ? null : attribute.coerce(input.value);
          if (attribute.value != null)
            input.value = attribute.value;
          break;
      }
      attribute.validate(function () {
      });
    };
    /**
     * Validate when focus lost
     */
    $(input).on('focusout', validateInput);
    panel.listeners.push(input); // so we can avoid leakage on deleting panel

    /**
     * Monitor state changes to attribute
     */
    attribute.onEvent('Validate', function () {
      attribute._validationDone = true;
    });
    attribute.onEvent('StateChange', function () {
      switch (mode + attribute.type) {
        case 'EditBoolean':
          if (( attribute.value ? true : false ) != input.checked)
            $(input).click();
          break;
        case 'EditDate':
          input.value = attribute.value ? '' + (1 + attribute.value.getMonth()) + '/' + attribute.value.getDate() + '/' + attribute.value.getFullYear() : '';
          break;
        case 'EditNumber':
          input.value = attribute.value ? attribute.value : 0;
          break;
        case 'EditString':
          input.value = attribute.value ? '' + attribute.value : '';
          break;
        case 'ViewDate':
          input.innerHTML = attribute.value ? '' + (1 + attribute.value.getMonth()) + '/' + attribute.value.getDate() + '/' + attribute.value.getFullYear() : '';
          break;
        default: // View String
          input.innerHTML = attribute.value;
          break;
      }
      renderHelpText(attribute._validationDone ? attribute.validationMessage : '');
      attribute._validationDone = false;
    });
    panel.attributeListeners.push(attribute); // so we can avoid leakage on deleting panel

    /**
     * For attribute error display
     */
    function renderHelpText(text) {
      if (text) {
        if (!helpTextDiv) {
          helpTextDiv = document.createElement("div");
          helpTextDiv.className = 'col-sm-9 col-sm-offset-3 has-error';
          formGroup.appendChild(helpTextDiv);
        }
        helpTextDiv.innerHTML = '<span style="display: block;" class="help-block">' + text + '</span>';
        $(formGroup).addClass('has-error');
        if (inputGroupButton)
          $(inputGroupButton).addClass('btn-danger');
      } else {
        setTimeout(function () {
          if (helpTextDiv) {
            $(helpTextDiv).remove();
            helpTextDiv = null;
          }
        }, 250);
        $(formGroup).removeClass('has-error');
        if (inputGroupButton)
          $(inputGroupButton).removeClass('btn-danger');
      }
    }
  }
850038
def get_search_form(self):
        
        magic_dico_form = self.get_dict_for_forms()
        forms = []
        initial = list(self.request.GET.lists())

        for key, value in magic_dico_form.items():
            form = Form()
            model = value["model"]
            if not value["fields"]:
                continue
            for field in value["fields"]:
                formfield = get_formfield(model, field)
                formfield.widget.attrs.update({'class': self.css_class})
                form.fields.update({
                    field : formfield
                })

            initial_tmp = {}
            for k, vals in initial:
                tmp_list = k.split(model.__name__ + "-")
                if len(tmp_list) == 2:
                    list_val_tmp = vals[0] if len(vals) == 1 else [val for val in vals if val != '']
                    initial_tmp[tmp_list[-1]] = list_val_tmp

            form.initial = initial_tmp
            form.prefix = model.__name__
            forms.append(form)
        return sorted(forms, key=lambda form: form.prefix)