Skip to content
Snippets Groups Projects
Commit a3c63eb1 authored by Tomáš Valenta's avatar Tomáš Valenta
Browse files

create base project

parent c371b2a6
No related branches found
No related tags found
No related merge requests found
Showing
with 461 additions and 0 deletions
import html
import markdownx
from django import template
register = template.Library()
@register.filter
def markdownify(text: str) -> str:
return markdownx.utils.markdownify(html.escape(text))
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
# Create your views here.
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
html {
font-family: "Roboto Condensed", system-ui, sans-serif;
}
}
const defaultTheme = require("tailwindcss/defaultTheme");
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"*/templates/*/*.html",
"*/templates/*/*/*.html",
],
theme: {
extend: {
fontFamily: {
"bebas": ["Bebas Neue", defaultTheme.fontFamily.sans],
"sans": ["Roboto Condensed", defaultTheme.fontFamily.sans],
},
},
},
plugins: [
require('@tailwindcss/typography'),
],
}
import copy
from django.conf import settings
from django.contrib import admin
from django_admin_index.models import AppGroup, AppGroupQuerySet
def get_app_list(self, request):
app_dict = self._build_app_dict(request)
for app_name, object_list in app_dict.items():
if app_name in settings.ADMIN_ORDERING:
app = app_dict[app_name]
app["models"].sort(
key=lambda model: settings.ADMIN_ORDERING[app_name].index(
model["object_name"]
)
)
app_dict[app_name]
yield app
else:
yield app_dict[app_name]
admin.AdminSite.get_app_list = get_app_list
original_as_list_func = copy.deepcopy(AppGroupQuerySet.as_list)
def as_list(self, request, include_remaining=True):
result = original_as_list_func(self, request, include_remaining=include_remaining)
for item in result:
if item["app_label"] not in settings.ADMIN_ORDERING:
continue
item["models"].sort(
key=lambda model: (
settings.ADMIN_ORDERING[item["app_label"]].index(model["object_name"])
)
)
return result
AppGroupQuerySet.as_list = as_list
"""
ASGI config for registry 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/4.0/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "registry.settings")
application = get_asgi_application()
"""
Django settings for the Ucebnice project.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.0/ref/settings/
"""
import os
import pathlib
import dj_database_url
import environ
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = pathlib.Path(__file__).parents[2]
env = environ.Env()
environ.Env.read_env(os.path.join(BASE_DIR, ".env"))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
DEBUG = False
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = env.str("SECRET_KEY")
ALLOWED_HOSTS = []
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
SITE_URL = env.str("SITE_URL")
## Application definition
INSTALLED_APPS = [
"admin_interface",
"colorfield",
"django_admin_index",
"ordered_model",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"guardian",
"markdownx",
"pirates",
"webpack_loader",
"shared",
"oidc",
"users",
]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"django_http_exceptions.middleware.ExceptionHandlerMiddleware",
"django_http_exceptions.middleware.ThreadLocalRequestMiddleware",
]
ROOT_URLCONF = "ucebnice.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(BASE_DIR, "ucebnice", "templates")],
"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 = "ucebnice.wsgi.application"
## Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
DATABASES = {"default": dj_database_url.config(conn_max_age=600)}
# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
## Authentication
# Password validation
# https://docs.djangoproject.com/en/4.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",
},
]
AUTH_USER_MODEL = "users.User"
AUTHENTICATION_BACKENDS = (
"oidc.auth.UcebniceOIDCAuthenticationBackend",
"django.contrib.auth.backends.ModelBackend",
"guardian.backends.ObjectPermissionBackend",
)
LOGIN_URL = "/"
LOGIN_REDIRECT_URL = "/"
LOGOUT_REDIRECT_URL = "/"
OIDC_RP_CLIENT_ID = env.str("OIDC_RP_CLIENT_ID")
OIDC_RP_CLIENT_SECRET = env.str("OIDC_RP_CLIENT_SECRET")
OIDC_RP_REALM_URL = env.str("OIDC_RP_REALM_URL")
OIDC_RP_SCOPES = "openid profile groups"
OIDC_RP_SIGN_ALGO = "RS256"
OIDC_RP_RESOURCE_ACCESS_CLIENT = env.str(
"OIDC_RESOURCE_ACCESS_CLIENT", OIDC_RP_CLIENT_ID
)
OIDC_OP_JWKS_ENDPOINT = OIDC_RP_REALM_URL + "protocol/openid-connect/certs"
OIDC_OP_AUTHORIZATION_ENDPOINT = OIDC_RP_REALM_URL + "protocol/openid-connect/auth"
OIDC_OP_TOKEN_ENDPOINT = OIDC_RP_REALM_URL + "protocol/openid-connect/token"
OIDC_OP_USER_ENDPOINT = OIDC_RP_REALM_URL + "protocol/openid-connect/userinfo"
## Internationalization
# https://docs.djangoproject.com/en/4.0/topics/i18n/
LANGUAGE_CODE = "cs-cz"
TIME_ZONE = "Europe/Prague"
USE_I18N = True
USE_TZ = True
## Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/
STATIC_URL = "/static/"
WEBPACK_LOADER = {
"DEFAULT": {
"CACHE": not DEBUG,
"BUNDLE_DIR_NAME": "shared",
"STATS_FILE": os.path.join(BASE_DIR, "webpack-stats.json"),
"POLL_INTERVAL": 0.1,
"IGNORE": [r".+\.hot-update.js", r".+\.map"],
}
}
## Media files
MEDIA_URL = "/media/"
## Server
USE_X_FORWARDED_HOST = True
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
X_FRAME_OPTIONS = "SAMEORIGIN"
SILENCED_SYSTEM_CHECKS = ["security.W019"]
## Admin
ADMIN_INDEX_AUTO_CREATE_APP_GROUP = True
ADMIN_INDEX_SHOW_REMAINING_APPS = True
ADMIN_ORDERING = {}
from .base import *
DEBUG = True
"""
Production settings.
"""
from .base import *
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS")
MIDDLEWARE.insert(1, "whitenoise.middleware.WhiteNoiseMiddleware")
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
{% extends 'admin/base_site.html' %}
{% load static %}
{% block extrastyle %}
{{ block.super }}
<style>
:root, :root .admin-interface {
--djai-tab-bg: var(--admin-interface-header-background-color);
--djai-tab-fg: var(--admin-interface-header-text-color);
--djai-tab-bg--active: var(--djai-tab-fg);
--djai-tab-bg--hover: var(--djai-tab-fg);
--djai-tab-fg--active: var(--djai-tab-bg);
--djai-tab-fg--hover: var(--djai-tab-bg);
--djai-dropdown-bg: var(--djai-tab-bg);
--djai-dropdown-fg: var(--djai-tab-fg);
--djai-dropdown-bg--active: var(--djai-tab-fg);
--djai-dropdown-bg--hover: var(--djai-tab-fg);
--djai-dropdown-fg--active: var(--djai-tab-bg);
--djai-dropdown-fg--hover: var(--djai-tab-bg);
}
.djai-dropdown-menu .djai-dropdown-menu__drop {
box-shadow: 2px 2px 3px rgba(0, 0, 0, 0.1), -2px 2px 3px rgba(0, 0, 0, 0.1) !important;
}
.djai-dropdown-menu a.djai-dropdown-menu__item:hover {
color: var(--djai-tab-fg--hover) !important;
}
.djai-dropdown-menu a.djai-dropdown-menu__item.djai-dropdown-menu__item--active {
color: var(--djai-tab-fg--active) !important;
}
.djai-dropdown-menu .djai-dropdown-menu__drop-item--active a {
color: var(--djai-tab-fg--active) !important;
}
#header .djai-dropdown-menu .djai-dropdown-menu__drop-item {
transition: .15s;
}
#header .djai-dropdown-menu .djai-dropdown-menu__drop-item a {
color: var(--djai-dropdown-fg);
}
#header .djai-dropdown-menu .djai-dropdown-menu__drop-item a:hover {
color: var(--djai-dropdown-fg--hover) !important;
text-decoration: none;
}
.index-action-buttons {
display: flex;
flex-direction: row;
column-gap: 10px;
}
.index-action-buttons button,
.index-action-buttons [aria-role="button"],
.index-action-buttons button:visited,
.index-action-buttons [aria-role="button"]:visited,
.index-action-buttons button:hover,
.index-action-buttons [aria-role="button"]:hover {
padding: 10px 15px;
margin-bottom: 15px;
background-color: var(--admin-interface-module-background-color) !important;
color: var(--admin-interface-module-text-color) !important;
border-radius: var(--admin-interface-module-border-radius) !important;
text-decoration: none !important;
}
.module caption, .inline-group h2 {
text-transform: none;
}
</style>
{% endblock %}
"""URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.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.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path, re_path
from django.views.static import serve
from pirates.urls import urlpatterns as pirates_urlpatterns
import ucebnice.admin
urlpatterns = [
path("admin/", admin.site.urls),
] + pirates_urlpatterns
"""
WSGI config for registry 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/4.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "registry.settings")
application = get_wsgi_application()
from django.contrib import admin
from shared.admin import MarkdownxGuardedModelAdmin
from .models import User
admin.site.register(User, MarkdownxGuardedModelAdmin)
from django.apps import AppConfig
class UsersConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "users"
verbose_name = "Uživatelé"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment