#NEWLINE# @ staff_member_required #NEWLINE# def cancel_delivery_group( request , order_pk , group_pk ) : #NEWLINE# #INDENT# order = get_object_or_404 ( Order , pk = order_pk ) #NEWLINE# group = get_object_or_404 ( order . groups . all ( ) , pk = group_pk ) #NEWLINE# form = CancelGroupForm ( ( request . POST or None ) , delivery_group = group ) #NEWLINE# status = 200 #NEWLINE# if form . is_valid ( ) : #NEWLINE# #INDENT# with transaction . atomic ( ) : #NEWLINE# #INDENT# form . cancel_group ( ) #NEWLINE# #UNINDENT# msg = ( _ ( 'Cancelled %s' ) % group ) #NEWLINE# messages . success ( request , msg ) #NEWLINE# group . order . create_history_entry ( comment = msg , user = request . user ) #NEWLINE# return redirect ( 'dashboard:order-details' , order_pk = order_pk ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if form . errors : #NEWLINE# #INDENT# status = 400 #NEWLINE# #UNINDENT# #UNINDENT# ctx = { #NEWLINE# #INDENT# 'order' : order , #NEWLINE# 'group' : group , #NEWLINE# #UNINDENT# } #NEWLINE# template = 'dashboard/order/modal_cancel_delivery_group.html' #NEWLINE# return TemplateResponse ( request , template , ctx , status = status )