Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
abe1c98
修改模型字段的顺序
HelloWorldZTR Sep 8, 2025
9520f99
添加基础wxid jwt authentication
HelloWorldZTR Jan 19, 2026
bdc09bb
Force jwt authentication
HelloWorldZTR Jan 20, 2026
73a3e56
Add notification API
HelloWorldZTR Jan 20, 2026
060d9eb
Add wx bind to admin, and migrate
HelloWorldZTR Jan 20, 2026
0104d7f
Rename strictjwtAuthentication to wxJWTAuthentication
HelloWorldZTR Jan 21, 2026
54fded9
Add appointment API
HelloWorldZTR Jan 22, 2026
c6ac209
Add group subscription API for mini program
Jan 24, 2026
7a107d6
Refactor appointment API endpoints and tests to optimize UI for wxApp
HelloWorldZTR Jan 24, 2026
f60d030
feat: 书房后端 API
Jiu-He25 Jan 25, 2026
6da6f73
尝试添加了元气商城相关的API
LittleLito Jan 26, 2026
827d40e
补充完善了/api/views中的extend_schema
LittleLito Jan 26, 2026
8276466
Fix library urls include
Jiu-He25 Jan 26, 2026
06be58f
Merge pull request #4 from LittleLito/lzh
HelloWorldZTR Jan 26, 2026
10e54f1
Merge branch 'mini-app' into CMZmini
HelloWorldZTR Jan 26, 2026
2469209
Merge pull request #3 from Jiu-He25/CMZmini
HelloWorldZTR Jan 26, 2026
1c489d5
Fix bugs in appoint
HelloWorldZTR Jan 27, 2026
e2fd00c
添加每日登录API
HelloWorldZTR Jan 27, 2026
cc5db23
feat: Enhance WeChat mini program authentication for account switching
HelloWorldZTR Jan 27, 2026
ccdde7e
Merge branch 'mini-app' into mini-app
HelloWorldZTR Jan 28, 2026
055c220
Merge pull request #6 from DreamWint2007/mini-app
HelloWorldZTR Jan 28, 2026
a3a8c61
fix: unit test not passing
HelloWorldZTR Jan 28, 2026
0552eba
fix: rename group to org, add unit test for org
HelloWorldZTR Jan 28, 2026
9d5b60d
补充了元气商城api的tests,并完善了相关api以便于测试
LittleLito Jan 28, 2026
c9d3204
反馈中心后端
Jiu-He25 Jan 30, 2026
c363837
Merge branch 'mini-app' into CMZmini
HelloWorldZTR Jan 31, 2026
0cd71ec
Merge pull request #8 from Jiu-He25/CMZmini
HelloWorldZTR Jan 31, 2026
3c8e981
refactor: Simplify AgreementView request handling, add serializer for…
HelloWorldZTR Jan 31, 2026
35685e8
Merge branch 'fix-unittest-rename' into mini-app
HelloWorldZTR Jan 31, 2026
9977878
Merge branch 'fix-drf-spectacular-docs' into mini-app
HelloWorldZTR Jan 31, 2026
37b4580
Merge pull request #7 from LittleLito/lzh
HelloWorldZTR Feb 3, 2026
1d828f3
feat: Allow api calls to create participant automatically
HelloWorldZTR Jan 31, 2026
d563512
feat: Add support for wx jwt in webview.
HelloWorldZTR Feb 1, 2026
a1f443d
fix: detect if the page is in miniProgram environment
HelloWorldZTR Feb 1, 2026
65cecbf
feat: Implement one-time ticket authentication for webview
HelloWorldZTR Feb 1, 2026
88954b3
fix: pool item image missing media prefix
HelloWorldZTR Feb 3, 2026
ca44ba5
修改 feedback API
Jiu-He25 Feb 4, 2026
da4920b
feat: Add support for wx jwt in webview.
HelloWorldZTR Feb 1, 2026
17ca315
feat: add index carousel
HelloWorldZTR Feb 5, 2026
d5a2f16
feat: add unbind wx
HelloWorldZTR Feb 5, 2026
d8be0b2
fix: only person can bind to wx code
HelloWorldZTR Feb 5, 2026
f267abb
增加feedback api
Jiu-He25 Feb 5, 2026
fd4cbd7
feat: add activities display for mainpage
HelloWorldZTR Feb 5, 2026
1749608
feat: myAccounts now returns avatars as well
HelloWorldZTR Feb 5, 2026
a3aa65f
Merge remote-tracking branch 'origin/mini-app' into CMZmini
Jiu-He25 Feb 5, 2026
9e1fead
增加feedback组织部分api
Jiu-He25 Feb 5, 2026
ff00b7d
Merge pull request #9 from Jiu-He25/CMZmini
HelloWorldZTR Feb 5, 2026
9310578
fix: feedback center api for orgs
HelloWorldZTR Feb 6, 2026
165ed86
feat: add mini program redirect functionality on successful operations
HelloWorldZTR Feb 6, 2026
18b8e32
feat: implement activity check-in api, change check-in qrcode to wx m…
HelloWorldZTR Feb 7, 2026
8df2cee
feat: add activity detail retrieval API for check-in page
HelloWorldZTR Feb 7, 2026
a8a1990
feat: register ActivityPhoto model in admin panel
HelloWorldZTR Feb 7, 2026
8168ee1
feat: update QR code generation for activities to use WeChat API
HelloWorldZTR Feb 7, 2026
f6a81f6
Merge branch 'develop' into mini-app
Deophius Feb 26, 2026
88f0cc0
refactor: fix broken tests
HelloWorldZTR Feb 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions .cursor/djangorest.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
alwaysApply: false
---
You are an expert in Python, Django, and scalable RESTful API development.

