PICK SKY overlay: D3 natal wheel, Character model, PySwiss aspects+tz
PySwiss: - calculate_aspects() in calc.py (conjunction/sextile/square/trine/opposition with orbs) - /api/tz/ endpoint (timezonefinder lat/lon → IANA timezone) - aspects included in /api/chart/ response - timezonefinder==8.2.2 added to requirements - 14 new unit tests (test_calc.py) + 12 new integration tests (TimezoneApiTest, aspect fields) Main app: - Sign, Planet, AspectType, HouseLabel reference models + seeded migrations (0032–0033) - Character model with birth_dt/lat/lon/place, house_system, chart_data, celtic_cross, confirmed_at/retired_at lifecycle (migration 0034) - natus_preview proxy view: calls PySwiss /api/chart/ + optional /api/tz/ auto-resolution, computes planet-in-house distinctions, returns enriched JSON - natus_save view: find-or-create draft Character, confirmed_at on action='confirm' - natus-wheel.js: D3 v7 SVG natal wheel (elements pie, signs, houses, planets, aspects, ASC/MC axes); NatusWheel.draw() / redraw() / clear() - _natus_overlay.html: Nominatim place autocomplete (debounced 400ms), geolocation button with reverse-geocode city name, live chart preview (debounced 300ms), tz auto-fill, NVM / SAVE SKY footer; html.natus-open class toggle pattern - _natus.scss: Gaussian backdrop+modal, two-column form|wheel layout, suggestion dropdown, portrait collapse at 600px, landscape sidebar z-index sink - room.html: include overlay when table_status == SKY_SELECT Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
65
src/apps/epic/migrations/0032_astro_reference_tables.py
Normal file
65
src/apps/epic/migrations/0032_astro_reference_tables.py
Normal file
@@ -0,0 +1,65 @@
|
||||
# Generated by Django 6.0 on 2026-04-14 05:27
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('epic', '0031_sig_ready_sky_select'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='AspectType',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=20, unique=True)),
|
||||
('symbol', models.CharField(max_length=5)),
|
||||
('angle', models.PositiveSmallIntegerField()),
|
||||
('orb', models.FloatField()),
|
||||
],
|
||||
options={
|
||||
'ordering': ['angle'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='HouseLabel',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('number', models.PositiveSmallIntegerField(unique=True)),
|
||||
('name', models.CharField(max_length=30)),
|
||||
('keywords', models.CharField(blank=True, max_length=100)),
|
||||
],
|
||||
options={
|
||||
'ordering': ['number'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Planet',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=20, unique=True)),
|
||||
('symbol', models.CharField(max_length=5)),
|
||||
('order', models.PositiveSmallIntegerField(unique=True)),
|
||||
],
|
||||
options={
|
||||
'ordering': ['order'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Sign',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=20, unique=True)),
|
||||
('symbol', models.CharField(max_length=5)),
|
||||
('element', models.CharField(choices=[('Fire', 'Fire'), ('Earth', 'Earth'), ('Air', 'Air'), ('Water', 'Water')], max_length=5)),
|
||||
('modality', models.CharField(choices=[('Cardinal', 'Cardinal'), ('Fixed', 'Fixed'), ('Mutable', 'Mutable')], max_length=8)),
|
||||
('order', models.PositiveSmallIntegerField(unique=True)),
|
||||
('start_degree', models.FloatField()),
|
||||
],
|
||||
options={
|
||||
'ordering': ['order'],
|
||||
},
|
||||
),
|
||||
]
|
||||
106
src/apps/epic/migrations/0033_seed_astro_reference_tables.py
Normal file
106
src/apps/epic/migrations/0033_seed_astro_reference_tables.py
Normal file
@@ -0,0 +1,106 @@
|
||||
"""
|
||||
Data migration: seed Sign, Planet, AspectType, and HouseLabel tables.
|
||||
|
||||
These are stable astrological reference rows — never user-edited.
|
||||
The data matches the constants in pyswiss/apps/charts/calc.py so that
|
||||
the proxy view and D3 wheel share a single source of truth.
|
||||
"""
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
# ── Signs ────────────────────────────────────────────────────────────────────
|
||||
# (order, name, symbol, element, modality, start_degree)
|
||||
SIGNS = [
|
||||
(0, 'Aries', '♈', 'Fire', 'Cardinal', 0.0),
|
||||
(1, 'Taurus', '♉', 'Earth', 'Fixed', 30.0),
|
||||
(2, 'Gemini', '♊', 'Air', 'Mutable', 60.0),
|
||||
(3, 'Cancer', '♋', 'Water', 'Cardinal', 90.0),
|
||||
(4, 'Leo', '♌', 'Fire', 'Fixed', 120.0),
|
||||
(5, 'Virgo', '♍', 'Earth', 'Mutable', 150.0),
|
||||
(6, 'Libra', '♎', 'Air', 'Cardinal', 180.0),
|
||||
(7, 'Scorpio', '♏', 'Water', 'Fixed', 210.0),
|
||||
(8, 'Sagittarius', '♐', 'Fire', 'Mutable', 240.0),
|
||||
(9, 'Capricorn', '♑', 'Earth', 'Cardinal', 270.0),
|
||||
(10, 'Aquarius', '♒', 'Air', 'Fixed', 300.0),
|
||||
(11, 'Pisces', '♓', 'Water', 'Mutable', 330.0),
|
||||
]
|
||||
|
||||
# ── Planets ───────────────────────────────────────────────────────────────────
|
||||
# (order, name, symbol)
|
||||
PLANETS = [
|
||||
(0, 'Sun', '☉'),
|
||||
(1, 'Moon', '☽'),
|
||||
(2, 'Mercury', '☿'),
|
||||
(3, 'Venus', '♀'),
|
||||
(4, 'Mars', '♂'),
|
||||
(5, 'Jupiter', '♃'),
|
||||
(6, 'Saturn', '♄'),
|
||||
(7, 'Uranus', '♅'),
|
||||
(8, 'Neptune', '♆'),
|
||||
(9, 'Pluto', '♇'),
|
||||
]
|
||||
|
||||
# ── Aspect types ──────────────────────────────────────────────────────────────
|
||||
# (name, symbol, angle, orb) — mirrors ASPECTS constant in pyswiss calc.py
|
||||
ASPECT_TYPES = [
|
||||
('Conjunction', '☌', 0, 8.0),
|
||||
('Sextile', '⚹', 60, 6.0),
|
||||
('Square', '□', 90, 8.0),
|
||||
('Trine', '△', 120, 8.0),
|
||||
('Opposition', '☍', 180, 10.0),
|
||||
]
|
||||
|
||||
# ── House labels (distinctions) ───────────────────────────────────────────────
|
||||
# (number, name, keywords)
|
||||
HOUSE_LABELS = [
|
||||
(1, 'Self', 'identity, appearance, first impressions'),
|
||||
(2, 'Worth', 'possessions, values, finances'),
|
||||
(3, 'Education', 'communication, siblings, short journeys'),
|
||||
(4, 'Family', 'home, roots, ancestry'),
|
||||
(5, 'Creation', 'creativity, romance, children, pleasure'),
|
||||
(6, 'Ritual', 'service, health, daily routines'),
|
||||
(7, 'Cooperation', 'partnerships, marriage, open enemies'),
|
||||
(8, 'Regeneration', 'transformation, shared resources, death'),
|
||||
(9, 'Enterprise', 'philosophy, travel, higher learning'),
|
||||
(10, 'Career', 'public life, reputation, authority'),
|
||||
(11, 'Reward', 'friends, groups, aspirations'),
|
||||
(12, 'Reprisal', 'hidden matters, karma, self-undoing'),
|
||||
]
|
||||
|
||||
|
||||
def forward(apps, schema_editor):
|
||||
Sign = apps.get_model('epic', 'Sign')
|
||||
Planet = apps.get_model('epic', 'Planet')
|
||||
AspectType = apps.get_model('epic', 'AspectType')
|
||||
HouseLabel = apps.get_model('epic', 'HouseLabel')
|
||||
|
||||
for order, name, symbol, element, modality, start_degree in SIGNS:
|
||||
Sign.objects.create(
|
||||
order=order, name=name, symbol=symbol,
|
||||
element=element, modality=modality, start_degree=start_degree,
|
||||
)
|
||||
|
||||
for order, name, symbol in PLANETS:
|
||||
Planet.objects.create(order=order, name=name, symbol=symbol)
|
||||
|
||||
for name, symbol, angle, orb in ASPECT_TYPES:
|
||||
AspectType.objects.create(name=name, symbol=symbol, angle=angle, orb=orb)
|
||||
|
||||
for number, name, keywords in HOUSE_LABELS:
|
||||
HouseLabel.objects.create(number=number, name=name, keywords=keywords)
|
||||
|
||||
|
||||
def reverse(apps, schema_editor):
|
||||
for model_name in ('Sign', 'Planet', 'AspectType', 'HouseLabel'):
|
||||
apps.get_model('epic', model_name).objects.all().delete()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('epic', '0032_astro_reference_tables'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(forward, reverse_code=reverse),
|
||||
]
|
||||
35
src/apps/epic/migrations/0034_character_model.py
Normal file
35
src/apps/epic/migrations/0034_character_model.py
Normal file
@@ -0,0 +1,35 @@
|
||||
# Generated by Django 6.0 on 2026-04-14 05:29
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('epic', '0033_seed_astro_reference_tables'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Character',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('birth_dt', models.DateTimeField(blank=True, null=True)),
|
||||
('birth_lat', models.DecimalField(blank=True, decimal_places=6, max_digits=9, null=True)),
|
||||
('birth_lon', models.DecimalField(blank=True, decimal_places=6, max_digits=9, null=True)),
|
||||
('birth_place', models.CharField(blank=True, max_length=200)),
|
||||
('house_system', models.CharField(choices=[('O', 'Porphyry'), ('P', 'Placidus'), ('K', 'Koch'), ('W', 'Whole Sign')], default='O', max_length=1)),
|
||||
('chart_data', models.JSONField(blank=True, null=True)),
|
||||
('celtic_cross', models.JSONField(blank=True, null=True)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('confirmed_at', models.DateTimeField(blank=True, null=True)),
|
||||
('retired_at', models.DateTimeField(blank=True, null=True)),
|
||||
('seat', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='characters', to='epic.tableseat')),
|
||||
('significator', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='character_significators', to='epic.tarotcard')),
|
||||
],
|
||||
options={
|
||||
'ordering': ['-created_at'],
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -470,3 +470,141 @@ def active_sig_seat(room):
|
||||
if seat.significator_id is None:
|
||||
return seat
|
||||
return None
|
||||
|
||||
|
||||
# ── Astrological reference tables (seeded, never user-edited) ─────────────────
|
||||
|
||||
class Sign(models.Model):
|
||||
FIRE = 'Fire'
|
||||
EARTH = 'Earth'
|
||||
AIR = 'Air'
|
||||
WATER = 'Water'
|
||||
ELEMENT_CHOICES = [(e, e) for e in (FIRE, EARTH, AIR, WATER)]
|
||||
|
||||
CARDINAL = 'Cardinal'
|
||||
FIXED = 'Fixed'
|
||||
MUTABLE = 'Mutable'
|
||||
MODALITY_CHOICES = [(m, m) for m in (CARDINAL, FIXED, MUTABLE)]
|
||||
|
||||
name = models.CharField(max_length=20, unique=True)
|
||||
symbol = models.CharField(max_length=5) # ♈ ♉ … ♓
|
||||
element = models.CharField(max_length=5, choices=ELEMENT_CHOICES)
|
||||
modality = models.CharField(max_length=8, choices=MODALITY_CHOICES)
|
||||
order = models.PositiveSmallIntegerField(unique=True) # 0–11, Aries first
|
||||
start_degree = models.FloatField() # 0, 30, 60 … 330
|
||||
|
||||
class Meta:
|
||||
ordering = ['order']
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class Planet(models.Model):
|
||||
name = models.CharField(max_length=20, unique=True)
|
||||
symbol = models.CharField(max_length=5) # ☉ ☽ ☿ ♀ ♂ ♃ ♄ ♅ ♆ ♇
|
||||
order = models.PositiveSmallIntegerField(unique=True) # 0–9, Sun first
|
||||
|
||||
class Meta:
|
||||
ordering = ['order']
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class AspectType(models.Model):
|
||||
name = models.CharField(max_length=20, unique=True)
|
||||
symbol = models.CharField(max_length=5) # ☌ ⚹ □ △ ☍
|
||||
angle = models.PositiveSmallIntegerField() # 0, 60, 90, 120, 180
|
||||
orb = models.FloatField() # max allowed orb in degrees
|
||||
|
||||
class Meta:
|
||||
ordering = ['angle']
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class HouseLabel(models.Model):
|
||||
"""Life-area label for each of the 12 astrological houses (distinctions)."""
|
||||
|
||||
number = models.PositiveSmallIntegerField(unique=True) # 1–12
|
||||
name = models.CharField(max_length=30)
|
||||
keywords = models.CharField(max_length=100, blank=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['number']
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.number}: {self.name}"
|
||||
|
||||
|
||||
# ── Character ─────────────────────────────────────────────────────────────────
|
||||
|
||||
class Character(models.Model):
|
||||
"""A gamer's player-character for one seat in one game session.
|
||||
|
||||
Lifecycle:
|
||||
- Created (draft) when gamer opens PICK SKY overlay.
|
||||
- confirmed_at set on confirm → locked.
|
||||
- retired_at set on retirement → archived (seat may hold a new Character).
|
||||
|
||||
Active character for a seat: confirmed_at__isnull=False, retired_at__isnull=True.
|
||||
"""
|
||||
|
||||
PORPHYRY = 'O'
|
||||
PLACIDUS = 'P'
|
||||
KOCH = 'K'
|
||||
WHOLE = 'W'
|
||||
HOUSE_SYSTEM_CHOICES = [
|
||||
(PORPHYRY, 'Porphyry'),
|
||||
(PLACIDUS, 'Placidus'),
|
||||
(KOCH, 'Koch'),
|
||||
(WHOLE, 'Whole Sign'),
|
||||
]
|
||||
|
||||
# ── seat relationship ─────────────────────────────────────────────────
|
||||
seat = models.ForeignKey(
|
||||
TableSeat, on_delete=models.CASCADE, related_name='characters',
|
||||
)
|
||||
|
||||
# ── significator (set at PICK SKY) ────────────────────────────────────
|
||||
significator = models.ForeignKey(
|
||||
TarotCard, null=True, blank=True,
|
||||
on_delete=models.SET_NULL, related_name='character_significators',
|
||||
)
|
||||
|
||||
# ── natus input (what the gamer entered) ─────────────────────────────
|
||||
birth_dt = models.DateTimeField(null=True, blank=True) # UTC
|
||||
birth_lat = models.DecimalField(max_digits=9, decimal_places=6, null=True, blank=True)
|
||||
birth_lon = models.DecimalField(max_digits=9, decimal_places=6, null=True, blank=True)
|
||||
birth_place = models.CharField(max_length=200, blank=True) # display string only
|
||||
house_system = models.CharField(
|
||||
max_length=1, choices=HOUSE_SYSTEM_CHOICES, default=PORPHYRY,
|
||||
)
|
||||
|
||||
# ── computed natus snapshot (full PySwiss response) ───────────────────
|
||||
chart_data = models.JSONField(null=True, blank=True)
|
||||
|
||||
# ── celtic cross spread (added at PICK SEA) ───────────────────────────
|
||||
celtic_cross = models.JSONField(null=True, blank=True)
|
||||
|
||||
# ── lifecycle ─────────────────────────────────────────────────────────
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
confirmed_at = models.DateTimeField(null=True, blank=True)
|
||||
retired_at = models.DateTimeField(null=True, blank=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['-created_at']
|
||||
|
||||
def __str__(self):
|
||||
status = 'confirmed' if self.confirmed_at else 'draft'
|
||||
return f"Character(seat={self.seat_id}, {status})"
|
||||
|
||||
@property
|
||||
def is_confirmed(self):
|
||||
return self.confirmed_at is not None
|
||||
|
||||
@property
|
||||
def is_active(self):
|
||||
return self.confirmed_at is not None and self.retired_at is None
|
||||
|
||||
@@ -25,4 +25,6 @@ urlpatterns = [
|
||||
path('room/<uuid:room_id>/abandon', views.abandon_room, name='abandon_room'),
|
||||
path('room/<uuid:room_id>/tarot/', views.tarot_deck, name='tarot_deck'),
|
||||
path('room/<uuid:room_id>/tarot/deal', views.tarot_deal, name='tarot_deal'),
|
||||
path('room/<uuid:room_id>/natus/preview', views.natus_preview, name='natus_preview'),
|
||||
path('room/<uuid:room_id>/natus/save', views.natus_save, name='natus_save'),
|
||||
]
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import json
|
||||
from datetime import timedelta
|
||||
import zoneinfo
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import requests as http_requests
|
||||
from asgiref.sync import async_to_sync
|
||||
from channels.layers import get_channel_layer
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.db import transaction
|
||||
from django.http import HttpResponse
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
from django.shortcuts import redirect, render
|
||||
from django.utils import timezone
|
||||
|
||||
@@ -13,6 +16,7 @@ from apps.drama.models import GameEvent, record
|
||||
from django.db.models import Case, IntegerField, Value, When
|
||||
|
||||
from apps.epic.models import (
|
||||
Character,
|
||||
GateSlot, Room, RoomInvite, SIG_SEAT_ORDER, SigReservation, TableSeat,
|
||||
TarotCard, TarotDeck,
|
||||
active_sig_seat, debit_token, levity_sig_cards, gravity_sig_cards,
|
||||
@@ -916,3 +920,167 @@ def tarot_deal(request, room_id):
|
||||
"positions": positions,
|
||||
})
|
||||
|
||||
|
||||
# ── Natus (natal chart) ───────────────────────────────────────────────────────
|
||||
|
||||
def _planet_house(degree, cusps):
|
||||
"""Return 1-based house number for a planet at ecliptic degree.
|
||||
|
||||
cusps is the 12-element list from PySwiss where cusps[i] is the start of
|
||||
house i+1. Handles the wrap-around case where a cusp crosses 0°/360°.
|
||||
"""
|
||||
degree = degree % 360
|
||||
for i in range(12):
|
||||
start = cusps[i] % 360
|
||||
end = cusps[(i + 1) % 12] % 360
|
||||
if start < end:
|
||||
if start <= degree < end:
|
||||
return i + 1
|
||||
else: # wrap-around: e.g. cusp at 350° → next at 10°
|
||||
if degree >= start or degree < end:
|
||||
return i + 1
|
||||
return 1
|
||||
|
||||
|
||||
def _compute_distinctions(planets, houses):
|
||||
"""Return dict {house_number_str: planet_count} for all 12 houses."""
|
||||
cusps = houses['cusps']
|
||||
counts = {str(i): 0 for i in range(1, 13)}
|
||||
for planet_data in planets.values():
|
||||
h = _planet_house(planet_data['degree'], cusps)
|
||||
counts[str(h)] += 1
|
||||
return counts
|
||||
|
||||
|
||||
@login_required
|
||||
def natus_preview(request, room_id):
|
||||
"""Proxy GET to PySwiss /api/chart/ and augment with distinction counts.
|
||||
|
||||
Query params:
|
||||
date — YYYY-MM-DD (local birth date)
|
||||
time — HH:MM (local birth time, default 12:00)
|
||||
tz — IANA timezone string (optional; auto-resolved from lat/lon if absent)
|
||||
lat — float
|
||||
lon — float
|
||||
|
||||
If tz is absent or blank, calls PySwiss /api/tz/ to resolve it from the
|
||||
coordinates before converting the local datetime to UTC.
|
||||
|
||||
Response includes a 'timezone' key (resolved or supplied) so the client
|
||||
can back-fill the timezone field after the first wheel render.
|
||||
|
||||
No database writes — safe for debounced real-time calls.
|
||||
"""
|
||||
seat = _canonical_user_seat(Room.objects.get(id=room_id), request.user)
|
||||
if seat is None:
|
||||
return HttpResponse(status=403)
|
||||
|
||||
date_str = request.GET.get('date')
|
||||
time_str = request.GET.get('time', '12:00')
|
||||
tz_str = request.GET.get('tz', '').strip()
|
||||
lat_str = request.GET.get('lat')
|
||||
lon_str = request.GET.get('lon')
|
||||
|
||||
if not date_str or lat_str is None or lon_str is None:
|
||||
return HttpResponse(status=400)
|
||||
|
||||
try:
|
||||
lat = float(lat_str)
|
||||
lon = float(lon_str)
|
||||
except ValueError:
|
||||
return HttpResponse(status=400)
|
||||
|
||||
if not (-90 <= lat <= 90) or not (-180 <= lon <= 180):
|
||||
return HttpResponse(status=400)
|
||||
|
||||
# Resolve timezone from coordinates if not supplied
|
||||
if not tz_str:
|
||||
try:
|
||||
tz_resp = http_requests.get(
|
||||
settings.PYSWISS_URL + '/api/tz/',
|
||||
params={'lat': lat_str, 'lon': lon_str},
|
||||
timeout=5,
|
||||
)
|
||||
tz_resp.raise_for_status()
|
||||
tz_str = tz_resp.json().get('timezone') or 'UTC'
|
||||
except Exception:
|
||||
tz_str = 'UTC'
|
||||
|
||||
try:
|
||||
tz = zoneinfo.ZoneInfo(tz_str)
|
||||
except (zoneinfo.ZoneInfoNotFoundError, KeyError):
|
||||
return HttpResponse(status=400)
|
||||
|
||||
try:
|
||||
local_dt = datetime.strptime(f'{date_str} {time_str}', '%Y-%m-%d %H:%M')
|
||||
local_dt = local_dt.replace(tzinfo=tz)
|
||||
utc_dt = local_dt.astimezone(zoneinfo.ZoneInfo('UTC'))
|
||||
dt_iso = utc_dt.strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||
except ValueError:
|
||||
return HttpResponse(status=400)
|
||||
|
||||
try:
|
||||
resp = http_requests.get(
|
||||
settings.PYSWISS_URL + '/api/chart/',
|
||||
params={'dt': dt_iso, 'lat': lat_str, 'lon': lon_str},
|
||||
timeout=5,
|
||||
)
|
||||
resp.raise_for_status()
|
||||
except Exception:
|
||||
return HttpResponse(status=502)
|
||||
|
||||
data = resp.json()
|
||||
data['distinctions'] = _compute_distinctions(data['planets'], data['houses'])
|
||||
data['timezone'] = tz_str
|
||||
return JsonResponse(data)
|
||||
|
||||
|
||||
@login_required
|
||||
def natus_save(request, room_id):
|
||||
"""Create or update the draft Character for the requesting gamer's seat.
|
||||
|
||||
POST body (JSON):
|
||||
birth_dt — ISO 8601 UTC datetime
|
||||
birth_lat — float
|
||||
birth_lon — float
|
||||
birth_place — display string (optional)
|
||||
house_system — single char, default 'O'
|
||||
chart_data — full PySwiss response dict (incl. distinctions)
|
||||
action — 'save' (default) or 'confirm'
|
||||
|
||||
On 'confirm': sets confirmed_at, locking the Character.
|
||||
Returns: {id, confirmed}
|
||||
"""
|
||||
if request.method != 'POST':
|
||||
return HttpResponse(status=405)
|
||||
|
||||
room = Room.objects.get(id=room_id)
|
||||
seat = _canonical_user_seat(room, request.user)
|
||||
if seat is None:
|
||||
return HttpResponse(status=403)
|
||||
|
||||
try:
|
||||
body = json.loads(request.body)
|
||||
except json.JSONDecodeError:
|
||||
return HttpResponse(status=400)
|
||||
|
||||
# Find or create the active draft (unconfirmed, unretired) for this seat
|
||||
char = Character.objects.filter(
|
||||
seat=seat, confirmed_at__isnull=True, retired_at__isnull=True,
|
||||
).first()
|
||||
if char is None:
|
||||
char = Character(seat=seat)
|
||||
|
||||
char.birth_dt = body.get('birth_dt')
|
||||
char.birth_lat = body.get('birth_lat')
|
||||
char.birth_lon = body.get('birth_lon')
|
||||
char.birth_place = body.get('birth_place', '')
|
||||
char.house_system = body.get('house_system', Character.PORPHYRY)
|
||||
char.chart_data = body.get('chart_data')
|
||||
|
||||
if body.get('action') == 'confirm':
|
||||
char.confirmed_at = timezone.now()
|
||||
|
||||
char.save()
|
||||
return JsonResponse({'id': char.id, 'confirmed': char.is_confirmed})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user