def _group_group_modifiers(modifiers): result = {} for modifier in modifiers: key = '%s%s' % (modifier[0].id, modifier[1]) if key in result: result[key]['quantity'] += 1 else: modifier_obj = GroupModifier.get(modifier[0].id()) if not modifier_obj: continue choice = modifier_obj.get_choice_by_id(modifier[1]) if modifier_obj and choice: result[key] = { 'id': str(modifier[0].id()), 'name': choice.title, 'choice': str(modifier[1]), 'quantity': 1 } return result.values()
def set_modifiers(items, with_gift_obj=False, with_share_gift_obj=False): mod_items = [] for item in items: menu_item = MenuItem.get(item['item_id']) if not menu_item and SubscriptionModule.has_module(): menu_item = get_subscription_menu_item(item) menu_item = copy.copy(menu_item) if with_gift_obj: menu_item.gift_obj = item['gift_obj'] else: if menu_item: menu_item.gift_obj = None if with_share_gift_obj: menu_item.share_gift_obj = item['share_gift_obj'] else: menu_item.share_gift_obj = None menu_item.chosen_single_modifiers = [] for single_modifier in item['single_modifiers']: single_modifier_obj = copy.copy( SingleModifier.get(single_modifier['single_modifier_id'])) for i in xrange(single_modifier['quantity']): menu_item.chosen_single_modifiers.append(single_modifier_obj) menu_item.chosen_group_modifiers = [] for group_modifier in item['group_modifiers']: group_modifier_obj = copy.copy( GroupModifier.get(group_modifier['group_modifier_id'])) if not group_modifier_obj: continue group_modifier_obj.choice = group_modifier_obj.get_choice_by_id( group_modifier['choice']) if group_modifier_obj.choice: for i in xrange(group_modifier['quantity']): menu_item.chosen_group_modifiers.append(group_modifier_obj) for i in xrange(item['quantity']): mod_items.append(menu_item) return mod_items