This commit is contained in:
2026-02-12 21:03:53 +08:00
parent 414d3334fd
commit bbb8f3bbaf
20 changed files with 11277 additions and 235 deletions

View File

@@ -41,14 +41,31 @@ class ActivityViewSet(viewsets.ReadOnlyModelViewSet):
signup_info = request.data.get('signup_info', {})
# Basic validation
if activity.signup_form_config:
required_fields = [f['name'] for f in activity.signup_form_config if f.get('required')]
# Re-fetch the config from the object method or serializer logic if needed,
# but here we can just use the serializer's method to get the effective config.
# However, accessing serializer method from view is tricky without instantiating.
# Let's replicate the logic or rely on the fact that we can construct it.
effective_config = activity.signup_form_config
if not effective_config:
effective_config = []
if activity.ask_name:
effective_config.append({"name": "name", "label": "姓名", "type": "text", "required": True})
if activity.ask_phone:
effective_config.append({"name": "phone", "label": "手机号", "type": "number", "required": True})
if activity.ask_wechat:
effective_config.append({"name": "wechat", "label": "微信号", "type": "text", "required": True})
if activity.ask_company:
effective_config.append({"name": "company", "label": "公司/机构", "type": "text", "required": False})
if effective_config:
required_fields = [f['name'] for f in effective_config if f.get('required')]
for field in required_fields:
# Simple check: field exists and is not empty string (if it's a string)
val = signup_info.get(field)
if val is None or (isinstance(val, str) and not val.strip()):
# Try to find label for better error message
label = next((f['label'] for f in activity.signup_form_config if f['name'] == field), field)
label = next((f['label'] for f in effective_config if f['name'] == field), field)
return Response({'error': f'请填写: {label}'}, status=400)
signup = ActivitySignup.objects.create(