Skip to content

Commit

Permalink
use shutil for disk space, add modellogging, fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jeriox committed Oct 11, 2024
1 parent d5eb8a0 commit b60d503
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
2 changes: 2 additions & 0 deletions docs/admin/deployment/manual/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ For apache you can build on this:
ProxyPassReverse / http://localhost:8327/
</VirtualHost>
Please note that `FALLBACK_MEDIA_SERVING` needs to be set to `True` in the ephios configuration when using apache.

Remember to replace all the domain names and certificate paths with your own.
Make sure to use secure SSL settings.
To obtain SSL certificates, you can use `certbot <https://certbot.eff.org/>`_ with Let's Encrypt.
Expand Down
12 changes: 2 additions & 10 deletions ephios/core/services/health/healthchecks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
import shutil

from django.conf import settings
from django.contrib.auth.models import Permission
Expand Down Expand Up @@ -162,15 +162,7 @@ def check(self):
# if under 100 MB are available, we consider this an error
# if under 1 GB are available, we consider this a warning
# otherwise, we consider this ok
try:
disk_usage = os.statvfs(settings.MEDIA_ROOT)
except AttributeError:
# not available on windows
return (
HealthCheckStatus.UNKNOWN,
mark_safe(_("Disk space check not available.")),
)
free_bytes = disk_usage.f_bavail * disk_usage.f_frsize
free_bytes = shutil.disk_usage(settings.MEDIA_ROOT).free
MEGA = 1024 * 1024
if free_bytes < 100 * MEGA:
return (
Expand Down
1 change: 1 addition & 0 deletions ephios/plugins/files/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def clean_file(self):
_("The file is too large. There are only %(quota)s available."),
params={"quota": filesizeformat(settings.GET_USERCONTENT_QUOTA())},
)
return self.cleaned_data["file"]


class EventAttachedDocumentForm(BasePluginFormMixin, Form):
Expand Down
12 changes: 12 additions & 0 deletions ephios/plugins/files/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.db import models

from ephios.core.models import Event
from ephios.modellogging.log import ModelFieldsLogConfig, register_model_for_logging


class Document(models.Model):
Expand All @@ -11,3 +12,14 @@ class Document(models.Model):

def __str__(self):
return str(self.title)


register_model_for_logging(
Document,
ModelFieldsLogConfig(
unlogged_fields=[
"id",
"file",
],
),
)
8 changes: 2 additions & 6 deletions ephios/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import copy
import datetime
import os
import shutil
from datetime import timedelta
from email.utils import getaddresses
from importlib import metadata
Expand Down Expand Up @@ -325,12 +326,7 @@ def GET_USERCONTENT_URL():


def GET_USERCONTENT_QUOTA():
try:
disk_usage = os.statvfs(MEDIA_ROOT)
return disk_usage.f_bavail * disk_usage.f_frsize
except AttributeError:
# not available on windows
return None
return shutil.disk_usage(MEDIA_ROOT).free


# Guardian configuration
Expand Down

0 comments on commit b60d503

Please sign in to comment.