Reformated project structure

This commit is contained in:
Kristofers Solo 2023-07-14 00:36:02 +03:00
parent 93b83f02f8
commit b51b43c7a1
66 changed files with 122 additions and 167 deletions

View File

@ -1,23 +0,0 @@
name: Lint
on:
- push
- pull_request
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.10"]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Lint with tox
run: tox

8
.github/workflows/ruff.yml vendored Normal file
View File

@ -0,0 +1,8 @@
name: Ruff
on: [push, pull_request]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: chartboost/ruff-action@v1

18
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,18 @@
name: Django Test
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run tests
run: python src/manage.py test

7
.gitignore vendored
View File

@ -129,8 +129,9 @@ dmypy.json
.pyre/
local-cdn/
config.json
debug
node_modules/
package-lock.json
/static/admin/
/static/fontawesomefree/
db.sqlite3

5
config.json.example Normal file
View File

@ -0,0 +1,5 @@
{
"DEBUG": false,
"SECRET_KEY": "",
"ALLOWED_HOSTS": [""],
}

View File

@ -1,3 +0,0 @@
# from django.contrib import admin
# Register your models here.

View File

@ -1,3 +0,0 @@
# from django.db import models
# Create your models here.

View File

@ -1,3 +0,0 @@
# from django.test import TestCase
# Create your tests here.

View File

@ -1,18 +0,0 @@
from django.shortcuts import redirect, render
def index(request):
return render(request, "main/index.html", {"title": "Kristofers Solo Webpage"})
def lightsaber(request):
return render(request, "main/lightsaber.html", {"title": "Lightsaber"})
def projects(request):
return render(request, "main/projects.html", {"title": "Projects"})
def karbs(request):
"""Karbs install script"""
return redirect("/projects/karbs")

View File

@ -1,3 +0,0 @@
# from django.contrib import admin
# Register your models here.

View File

@ -1,3 +0,0 @@
# from django.db import models
# Create your models here.

View File

@ -1,3 +0,0 @@
# from django.test import TestCase
# Create your tests here.

View File

@ -1,17 +0,0 @@
from django.shortcuts import render
def projects(request):
return render(request, "projects/projects.html", {"title": "Projects"})
def karbs(request):
return render(request, "projects/karbs/karbs/karbs", {"title": "KARBS"})
def instructions(request):
return render(request, "projects/karbs/instructions.html", {"title": "Karbs Instructions"})
def traffic_light_detector(request):
return render(request, "projects/traffic_light_detector/traffic_light_detector.html", {"title": "Traffic Light Detector"})

View File

@ -1,7 +1,3 @@
[build-system]
requires = ["setuptools>=42.0", "wheel"]
build-backend = "setuptools.build_meta"
[tool.mypy]
check_untyped_defs = true
disallow_any_generics = true
@ -15,3 +11,26 @@ warn_redundant_casts = true
warn_return_any = true
warn_unreachable = true
warn_unused_configs = true
[tool.ruff]
line-length = 160
exclude = ["**/**/migrations"]
[tool.black]
line-length = 160
[tool.ruff.flake8-quotes]
docstring-quotes = "double"
[tool.djlint]
close_void_tags = true
format_attribute_template_tags = true
format_css = true
format_js = true
max_line_length = 120
[tool.djlint.css]
indent_size = 4
[tool.djlint.js]
indent_size = 4

View File

@ -1,2 +1,3 @@
Django==4.1
fontawesomefree==6.2.1
Django==4.2
fontawesomefree==6.2
gunicorn==20.1

View File

@ -1,5 +1,2 @@
flake8==6.0.0
mypy==0.991
pytest-cov==4.0.0
pytest==7.2.0
tox==3.27.1
mypy==1.3.0
ruff==0.0.272

View File

@ -1,33 +0,0 @@
[metadata]
name = kristofersxyz
description = Kristofers Solo website
author = Kristofers Solo
license = GPL3
license_files = LICENSE
platforms = unix, linux, osx, cygwin, win32
classifiers =
Programming Language :: Python :: 3.10
[options]
packages = kristofersxyz
install_requires =
Django>=4.1
fontawesomefree>=6.2.1
python_requires = >=3.10
package_dir = =.
zip_safe = no
[options.extras_require]
testing =
flake8>=6.0.0
mypy>=0.991
pytest-cov>=4.0.0
pytest>=7.2.0
tox>=3.27.1
[options.package_data]
detector = py.typed
[flake8]
max-line-length = 160

