File tree Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -87,12 +87,14 @@ def add_product_type(request):
8787@user_passes_test (lambda u : u .is_staff )
8888def edit_product_type (request , ptid ):
8989 pt = get_object_or_404 (Product_Type , pk = ptid )
90- pt_form = Product_TypeForm (instance = pt )
90+ authed_users = pt .authorized_users .all ()
91+ pt_form = Product_TypeForm (instance = pt , initial = {'authorized_users' : authed_users })
9192 delete_pt_form = Delete_Product_TypeForm (instance = pt )
9293 if request .method == "POST" and request .POST .get ('edit_product_type' ):
9394 pt_form = Product_TypeForm (request .POST , instance = pt )
9495 if pt_form .is_valid ():
9596 pt = pt_form .save ()
97+ pt .authorized_users .set (pt_form .cleaned_data ['authorized_users' ])
9698 messages .add_message (
9799 request ,
98100 messages .SUCCESS ,
Original file line number Diff line number Diff line change @@ -310,6 +310,12 @@ def edit_user(request, uid):
310310
311311 if form .is_valid () and contact_form .is_valid ():
312312 form .save ()
313+ for init_auth_prods in authed_products :
314+ init_auth_prods .authorized_users .remove (user )
315+ init_auth_prods .save ()
316+ for init_auth_prod_types in authed_product_types :
317+ init_auth_prod_types .authorized_users .remove (user )
318+ init_auth_prod_types .save ()
313319 if 'authorized_products' in form .cleaned_data and len (form .cleaned_data ['authorized_products' ]) > 0 :
314320 for p in form .cleaned_data ['authorized_products' ]:
315321 p .authorized_users .add (user )
You can’t perform that action at this time.
0 commit comments