Mixins & Signals¶
This section documents implicit behavior in Project logic that runs without being explicitly called .
These are the most dangerous areas to change blindly , so understanding them is critical.
PART A — MIXINS (Access Control & Role Enforcement)¶
Mixins are used to enforce role boundaries and prevent cross-panel access .
1. IsCustomerMixin¶
Used in
- Customer profile
- Customer products
- Customer supports
- Customer orders
What it enforces¶
- User must be:
- Authenticated
is_customer = True
Execution behavior¶
- Runs before view logic
- If authenticated but not customer → returns 403 HTML page
- If unauthenticated → redirects to login
Why it exists¶
- Prevent seller/admin users from accessing customer-only routes
- Avoid silent permission leaks
2. IsSellerMixin¶
Used in
- Seller dashboard
- Product management
- Category management
- Support management
- Short URL management
What it enforces¶
- User must be:
- Authenticated
is_seller = True
Execution behavior¶
- Runs before view logic
- If role mismatch → returns 403 page
- If not logged in → redirects to login
Why it exists¶
- Hard separation between buyer UI and seller business UI
- Critical for multi-tenant safety
3. Generic View + Mixin Pattern¶
Pattern used everywhere:
Why this matters¶
- Authentication
- Authorization
- Business logic
are layered , not mixed.
If something breaks:
- First check mixin
- Then check generic base view
- Then check app-specific view
PART B — SIGNALS (Automatic Side Effects)¶
Signals are used for cross-system synchronization .
They are intentionally limited and high-impact .
1. User → Dodo Customer Creation¶
Signal¶
post_save(User)
Triggered when¶
- A new user is created (registration, admin, migration, etc.)
What happens¶
- User is created in Django
- Dodo API is called
- External Dodo Customer is created
DodoCustomerrow is stored locally
Why it exists¶
- Payments require a customer entity
- Keeps payment logic out of auth views
Failure behavior¶
- Failure is logged
- User creation does NOT fail
- Payment will fail later if customer missing
2. Product → Dodo Product Creation¶
Signal¶
post_save(Product)(created = True)
Triggered when¶
- Seller creates a new product
What happens¶
- Product saved in DB
- Dodo Product created
- Dodo Product ID stored locally
Why it exists¶
- Ensures product is purchasable immediately
- Removes manual payment configuration
3. Product → Dodo Product Update¶
Signal¶
post_save(Product)(created = False)
Triggered when¶
- Seller updates:
- Title
- Price
- Selling price
What happens¶
- Corresponding Dodo product is updated
Why it exists¶
- Price consistency across systems
- Avoids mismatch between UI and checkout
4. Product → Dodo Product Archive¶
Signal¶
pre_delete(Product)
Triggered when¶
- Seller deletes a product
What happens¶
- Product is archived on Dodo
- Prevents further purchases
Important rule¶
- Product deletion is blocked if purchases exist
- Signal is last safety net
5. Product Slug Auto-Generation¶
Signal¶
pre_save(Product)
Triggered when¶
- Product is saved without a slug
What happens¶
- Slug auto-generated using:
- Title prefix
- Random suffix
Why it exists¶
- SEO-safe URLs
- Prevent slug collisions
- Allow seller to skip slug field
6. Product Category Slug Generation¶
Signal¶
pre_save(ProductCategory)
Triggered when¶
- Category saved without slug
What happens¶
- Slug auto-generated from name
7. Product File Cleanup¶
Signal¶
post_delete(Product)
Triggered when¶
- Product deleted successfully
What happens¶
- Physical product file is deleted
- Prevents orphaned files in storage
PART C — WHY THIS DESIGN MATTERS¶
What Signals Are Used For¶
- External system sync
- Auto-generated identifiers
- Cleanup operations
What Signals Are NOT Used For¶
- Business rules
- Permission checks
- UI logic
This is intentional.
PART D — DANGER ZONES (Read Carefully)¶
⚠️ Do NOT disable signals unless you know the impact
| Change | Side Effect |
|---|---|
| Disable User → Dodo signal | Payments break |
| Disable Product → Dodo signal | Checkout breaks |
| Disable slug signal | URLs break |
| Disable delete cleanup | Storage leaks |
PART E — Customization Guidelines¶
Safe customizations¶
- Add new role mixins
- Extend seller/customer permissions
- Add new signals for new integrations
Unsafe customizations¶
- Removing existing signals
- Adding heavy logic inside signals
- Making signals transactional across APIs
Execution Summary¶
| Area | Behavior |
|---|---|
| Mixins | Enforce role & access |
| Signals | Sync systems automatically |
| Failure handling | Logged, non-blocking |
| Side effects | Intentional & minimal |