Skip to content

Commit d0fca0a

Browse files
Merge pull request #11 from iosifnicolae2/main
feat: various improvements
2 parents c5b0451 + 5fdf346 commit d0fca0a

12 files changed

+414
-240
lines changed

.aider.conf.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
read: CONVENTIONS.md

.dockerignore

100644100755
File mode changed.

.gitignore

100644100755
+1
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,4 @@ pyrightconfig.json
360360
!.env.local.example
361361
superapp_fork
362362
superapp/staticfiles
363+
!.aider.conf.yml

CONVENTIONS.md

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
Canvas Canvas
2+
You are an expert in Python, Django, scalable web development, and Django SuperApp structure.
3+
4+
## Key Principles
5+
- Prioritize readability, maintainability, and Django best practices (PEP 8 compliance).
6+
- Modular structure: organize code using Django apps within SuperApp for clear separation and reuse.
7+
- Leverage built-in Django features; avoid raw SQL, prefer Django ORM.
8+
9+
## Django SuperApp Structure
10+
- Quickly bootstrap projects using pre-built standalone apps.
11+
- Each app includes independent `settings.py` and `urls.py` automatically integrated by the SuperApp system.
12+
13+
### App Settings Integration
14+
`superapp/apps/<app_name>/settings.py`
15+
```python
16+
def extend_superapp_settings(main_settings):
17+
main_settings['INSTALLED_APPS'] += ['superapp.apps.sample_app']
18+
```
19+
20+
### App URLs Integration
21+
`superapp/apps/<app_name>/urls.py`
22+
```python
23+
from django.urls import path
24+
from superapp.apps.sample_app.views import hello_world
25+
26+
def extend_superapp_urlpatterns(main_urlpatterns):
27+
main_urlpatterns += [path('hello_world/', hello_world)]
28+
```
29+
30+
### App-Specific Requirements
31+
Each app can define its own Python dependencies in:
32+
`superapp/apps/<app_name>/requirements.txt`
33+
34+
These requirements should be installed during deployment or development setup if the app is used. The SuperApp system may include tooling to auto-install these when apps are enabled.
35+
36+
## Django Guidelines
37+
- Use CBVs for complex logic, FBVs for simple tasks.
38+
- Keep business logic in models/forms; views should handle requests/responses only.
39+
- Utilize built-in authentication and forms/models validation.
40+
- Follow strict MVT separation.
41+
- Implement middleware strategically for authentication, logging, caching.
42+
- Error handling via built-in mechanisms; customize error pages.
43+
- Leverage signals for decoupled logging/error handling.
44+
- Do not update migrations in the `migrations` folder. Update migrations only if there are exceptions or issues inside of it.
45+
46+
## Admin Integration
47+
48+
### Use `django-unfold` and SuperApp admin site with Sidebar Navigation
49+
50+
- Admins must live in: `superapp/apps/<app_name>/admin/<model_name_slug>.py`
51+
- Models must live in: `superapp/apps/<app_name>/models/<model_name_slug>.py`
52+
- Signals must live in: `superapp/apps/<app_name>/signals/<model_name_slug>.py`
53+
- Services must live in: `superapp/apps/<app_name>/services/<service_name>.py`
54+
- Views must live in: `superapp/apps/<app_name>/views/<view_name>.py`
55+
- Tasks must live in: `superapp/apps/<app_name>/tasks/<task_name>.py`
56+
- Other things must live in: `superapp/apps/<app_name>/<other>/<view_name>.py`
57+
- Usually each of the above folders will have an `__init__.py` file to make them packages or to export `__all__` so make sure to keep it up to date.
58+
- Register using `superapp_admin_site` from `superapp.apps.admin_portal.sites`
59+
- Use `SuperAppModelAdmin` based on `unfold.admin.ModelAdmin`
60+
- Prefer `autocomplete_fields` for `ForeignKey` and `ManyToManyField`
61+
62+
### Add Admin Navigation
63+
64+
Each app should configure sidebar entries under `UNFOLD['SIDEBAR']['navigation']` in its `settings.py`.
65+
66+
Example:
67+
```python
68+
from django.utils.translation import gettext_lazy as _
69+
from django.urls import reverse_lazy
70+
71+
def extend_superapp_settings(main_settings):
72+
main_settings['INSTALLED_APPS'] += ['superapp.apps.sample_app']
73+
74+
main_settings['UNFOLD']['SIDEBAR']['navigation'] = [
75+
{
76+
"title": _("Sample App"),
77+
"icon": "extension",
78+
"items": [
79+
{
80+
"title": lambda request: _("Sample Models"),
81+
"icon": "table_rows",
82+
"link": reverse_lazy("admin:sample_app_samplemodel_changelist"),
83+
"permission": lambda request: request.user.has_perm("sample_app.view_samplemodel"),
84+
},
85+
]
86+
},
87+
]
88+
```
89+
Place this logic inside `superapp/apps/<app_name>/settings.py` within `extend_superapp_settings()`.
90+
91+
Example: `superapp/apps/sample_app/admin/sample_model.py`
92+
```python
93+
from superapp.apps.admin_portal.admin import SuperAppModelAdmin
94+
from superapp.apps.admin_portal.sites import superapp_admin_site
95+
from .models import SampleModel
96+
97+
@admin.register(SampleModel, site=superapp_admin_site)
98+
class SampleModelAdmin(SuperAppModelAdmin):
99+
list_display = ['slug', 'name', 'created_at', 'updated_at']
100+
search_fields = ['name__slug', 'slug']
101+
autocomplete_fields = ['name']
102+
```
103+
104+
## Dependencies
105+
- Django
106+
- Django REST Framework (APIs)
107+
- Celery (background tasks)
108+
- Redis (caching/task queues)
109+
- PostgreSQL/MySQL (production databases)
110+
- django-unfold (admin UI)
111+
112+
## Performance & Security
113+
- Optimize ORM queries (`select_related`, `prefetch_related`).
114+
- Use caching framework (Redis/Memcached).
115+
- Apply async views/background tasks (Celery).
116+
- Enforce Django security best practices (CSRF, XSS, SQL injection protections).
117+
118+
## Translation Convention
119+
- Add translation items explicitly in `AppTranslations` from `backend/superapp/apps/easywindow/enums.py`.
120+
121+
Follow Django and SuperApp documentation for detailed practices.
122+
123+
## Environment Variables
124+
Use `.env.local.example` and `.env.example` files to manage environment variables for local development, deployment templates, and Docker containers, respectively. The AI agent should take these into account when generating or configuring project settings.
125+

