def edit_cb(self, widget): """Edits category or product.""" model, iterator = self.treeview.get_selection().get_selected() if self.mode == CATEGORIES_MODE: try: cname, cid = model[iterator][0], model[iterator][1] except: # no category is selected return else: new_cname = show_add_category_dialog(self.window, cname) if self.controller.update_category(new_cname, cid): self._show_categories() else: try: pname, pu, pi, pid, cid = ( model[iterator][0], model[iterator][1], model[iterator][2], model[iterator][3], model[iterator][5], ) except: # no product is selected return else: pname, pu, pi, cid = show_add_product_dialog( self.window, self.controller.get_categories(), (pname, pu, pi, cid) ) if self.controller.update_product(pname, pu, pi, pid, cid): self._show_products(self.cid)
def add_cb(self, widget): """Adds new category or product.""" if self.mode == CATEGORIES_MODE: cname = show_add_category_dialog(self.window) if self.controller.add_category(cname): self._show_categories() else: product = show_add_product_dialog( self.window, self.controller.get_categories(), selected_category_id=self.cid ) if self.controller.add_product(product): self._show_products(self.cid)