def get(self): modifier_type = self.request.get_range('modifier_type') modifier = None if modifier_type == SINGLE_MODIFIER: modifier = SingleModifier.get_by_id(self.request.get_range('modifier_id')) elif modifier_type == GROUP_MODIFIER: modifier = GroupModifier.get_by_id(self.request.get_range('modifier_id')) else: self.abort(400) categories = MenuCategory.query().fetch() for category in categories: category.products = [] for product in category.get_items(only_available=True): category.products.append(product) if modifier_type == SINGLE_MODIFIER: if modifier.key in product.single_modifiers: product.has_modifier = True else: product.has_modifier = False elif modifier_type == GROUP_MODIFIER: if modifier.key in product.group_modifiers: product.has_modifier = True else: product.has_modifier = False self.render('/menu/select_products_modifier.html', **{ 'categories': categories, 'modifier': modifier, 'modifier_type': modifier_type })
def post(self): group_modifier_id = self.request.get_range('group_modifier_id') group_modifier = GroupModifier.get_by_id(group_modifier_id) if not group_modifier: self.abort(400) group_modifier.title = self.request.get('name') group_modifier.put() self.redirect_to('modifiers_list')
def get(self): group_modifier_id = self.request.get_range('group_modifier_id') group_modifier = GroupModifier.get_by_id(group_modifier_id) if not group_modifier: self.abort(400) self.render('/menu/add_group_modifier.html', **{ 'group_modifier': group_modifier })
def get(self): modifier_id = self.request.get_range('modifier_id') modifier = GroupModifier.get_by_id(modifier_id) if not modifier: self.abort(400) self.render('/menu/select_default_choice.html', **{ 'modifier': modifier, 'choices': modifier.choices })
def post(self): modifier_id = self.request.get_range('modifier_id') modifier = GroupModifier.get_by_id(modifier_id) if not modifier: self.abort(400) choice_id = self.request.get_range('choice_id') for choice in modifier.choices: choice.default = choice.choice_id == choice_id modifier.put() self.redirect_to('modifiers_list')
def post(self): modifier_id = self.request.get_range('modifier_id') modifier = GroupModifier.get_by_id(modifier_id) previous = modifier.get_previous_modifier() if not previous: self.abort(400) _swap_sequence_numbers(previous, modifier) modifier.put() previous.put() self.response.headers["Content-Type"] = "application/json" self.response.write(json.dumps({ 'success': True, 'modifier_id': modifier.key.id(), 'previous_id': previous.key.id() }, separators=(',', ':')))
def post(self, group_modifier_id): name = self.request.get('name') prices = unique(self.request.params.getall('price')) group_modifier = GroupModifier.get_by_id(int(group_modifier_id)) for price in prices: if not len(price): continue price = float(price) price = int(round(price * 100)) choice = GroupModifierChoice.create(title=name, price=price) choice.sequence_number = group_modifier.generate_choice_sequence_number() group_modifier.choices.append(choice) group_modifier.put() self.redirect_to('modifiers_list')
def post(self): modifier_id = self.request.get_range('modifier_id') modifier = GroupModifier.get_by_id(modifier_id) if not modifier: self.abort(400) next_ = modifier.get_next_modifier() if not next_: self.abort(400) _swap_sequence_numbers(modifier, next_) modifier.put() next_.put() self.response.headers["Content-Type"] = "application/json" self.response.write(json.dumps({ 'success': True, 'modifier_id': modifier.key.id(), 'next_id': next_.key.id() }, separators=(',', ':')))
def post(self): key = self.request.get('key') choice_id = int(key.split('_')[0]) modifier_id = int(key.split('_')[1]) modifier = GroupModifier.get_by_id(modifier_id) if not modifier: self.abort(400) choice = modifier.get_choice_by_id(choice_id) if not choice: self.abort(400) next_ = modifier.get_next_choice(choice) if not next_: self.abort(400) _swap_sequence_numbers(choice, next_) modifier.put() self.response.headers["Content-Type"] = "application/json" self.response.write(json.dumps({ 'success': True }, separators=(',', ':')))
def _process_item_dict(item_dict, gift=False): item_obj = copy.copy(MenuItem.get_by_id(int(item_dict['id']))) item_obj.amount = item_dict['quantity'] item_obj.total_float_price = item_obj.float_price * item_obj.amount item_obj.modifiers = [] item_obj.is_gift = gift for modifier_dict in item_dict['single_modifiers']: modifier = SingleModifier.get_by_id(int(modifier_dict['id'])) modifier.amount = modifier_dict['quantity'] modifier.total_float_price = modifier.float_price * modifier.amount item_obj.total_float_price += modifier.total_float_price * item_obj.amount item_obj.modifiers.append(modifier) for modifier_dict in item_dict['group_modifiers']: modifier = GroupModifier.get_by_id(int(modifier_dict['id'])) choice = modifier.get_choice_by_id(int(modifier_dict['choice'])) choice.amount = modifier_dict['quantity'] choice.total_float_price = choice.float_price * choice.amount item_obj.total_float_price += choice.total_float_price * item_obj.amount item_obj.modifiers.append(choice) if gift: item_obj.total_float_price = 0.0 return item_obj
def post(self): modifier_type = self.request.get_range('modifier_type') modifier = None if modifier_type == SINGLE_MODIFIER: modifier = SingleModifier.get_by_id(self.request.get_range('modifier_id')) elif modifier_type == GROUP_MODIFIER: modifier = GroupModifier.get_by_id(self.request.get_range('modifier_id')) else: self.abort(400) for product in MenuItem.query().fetch(): confirmed = bool(self.request.get(str(product.key.id()))) if modifier_type == SINGLE_MODIFIER: found = False for single_modifier in product.single_modifiers: if single_modifier == modifier.key: if not confirmed: product.single_modifiers.remove(single_modifier) product.put() found = True if not found: if confirmed: product.single_modifiers.append(modifier.key) product.put() elif modifier_type == GROUP_MODIFIER: found = False for group_modifier in product.group_modifiers: if group_modifier == modifier.key: if not confirmed: product.group_modifiers.remove(group_modifier) product.put() found = True if not found: if confirmed: product.group_modifiers.append(modifier.key) product.put() self.redirect_to('modifiers_list')