commit e1b5e95e0e8fea8bf0b82c511b97d1dea05a9c09 Author: faraphel Date: Thu Jan 23 07:53:29 2025 +0100 initial project diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..790ca20 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +# Development +.idea/ +.venv/ + +# Environment +.env diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b6785d1 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +# Django +django +djangorestframework +markdown +django-filter + +# Others +python-dotenv diff --git a/source/apps/__init__.py b/source/apps/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/source/apps/ctf/__init__.py b/source/apps/ctf/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/source/apps/ctf/admin.py b/source/apps/ctf/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/source/apps/ctf/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/source/apps/ctf/apps.py b/source/apps/ctf/apps.py new file mode 100644 index 0000000..72da749 --- /dev/null +++ b/source/apps/ctf/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class CtfConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'apps.ctf' diff --git a/source/apps/ctf/migrations/__init__.py b/source/apps/ctf/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/source/apps/ctf/models.py b/source/apps/ctf/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/source/apps/ctf/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/source/apps/ctf/templates/ctf/base/base.html b/source/apps/ctf/templates/ctf/base/base.html new file mode 100644 index 0000000..35ddc74 --- /dev/null +++ b/source/apps/ctf/templates/ctf/base/base.html @@ -0,0 +1,13 @@ + + + + + {% block title %}{% endblock %} + {% block head %} + {% endblock %} + + + {% block body %} + {% endblock %} + + diff --git a/source/apps/ctf/templates/ctf/homepage.html b/source/apps/ctf/templates/ctf/homepage.html new file mode 100644 index 0000000..09f70cd --- /dev/null +++ b/source/apps/ctf/templates/ctf/homepage.html @@ -0,0 +1,7 @@ +{% extends "ctf/base/base.html" %} + +{% block title %}Homepage{% endblock %} + +{% block body %} + Homepage +{% endblock %} \ No newline at end of file diff --git a/source/apps/ctf/tests.py b/source/apps/ctf/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/source/apps/ctf/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/source/apps/ctf/urls.py b/source/apps/ctf/urls.py new file mode 100644 index 0000000..3a7d2a0 --- /dev/null +++ b/source/apps/ctf/urls.py @@ -0,0 +1,7 @@ +from django.urls import path + +from source.apps.ctf import views + +urlpatterns = [ + path("", views.homepage, name='homepage'), +] diff --git a/source/apps/ctf/views.py b/source/apps/ctf/views.py new file mode 100644 index 0000000..10888f3 --- /dev/null +++ b/source/apps/ctf/views.py @@ -0,0 +1,5 @@ +from django.shortcuts import render + +# Create your views here. +async def homepage(request): + return render(request, "ctf/homepage.html") diff --git a/source/manage.py b/source/manage.py new file mode 100755 index 0000000..0c58a03 --- /dev/null +++ b/source/manage.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + +import dotenv + + +def main(): + """Run administrative tasks.""" + dotenv.load_dotenv() + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/source/project/__init__.py b/source/project/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/source/project/asgi.py b/source/project/asgi.py new file mode 100644 index 0000000..3e21ffa --- /dev/null +++ b/source/project/asgi.py @@ -0,0 +1,19 @@ +""" +ASGI config for source project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/ +""" + +import os + +import dotenv +from django.core.asgi import get_asgi_application + +dotenv.load_dotenv() + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings') + +application = get_asgi_application() diff --git a/source/project/settings.py b/source/project/settings.py new file mode 100644 index 0000000..beb5fee --- /dev/null +++ b/source/project/settings.py @@ -0,0 +1,140 @@ +""" +Django settings for source project. + +Generated by 'django-admin startproject' using Django 5.1.5. + +For more information on this file, see +https://docs.djangoproject.com/en/5.1/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/5.1/ref/settings/ +""" + +import os +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY: str = os.environ["DJANGO_SECRET_KEY"] + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG: bool = os.environ.get("DEBUG", "False") == "True" + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + # standard + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + # extensions + "rest_framework", + + # applications + "apps.ctf" +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'source.project.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'source.project.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/5.1/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/5.1/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/5.1/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +# API + +REST_FRAMEWORK = { + # Use Django's standard `django.contrib.auth` permissions, + # or allow read-only access for unauthenticated users. + 'DEFAULT_PERMISSION_CLASSES': [ + 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly' + ] +} \ No newline at end of file diff --git a/source/project/urls.py b/source/project/urls.py new file mode 100644 index 0000000..13cdfb0 --- /dev/null +++ b/source/project/urls.py @@ -0,0 +1,25 @@ +""" +URL configuration for source project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/5.1/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path, include + +urlpatterns = [ + path("", include("apps.ctf.urls")), + + path('admin/', admin.site.urls), + path('api/', include('rest_framework.urls')) +] diff --git a/source/project/wsgi.py b/source/project/wsgi.py new file mode 100644 index 0000000..3e1c438 --- /dev/null +++ b/source/project/wsgi.py @@ -0,0 +1,19 @@ +""" +WSGI config for source project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.1/howto/deployment/wsgi/ +""" + +import os + +import dotenv +from django.core.wsgi import get_wsgi_application + +dotenv.load_dotenv() + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings') + +application = get_wsgi_application()