taskapp/views/user.py
changeset 148 665eaf56e1d0
parent 145 0c97a02b9bdb
child 152 a65e1ef725dd
equal deleted inserted replaced
147:8c1ed28d04d2 148:665eaf56e1d0
   281 
   281 
   282     user_can_view = True if user_rights == "AD" or ( user_rights == "MG" and role in ["MG", "DV"] ) else False
   282     user_can_view = True if user_rights == "AD" or ( user_rights == "MG" and role in ["MG", "DV"] ) else False
   283 
   283 
   284     if user_can_view:
   284     if user_can_view:
   285         if role == "DV":
   285         if role == "DV":
   286             choices = [ (_.user.id,_.user.username ) for _ in Profile.objects.filter(rights="CT",user__is_active=True) ]
   286             current_contributors = list(User.objects.filter(is_active=True,profile__rights="CT"))
       
   287             pending_requests = user.request_sent_by.filter(is_replied=False,is_valid=True)
       
   288             pending_dv_requests = pending_requests.filter(role="DV")
       
   289 
       
   290             ## one cannot make same request many times
       
   291             for req in pending_dv_requests:
       
   292                 current_contributors.remove(req.sent_to.all()[0])
       
   293 
       
   294             choices = [ (_.id,_.username ) for _ in current_contributors ]
       
   295 
   287         elif role == "MG":
   296         elif role == "MG":
   288             choices = [ (_.user.id,_.user.username ) for _ in Profile.objects.exclude(rights="MG",user__is_active=True).exclude(rights="AD") ]
   297             active_users = User.objects.filter(is_active=True)
       
   298             dv_ct_users = list(active_users.filter(profile__rights="CT") | active_users.filter(profile__rights="DV"))
       
   299             pending_requests = user.request_sent_by.filter(is_replied=False,is_valid=True)
       
   300             pending_mg_requests = pending_requests.filter(role="MG")
       
   301 
       
   302             ## same logic here. you cannot make another request exactly the same.
       
   303             ## but iam still not decided whether someone who requests a user to be admin,
       
   304             ## can be given a chance to request the same user to be a manager or developer
       
   305             for req in pending_mg_requests:
       
   306                 dv_ct_users.remove(req.sent_to.all()[0])
       
   307 
       
   308             choices = [ (_.id, _.username ) for _ in dv_ct_users ]
       
   309 
   289         elif role == "AD":
   310         elif role == "AD":
   290             choices = [ (_.user.id,_.user.username ) for _ in Profile.objects.exclude(rights="AD",user__is_active=True) ]
   311             active_users = User.objects.filter(is_active=True)
       
   312             non_ad_users = list(active_users.exclude(profile__rights="AD"))
       
   313             pending_requests = user.request_sent_by.filter(is_replied=False,is_valid=True)
       
   314             pending_ad_requests = pending_requests.filter(role="AD")
       
   315 
       
   316             ## we filter out users who have already been requested by the user to be an admin
       
   317             for req in pending_ad_requests:
       
   318                 non_ad_users.remove(req.sent_to.all()[0])
       
   319 
       
   320             choices = [ (_.id,_.username ) for _ in non_ad_users ]
   291 
   321 
   292         form = UserChoiceForm(choices)
   322         form = UserChoiceForm(choices)
   293 
   323 
   294         context = {
   324         context = {
   295             'user':user,
   325             'user':user,