Skip to content

Commit 31a06fd

Browse files
committed
fix codemirror editor width
1 parent 10e7de2 commit 31a06fd

File tree

11 files changed

+208
-0
lines changed

11 files changed

+208
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ docs/_build
1212
*.egg/
1313
.coverage
1414
coverage.xml
15+
db.sqlite3

dbtemplates/static/dbtemplates/css/editor.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@
1717
color: #999;
1818
}
1919

20+
.CodeMirror-wrapping {
21+
width: 85%;
22+
}

example/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Example project
2+
3+
This example Django app helps us develop the library, so we can quickly set it up for testing.
4+
5+
## Usage
6+
7+
Using uv you can run the following commands to have a working application
8+
9+
```bash
10+
# create the virtualenv
11+
uv venv --python 3.13
12+
# activate it
13+
source .venv/bin/activate
14+
# install Django
15+
uv pip install -r requirements.txt
16+
# install the library as editable
17+
uv pip install -e ../.
18+
# run migrations to create the base database
19+
python manage.py migrate
20+
# create a superuser test account
21+
python manage.py createsuperuser
22+
# start the dev server
23+
python manage.py runserver
24+
```
25+
26+
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.

example/example/__init__.py

Whitespace-only changes.

example/example/models.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from django.db import models
2+
3+
4+
class Author(models.Model):
5+
first_name = models.CharField(max_length=50)
6+
last_name = models.CharField(max_length=50)
7+
age = models.IntegerField()
8+
metadata = models.JSONField()
9+
10+
11+
class Book(models.Model):
12+
title = models.CharField(max_length=100)
13+
author = models.ForeignKey(Author, on_delete=models.CASCADE)
14+
metadata = models.JSONField()

example/example/settings.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
from pathlib import Path
2+
3+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
4+
BASE_DIR = Path(__file__).resolve().parent.parent
5+
6+
7+
# Quick-start development settings - unsuitable for production
8+
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
9+
10+
# SECURITY WARNING: keep the secret key used in production secret!
11+
SECRET_KEY = "django-insecure-r^0hv0s#-%%jt!a7v1e7_#s+(@**(wn1n59iauee3e4t4e0&7r"
12+
13+
# SECURITY WARNING: don't run with debug turned on in production!
14+
DEBUG = True
15+
16+
ALLOWED_HOSTS = ["*"]
17+
18+
19+
# Application definition
20+
21+
INSTALLED_APPS = [
22+
"django.contrib.admin",
23+
"django.contrib.auth",
24+
"django.contrib.contenttypes",
25+
"django.contrib.sessions",
26+
"django.contrib.sites",
27+
"django.contrib.messages",
28+
"django.contrib.staticfiles",
29+
"dbtemplates",
30+
"example",
31+
]
32+
33+
MIDDLEWARE = [
34+
"django.middleware.security.SecurityMiddleware",
35+
"django.contrib.sessions.middleware.SessionMiddleware",
36+
"django.middleware.common.CommonMiddleware",
37+
"django.middleware.csrf.CsrfViewMiddleware",
38+
"django.contrib.auth.middleware.AuthenticationMiddleware",
39+
"django.contrib.messages.middleware.MessageMiddleware",
40+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
41+
]
42+
43+
ROOT_URLCONF = "example.urls"
44+
45+
TEMPLATES = [
46+
{
47+
"BACKEND": "django.template.backends.django.DjangoTemplates",
48+
"DIRS": [BASE_DIR / "example" / "templates"],
49+
"APP_DIRS": False,
50+
"OPTIONS": {
51+
"context_processors": [
52+
"django.template.context_processors.debug",
53+
"django.template.context_processors.request",
54+
"django.contrib.auth.context_processors.auth",
55+
"django.contrib.messages.context_processors.messages",
56+
],
57+
"loaders": [
58+
"django.template.loaders.filesystem.Loader",
59+
"django.template.loaders.app_directories.Loader",
60+
"dbtemplates.loader.Loader",
61+
],
62+
},
63+
},
64+
]
65+
66+
WSGI_APPLICATION = "example.wsgi.application"
67+
68+
69+
# Database
70+
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
71+
72+
DATABASES = {
73+
"default": {
74+
"ENGINE": "django.db.backends.sqlite3",
75+
"NAME": BASE_DIR / "db.sqlite3",
76+
}
77+
}
78+
79+
# Password validation
80+
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
81+
82+
AUTH_PASSWORD_VALIDATORS = []
83+
84+
85+
# Internationalization
86+
# https://docs.djangoproject.com/en/4.2/topics/i18n/
87+
88+
LANGUAGE_CODE = "en-us"
89+
90+
TIME_ZONE = "UTC"
91+
92+
USE_I18N = True
93+
94+
USE_TZ = True
95+
96+
97+
# Static files (CSS, JavaScript, Images)
98+
# https://docs.djangoproject.com/en/4.2/howto/static-files/
99+
100+
STATIC_URL = "static/"
101+
102+
# Default primary key field type
103+
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
104+
105+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
106+
107+
SITE_ID = 1
108+
109+
DBTEMPLATES_USE_CODEMIRROR = True

example/example/urls.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from django.contrib import admin
2+
from django.urls import path
3+
4+
from .views import index
5+
6+
urlpatterns = [
7+
path("", index),
8+
path("admin/", admin.site.urls),
9+
]

example/example/views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.shortcuts import render
2+
3+
4+
def index(request):
5+
return render(request, "db-index.html")

example/example/wsgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for example project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")
15+
16+
application = get_wsgi_application()

example/manage.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
4+
import os
5+
import sys
6+
7+
8+
def main():
9+
"""Run administrative tasks."""
10+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")
11+
try:
12+
from django.core.management import execute_from_command_line
13+
except ImportError as exc:
14+
raise ImportError(
15+
"Couldn't import Django. Are you sure it's installed and "
16+
"available on your PYTHONPATH environment variable? Did you "
17+
"forget to activate a virtual environment?"
18+
) from exc
19+
execute_from_command_line(sys.argv)
20+
21+
22+
if __name__ == "__main__":
23+
main()

0 commit comments

Comments
 (0)