Makefile

+38-13
Original file line numberDiff line numberDiff line change
@@ -22,47 +22,72 @@ setup-sample-env:
2222
cp .env.local.example .env.local;
2323
cp .env.example .env;
2424

25+
web-bash:
26+
docker-compose exec -ti web bash
27+
28+
web-logs:
29+
docker-compose logs -f web -n 1000
2530

2631
start-docker:
2732
docker-compose up -d --build
2833

34+
force-start-docker:
35+
docker-compose up -d --build --force-recreate
36+
2937
stop-docker:
3038
docker-compose stop
3139

3240
destroy-docker:
3341
docker-compose stop
3442
docker-compose down -v
3543

36-
migrate:
37-
python3 manage.py migrate
38-
3944
makemigrations:
40-
python3 manage.py makemigrations
45+
docker-compose run web python3 manage.py makemigrations
46+
47+
migrate:
48+
docker-compose run web python3 manage.py migrate
4149

4250
createsuperuser:
43-
python3 manage.py createsuperuser
51+
docker-compose run web python3 manage.py createsuperuser
4452

4553
collectstatic:
46-
python3 manage.py collectstatic --no-input
54+
docker-compose exec web python3 manage.py collectstatic --no-input
4755

4856
start-tailwind-watch:
4957
cd superapp/apps/admin_portal/tailwind; \
5058
npm run tailwind:watch
5159

60+
list_all_permissions:
61+
docker-compose exec web python3 manage.py list_all_permissions
62+
63+
list_all_urls_patterns:
64+
docker-compose exec web python3 manage.py list_all_urls_patterns
5265

5366
makemessages:
5467
mkdir -p site-packages
55-
ln -s /usr/local/lib/python33.11/site-packages/unfold site-packages/unfold
56-
ln -s /usr/local/lib/python33.11/site-packages/django site-packages/django
57-
python3 manage.py makemessages -l de -l en -i venv -s
58-
rm -r site-packages
68+
ln -s venv/lib/python3.13/site-packages/unfold site-packages/unfold
69+
ln -s venv/lib/python3.13/site-packages/django site-packages/django
70+
docker-compose exec web python3 manage.py makemessages -l ro -l en -i venv -s
71+
rm -rf site-packages
5972

6073
compilemessages:
61-
python3 manage.py compilemessages
74+
docker-compose exec web python3 manage.py compilemessages
75+
rm -rf site-packages
76+
77+
generate_django_translations:
78+
docker-compose exec web python3 manage.py generate_django_translations
79+
80+
generate_material_variant_prices:
81+
docker-compose exec web python3 manage.py generate_material_variant_prices
82+
83+
generate_translation_values:
84+
docker-compose exec web python3 manage.py generate_translation_values
6285

6386

6487
create-fixtures:
65-
python3 manage.py dumpdata --natural-foreign --natural-primary --indent 2 --output fixtures/initial_data.json
88+
docker-compose exec web python3 manage.py dumpdata --natural-foreign --natural-primary --indent 2 --output fixtures/fixtures.json
6689

6790
load-fixtures:
68-
python3 manage.py loaddata fixtures/initial_data.json
91+
docker-compose exec web python3 manage.py loaddata \
92+
fixtures/fixtures
93+

requirements.txt

100644100755
+9-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
Django==5.0.*
2-
gunicorn==22.0.*
3-
whitenoise==6.7.*
4-
django-debug-toolbar==4.3.*
5-
dj-database-url==2.1.0
1+
Django==5.1.*
2+
gunicorn==23.0.*
3+
whitenoise==6.9.*
4+
django-debug-toolbar==5.0.*
5+
dj-database-url==2.3.*
66
django_superapp==1.*
7-
redis==5.0.*
7+
redis==5.2.*
8+
django-storages[s3]==1.14.*
9+
boto3==1.37.*
10+
beautifulsoup4==4.12.*

scripts/run-migrations.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
set -e;
3+
4+
python manage.py migrate
5+
6+
python manage.py collectstatic --noinput

scripts/run-server.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/bin/bash
22
set -e;
33

4-
python manage.py collectstatic --noinput
5-
python manage.py migrate
4+
#python manage.py migrate
65

76
# Check the DEBUG environment variable
87
if [ "$DEBUG" = "true" ] || [ "$DEBUG" = "1" ] || [ "$DEBUG" = "t" ]; then

scripts/run-worker.sh

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ else
1010
# Run the celery worker
1111
celery -A superapp worker --loglevel=INFO --beat --scheduler django_celery_beat.schedulers:DatabaseScheduler --concurrency=5
1212
fi
13+

0 commit comments

Comments
 (0)