diff --git a/django_mongodb_cli/project.py b/django_mongodb_cli/project.py
index c0923e9..75ba30c 100644
--- a/django_mongodb_cli/project.py
+++ b/django_mongodb_cli/project.py
@@ -228,6 +228,10 @@ def migrate_project(
None,
help="Optional MongoDB connection URI. Falls back to $MONGODB_URI if not provided.",
),
+ database: str = typer.Option(
+ None,
+ help="Specify the database to migrate.",
+ ),
):
"""
Run Django migrations using django-admin instead of manage.py.
@@ -238,7 +242,8 @@ def migrate_project(
cmd.append(app_label)
if migration_name:
cmd.append(migration_name)
-
+ if database:
+ cmd.append(f"--database={database}")
typer.echo(f"📦 Applying migrations for project '{name}'")
_django_manage_command(
name, directory, *cmd, extra_env=_build_mongodb_env(mongodb_uri)
@@ -277,6 +282,10 @@ def manage_command(
mongodb_uri: str = typer.Option(
None, "--mongodb-uri", help="MongoDB connection URI"
),
+ database: str = typer.Option(
+ None,
+ help="Specify the database to use.",
+ ),
):
"""
Run any django-admin command for a project.
@@ -297,6 +306,9 @@ def manage_command(
os.environ["MONGODB_URI"] = mongodb_uri
+ if database:
+ args.append(f"--database={database}")
+
if command:
typer.echo(f"⚙️ Running django-admin {command} {' '.join(args)} for '{name}'")
_django_manage_command(name, directory, command, *args)
diff --git a/django_mongodb_cli/templates/project_template/project_name/routers.py b/django_mongodb_cli/templates/project_template/project_name/routers.py
index ffdb421..08ee04d 100644
--- a/django_mongodb_cli/templates/project_template/project_name/routers.py
+++ b/django_mongodb_cli/templates/project_template/project_name/routers.py
@@ -1,19 +1,23 @@
+from django_mongodb_backend.utils import model_has_encrypted_fields
+
+
class EncryptedRouter:
- def db_for_read(self, model, **hints):
- if model._meta.app_label == "django_mongodb_demo":
- return "encrypted"
+ def allow_migrate(self, db, app_label, model_name=None, **hints):
+ if hints.get("model"):
+ if model_has_encrypted_fields(hints["model"]):
+ return db == "encrypted"
+ else:
+ return db == "default"
return None
- db_for_write = db_for_read
+ def db_for_read(self, model, **hints):
+ if model_has_encrypted_fields(model):
+ return "encrypted"
+ return "default"
- def allow_migrate(self, db, app_label, model_name=None, **hints):
- if app_label == "django_mongodb_demo":
- print("allow_migrate for django_mongodb_demo:", db)
- return db == "encrypted"
- # Don't create other app's models in the encrypted database.
- if db == "encrypted":
- return False
+ def kms_provider(self, model):
+ if model_has_encrypted_fields(model):
+ return "local"
return None
- def kms_provider(self, model, **hints):
- return "local"
+ db_for_write = db_for_read
diff --git a/django_mongodb_cli/templates/project_template/project_name/settings/project_name.py b/django_mongodb_cli/templates/project_template/project_name/settings/project_name.py
index 7f0106f..a516a30 100644
--- a/django_mongodb_cli/templates/project_template/project_name/settings/project_name.py
+++ b/django_mongodb_cli/templates/project_template/project_name/settings/project_name.py
@@ -16,8 +16,12 @@
"NAME": "{{ project_name }}_encrypted",
"OPTIONS": {
"auto_encryption_opts": AutoEncryptionOpts(
- kms_providers={"local": {"key": os.urandom(96)}}, # noqa
- key_vault_namespace="keyvault.__keyVault",
+ kms_providers={
+ "local": {
+ "key": b"tO\x7f\xf2L0\x9e\xab\xcd'\xd3\xd4'P\xf5;3\x94\xde8\xd7\xa4\xc5J\xe9\xb7\xc6\t\xbe\xa3<\xb3\xbe\xb3\xe5E\xb1\xdf[\xfb\x94\x8c`\x9e\xa20*\x82\x16\x98\xa32\x11\xa6\xeb\xfa\x05e\x08/\xe2\x01\xe8\xf1'#\xf9E\xde\xb0\x07Z\x93V\x84.\xf5\xb9\xdbR\xf6\xf6!\xd7;\xa9c\x087\xa1f\x9c\x1b\x86\xe8D"
+ }
+ },
+ key_vault_namespace="{{ project_name }}_encrypted.__keyVault",
),
},
}
diff --git a/pyproject.toml b/pyproject.toml
index b7fd32b..7337cde 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -86,6 +86,7 @@ repos = [
"mongo @ git+ssh://git@github.com/mongodb/mongo@master",
"drivers-evergreen-tools @ git+ssh://git@github.com/mongodb-labs/drivers-evergreen-tools@master",
"docs @ git+ssh://git@github.com/mongodb/docs@main",
+ "docs-sample-apps @ git+ssh://git@github.com/mongodb/docs-sample-apps@main",
"flask-pymongo @ git+ssh://git@github.com/mongodb-labs/flask-pymongo",
"mongo-arrow @ git+ssh://git@github.com/mongodb-labs/mongo-arrow@main",
"mongo-orchestration @ git+ssh://git@github.com/mongodb-labs/mongo-orchestration@master",
diff --git a/templates/app_template/.github/workflows/django.yml b/templates/app_template/.github/workflows/django.yml
deleted file mode 100644
index 9766b45..0000000
--- a/templates/app_template/.github/workflows/django.yml
+++ /dev/null
@@ -1,30 +0,0 @@
-name: Django CI
-
-on:
- push:
- branches: [ "main" ]
- pull_request:
- branches: [ "main" ]
-
-jobs:
- build:
-
- runs-on: ubuntu-latest
- strategy:
- max-parallel: 4
- matrix:
- python-version: [3.7, 3.8, 3.9]
-
- steps:
- - uses: actions/checkout@v4
- - name: Set up Python ${{ matrix.python-version }}
- uses: actions/setup-python@v3
- with:
- python-version: ${{ matrix.python-version }}
- - name: Install Dependencies
- run: |
- python -m pip install --upgrade pip
- pip install -r requirements.txt
- - name: Run Tests
- run: |
- python manage.py test
diff --git a/templates/app_template/__init__.py-tpl b/templates/app_template/__init__.py-tpl
deleted file mode 100644
index e69de29..0000000
diff --git a/templates/app_template/admin.py-tpl b/templates/app_template/admin.py-tpl
deleted file mode 100644
index 8c38f3f..0000000
--- a/templates/app_template/admin.py-tpl
+++ /dev/null
@@ -1,3 +0,0 @@
-from django.contrib import admin
-
-# Register your models here.
diff --git a/templates/app_template/apps.py-tpl b/templates/app_template/apps.py-tpl
deleted file mode 100644
index 644f491..0000000
--- a/templates/app_template/apps.py-tpl
+++ /dev/null
@@ -1,6 +0,0 @@
-from django.apps import AppConfig
-
-
-class {{ camel_case_app_name }}Config(AppConfig):
- default_auto_field = 'django_mongodb_backend.fields.ObjectIdAutoField'
- name = 'apps.{{ app_name }}'
diff --git a/templates/app_template/migrations/__init__.py-tpl b/templates/app_template/migrations/__init__.py-tpl
deleted file mode 100644
index e69de29..0000000
diff --git a/templates/app_template/models.py-tpl b/templates/app_template/models.py-tpl
deleted file mode 100644
index 71a8362..0000000
--- a/templates/app_template/models.py-tpl
+++ /dev/null
@@ -1,3 +0,0 @@
-from django.db import models
-
-# Create your models here.
diff --git a/templates/app_template/templates/app_name.html b/templates/app_template/templates/app_name.html
deleted file mode 100644
index e5c9fbb..0000000
--- a/templates/app_template/templates/app_name.html
+++ /dev/null
@@ -1,552 +0,0 @@
-{% load static webpack_loader %}
-
-
-
- {% stylesheet_pack 'app' %}
-
-
-
-
-
-
-
- Dashboard Template · Bootstrap v5.3
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Saved reports
-
-
-
-
-
-
-
-
-
-
-
-
-
- Section title
-
-
-
-
- | # |
- Header |
- Header |
- Header |
- Header |
-
-
-
-
- | 1,001 |
- random |
- data |
- placeholder |
- text |
-
-
- | 1,002 |
- placeholder |
- irrelevant |
- visual |
- layout |
-
-
- | 1,003 |
- data |
- rich |
- dashboard |
- tabular |
-
-
- | 1,003 |
- information |
- placeholder |
- illustrative |
- data |
-
-
- | 1,004 |
- text |
- random |
- layout |
- dashboard |
-
-
- | 1,005 |
- dashboard |
- irrelevant |
- text |
- placeholder |
-
-
- | 1,006 |
- dashboard |
- illustrative |
- rich |
- data |
-
-
- | 1,007 |
- placeholder |
- tabular |
- information |
- irrelevant |
-
-
- | 1,008 |
- random |
- data |
- placeholder |
- text |
-
-
- | 1,009 |
- placeholder |
- irrelevant |
- visual |
- layout |
-
-
- | 1,010 |
- data |
- rich |
- dashboard |
- tabular |
-
-
- | 1,011 |
- information |
- placeholder |
- illustrative |
- data |
-
-
- | 1,012 |
- text |
- placeholder |
- layout |
- dashboard |
-
-
- | 1,013 |
- dashboard |
- irrelevant |
- text |
- visual |
-
-
- | 1,014 |
- dashboard |
- illustrative |
- rich |
- data |
-
-
- | 1,015 |
- random |
- tabular |
- information |
- text |
-
-
-
-
-
-
-
-
-
- {% javascript_pack 'app' %}
-
-
diff --git a/templates/app_template/tests.py-tpl b/templates/app_template/tests.py-tpl
deleted file mode 100644
index 7ce503c..0000000
--- a/templates/app_template/tests.py-tpl
+++ /dev/null
@@ -1,3 +0,0 @@
-from django.test import TestCase
-
-# Create your tests here.
diff --git a/templates/app_template/urls.py b/templates/app_template/urls.py
deleted file mode 100644
index cacc09a..0000000
--- a/templates/app_template/urls.py
+++ /dev/null
@@ -1,7 +0,0 @@
-from django.urls import path
-
-from . import views
-
-urlpatterns = [
- path("", views.HomeView.as_view(), name="home"),
-]
diff --git a/templates/app_template/views.py-tpl b/templates/app_template/views.py-tpl
deleted file mode 100644
index 2d07c3e..0000000
--- a/templates/app_template/views.py-tpl
+++ /dev/null
@@ -1,7 +0,0 @@
-from django.views.generic import TemplateView
-
-# Create your views here.
-
-
-class {{ camel_case_app_name}}View(TemplateView):
- template_name = '{{ app_name }}.html'
diff --git a/templates/frontend_template/project_name/.gitignore b/templates/frontend_template/project_name/.gitignore
deleted file mode 100644
index ddcb880..0000000
--- a/templates/frontend_template/project_name/.gitignore
+++ /dev/null
@@ -1,15 +0,0 @@
-# dependencies
-node_modules
-
-# production
-build
-
-# misc
-.DS_Store
-
-npm-debug.log
-yarn-error.log
-yarn.lock
-.yarnclean
-.vscode
-.idea
diff --git a/templates/frontend_template/project_name/README.md b/templates/frontend_template/project_name/README.md
deleted file mode 100644
index 0b0d8e0..0000000
--- a/templates/frontend_template/project_name/README.md
+++ /dev/null
@@ -1,21 +0,0 @@
-# README
-
-This project was created with [python-webpack-boilerplate](https://github.com/AccordBox/python-webpack-boilerplate)
-
-## Available Scripts
-
-In the project directory, you can run:
-
-### `npm run start`
-
-`npm run start` will launch a server process, which makes `live reloading` possible.
-
-If you change JS or SCSS files, the web page would auto refresh after the change. Now the server is working on port 9091 by default, but you can change it in `webpack/webpack.config.dev.js`
-
-### `npm run watch`
-
-run webpack in `watch` mode.
-
-### `npm run build`
-
-[production mode](https://webpack.js.org/guides/production/), Webpack would focus on minified bundles, lighter weight source maps, and optimized assets to improve load time.
diff --git a/templates/frontend_template/project_name/vendors/.gitkeep b/templates/frontend_template/project_name/vendors/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/templates/frontend_template/project_name/vendors/images/.gitkeep b/templates/frontend_template/project_name/vendors/images/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/templates/frontend_template/project_name/vendors/images/mongodb.ico b/templates/frontend_template/project_name/vendors/images/mongodb.ico
deleted file mode 100644
index 237f3bb..0000000
Binary files a/templates/frontend_template/project_name/vendors/images/mongodb.ico and /dev/null differ
diff --git a/templates/frontend_template/project_name/vendors/images/sample.jpg b/templates/frontend_template/project_name/vendors/images/sample.jpg
deleted file mode 100644
index 257c5dc..0000000
Binary files a/templates/frontend_template/project_name/vendors/images/sample.jpg and /dev/null differ
diff --git a/templates/frontend_template/project_name/vendors/images/webpack.png b/templates/frontend_template/project_name/vendors/images/webpack.png
deleted file mode 100644
index 6d788d5..0000000
Binary files a/templates/frontend_template/project_name/vendors/images/webpack.png and /dev/null differ
diff --git a/templates/frontend_template/project_name/webpack/webpack.common.js b/templates/frontend_template/project_name/webpack/webpack.common.js
deleted file mode 100644
index 9d82a49..0000000
--- a/templates/frontend_template/project_name/webpack/webpack.common.js
+++ /dev/null
@@ -1,71 +0,0 @@
-const glob = require("glob");
-const Path = require("path");
-const { CleanWebpackPlugin } = require("clean-webpack-plugin");
-const CopyWebpackPlugin = require("copy-webpack-plugin");
-const WebpackAssetsManifest = require("webpack-assets-manifest");
-
-const getEntryObject = () => {
- const entries = {};
- // for javascript/typescript entry file
- glob
- .sync(Path.join(__dirname, "../src/application/*.{js,ts}"))
- .forEach((path) => {
- const name = Path.basename(path);
- const extension = Path.extname(path);
- const entryName = name.replace(extension, "");
- if (entryName in entries) {
- throw new Error(`Entry file conflict: ${entryName}`);
- }
- entries[entryName] = path;
- });
- return entries;
-};
-
-module.exports = {
- entry: getEntryObject(),
- output: {
- path: Path.join(__dirname, "../build"),
- filename: "js/[name].js",
- publicPath: "/static/",
- assetModuleFilename: "[path][name][ext]",
- },
- optimization: {
- splitChunks: {
- chunks: "all",
- },
-
- runtimeChunk: "single",
- },
- plugins: [
- new CleanWebpackPlugin(),
- new CopyWebpackPlugin({
- patterns: [
- { from: Path.resolve(__dirname, "../vendors"), to: "vendors" },
- ],
- }),
- new WebpackAssetsManifest({
- entrypoints: true,
- output: "manifest.json",
- writeToDisk: true,
- publicPath: true,
- }),
- ],
- resolve: {
- alias: {
- "~": Path.resolve(__dirname, "../src"),
- },
- },
- module: {
- rules: [
- {
- test: /\.mjs$/,
- include: /node_modules/,
- type: "javascript/auto",
- },
- {
- test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/,
- type: "asset",
- },
- ],
- },
-};
diff --git a/templates/frontend_template/project_name/webpack/webpack.config.dev.js b/templates/frontend_template/project_name/webpack/webpack.config.dev.js
deleted file mode 100644
index d02292a..0000000
--- a/templates/frontend_template/project_name/webpack/webpack.config.dev.js
+++ /dev/null
@@ -1,73 +0,0 @@
-const Path = require("path");
-const Webpack = require("webpack");
-const { merge } = require("webpack-merge");
-const StylelintPlugin = require("stylelint-webpack-plugin");
-const MiniCssExtractPlugin = require("mini-css-extract-plugin");
-const ESLintPlugin = require("eslint-webpack-plugin");
-
-const common = require("./webpack.common.js");
-
-module.exports = merge(common, {
- target: "web",
- mode: "development",
- devtool: "inline-source-map",
- output: {
- chunkFilename: "js/[name].chunk.js",
- publicPath: "http://localhost:9091/",
- },
- devServer: {
- hot: true,
- host: "0.0.0.0",
- port: 9091,
- headers: {
- "Access-Control-Allow-Origin": "*",
- },
- devMiddleware: {
- writeToDisk: true,
- },
- },
- plugins: [
- new Webpack.DefinePlugin({
- "process.env.NODE_ENV": JSON.stringify("development"),
- }),
- new StylelintPlugin({
- files: Path.resolve(__dirname, "../src/**/*.s?(a|c)ss"),
- }),
- new ESLintPlugin({
- extensions: "js",
- emitWarning: true,
- files: Path.resolve(__dirname, "../src"),
- }),
- new MiniCssExtractPlugin({
- filename: "css/[name].css",
- chunkFilename: "css/[id].css",
- }),
- ],
- module: {
- rules: [
- {
- test: /\.html$/i,
- loader: "html-loader",
- },
- {
- test: /\.js$/,
- include: Path.resolve(__dirname, "../src"),
- loader: "babel-loader",
- },
- {
- test: /\.s?css$/i,
- use: [
- MiniCssExtractPlugin.loader,
- {
- loader: "css-loader",
- options: {
- sourceMap: true,
- },
- },
- "postcss-loader",
- "sass-loader",
- ],
- },
- ],
- },
-});
diff --git a/templates/frontend_template/project_name/webpack/webpack.config.prod.js b/templates/frontend_template/project_name/webpack/webpack.config.prod.js
deleted file mode 100644
index 4a0dd8f..0000000
--- a/templates/frontend_template/project_name/webpack/webpack.config.prod.js
+++ /dev/null
@@ -1,41 +0,0 @@
-const Webpack = require("webpack");
-const { merge } = require("webpack-merge");
-const MiniCssExtractPlugin = require("mini-css-extract-plugin");
-const common = require("./webpack.common.js");
-
-module.exports = merge(common, {
- mode: "production",
- devtool: "source-map",
- bail: true,
- output: {
- filename: "js/[name].[chunkhash:8].js",
- chunkFilename: "js/[name].[chunkhash:8].chunk.js",
- },
- plugins: [
- new Webpack.DefinePlugin({
- "process.env.NODE_ENV": JSON.stringify("production"),
- }),
- new MiniCssExtractPlugin({
- filename: "css/[name].[contenthash].css",
- chunkFilename: "css/[id].[contenthash].css",
- }),
- ],
- module: {
- rules: [
- {
- test: /\.js$/,
- exclude: /node_modules/,
- use: "babel-loader",
- },
- {
- test: /\.s?css/i,
- use: [
- MiniCssExtractPlugin.loader,
- "css-loader",
- "postcss-loader",
- "sass-loader",
- ],
- },
- ],
- },
-});
diff --git a/templates/frontend_template/project_name/webpack/webpack.config.watch.js b/templates/frontend_template/project_name/webpack/webpack.config.watch.js
deleted file mode 100644
index e8796cb..0000000
--- a/templates/frontend_template/project_name/webpack/webpack.config.watch.js
+++ /dev/null
@@ -1,61 +0,0 @@
-const Path = require("path");
-const Webpack = require("webpack");
-const { merge } = require("webpack-merge");
-const StylelintPlugin = require("stylelint-webpack-plugin");
-const MiniCssExtractPlugin = require("mini-css-extract-plugin");
-const ESLintPlugin = require("eslint-webpack-plugin");
-
-const common = require("./webpack.common.js");
-
-module.exports = merge(common, {
- target: "web",
- mode: "development",
- devtool: "inline-source-map",
- output: {
- chunkFilename: "js/[name].chunk.js",
- },
- plugins: [
- new Webpack.DefinePlugin({
- "process.env.NODE_ENV": JSON.stringify("development"),
- }),
- new StylelintPlugin({
- files: Path.resolve(__dirname, "../src/**/*.s?(a|c)ss"),
- }),
- new ESLintPlugin({
- extensions: "js",
- emitWarning: true,
- files: Path.resolve(__dirname, "../src"),
- }),
- new MiniCssExtractPlugin({
- filename: "css/[name].css",
- chunkFilename: "css/[id].css",
- }),
- ],
- module: {
- rules: [
- {
- test: /\.html$/i,
- loader: "html-loader",
- },
- {
- test: /\.js$/,
- include: Path.resolve(__dirname, "../src"),
- loader: "babel-loader",
- },
- {
- test: /\.s?css$/i,
- use: [
- MiniCssExtractPlugin.loader,
- {
- loader: "css-loader",
- options: {
- sourceMap: true,
- },
- },
- "postcss-loader",
- "sass-loader",
- ],
- },
- ],
- },
-});
diff --git a/templates/home_template/__init__.py b/templates/home_template/__init__.py
deleted file mode 100644
index e69de29..0000000
diff --git a/templates/home_template/apps.py b/templates/home_template/apps.py
deleted file mode 100644
index 5f7be0a..0000000
--- a/templates/home_template/apps.py
+++ /dev/null
@@ -1,6 +0,0 @@
-from django.apps import AppConfig
-
-
-class HomeAppConfig(AppConfig):
- default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField"
- name = "home"
diff --git a/templates/home_template/migrations/0001_initial.py b/templates/home_template/migrations/0001_initial.py
deleted file mode 100644
index c437c7f..0000000
--- a/templates/home_template/migrations/0001_initial.py
+++ /dev/null
@@ -1,35 +0,0 @@
-# Generated by Django 5.0.11.dev20250107212806 on 2025-01-19 02:11
-
-import django.db.models.deletion
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
- initial = True
-
- dependencies = [
- ("wagtailcore", "0001_initial"),
- ]
-
- operations = [
- migrations.CreateModel(
- name="HomePage",
- fields=[
- (
- "page_ptr",
- models.OneToOneField(
- auto_created=True,
- on_delete=django.db.models.deletion.CASCADE,
- parent_link=True,
- primary_key=True,
- serialize=False,
- to="wagtailcore.page",
- ),
- ),
- ],
- options={
- "abstract": False,
- },
- bases=("wagtailcore.page",),
- ),
- ]
diff --git a/templates/home_template/migrations/0002_create_homepage.py b/templates/home_template/migrations/0002_create_homepage.py
deleted file mode 100644
index 4c02bef..0000000
--- a/templates/home_template/migrations/0002_create_homepage.py
+++ /dev/null
@@ -1,86 +0,0 @@
-from bson import ObjectId
-from django.db import migrations
-
-# Do not use settings in migrations under normal circumstances.
-from django.conf import settings
-
-
-def create_homepage(apps, schema_editor):
- # Get models
- ContentType = apps.get_model("contenttypes.ContentType")
- Page = apps.get_model("wagtailcore.Page")
- Site = apps.get_model("wagtailcore.Site")
- HomePage = apps.get_model("home.HomePage")
-
- # Delete the default homepage
- # If migration is run multiple times, it may have already been deleted
- Page.objects.filter(id=ObjectId("000000000000000000000001")).delete()
-
- # Create content type for homepage model
- homepage_content_type, __ = ContentType.objects.get_or_create(
- model="homepage", app_label="home"
- )
-
- # Why this is needed in MongoDB and not in PostgreSQL?
- locale = None
- if settings.DATABASES["default"]["ENGINE"] == "django_mongodb_backend":
- Locale = apps.get_model("wagtailcore.Locale")
- locale = Locale.objects.get(language_code="en")
-
- # Create a new homepage
- homepage_attrs = {
- "title": "Home",
- "draft_title": "Home",
- "slug": "home",
- "content_type": homepage_content_type,
- "path": "00010001",
- "depth": 1,
- "numchild": 0,
- "url_path": "/home/",
- }
- # Add the locale only if it's defined
- if locale:
- homepage_attrs["locale"] = locale
-
- homepage = HomePage.objects.create(**homepage_attrs)
-
- # Create a site with the new homepage set as the root
- Site.objects.create(hostname="localhost", root_page=homepage, is_default_site=True)
-
-
-def remove_homepage(apps, schema_editor):
- # Get models
- ContentType = apps.get_model("contenttypes.ContentType")
- HomePage = apps.get_model("home.HomePage")
-
- # Delete the default homepage
- # Page and Site objects CASCADE
- HomePage.objects.filter(slug="home", depth=2).delete()
-
- # Delete content type for homepage model
- ContentType.objects.filter(model="homepage", app_label="home").delete()
-
-
-def create_locale(apps, schema_editor):
- Locale = apps.get_model("wagtailcore", "Locale")
- # Replace 'en' with your desired language code and add other fields as necessary.
- Locale.objects.create(language_code="en")
-
-
-def remove_locale(apps, schema_editor):
- Locale = apps.get_model("wagtailcore", "Locale")
- # Replace 'en' with the language code used in create_locale
- Locale.objects.filter(language_code="en").delete()
-
-
-class Migration(migrations.Migration):
- dependencies = [
- ("home", "0001_initial"),
- ]
-
- operations = [
- migrations.RunPython(create_homepage, remove_homepage),
- ]
-
- if settings.DATABASES["default"]["ENGINE"] == "django_mongodb_backend":
- operations.insert(0, migrations.RunPython(create_locale, remove_locale))
diff --git a/templates/home_template/migrations/__init__.py b/templates/home_template/migrations/__init__.py
deleted file mode 100644
index e69de29..0000000
diff --git a/templates/home_template/models.py b/templates/home_template/models.py
deleted file mode 100644
index f24c860..0000000
--- a/templates/home_template/models.py
+++ /dev/null
@@ -1,5 +0,0 @@
-from wagtail.models import Page
-
-
-class HomePage(Page):
- pass
diff --git a/templates/home_template/static/css/welcome_page.css b/templates/home_template/static/css/welcome_page.css
deleted file mode 100644
index bad2933..0000000
--- a/templates/home_template/static/css/welcome_page.css
+++ /dev/null
@@ -1,184 +0,0 @@
-html {
- box-sizing: border-box;
-}
-
-*,
-*:before,
-*:after {
- box-sizing: inherit;
-}
-
-body {
- max-width: 960px;
- min-height: 100vh;
- margin: 0 auto;
- padding: 0 15px;
- color: #231f20;
- font-family: 'Helvetica Neue', 'Segoe UI', Arial, sans-serif;
- line-height: 1.25;
-}
-
-a {
- background-color: transparent;
- color: #308282;
- text-decoration: underline;
-}
-
-a:hover {
- color: #ea1b10;
-}
-
-h1,
-h2,
-h3,
-h4,
-h5,
-p,
-ul {
- padding: 0;
- margin: 0;
- font-weight: 400;
-}
-
-svg:not(:root) {
- overflow: hidden;
-}
-
-.header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding-top: 20px;
- padding-bottom: 10px;
- border-bottom: 1px solid #e6e6e6;
-}
-
-.logo {
- width: 150px;
- margin-inline-end: 20px;
-}
-
-.logo a {
- display: block;
-}
-
-.figure-logo {
- max-width: 150px;
- max-height: 55.1px;
-}
-
-.release-notes {
- font-size: 14px;
-}
-
-.main {
- padding: 40px 0;
- margin: 0 auto;
- text-align: center;
-}
-
-.figure-space {
- max-width: 265px;
-}
-
-@keyframes pos {
- 0%, 100% {
- transform: rotate(-6deg);
- }
- 50% {
- transform: rotate(6deg);
- }
-}
-
-.egg {
- fill: #43b1b0;
- animation: pos 3s ease infinite;
- transform: translateY(50px);
- transform-origin: 50% 80%;
-}
-
-.main-text {
- max-width: 400px;
- margin: 5px auto;
-}
-
-.main-text h1 {
- font-size: 22px;
-}
-
-.main-text p {
- margin: 15px auto 0;
-}
-
-.footer {
- display: flex;
- flex-wrap: wrap;
- justify-content: space-between;
- border-top: 1px solid #e6e6e6;
- padding: 10px;
-}
-
-.option {
- display: block;
- padding: 10px 10px 10px 34px;
- position: relative;
- text-decoration: none;
-}
-
-.option svg {
- width: 24px;
- height: 24px;
- fill: gray;
- border: 1px solid #d9d9d9;
- padding: 5px;
- border-radius: 100%;
- top: 10px;
- inset-inline-start: 0;
- position: absolute;
-}
-
-.option h2 {
- font-size: 19px;
- text-decoration: underline;
-}
-
-.option p {
- padding-top: 3px;
- color: #231f20;
- font-size: 15px;
- font-weight: 300;
-}
-
-@media (max-width: 996px) {
- body {
- max-width: 780px;
- }
-}
-
-@media (max-width: 767px) {
- .option {
- flex: 0 0 50%;
- }
-}
-
-@media (max-width: 599px) {
- .main {
- padding: 20px 0;
- }
-
- .figure-space {
- max-width: 200px;
- }
-
- .footer {
- display: block;
- width: 300px;
- margin: 0 auto;
- }
-}
-
-@media (max-width: 360px) {
- .header-link {
- max-width: 100px;
- }
-}
diff --git a/templates/home_template/static/js/bson_adapter.js b/templates/home_template/static/js/bson_adapter.js
deleted file mode 100644
index e845999..0000000
--- a/templates/home_template/static/js/bson_adapter.js
+++ /dev/null
@@ -1,17 +0,0 @@
-(function() {
- class ObjectId {
- constructor(value) {
- this.value = value;
- }
-
- toString() {
- return this.value;
- }
-
- static fromArgs(args) {
- return new ObjectId(args[0]);
- }
- }
-
- window.telepath.register('ObjectId', ObjectId);
-})();
diff --git a/templates/home_template/telepath_adapters/__init__.py b/templates/home_template/telepath_adapters/__init__.py
deleted file mode 100644
index e69de29..0000000
diff --git a/templates/home_template/telepath_adapters/bson_adapter.py b/templates/home_template/telepath_adapters/bson_adapter.py
deleted file mode 100644
index 2d3039d..0000000
--- a/templates/home_template/telepath_adapters/bson_adapter.py
+++ /dev/null
@@ -1,12 +0,0 @@
-from bson import ObjectId
-from wagtail.telepath import Adapter, register
-
-
-class ObjectIdAdapter(Adapter):
- js_constructor = "ObjectId"
-
- def js_args(self, obj):
- return [str(obj)]
-
-
-register(ObjectId, ObjectIdAdapter)
diff --git a/templates/home_template/wagtail_hooks.py b/templates/home_template/wagtail_hooks.py
deleted file mode 100644
index f83e308..0000000
--- a/templates/home_template/wagtail_hooks.py
+++ /dev/null
@@ -1,7 +0,0 @@
-from wagtail import hooks
-
-
-@hooks.register("insert_editor_js")
-def add_objectid_js():
- return """
- """
diff --git a/templates/project_template/project_name/__init__.py b/templates/project_template/project_name/__init__.py
deleted file mode 100644
index e69de29..0000000
diff --git a/templates/project_template/project_name/mongo_apps.py b/templates/project_template/project_name/mongo_apps.py
deleted file mode 100644
index 0f44846..0000000
--- a/templates/project_template/project_name/mongo_apps.py
+++ /dev/null
@@ -1,67 +0,0 @@
-from django.contrib.admin.apps import AdminConfig
-from django.contrib.auth.apps import AuthConfig
-from django.contrib.contenttypes.apps import ContentTypesConfig
-
-
-from taggit.apps import TaggitAppConfig
-from wagtail.documents.apps import WagtailDocsAppConfig
-from wagtail.contrib.redirects.apps import WagtailRedirectsAppConfig
-from wagtail.images.apps import WagtailImagesAppConfig
-from wagtail.search.apps import WagtailSearchAppConfig
-from wagtail.admin.apps import WagtailAdminAppConfig
-from wagtail.apps import WagtailAppConfig
-from wagtail.contrib.forms.apps import WagtailFormsAppConfig
-from wagtail.embeds.apps import WagtailEmbedsAppConfig
-from wagtail.users.apps import WagtailUsersAppConfig
-
-
-class MongoTaggitAppConfig(TaggitAppConfig):
- default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField"
-
-
-class MongoWagtailDocsAppConfig(WagtailDocsAppConfig):
- default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField"
-
-
-class MongoAdminConfig(AdminConfig):
- default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField"
-
-
-class MongoAuthConfig(AuthConfig):
- default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField"
-
-
-class MongoContentTypesConfig(ContentTypesConfig):
- default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField"
-
-
-class MongoWagtailRedirectsAppConfig(WagtailRedirectsAppConfig):
- default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField"
-
-
-class MongoWagtailImagesAppConfig(WagtailImagesAppConfig):
- default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField"
-
-
-class MongoWagtailSearchAppConfig(WagtailSearchAppConfig):
- default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField"
-
-
-class MongoWagtailAdminAppConfig(WagtailAdminAppConfig):
- default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField"
-
-
-class MongoWagtailAppConfig(WagtailAppConfig):
- default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField"
-
-
-class MongoWagtailFormsAppConfig(WagtailFormsAppConfig):
- default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField"
-
-
-class MongoWagtailEmbedsAppConfig(WagtailEmbedsAppConfig):
- default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField"
-
-
-class MongoWagtailUsersAppConfig(WagtailUsersAppConfig):
- default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField"
diff --git a/templates/project_template/project_name/settings/__init__.py b/templates/project_template/project_name/settings/__init__.py
deleted file mode 100644
index dd8469c..0000000
--- a/templates/project_template/project_name/settings/__init__.py
+++ /dev/null
@@ -1,159 +0,0 @@
-import os
-
-from bson import ObjectId
-from django_mongodb_backend import parse_uri
-
-
-PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
-
-BASE_DIR = os.path.dirname(PROJECT_DIR)
-
-DEFAULT_AUTO_FIELD = "django_mongodb_backend.fields.ObjectIdAutoField"
-
-INSTALLED_APPS = [
- "{{ project_name }}.mongo_apps.MongoWagtailFormsAppConfig",
- "{{ project_name }}.mongo_apps.MongoWagtailRedirectsAppConfig",
- "{{ project_name }}.mongo_apps.MongoWagtailEmbedsAppConfig",
- "wagtail.sites",
- "{{ project_name }}.mongo_apps.MongoWagtailUsersAppConfig",
- "wagtail.snippets",
- "{{ project_name }}.mongo_apps.MongoWagtailDocsAppConfig",
- "{{ project_name }}.mongo_apps.MongoWagtailImagesAppConfig",
- "{{ project_name }}.mongo_apps.MongoWagtailSearchAppConfig",
- "{{ project_name }}.mongo_apps.MongoWagtailAdminAppConfig",
- "{{ project_name }}.mongo_apps.MongoWagtailAppConfig",
- "modelcluster",
- "{{ project_name }}.mongo_apps.MongoTaggitAppConfig",
- "{{ project_name }}.mongo_apps.MongoAdminConfig",
- "{{ project_name }}.mongo_apps.MongoAuthConfig",
- "{{ project_name }}.mongo_apps.MongoContentTypesConfig",
- "django.contrib.sessions",
- "django.contrib.messages",
- "django.contrib.staticfiles",
- "django_extensions",
- "webpack_boilerplate",
- "debug_toolbar",
- "home",
- "django_mongodb_extensions",
-]
-
-MIGRATION_MODULES = {
- "admin": "mongo_migrations.admin",
- "auth": "mongo_migrations.auth",
- "contenttypes": "mongo_migrations.contenttypes",
- "taggit": "mongo_migrations.taggit",
- "wagtaildocs": "mongo_migrations.wagtaildocs",
- "wagtailredirects": "mongo_migrations.wagtailredirects",
- "wagtailimages": "mongo_migrations.wagtailimages",
- "wagtailsearch": "mongo_migrations.wagtailsearch",
- "wagtailadmin": "mongo_migrations.wagtailadmin",
- "wagtailcore": "mongo_migrations.wagtailcore",
- "wagtailforms": "mongo_migrations.wagtailforms",
- "wagtailembeds": "mongo_migrations.wagtailembeds",
- "wagtailusers": "mongo_migrations.wagtailusers",
-}
-
-DATABASES = {
- "default": parse_uri(
- os.environ.get("MONGODB_URI", "mongodb://localhost:27017/{{ project_name }}")
- )
-}
-
-DEBUG = True
-
-ROOT_URLCONF = "{{ project_name }}.urls"
-
-STATICFILES_DIRS = [os.path.join(BASE_DIR, "frontend", "build")]
-
-WEBPACK_LOADER = {
- "MANIFEST_FILE": os.path.join(BASE_DIR, "frontend", "build", "manifest.json")
-}
-
-SECRET_KEY = "{{ secret_key }}"
-
-ALLOWED_HOSTS = ["*"]
-
-STATIC_URL = "static/"
-
-TEMPLATES = [
- {
- "BACKEND": "django.template.backends.django.DjangoTemplates",
- "DIRS": [os.path.join("{{ project_name }}", "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",
- ],
- },
- },
-]
-
-MIDDLEWARE = [
- "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",
- "django.middleware.security.SecurityMiddleware",
- "wagtail.contrib.redirects.middleware.RedirectMiddleware",
- "debug_toolbar.middleware.DebugToolbarMiddleware",
-]
-
-WAGTAIL_SITE_NAME = "{{ project_name }}"
-
-INTERNAL_IPS = [
- "127.0.0.1",
-]
-
-SITE_ID = ObjectId("000000000000000000000001")
-
-
-DEBUG_TOOLBAR_PANELS = [
- "debug_toolbar.panels.history.HistoryPanel",
- "debug_toolbar.panels.versions.VersionsPanel",
- "debug_toolbar.panels.timer.TimerPanel",
- "debug_toolbar.panels.settings.SettingsPanel",
- "debug_toolbar.panels.headers.HeadersPanel",
- "debug_toolbar.panels.request.RequestPanel",
- "django_mongodb_extensions.debug_toolbar.panels.mql.MQLPanel",
- "debug_toolbar.panels.staticfiles.StaticFilesPanel",
- "debug_toolbar.panels.templates.TemplatesPanel",
- "debug_toolbar.panels.alerts.AlertsPanel",
- "debug_toolbar.panels.cache.CachePanel",
- "debug_toolbar.panels.signals.SignalsPanel",
- "debug_toolbar.panels.redirects.RedirectsPanel",
- "debug_toolbar.panels.profiling.ProfilingPanel",
-]
-
-LOGGING = {
- "version": 1,
- "disable_existing_loggers": False,
- "formatters": {
- "verbose": {
- "format": "{levelname} {asctime} {module} {message}",
- "style": "{",
- },
- "simple": {
- "format": "{levelname} {message}",
- "style": "{",
- },
- },
- "handlers": {
- "console": {
- "level": "DEBUG",
- "class": "logging.StreamHandler",
- "formatter": "verbose",
- },
- },
- "loggers": {
- "django": {
- "handlers": ["console"],
- "level": "DEBUG",
- "propagate": True,
- },
- },
-}
diff --git a/templates/project_template/project_name/templates/404.html b/templates/project_template/project_name/templates/404.html
deleted file mode 100644
index f19ab95..0000000
--- a/templates/project_template/project_name/templates/404.html
+++ /dev/null
@@ -1,11 +0,0 @@
-{% extends "base.html" %}
-
-{% block title %}Page not found{% endblock %}
-
-{% block body_class %}template-404{% endblock %}
-
-{% block content %}
-Page not found
-
-Sorry, this page could not be found.
-{% endblock %}
diff --git a/templates/project_template/project_name/templates/500.html b/templates/project_template/project_name/templates/500.html
deleted file mode 100644
index 77379e5..0000000
--- a/templates/project_template/project_name/templates/500.html
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
- Internal server error
-
-
-
- Internal server error
-
- Sorry, there seems to be an error. Please try again soon.
-
-
diff --git a/templates/project_template/project_name/templates/base.html b/templates/project_template/project_name/templates/base.html
deleted file mode 100644
index 5d8b2bb..0000000
--- a/templates/project_template/project_name/templates/base.html
+++ /dev/null
@@ -1,70 +0,0 @@
-{% load static webpack_loader %}
-
-
-
-
-
- {% block title %}{% endblock %}
- {% block title_suffix %}{% endblock %}
-
-
- {% stylesheet_pack 'app' %}
- {% block extra_css %}{# Override this in templates to add extra stylesheets #}{% endblock %}
-
- {% include 'favicon.html' %}
- {% csrf_token %}
-
-
-
-
- {% include 'header.html' %}
- {% if messages %}
-
- {% for message in messages %}
-
- {{ message }}
-
-
- {% endfor %}
-
- {% endif %}
-
- {% block content %}{% endblock %}
-
-
- {% include 'footer.html' %}
- {% include 'offcanvas.html' %}
- {% javascript_pack 'app' %}
- {% block extra_js %}{# Override this in templates to add extra javascript #}{% endblock %}
-
-
diff --git a/templates/project_template/project_name/templates/favicon.html b/templates/project_template/project_name/templates/favicon.html
deleted file mode 100644
index a7f0c0f..0000000
--- a/templates/project_template/project_name/templates/favicon.html
+++ /dev/null
@@ -1,2 +0,0 @@
-{% load static %}
-
diff --git a/templates/project_template/project_name/templates/footer.html b/templates/project_template/project_name/templates/footer.html
deleted file mode 100644
index 6a6862d..0000000
--- a/templates/project_template/project_name/templates/footer.html
+++ /dev/null
@@ -1,15 +0,0 @@
-
diff --git a/templates/project_template/project_name/templates/header.html b/templates/project_template/project_name/templates/header.html
deleted file mode 100644
index 5456cde..0000000
--- a/templates/project_template/project_name/templates/header.html
+++ /dev/null
@@ -1,65 +0,0 @@
-
diff --git a/templates/project_template/project_name/templates/offcanvas.html b/templates/project_template/project_name/templates/offcanvas.html
deleted file mode 100644
index 29c1171..0000000
--- a/templates/project_template/project_name/templates/offcanvas.html
+++ /dev/null
@@ -1,38 +0,0 @@
-
-
-
-
- -
- Home
-
- {% for child in current_site.root_page.get_children %}
- -
- {{ child }}
-
- {% endfor %}
- -
-
-
-
-
-
-
-
-
diff --git a/templates/project_template/project_name/urls.py b/templates/project_template/project_name/urls.py
deleted file mode 100644
index 7706e1c..0000000
--- a/templates/project_template/project_name/urls.py
+++ /dev/null
@@ -1,11 +0,0 @@
-from debug_toolbar.toolbar import debug_toolbar_urls
-from django.urls import path, include
-from django.contrib import admin
-from .views import BaseView
-
-
-urlpatterns = [
- path("django/", admin.site.urls),
- path("wagtail/", include("wagtail.admin.urls")),
- path("", BaseView.as_view(), name="base"),
-] + debug_toolbar_urls()
diff --git a/templates/project_template/project_name/utils.py b/templates/project_template/project_name/utils.py
deleted file mode 100644
index c4fd679..0000000
--- a/templates/project_template/project_name/utils.py
+++ /dev/null
@@ -1,37 +0,0 @@
-from django.urls import URLResolver
-import requests
-
-
-def get_ec2_metadata():
- try:
- # Step 1: Get the token
- token_url = "http://169.254.169.254/latest/api/token"
- headers = {"X-aws-ec2-metadata-token-ttl-seconds": "21600"}
- response = requests.put(token_url, headers=headers)
- response.raise_for_status() # Raise an error for bad responses
-
- token = response.text
-
- # Step 2: Use the token to get the instance metadata
- metadata_url = "http://169.254.169.254/latest/meta-data/local-ipv4"
- headers = {"X-aws-ec2-metadata-token": token}
- response = requests.get(metadata_url, headers=headers)
- response.raise_for_status() # Raise an error for bad responses
-
- metadata = response.text
- return metadata
- except requests.RequestException as e:
- print(f"Error retrieving EC2 metadata: {e}")
- return None
-
-
-# Function to remove a specific URL pattern based on its route (including catch-all)
-def remove_urlpattern(urlpatterns, route_to_remove):
- urlpatterns[:] = [
- urlpattern
- for urlpattern in urlpatterns
- if not (
- isinstance(urlpattern, URLResolver)
- and urlpattern.pattern._route == route_to_remove
- )
- ]
diff --git a/templates/project_template/project_name/views.py-tpl b/templates/project_template/project_name/views.py-tpl
deleted file mode 100644
index 188d033..0000000
--- a/templates/project_template/project_name/views.py-tpl
+++ /dev/null
@@ -1,7 +0,0 @@
-from django.views.generic import TemplateView
-
-# Create your views here.
-
-
-class BaseView(TemplateView):
- template_name = 'base.html'
diff --git a/test/settings/qe.py b/test/settings/qe.py
index 7fa11df..995c52c 100644
--- a/test/settings/qe.py
+++ b/test/settings/qe.py
@@ -6,6 +6,12 @@
MONGODB_URI = os.environ.get("MONGODB_URI", "mongodb://localhost:27017")
+
+KMS_CREDENTIALS = {
+ "local": {
+ "key": os.urandom(96),
+ },
+}
DATABASES = {
"default": {
"ENGINE": "django_mongodb_backend",
@@ -24,9 +30,7 @@
"OPTIONS": {
"auto_encryption_opts": AutoEncryptionOpts(
key_vault_namespace="djangotests_encrypted.__keyVault",
- kms_providers={
- "local": {"key": os.urandom(96)},
- },
+ kms_providers=KMS_CREDENTIALS,
),
},
},
@@ -34,16 +38,6 @@
class EncryptedRouter:
- def db_for_read(self, model, **hints):
- if model_has_encrypted_fields(model):
- return "encrypted"
- return "default"
-
- def db_for_write(self, model, **hints):
- if model_has_encrypted_fields(model):
- return "encrypted"
- return "default"
-
def allow_migrate(self, db, app_label, model_name=None, **hints):
if hints.get("model"):
if model_has_encrypted_fields(hints["model"]):
@@ -52,11 +46,18 @@ def allow_migrate(self, db, app_label, model_name=None, **hints):
return db == "default"
return None
+ def db_for_read(self, model, **hints):
+ if model_has_encrypted_fields(model):
+ return "encrypted"
+ return "default"
+
def kms_provider(self, model):
if model_has_encrypted_fields(model):
return "local"
return None
+ db_for_write = db_for_read
+
DATABASE_ROUTERS = [EncryptedRouter()]
DEFAULT_AUTO_FIELD = "django_mongodb_backend.fields.ObjectIdAutoField"