Skip to content

Commit

Permalink
Remove hard coded dependency on stats from the files app
Browse files Browse the repository at this point in the history
  • Loading branch information
kimakan committed Oct 8, 2024
1 parent f980bc9 commit 18a84de
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions daiquiri/files/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from django_sendfile import sendfile

from daiquiri.core.utils import get_client_ip, markdown
from daiquiri.stats.models import Record

from .models import Directory

Expand Down Expand Up @@ -89,14 +88,16 @@ def send_file(request, file_path, search=None):

absolute_file_path = os.path.join(settings.FILES_BASE_PATH, file_path)

Record.objects.create(
time=now(),
resource_type='FILE',
resource=resource,
client_ip=get_client_ip(request),
user=request.user if request.user.is_authenticated else None,
size=os.path.getsize(absolute_file_path)
)
if 'daiquiri.stats' in settings.INSTALLED_APPS:
from daiquiri.stats.models import Record
Record.objects.create(
time=now(),
resource_type='FILE',
resource=resource,
client_ip=get_client_ip(request),
user=request.user if request.user.is_authenticated else None,
size=os.path.getsize(absolute_file_path)
)

# send the file to the client
return sendfile(request, absolute_file_path)
Expand Down

0 comments on commit 18a84de

Please sign in to comment.