Changeset 3674
- Timestamp:
- 08/28/06 14:53:26 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/per-object-permissions/django/contrib/admin/templatetags/admin_list.py
r3628 r3674 106 106 pk = cl.lookup_opts.pk.attname 107 107 #If show_all_rows is set to False, then we have to check the permission on the object 108 if not cl.opts.admin.show_all_rows: 109 if not cl.user.has_perm(cl.opts.app_label + "." + cl.opts.get_change_permission(), object=result): 110 return 111 #Update the count 112 cl.result_count = cl.result_count +1 108 113 109 for field_name in cl.lookup_opts.admin.list_display: 114 110 row_class = '' django/branches/per-object-permissions/django/contrib/admin/views/main.py
r3669 r3674 652 652 #is done later in the result_list tag at which point it will calculate the correct 653 653 #number of rows shown 654 if self.opts.admin.show_all_rows: 655 self.result_count = result_count 656 else: 657 self.result_count = 0 654 655 self.result_count = result_count 658 656 self.full_result_count = full_result_count 659 657 self.result_list = result_list … … 693 691 694 692 def get_query_set(self): 695 qs = self.manager.get_query_set() 693 if (not self.opts.admin.show_all_rows) and self.opts.row_level_permissions and (not self.user.has_perm(self.opts.app_label + "."+self.opts.get_change_permission()): 694 from django.contrib.auth.models import RowLevelPermission 695 qs = self.manager.filter(id__in=RowLevelPermission.objects.get_model_list(self.user, 696 self.model, 697 self.opts.get_change_permission())) 698 else: 699 qs = self.manager.get_query_set() 696 700 lookup_params = self.params.copy() # a dictionary of the query string 697 701 for i in (ALL_VAR, ORDER_VAR, ORDER_TYPE_VAR, SEARCH_VAR, IS_POPUP_VAR): django/branches/per-object-permissions/django/contrib/auth/models.py
r3657 r3674 72 72 ret_dict[delete_str]=self.create_row_level_permission(model_instance, owner, delete_str, negative=negDel) 73 73 return ret_dict 74 75 def get_model_list(self,user, model, perm): 76 model_ct=ContentType.objects.get_for_model(model) 77 if isinstance(perm, str): 78 perm = Permission.objects.get(codename__exact=perm, content_type=model_ct.id) 79 user_model_ids = RowLevelPermission.objects.filter(owner_ct=ContentType.objects.get_for_model(User), 80 owner_id=user.id, permission=perm.id, 81 model_ct=model_ct 82 ).values('model_id') 83 user_group_list = [g['id'] for g in user.groups.select_related().values('id')] 84 group_model_ids = RowLevelPermission.objects.filter(owner_ct=ContentType.objects.get_for_model(Group).id, 85 owner_id__in=user_group_list, 86 model_ct = model_ct 87 ).values('model_id') 88 id_list = [o['model_id'] for o in user_model_ids] + [o['model_id'] for o in group_model_ids] 89 return id_list 74 90 75 91 class RowLevelPermission(models.Model):
