Skip to content

Commit 59a40b3

Browse files
authored
Merge pull request #3 from toggle-corp/feature/initial-users
2 parents a8920e0 + 1b3df9a commit 59a40b3

File tree

22 files changed

+272
-92
lines changed

22 files changed

+272
-92
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: CI
22

33
on:
44
pull_request:
5+
push:
6+
branches:
7+
- main
58
workflow_dispatch:
69

710
jobs:

.github/workflows/release.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77

88
permissions:
99
contents: write
10+
packages: write
1011

1112
jobs:
1213
generate-release:
@@ -23,7 +24,7 @@ jobs:
2324
id: release
2425
shell: bash
2526
run: |
26-
RELEASE_VERSION=${GITHUB_REF:11}
27+
RELEASE_VERSION=${GITHUB_REF:10}
2728
2829
IS_PRERELEASE=false
2930
if [[ "$RELEASE_VERSION" == *dev* ]]; then
@@ -46,7 +47,7 @@ jobs:
4647
args: -vv --latest --no-exec --github-repo ${{ github.repository }} --strip all
4748
env:
4849
GIT_CLIFF__REMOTE__GITHUB__OWNER: toggle-corp
49-
GIT_CLIFF__REMOTE__GITHUB__REPO: toggle-django-utils
50+
GIT_CLIFF__REMOTE__GITHUB__REPO: banjo-utils
5051

5152
- name: Create Github Release
5253
uses: softprops/action-gh-release@v2

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[submodule "fugit"]
22
path = fugit
33
url = https://github.com/toggle-corp/fugit.git
4-
branch = v0.1.1
4+
branch = v0.1.6

README.md

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# toggle-django-utils
1+
# Banjo utils
22

33
Reusable Django utilities and management commands for Toggle projects.
44

@@ -8,43 +8,42 @@ Reusable Django utilities and management commands for Toggle projects.
88

99
- Shared management command: `wait_for_resources`
1010
— Wait for database, Redis, Minio (S3) resources to be available before startup
11+
- Create Initial Users: `create_initial_users`
12+
- Create Users with specified roles and permissions, useful to populate the database with default users during development or testing
1113

1214
---
1315

1416
## Installation
1517

1618
**Using [uv](https://github.com/astral-sh/uv):**
1719
```bash
18-
uv pip install "git+ssh://git@github.com/toggle-corp/toggle-django-utils.git@main"
20+
uv pip install "git+https://github.com/toggle-corp/banjo-utils.git@v0.1.0"
1921
```
2022

2123
Or add to your `pyproject.toml`:
2224
```toml
2325
[project]
2426
dependencies = [
25-
"toggle-django-utils",
27+
"banjo-utils",
2628
]
2729

2830
[tool.uv.sources]
29-
toggle-django-utils = { git = "https://github.com/toggle-corp/toggle-django-utils", branch = "main" }
31+
banjo-utils = { git = "https://github.com/toggle-corp/banjo-utils", tag = "v0.1.0" }
3032
```
3133

3234
---
3335

3436
## Setup in Django
3537

36-
1. **Add to `INSTALLED_APPS` in your Django project's `settings.py`:**
38+
- **Add to `INSTALLED_APPS` in your Django project's `settings.py`:**
3739

3840
```python
3941
INSTALLED_APPS = [
4042
# ... your other apps ...
41-
"toggle_django_utils",
43+
"banjo_utils",
4244
]
4345
```
4446

45-
2. (Optional) If your `settings.py` uses custom configs, ensure `"toggle_django_utils"` remains in the app list.
46-
47-
4847
---
4948

5049
## Usage
@@ -55,15 +54,32 @@ python manage.py wait_for_resources --db --redis
5554
```
5655

5756
**Command options:**
58-
- `--db`      Wait for database
59-
- `--redis`   Wait for Redis server
60-
- `--minio`   Wait for Minio (S3 storage)
61-
- `--timeout`   Set max wait time (seconds)
57+
- `--db`: Wait for database
58+
- `--redis`: Wait for Redis server
59+
- `--minio`: Wait for Minio (S3 storage)
60+
- `--timeout`: Set max wait time (seconds)
6261

6362
**Examples:**
6463
```bash
6564
python manage.py wait_for_resources --db --redis
6665
python manage.py wait_for_resources --timeout 300 --minio
66+
python manage.py create_initial_users --users-json="
67+
[
68+
{
69+
"username": "admin",
70+
"email": "test@example.com",
71+
"password": "admin123",
72+
"is_superuser": true,
73+
"is_staff": true
74+
},
75+
{
76+
"username": "user1",
77+
"email": "user1@gmail.com",
78+
"password": "user123",
79+
"is_superuser": false,
80+
"is_staff": false
81+
}
82+
]'
6783
```
6884
6985
---
@@ -83,6 +99,11 @@ python manage.py wait_for_resources --timeout 300 --minio
8399
```bash
84100
uv run --all-groups --all-extras pytest
85101
```
102+
4. Run commands for example project
103+
```bash
104+
uv run --all-groups --all-extras python example/manage.py runserver
105+
uv run --all-groups --all-extras python example/manage.py wait_for_resources --db --redis
106+
```
86107
87108
---
88109

TODOS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
- We can use something like this inside <settings.py>
22

33
```
4-
TOGGLE_DJANGO_UTILS_CONFIG = {
4+
BANJO_UTILS_CONFIG = {
55
"WAIT_FOR_RESOURCES": {
66
"ALIAS": {
77
"dev": ["db", "redis", "minio"],

example/main/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"django.contrib.contenttypes",
1414
"django.contrib.sessions",
1515
"django.contrib.messages",
16-
"toggle_django_utils",
16+
"banjo_utils",
1717
]
1818

1919
MIDDLEWARE = [
@@ -26,7 +26,7 @@
2626
DATABASES = {
2727
"default": {
2828
"ENGINE": "django.db.backends.sqlite3",
29-
"NAME": ":memory:",
29+
"NAME": BASE_DIR / "db.sqlite3",
3030
},
3131
}
3232

pyproject.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ requires = [
55
]
66

77
[project]
8-
name = "toggle-django-utils"
8+
name = "banjo-utils"
99
version = "0.1.0"
1010
description = "Shared Django utilities for Toggle projects"
1111
readme = "README.md"
@@ -36,12 +36,12 @@ test = [
3636
]
3737

3838
[project.urls]
39-
Homepage = "https://github.com/toggle-corp/toggle-django-utils"
40-
Repository = "https://github.com/toggle-corp/toggle-django-utils"
41-
Issues = "https://github.com/toggle-corp/toggle-django-utils/issues"
39+
Homepage = "https://github.com/toggle-corp/banjo-utils"
40+
Repository = "https://github.com/toggle-corp/banjo-utils"
41+
Issues = "https://github.com/toggle-corp/banjo-utils/issues"
4242

4343
[tool.hatch.build.targets.wheel]
44-
packages = ["src/toggle_django_utils"]
44+
packages = ["src/banjo_utils"]
4545

4646
[tool.ruff.lint.per-file-ignores]
4747
"__init__.py" = ["E402"]

src/banjo_utils/apps.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.apps import AppConfig
2+
3+
4+
class BanjoUtilsConfig(AppConfig):
5+
name = "banjo_utils"
6+
verbose_name = "Banjo Utils"
7+
default_auto_field = "django.db.models.BigAutoField"

0 commit comments

Comments
 (0)