Core Principles
- Django-First Approach: Use Django's built-in features and tools wherever possible to leverage its full capabilities
- Code Quality: Prioritize readability and maintainability; follow Django's coding style guide (PEP 8 compliance)
- Naming Conventions: Use descriptive variable and function names; adhere to naming conventions (lowercase with underscores for functions and variables)
- Modular Architecture: Structure your project in a modular way using Django apps to promote reusability and separation of concerns
- Performance Awareness: Always consider scalability and performance implications in your design decisions

Django/Python Development Guidelines

Views and API Design
- Use Class-Based Views: Leverage Django's class-based views (CBVs) with DRF's APIViews
- RESTful Design: Follow RESTful principles strictly with proper HTTP methods and status codes
- Keep Views Light: Focus views on request handling; keep business logic in models, managers, and services
- Consistent Response Format: Use unified response structure for both success and error cases
- Always write API documentation with @extend_schema

Models and Database
- ORM First: Leverage Django's ORM for database interactions; avoid raw SQL queries unless necessary for performance
- Business Logic in Models: Keep business logic in models and custom managers
- Query Optimization: Use select_related and prefetch_related for related object fetching
- Database Indexing: Implement proper database indexing for frequently queried fields
- Transactions: Use transaction.atomic() for data consistency in critical operations

Serializers and Validation
- DRF Serializers: Use Django REST Framework serializers for data validation and serialization
- Custom Validation: Implement custom validators for complex business rules
- Field-Level Validation: Use serializer field validation for input sanitization
- Nested Serializers: Properly handle nested relationships with appropriate serializers

Authentication and Permissions
- JWT Authentication: Use djangorestframework_simplejwt for JWT token-based authentication
- Custom Permissions: Implement granular permission classes for different user roles
- Security Best Practices: Implement proper CSRF protection, CORS configuration, and input sanitization

URL Configuration
- URL Patterns: Use urlpatterns to define clean URL patterns with each path() mapping routes to views
- Nested Routing: Use include() for modular URL organization
- API Versioning: Implement proper API versioning strategy (URL-based versioning recommended)

Performance and Scalability

Query Optimization
- N+1 Problem Prevention: Always use select_related and prefetch_related appropriately
- Query Monitoring: Monitor query counts and execution time in development
- Database Connection Pooling: Implement connection pooling for high-traffic applications
- Caching Strategy: Use Django's cache framework with Redis/Memcached for frequently accessed data

Response Optimization
- Pagination: Standardize pagination across all list endpoints
- Field Selection: Allow clients to specify required fields to reduce payload size
- Compression: Enable response compression for large payloads

Error Handling and Logging

Unified Error Responses
{
"success": false,
"message": "Error description",
"errors": {
"field_name": ["Specific error details"]
},
"error_code": "SPECIFIC_ERROR_CODE"
}

Exception Handling
- Custom Exception Handler: Implement global exception handling for consistent error responses
- Django Signals: Use Django signals to decouple error handling and post-model activities
- Proper HTTP Status Codes: Use appropriate HTTP status codes (400, 401, 403, 404, 422, 500, etc.)

Logging Strategy
- Structured Logging: Implement structured logging for API monitoring and debugging
- Request/Response Logging: Log API calls with execution time, user info, and response status
- Performance Monitoring: Log slow queries and performance bottlenecks
10 changes: 10 additions & 0 deletions .cursor/overview.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
alwaysApply: true
---

