Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove hard coded dependency on stats from the files app #249

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading