def show(self, name, contract=None, start=None, end=None, account=None, management=None, support_level="", support_type="", virt_only=None, products=[], highlight=None): """ Show subscription details. Start and end should be formatted strings, not actual date objects. Products is a list of tuples in the format (name, id) """ # set a new buffer to clear out all the old tag information self.subscription_text.set_buffer(gtk.TextBuffer()) self._set(self.subscription_text, name) buf = self.subscription_text.get_buffer() tag = buf.create_tag("highlight-tag", weight=pango.WEIGHT_BOLD) for index in utils.find_text(name, highlight): buf.apply_tag(tag, buf.get_iter_at_offset(index), buf.get_iter_at_offset(index + len(highlight))) self._set(self.support_level_text, support_level) self._set(self.support_type_text, support_type) if self.show_contract: self._set(self.contract_number_text, contract) self._set(self.start_end_date_text, "%s - %s" % ( managerlib.formatDate(start), managerlib.formatDate(end))) self._set(self.account_text, account) self._set(self.provides_management_text, management) self._set(self.virt_only_text, virt_only) self.bundled_products.clear() for product in products: self.bundled_products.add_product(utils.apply_highlight(product[0], highlight), product[1])
def show(self, name, contract=None, start=None, end=None, account=None, management=None, support_level="", support_type="", virt_only=None, products=[], highlight=None, sku=None): """ Show subscription details. Start and end should be datetime objects. Products is a list of tuples in the format (name, id) """ # set a new buffer to clear out all the old tag information self.subscription_text.set_buffer(gtk.TextBuffer()) self._set(self.subscription_text, name) buf = self.subscription_text.get_buffer() tag = buf.create_tag("highlight-tag", weight=pango.WEIGHT_BOLD) for index in utils.find_text(name, highlight): buf.apply_tag(tag, buf.get_iter_at_offset(index), buf.get_iter_at_offset(index + len(highlight))) self._set(self.sku_text, sku) display_level = support_level if support_level == "": display_level = _("Not Set") self._set(self.support_level_and_type_text, ", ".join([display_level, support_type])) self._show_other_details(name, contract, start, end, account, management, support_level, support_type, virt_only, products, highlight, sku) self.bundled_products.clear() for product in products: self.bundled_products.add_product(utils.apply_highlight(product[0], highlight), product[1])
def _create_parent_map(self, title): return { 'virt_only': False, 'product_name': title, 'product_name_formatted': apply_highlight(title, self.get_filter_text()), 'quantity_to_consume': 0, 'available': "", 'product_id': "", 'pool_id': "", # not displayed, just for lookup later 'merged_pools': None, # likewise not displayed, for subscription 'align': 0.5, 'multi-entitlement': False, 'background': None, 'quantity_available': 0, 'support_level': "", 'support_type': "", 'quantity_increment': 1, 'pool_type': '' }
def display_pools(self): """ Re-display the list of pools last queried, based on current filter options. """ selection = self.top_view.get_selection() selected_pool_id = None itr = selection.get_selected()[1] if itr: selected_pool_id = self.store.get_value(itr, self.store['pool_id']) self.store.clear() # It may seem backwards that incompatible = self.filters.show_compatible # etc., but think of it like "if show_compatible is true, then # filter out all the incompatible products." merged_pools = self.pool_stash.merge_pools( incompatible=self.filters.show_compatible, overlapping=self.filters.show_no_overlapping, uninstalled=self.filters.show_installed, subscribed=True, text=self.get_filter_text()) if self.pool_stash.all_pools_size() == 0: self.sub_details.clear() # If the date is None (now), use current time on_date = self.date_picker.date or datetime.datetime.now() self.display_message(_("No subscriptions are available on %s.") % on_date.strftime("%Y-%m-%d")) return if len(merged_pools) == 0: self.sub_details.clear() self.display_message(_("No subscriptions match current filters.")) return # Hide the no subscriptions label and show the pools list: self.widget_switcher.set_active(1) sorter = managerlib.MergedPoolsStackingGroupSorter(list(merged_pools.values())) for group in sorter.groups: tree_iter = None if group.name and len(group.entitlements) > 1: tree_iter = self.store.add_map(tree_iter, self._create_parent_map(group.name)) for entry in group.entitlements: quantity_available = 0 if entry.quantity < 0: available = _('Unlimited') quantity_available = -1 else: available = entry.quantity - entry.consumed quantity_available = entry.quantity - entry.consumed pool = entry.pools[0] # Use the maximum suggested quantity, not the first one. BZ 1022198 # This is still incorrect when quantities from multiple merged pools are required suggested_quantity = max([self.calculate_default_quantity(p) for p in entry.pools]) pool_type = PoolWrapper(pool).get_pool_type() attrs = self._product_attrs_to_dict(pool['productAttributes']) # Display support level and type if the attributes are present: support_level = "" support_type = "" if 'support_level' in attrs: support_level = attrs['support_level'] if 'support_type' in attrs: support_type = attrs['support_type'] quantity_increment = 1 if 'calculatedAttributes' in pool: calculated_attrs = pool['calculatedAttributes'] if 'quantity_increment' in calculated_attrs: quantity_increment = int(calculated_attrs['quantity_increment']) self.store.add_map(tree_iter, { 'virt_only': self._machine_type(entry.pools), 'product_name': str(entry.product_name), 'product_name_formatted': apply_highlight(entry.product_name, self.get_filter_text()), 'quantity_to_consume': suggested_quantity, 'available': str(available), 'product_id': str(entry.product_id), 'pool_id': entry.pools[0]['id'], # not displayed, just for lookup later 'merged_pools': entry, # likewise not displayed, for subscription 'align': 0.5, 'multi-entitlement': allows_multi_entitlement(pool), 'background': None, 'quantity_available': quantity_available, 'support_level': support_level, 'support_type': support_type, 'quantity_increment': quantity_increment, 'pool_type': str(pool_type) }) # Ensure that all nodes are expanded in the tree view. self.top_view.expand_all() self._stripe_rows(None, self.store) # set the selection/details back to what they were, if possible def select_row(model, path, itr, data): if model.get_value(itr, model['pool_id']) == data[0]: data[1].set_cursor(path) return True # Attempt to re-select if there was a selection if selected_pool_id: self.store.foreach(select_row, (selected_pool_id, self.top_view)) # If we don't have a selection, clear the sub_details view # TODO: is this conditional necessary? If so, when? if not self.top_view.get_selection().get_selected()[1]: self.sub_details.clear()
def display_pools(self): """ Re-display the list of pools last queried, based on current filter options. """ selection = self.top_view.get_selection() selected_pool_id = None itr = selection.get_selected()[1] if itr: selected_pool_id = self.store.get_value(itr, self.store['pool_id']) self.store.clear() # It may seem backwards that incompatible = self.filters.show_compatible # etc., but think of it like "if show_compatible is true, then # filter out all the incompatible products." merged_pools = self.pool_stash.merge_pools( incompatible=self.filters.show_compatible, overlapping=self.filters.show_no_overlapping, uninstalled=self.filters.show_installed, subscribed=True, text=self.get_filter_text()) if self.pool_stash.all_pools_size() == 0: self.sub_details.clear() # If the date is None (now), use current time on_date = self.date_picker.date or datetime.datetime.now() self.display_message( _("No subscriptions are available on %s.") % on_date.strftime("%Y-%m-%d")) return if len(merged_pools) == 0: self.sub_details.clear() self.display_message(_("No subscriptions match current filters.")) return # Hide the no subscriptions label and show the pools list: self.widget_switcher.set_active(1) sorter = managerlib.MergedPoolsStackingGroupSorter( list(merged_pools.values())) for group in sorter.groups: tree_iter = None if group.name and len(group.entitlements) > 1: tree_iter = self.store.add_map( tree_iter, self._create_parent_map(group.name)) for entry in group.entitlements: quantity_available = 0 if entry.quantity < 0: available = _('Unlimited') quantity_available = -1 else: available = entry.quantity - entry.consumed quantity_available = entry.quantity - entry.consumed pool = entry.pools[0] # Use the maximum suggested quantity, not the first one. BZ 1022198 # This is still incorrect when quantities from multiple merged pools are required suggested_quantity = max( [self.calculate_default_quantity(p) for p in entry.pools]) pool_type = PoolWrapper(pool).get_pool_type() attrs = self._product_attrs_to_dict(pool['productAttributes']) # Display support level and type if the attributes are present: support_level = "" support_type = "" if 'support_level' in attrs: support_level = attrs['support_level'] if 'support_type' in attrs: support_type = attrs['support_type'] quantity_increment = 1 if 'calculatedAttributes' in pool: calculated_attrs = pool['calculatedAttributes'] if 'quantity_increment' in calculated_attrs: quantity_increment = int( calculated_attrs['quantity_increment']) self.store.add_map( tree_iter, { 'virt_only': self._machine_type(entry.pools), 'product_name': str(entry.product_name), 'product_name_formatted': apply_highlight(entry.product_name, self.get_filter_text()), 'quantity_to_consume': suggested_quantity, 'available': str(available), 'product_id': str(entry.product_id), 'pool_id': entry.pools[0] ['id'], # not displayed, just for lookup later 'merged_pools': entry, # likewise not displayed, for subscription 'align': 0.5, 'multi-entitlement': allows_multi_entitlement(pool), 'background': None, 'quantity_available': quantity_available, 'support_level': support_level, 'support_type': support_type, 'quantity_increment': quantity_increment, 'pool_type': str(pool_type) }) # Ensure that all nodes are expanded in the tree view. self.top_view.expand_all() self._stripe_rows(None, self.store) # set the selection/details back to what they were, if possible def select_row(model, path, itr, data): if model.get_value(itr, model['pool_id']) == data[0]: data[1].set_cursor(path) return True # Attempt to re-select if there was a selection if selected_pool_id: self.store.foreach(select_row, (selected_pool_id, self.top_view)) # If we don't have a selection, clear the sub_details view # TODO: is this conditional necessary? If so, when? if not self.top_view.get_selection().get_selected()[1]: self.sub_details.clear()