Skip to content

Commit

Permalink
refactor real_models into concrete_inode_models and concrete_file_models
Browse files Browse the repository at this point in the history
  • Loading branch information
jrief committed Oct 22, 2024
1 parent 68cf988 commit 33768ba
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
5 changes: 2 additions & 3 deletions finder/admin/inode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions finder/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion finder/management/commands/reorganize_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
5 changes: 4 additions & 1 deletion finder/models/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions finder/models/inode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down

0 comments on commit 33768ba

Please sign in to comment.