Skip to content

Commit

Permalink
WIP, refactoring, part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
timok19 committed Nov 11, 2024
1 parent 706c0be commit dc53f4b
Show file tree
Hide file tree
Showing 1,093 changed files with 112,108 additions and 10,668 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ static/CACHE/
static/*.css
static/*.js
static/*.map
media/uploaded_images/

.DS_Store
yarn-error.log.DS_Store
Expand Down
28 changes: 14 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/python-poetry/poetry
rev: 1.8.3
rev: 1.8.4
hooks:
- id: poetry-check
name: "Check Poetry configuration"
Expand All @@ -19,16 +19,16 @@ repos:
name: "Export only dev dependencies"
args: ["--only", "dev", "--without-hashes", "-f", "requirements.txt", "--output", "requirements-dev.txt"]
verbose: true
- repo: https://github.com/pypa/pip-audit
rev: v2.7.3
hooks:
- id: pip-audit
name: "Audit dependencies"
args: ["-r", "requirements.txt"]
verbose: true
- id: pip-audit
name: "Audit dev dependencies"
args: ["-r", "requirements-dev.txt"]
verbose: true
ci:
skip: [pip-audit]
#- repo: https://github.com/pypa/pip-audit
# rev: v2.7.3
# hooks:
# - id: pip-audit
# name: "Audit dependencies"
# args: ["-r", "requirements.txt"]
# verbose: true
# - id: pip-audit
# name: "Audit dev dependencies"
# args: ["-r", "requirements-dev.txt"]
# verbose: true
#ci:
# skip: [pip-audit]
21 changes: 16 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,28 @@ FROM python:${PYTHON_VERSION}
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

RUN mkdir -p /code
RUN apt-get update && apt-get install -y cron

WORKDIR /code
RUN mkdir -p /app

WORKDIR /app

RUN pip install poetry
COPY pyproject.toml poetry.lock /code/
RUN poetry install --no-dev -n -v
COPY . /code
RUN poetry install --no-dev --no-interaction --no-ansi

COPY pyproject.toml poetry.lock /app/

COPY . /app

RUN python manage.py collectstatic --noinput

# Add the cron job for running the Django management command every day
RUN echo "0 0 * * * /usr/local/bin/python /app/manage.py runjobs daily >> /var/log/cron.log 2>&1" > /etc/cron.d/django-cron
RUN chmod 0644 /etc/cron.d/django-cron
RUN crontab /etc/cron.d/django-cron

RUN touch /var/log/cron.log

EXPOSE 8000

CMD ["gunicorn", "--bind", ":8000", "--workers", "2", "webpeditor.wsgi"]
32 changes: 32 additions & 0 deletions delete_old_css_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
import time

from webpeditor.settings import STATIC_ROOT


def delete_old_css_files(path_to_css: str) -> None:
files: list[str] = os.listdir(path_to_css)

deleted_files_count: int = 0

for file in files:
file_path: str = os.path.join(path_to_css, file)

file_name, file_extension = os.path.splitext(file)

if not os.path.isfile(file_path) and not file_extension.__contains__(".css"):
print("There is no css file to delete")
break

creation_time: float = os.path.getctime(file_path)

if time.time() - creation_time > 86400:
os.remove(file_path)
deleted_files_count += 1
print(f"Deleted file: {file_name}{file_extension}")

print(f"Total deleted CSS files: {deleted_files_count}")


if __name__ == "__main__":
delete_old_css_files(os.path.join(STATIC_ROOT, "CACHE", "css"))
29 changes: 0 additions & 29 deletions delete_old_css_styles.py

This file was deleted.

2 changes: 1 addition & 1 deletion fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ primary_region = "ams"
grace_period = "8s"

[[statics]]
guest_path = "/code/static"
guest_path = "/app/static"
url_prefix = "/static/"

[deploy]
Expand Down
7 changes: 4 additions & 3 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""

import os
import sys


def main():
def main() -> None:
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'webpeditor.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "webpeditor.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand All @@ -18,5 +19,5 @@ def main():
execute_from_command_line(sys.argv)


if __name__ == '__main__':
if __name__ == "__main__":
main()
Loading

0 comments on commit dc53f4b

Please sign in to comment.