# Quick Setup Guide - CANVA Member Cards

## 🚀 Quick Start

### 1. Run Setup Script
```bash
./setup_canva_cards.sh
```

Or manually:
```bash
source venv/bin/activate  # or your virtual environment
pip install -r requirements.txt
python manage.py makemigrations appauthentication
python manage.py migrate
```

### 2. Prepare Your CANVA Templates

Export from CANVA:
- **Format**: PNG
- **Size**: 1050 x 600 pixels
- **Quality**: High/Maximum

Save the 4 card designs to your computer.

### 3. Create Templates in Django Admin

Login to Django Admin: `http://localhost:8000/admin/` (or your domain)

Navigate to: **Templates de carte** → **Add Template**

Create 4 templates:

#### Template 1: Heritage
- **Name**: Heritage
- **Slug**: heritage
- **Template Image**: Upload `CARTE HERITAGE.png`
- **Coordinates** (starting point - adjust as needed):
  ```
  Name Position:    X=720, Y=187, Size=32, Color=#000000
  Code Position:    X=590, Y=290, Size=20, Color=#0094a0
  Photo Position:   X=950, Y=275, Size=50
  QR1 Position:     X=620, Y=380, Size=90
  QR2 Position:     X=892, Y=380, Size=90
  ```
- **Active**: ✓ Checked

#### Template 2: Royaume
- **Name**: Royaume
- **Slug**: royaume
- **Template Image**: Upload `CARTE ROYAUME.png`
- **Coordinates**: (same as Heritage - adjust if needed)
- **Active**: ✓ Checked

#### Template 3: Soleil
- **Name**: Soleil
- **Slug**: soleil
- **Template Image**: Upload `CARTE SOLEIL.png`
- **Coordinates**: (same as Heritage - adjust if needed)
- **Active**: ✓ Checked

#### Template 4: Teranga
- **Name**: Teranga
- **Slug**: teranga
- **Template Image**: Upload `CARTE TERANGA.png`
- **Coordinates**: (same as Heritage - adjust if needed)
- **Active**: ✓ Checked

### 4. Link Templates to Giving Circles

Navigate to: **Cercles de donateurs**

Edit each circle and assign template:

- **Teranga** (€10/month) → Template: **Teranga**
- **Soleil** (€40/month) → Template: **Soleil**
- **Royaume** (€160/month) → Template: **Royaume**
- **Héritage** (€1000/month) → Template: **Heritage**

### 5. Configure QR Codes

Navigate to: **Configuration carte membre**

Set URLs:
- **QR Code 1 URL**: `https://sponsor.enfantsoleilmonde.org/`
- **QR Code 2 URL**: `https://enfantsoleilmonde.org/`

## 🎯 Finding Perfect Coordinates

### Method: Use Your CANVA Design as Reference

Look at your card and estimate where text should go:

```
    0                   525                 1050
    ├────────────────────┼────────────────────┤
0 ──┬────────────────────────────────────────┐
    │  [LOGO]           CARTE HERITAGE       │
    │                                         │
    │                   User Full Name   [📷] │ ← name_y ≈ 187
150─┤                                         │
    │                                         │
    │              GENERATION CODE        [🆔]│ ← code_y ≈ 290
300─┤                                         │
    │                                         │
    │           [QR1]            [QR2]        │ ← qr_y ≈ 380
450─┤            ▄▄▄              ▄▄▄         │
    │            ███              ███         │
    │            ███              ███         │
    │  contact@enfantsoleilmonde.org | +221...│
600─└────────────────────────────────────────┘
```

**Positioning Logic:**
- **X coordinate**: Distance from left edge
- **Y coordinate**: Distance from top edge
- **Name** typically centered-right: X ≈ 720, Y ≈ 187
- **Code** below name: X ≈ 590, Y ≈ 290
- **QR codes** bottom-center: X1 ≈ 620, X2 ≈ 892, Y ≈ 380

### Testing Coordinates

1. Create a test user in admin
2. Set `card_active = True`
3. Assign to a giving circle
4. Login as that user
5. View dashboard
6. If text is misaligned, adjust coordinates in CardTemplate admin
7. Refresh dashboard to see changes

## ✅ Testing Checklist

- [ ] All 4 templates uploaded and active
- [ ] Templates linked to giving circles
- [ ] QR code URLs configured
- [ ] Test user created with `card_active = True`
- [ ] Test user assigned to a giving circle
- [ ] Card displays correctly on dashboard
- [ ] Download button works
- [ ] QR codes scan correctly
- [ ] User name appears correctly
- [ ] Generation code displays
- [ ] Profile photo shows (if uploaded)

## 🐛 Common Issues

### Card shows "Carte non disponible"
→ Check `UserProfile.card_active = True` in admin

### Card shows error 500
→ Check server logs: `python manage.py runserver` output
→ Verify template image is uploaded and accessible

### Text is cut off or misaligned
→ Adjust X/Y coordinates in CardTemplate admin
→ Try smaller font sizes if text is too long

### QR codes don't appear
→ Verify `qr1_x`, `qr1_y`, `qr2_x`, `qr2_y` are within bounds (0-1050, 0-600)
→ Check QR URLs are set in MemberCardConfig

### Photo doesn't show
→ User must have uploaded a profile photo
→ Check photo file exists in `media/profile_photos/`

## 📝 Coordinate Reference Table

| Element | Default X | Default Y | Size | Color |
|---------|-----------|-----------|------|-------|
| User Name | 720 | 187 | 32 | #000000 |
| Gen Code | 590 | 290 | 20 | #0094a0 |
| Photo | 950 | 275 | 50 | - |
| QR Code 1 | 620 | 380 | 90 | - |
| QR Code 2 | 892 | 380 | 90 | - |

Adjust these values based on your specific CANVA design!

## 🎨 Design Tips

- Keep name area at least 300px wide
- Use contrast colors for readability
- Test with long names (30+ characters)
- Ensure QR codes have white background in template
- Leave margins of at least 20px from edges

## 📚 Full Documentation

See `CANVA_CARD_SYSTEM.md` for complete technical documentation.
