Example #1
0
    def get_list_meta_data(self, entity):
        """Fetches meta-data and updates the list with 'em.

        Args:
            entity (List|Database): List you want to fetch the meta-data for.

        Returns:
            bool -- Tells you wether the operation was successful or not

        .. note::
            ``KEY_COLUMNS`` and ``SELECTION_VALUES`` aren't supported currently.
        """
        if not isinstance(entity, Database) and not isinstance(entity, Query) and not isinstance(entity, RelationalTable):
            raise ValueError('Invalid entity')

        body_node, doc = generate_envelope('GetListMetaData')
        append_text_node_to('LIST_ID', str(entity.id), body_node)

        (success, tree, self.error) = self.get(doc)
        if success:
            result_node = tree.find('Body/RESULT')

            table = Table()

            for item in result_node.findall('KEY_COLUMNS/COLUMN'):
                # @todo: DRY
                column_name = item.find('NAME').text
                column_type = getattr(item.find('TYPE'), 'text', None)
                default_value = getattr(item.find('DEFAULT_VALUE'), 'text', None)

                table.add_column(Column(column_name, column_type, default_value, is_key=True))

            # NOTE: ``COLUMNS`` contains also ``KEY_COLUMNS``
            for item in result_node.findall('COLUMNS/COLUMN'):
                # @todo: DRY
                column_name = item.find('NAME').text
                column_type = getattr(item.find('TYPE'), 'text', None)
                default_value = getattr(item.find('DEFAULT_VALUE'), 'text', None)

                # @todo Add support for selection values
                #                for selection_value in item.find('SELECTION_VALUES/VALUE'):
                #                    pass

                table.add_column(Column(column_name, column_type, default_value))

            to_python(
                entity,
                in_el=result_node,
                str_keys=('ORGANIZATION_ID', ),
                date_keys=('LAST_CONFIGURED', 'CREATED'),
                bool_keys=('OPT_IN_FORM_DEFINED', 'OPT_OUT_FORM_DEFINED', 'PROFILE_FORM_DEFINED',
                           'OPT_IN_AUTOREPLY_DEFINED', 'PROFILE_AUTOREPLY_DEFINED'),
                _table=table)
        return success
 def from_element(cls, el, api):
     return to_python(
         obj=cls(),
         in_el=el,
         str_keys=cls._str_keys,
         int_keys=cls._int_keys,
         date_keys=cls._date_keys,
         bool_keys=cls._bool_keys,
         dict_keys=cls._dict_keys,
         object_map=cls._object_map,
         api=api
     )