def get(self): venue_id = self.request.get_range('venue_id') if venue_id: venue = Venue.get_by_id(venue_id) else: venue = None single_modifier_ids = [] group_modifier_ids = [] products = MenuItem.query().fetch() for product in products: if venue and venue.key in product.restrictions: continue for modifier in product.group_modifiers: if modifier.id not in group_modifier_ids: group_modifier_ids.append(modifier.id()) for modifier in product.single_modifiers: if modifier.id not in single_modifier_ids: single_modifier_ids.append(modifier.id()) single_modifiers = SingleModifier.query().order(SingleModifier.sequence_number).fetch() for single_modifier in single_modifiers: single_modifier.products = [] for product in products: if single_modifier.key in product.single_modifiers: single_modifier.products.append(product) if single_modifier.key.id() in single_modifier_ids: single_modifier.enable = True else: single_modifier.enable = False group_modifiers = GroupModifier.query().order(GroupModifier.sequence_number).fetch() for group_modifier in group_modifiers: group_modifier.choices = sorted(group_modifier.choices, key=lambda choice: choice.sequence_number) group_modifier.products = [] for product in products: if group_modifier.key in product.group_modifiers: group_modifier.products.append(product) if group_modifier.key.id() in group_modifier_ids: group_modifier.enable = True else: group_modifier.enable = False self.render('/menu/modifiers.html', **{ 'single_modifiers': single_modifiers, 'group_modifiers': group_modifiers, 'inf': SingleModifier.INFINITY, 'venues': Venue.query().fetch(), 'chosen_venue': venue })
def post(self): for group_modifier in GroupModifier.query().fetch(): confirmed = bool(self.request.get('required_%s' % group_modifier.key.id())) group_modifier.required = confirmed group_modifier.put() self.redirect('/company/menu/main')