def cancel_one(self, request, order=None): if order is not None: if cancel_order(order): self.message_user(request, 'One order was cancelled!') else: self.message_user(request, 'No orders were cancelled!') else: return None
def make_cancelled(self, request, queryset): orders_cancelled = 0 for order in queryset: if cancel_order(order): orders_cancelled += 1 if orders_cancelled == 0: self.message_user(request, 'No orders were cancelled!') else: if orders_cancelled == 1: self.message_user(request, 'One order was cancelled!') else: self.message_user(request, '%d orders were cancelled!' % orders_cancelled)