You are working on a django web project.
The global urls pattern is in `/boot/urls.py`.
The global models can be found in `/generic/models.py`.
The module specific models can be found in `/module_name/models.py`.

When implementing a new function, add its corresponding test when possible.
22 changes: 22 additions & 0 deletions Appointment/utils/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ def get_participant(user: User | str, update: bool = False,
return None


def get_or_create_participant(request: UserRequest) -> Participant:
'''通过User对象或学号获取对应的参与人对象,如果不存在则创建
Args:
- user: User对象或学号
Returns:
- participant: 满足participant.Sid=user, 不存在时创建并返回新对象
Raises:
- Exception: 当不允许创建,或者创建失败时抛出异常
'''
participant = get_participant(request.user, raise_except=False)
if participant is not None:
return participant
if not CONFIG.allow_newstu_appoint:
raise Exception('不允许创建地下室账户')

participant = _create_account(request)

if participant is None:
raise Exception('创建地下室账户失败')
return participant


def _arg2user(participant: Participant | User) -> User:
'''把范围内的参数转化为User对象'''
if isinstance(participant, Participant):
Expand Down
3 changes: 3 additions & 0 deletions api/YQpools/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
YQpools API module.
"""
104 changes: 104 additions & 0 deletions api/YQpools/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
"""
Serializers for YQpools API.
"""
from rest_framework import serializers
from app.models import Pool, PoolItem


class PoolSerializer(serializers.ModelSerializer):
"""Serializer for Pool model with computed fields."""
# Computed fields from get_pools_and_items
status = serializers.IntegerField(read_only=True)
capacity = serializers.IntegerField(read_only=True, required=False)
items = serializers.ListField(
child=serializers.DictField(), read_only=True, required=False)
my_entry_time = serializers.IntegerField(read_only=True, required=False)
records_num = serializers.IntegerField(read_only=True, required=False)
results = serializers.DictField(
read_only=True, required=False, allow_null=True)

class Meta:
model = Pool
fields = '__all__'

def to_representation(self, instance):
"""Handle both Pool instances and dictionaries from get_pools_and_items."""
# If instance is a dict (from get_pools_and_items), preserve ALL fields including computed ones
if isinstance(instance, dict):
ret = instance.copy()
return self._convert_imagefields_in_dict(instance)

# Otherwise, serialize the Pool instance normally
ret = super().to_representation(instance)
return ret

# Keys that hold Prize/other image paths (from .values() they are already strings)
_IMAGE_PATH_KEYS = frozenset({"prize__image", "prize_image", "image"})

def _ensure_media_prefix(self, path):
"""Ensure image path has /media prefix for API response."""
if not path or not isinstance(path, str):
return path or ""
return path if path.startswith("/media") else f"/media/{path}"

def _convert_imagefields_in_dict(self, d):
"""Helper to convert ImageField objects and image path strings with /media prefix in nested dicts."""
result = {}
for key, value in d.items():
if hasattr(value, 'name') and hasattr(value, 'storage'): # ImageField object
result[key] = self._ensure_media_prefix(
str(value) if value else "")
# String path images
elif key in self._IMAGE_PATH_KEYS and isinstance(value, str):
result[key] = self._ensure_media_prefix(value)
elif isinstance(value, dict):
result[key] = self._convert_imagefields_in_dict(value)
elif isinstance(value, list):
result[key] = [
self._convert_imagefields_in_dict(
item) if isinstance(item, dict) else item
for item in value
]
else:
result[key] = value
return result


class PoolItemSerializer(serializers.ModelSerializer):
class Meta:
model = PoolItem
fields = '__all__'


class PoolListSerializer(serializers.Serializer):
pools_info = PoolSerializer(many=True)


class ExchangePurchaseSerializer(serializers.Serializer):
"""Serializer for exchange item purchase request."""

poolitem_id = serializers.IntegerField(
help_text="ID of the pool item to purchase")
attributes = serializers.DictField(
child=serializers.CharField(),
default=dict,
help_text="Exchange attributes if required"
)


class LotteryPurchaseSerializer(serializers.Serializer):
"""Serializer for lottery ticket purchase request."""

pool_id = serializers.IntegerField(help_text="ID of the lottery pool")


class RandomPurchaseSerializer(serializers.Serializer):
"""Serializer for random box purchase request."""

pool_id = serializers.IntegerField(help_text="ID of the random pool")


class YQPointBalanceSerializer(serializers.Serializer):
"""Serializer for user's YQPoint balance."""

YQpoint = serializers.IntegerField(help_text="Current YQPoint balance")
Loading