From 58f24d2173b54e7ad5ba8edc0be130acd1f840fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20K=C3=A1lm=C3=A1n?= Date: Thu, 29 Jan 2026 15:00:06 +0100 Subject: [PATCH] fix codemirror editor width --- .gitignore | 1 + dbtemplates/static/dbtemplates/css/editor.css | 3 + example/README.md | 26 +++++ example/example/__init__.py | 0 example/example/settings.py | 109 ++++++++++++++++++ example/example/urls.py | 9 ++ example/example/views.py | 5 + example/example/wsgi.py | 16 +++ example/manage.py | 23 ++++ example/requirements.txt | 2 + 10 files changed, 194 insertions(+) create mode 100644 example/README.md create mode 100644 example/example/__init__.py create mode 100644 example/example/settings.py create mode 100644 example/example/urls.py create mode 100644 example/example/views.py create mode 100644 example/example/wsgi.py create mode 100755 example/manage.py create mode 100644 example/requirements.txt diff --git a/.gitignore b/.gitignore index 66275b7..4105c81 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ docs/_build *.egg/ .coverage coverage.xml +db.sqlite3 diff --git a/dbtemplates/static/dbtemplates/css/editor.css b/dbtemplates/static/dbtemplates/css/editor.css index c50cb2a..854b86f 100644 --- a/dbtemplates/static/dbtemplates/css/editor.css +++ b/dbtemplates/static/dbtemplates/css/editor.css @@ -17,3 +17,6 @@ color: #999; } +.CodeMirror-wrapping { + width: 85%; +} diff --git a/example/README.md b/example/README.md new file mode 100644 index 0000000..19f04be --- /dev/null +++ b/example/README.md @@ -0,0 +1,26 @@ +# Example project + +This example Django app helps us develop the library, so we can quickly set it up for testing. + +## Usage + +Using uv you can run the following commands to have a working application + +```bash +# create the virtualenv +uv venv --python 3.13 +# activate it +source .venv/bin/activate +# install Django +uv pip install -r requirements.txt +# install the library as editable +uv pip install -e ../. +# run migrations to create the base database +python manage.py migrate +# create a superuser test account +python manage.py createsuperuser +# start the dev server +python manage.py runserver +``` + +After this is done you can navigate to http://localhost:8000/admin/ and login with your account, create a DB Template called `db-index.html` and then go to http://localhost:8000 to see it. diff --git a/example/example/__init__.py b/example/example/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/example/example/settings.py b/example/example/settings.py new file mode 100644 index 0000000..6acc163 --- /dev/null +++ b/example/example/settings.py @@ -0,0 +1,109 @@ +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/4.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = "django-insecure-r^0hv0s#-%%jt!a7v1e7_#s+(@**(wn1n59iauee3e4t4e0&7r" + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = ["*"] + + +# Application definition + +INSTALLED_APPS = [ + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.sites", + "django.contrib.messages", + "django.contrib.staticfiles", + "dbtemplates", + "example", +] + +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 = "example.urls" + +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [BASE_DIR / "example" / "templates"], + "APP_DIRS": False, + "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", + ], + "loaders": [ + "django.template.loaders.filesystem.Loader", + "django.template.loaders.app_directories.Loader", + "dbtemplates.loader.Loader", + ], + }, + }, +] + +WSGI_APPLICATION = "example.wsgi.application" + + +# Database +# https://docs.djangoproject.com/en/4.2/ref/settings/#databases + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": BASE_DIR / "db.sqlite3", + } +} + +# Password validation +# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [] + + +# Internationalization +# https://docs.djangoproject.com/en/4.2/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/4.2/howto/static-files/ + +STATIC_URL = "static/" + +# Default primary key field type +# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" + +SITE_ID = 1 + +DBTEMPLATES_USE_CODEMIRROR = True diff --git a/example/example/urls.py b/example/example/urls.py new file mode 100644 index 0000000..72d416e --- /dev/null +++ b/example/example/urls.py @@ -0,0 +1,9 @@ +from django.contrib import admin +from django.urls import path + +from .views import index + +urlpatterns = [ + path("", index), + path("admin/", admin.site.urls), +] diff --git a/example/example/views.py b/example/example/views.py new file mode 100644 index 0000000..1785121 --- /dev/null +++ b/example/example/views.py @@ -0,0 +1,5 @@ +from django.shortcuts import render + + +def index(request): + return render(request, "db-index.html") diff --git a/example/example/wsgi.py b/example/example/wsgi.py new file mode 100644 index 0000000..685ee50 --- /dev/null +++ b/example/example/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for example 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.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings") + +application = get_wsgi_application() diff --git a/example/manage.py b/example/manage.py new file mode 100755 index 0000000..7aab30f --- /dev/null +++ b/example/manage.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" + +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.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/example/requirements.txt b/example/requirements.txt new file mode 100644 index 0000000..1ff23fa --- /dev/null +++ b/example/requirements.txt @@ -0,0 +1,2 @@ +django==5.2.9 +django-dbtemplate