View File

@ -1,4 +0,0 @@
from setuptools import setup
if __name__ == "__main__":
setup()

17
src/apps/main/views.py Normal file
View File

@ -0,0 +1,17 @@
from django.shortcuts import redirect, render
def index(request):
return render(request, "index.html", {"title": "Kristofers Solo Webpage"})
def lightsaber(request):
return render(request, "lightsaber.html", {"title": "Lightsaber"})
def projects(request):
return render(request, "projects.html", {"title": "Projects"})
def karbs(request):
return redirect("karbs")

View File

View File

View File

View File

View File

View File

@ -0,0 +1,17 @@
from django.shortcuts import render
def projects(request):
return render(request, "projects.html", {"title": "Projects"})
def karbs(request):
return render(request, "karbs/karbs/karbs", {"title": "KARBS"})
def instructions(request):
return render(request, "karbs/instructions.html", {"title": "Karbs Instructions"})
def traffic_light_detector(request):
return render(request, "traffic_light_detector/traffic_light_detector.html", {"title": "Traffic Light Detector"})

View File

View File

@ -15,14 +15,11 @@ import sys
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / "subdir".
BASE_PATH = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(BASE_PATH.joinpath("kristofersxyz", "apps")))
# SECURITY WARNING: don"t run with debug turned on in production!
DEBUG = BASE_PATH.joinpath("debug").is_file()
BASE_DIR = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(BASE_DIR / "apps"))
with open(BASE_PATH.joinpath("config.json"), "r", encoding="UTF-8") as config_file:
with open(BASE_DIR.parent / "config.json", "r", encoding="UTF-8") as config_file:
config = json.load(config_file)
# Quick-start development settings - unsuitable for production
@ -34,6 +31,8 @@ SECRET_KEY = config["SECRET_KEY"]
ALLOWED_HOSTS = config["ALLOWED_HOSTS"]
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config["DEBUG"]
# Application definition
@ -64,7 +63,10 @@ ROOT_URLCONF = "kristofersxyz.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [BASE_PATH.joinpath("templates")],
"DIRS": [
BASE_DIR / "templates",
BASE_DIR / "**" / "templates",
],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
@ -86,7 +88,7 @@ WSGI_APPLICATION = "kristofersxyz.wsgi.application"
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_PATH / "db.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}
@ -126,8 +128,16 @@ USE_TZ = True
# https://docs.djangoproject.com/en/4.0/howto/static-files/
STATIC_URL = "/static/"
STATIC_ROOT = BASE_PATH.joinpath("static")
MEDIA_ROOT = BASE_PATH.joinpath("media")
STATICFILES_DIRS = [
BASE_DIR / "static",
]
STATIC_ROOT = BASE_DIR.parent / "local-cdn" / "static"
MEDIA_URL = "media/"
MEDIAFILES_DIRS = [
BASE_DIR / "media",
]
MEDIA_ROOT = BASE_DIR.parent / "local-cdn" / "media"
# Default primary key field type

View File

@ -14,14 +14,15 @@ Including another URLconf
2. Add a URL to urlpatterns: path("blog/", include("blog.urls"))
"""
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path("admin/", admin.site.urls),
path("", include("main.urls")),
path("projects/", include("projects.urls")),
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
if settings.DEBUG:
from django.conf.urls.static import static
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View File

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

@ -1 +0,0 @@
Subproject commit 2b3859eea3373df2f575ed5e8fc534bb118fb7c4

25
tox.ini
View File

@ -1,25 +0,0 @@
[tox]
minversion = 3.8.0
envlist = py310, flake8, mypy
isolated_build = true
[gh-actions]
python =
3.10: py310, mypy, flake8
[testenv]
setenv =
PYTHONPATH = {toxinidir}
deps =
-r{toxinidir}/requirements_dev.txt
[testenv:flake8]
basepython = python3.10
deps = flake8
commands = flake8 kristofersxyz
[testenv:mypy]
basepython = python3.10
deps =
-r{toxinidir}/requirements_dev.txt
commands = mypy kristofersxyz