diff --git a/finder/admin/inode.py b/finder/admin/inode.py index 044d74a20..611e20087 100644 --- a/finder/admin/inode.py +++ b/finder/admin/inode.py @@ -2,7 +2,6 @@ from django.contrib import admin from django.contrib.sites.shortcuts import get_current_site -from django.core.exceptions import ValidationError from django.db.models.expressions import F, Value from django.db.models.fields import BooleanField from django.db.models.functions import Lower @@ -40,7 +39,7 @@ def get_urls(self): def get_object(self, request, object_id, from_field=None): site = get_current_site(request) - for model in InodeModel.real_models: + for model in InodeModel.concrete_inode_models: try: obj = model.objects.get(id=object_id) if obj.is_folder and obj.realm.site == site and obj.realm.slug == self.admin_site.name: @@ -125,7 +124,7 @@ def get_inodes(self, request, sorting=None, **lookup): """ inodes, applicable_sorting = [], [] labels = lookup.pop('labels__in', None) - for inode_model in InodeModel.real_models: + for inode_model in InodeModel.concrete_inode_models: queryset = ( inode_model.objects.select_related('owner') .filter(**lookup) diff --git a/finder/api/views.py b/finder/api/views.py index 530ae9999..beff19a0f 100644 --- a/finder/api/views.py +++ b/finder/api/views.py @@ -114,8 +114,6 @@ def list(self, request, folder_id): folder = FolderModel.objects.get(id=folder_id) request.session['finder.last_folder'] = str(folder_id) - folder.listdir(is_folder=False) - return { 'files': [{ 'id': str(file.id), diff --git a/finder/management/commands/reorganize_finder.py b/finder/management/commands/reorganize_finder.py index 463c2a024..8bbe5855d 100644 --- a/finder/management/commands/reorganize_finder.py +++ b/finder/management/commands/reorganize_finder.py @@ -14,7 +14,7 @@ def handle(self, verbosity, *args, **options): self.reorganize() def reorganize(self): - for inode_model in InodeModel.real_models: + for inode_model in InodeModel.concrete_inode_models: if inode_model.is_folder: continue for file in inode_model.objects.all(): diff --git a/finder/models/folder.py b/finder/models/folder.py index a2c3b9a00..2ca737aad 100644 --- a/finder/models/folder.py +++ b/finder/models/folder.py @@ -85,7 +85,10 @@ def subfolders(self): @property def num_children(self): - num_children = sum(inode_model.objects.filter(parent=self).count() for inode_model in InodeModel.real_models) + num_children = sum( + inode_model.objects.filter(parent=self).count() + for inode_model in InodeModel.concrete_inode_models + ) return num_children @cached_property diff --git a/finder/models/inode.py b/finder/models/inode.py index 0f6840704..b2aa59502 100644 --- a/finder/models/inode.py +++ b/finder/models/inode.py @@ -40,17 +40,17 @@ def _validate_accept_mime_types(new_class): new_class._mime_types_mapping[accept_mime_type] = new_class @property - def real_models(self): + def concrete_inode_models(self): """ - Yields all real (excluding proxy models) that inherit from InodeModel. + Yields all concrete (excluding proxy models) that inherit from InodeModel. """ yield self._inode_models['finder.FolderModel'] - yield from self.real_file_models + yield from self.concrete_file_models @property - def real_file_models(self): + def concrete_file_models(self): """ - Yields all real (excluding proxy models) that inherit from AbstractFileModel. + Yields all concrete (excluding proxy models) that inherit from AbstractFileModel. """ for model in self._inode_models.values(): if not model.is_folder and not model._meta.proxy: @@ -74,9 +74,11 @@ class InodeManagerMixin: def filter_inodes(self, **lookup): from .folder import FolderModel - if lookup.pop('is_folder', False): + is_folder = lookup.pop('is_folder', None) + if is_folder: return FolderModel.objects.filter(**lookup).iterator() - inodes = [inode_model.objects.filter(**lookup) for inode_model in InodeModel.real_file_models] + concrete_models = InodeModel.concrete_file_models if is_folder is False else InodeModel.concrete_inode_models + inodes = [inode_model.objects.filter(**lookup) for inode_model in concrete_models] return chain(*inodes) def get_inode(self, **lookup):