feat: add community contribution ranks
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
"""Authentication-related API schemas."""
|
||||
|
||||
from datetime import datetime
|
||||
from typing import List, Optional
|
||||
from typing import List, Optional, Literal
|
||||
|
||||
from ninja import ModelSchema, Schema
|
||||
from pydantic import Field
|
||||
|
||||
from apps.gamification.api.schemas import PublicGamificationBadgeSchema
|
||||
|
||||
from apps.users.models import User
|
||||
from apps.blog.permissions import can_access_blog_admin, can_review_blog_posts, can_write_blog_posts
|
||||
@@ -94,13 +97,16 @@ class UserProfileSchema(ModelSchema):
|
||||
profile_picture_preview_url: Optional[str] = None
|
||||
student_id: Optional[str] = None
|
||||
major: Optional[str] = None
|
||||
major_code: Optional[str] = None
|
||||
university: Optional[str] = None
|
||||
university_code: Optional[str] = None
|
||||
mobile: Optional[str] = None
|
||||
requires_mobile_verification: bool
|
||||
has_google_link: bool
|
||||
can_access_blog_admin: bool
|
||||
can_write_blog_posts: bool
|
||||
can_review_blog_posts: bool
|
||||
show_public_profile_details: bool = False
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
@@ -119,6 +125,7 @@ class UserProfileSchema(ModelSchema):
|
||||
"date_joined",
|
||||
"is_email_verified",
|
||||
"is_mobile_verified",
|
||||
"show_public_profile_details",
|
||||
"is_active",
|
||||
"is_staff",
|
||||
"is_superuser",
|
||||
@@ -130,10 +137,18 @@ class UserProfileSchema(ModelSchema):
|
||||
def resolve_major(obj):
|
||||
return obj.get_major_display()
|
||||
|
||||
@staticmethod
|
||||
def resolve_major_code(obj):
|
||||
return obj.major.code if obj.major_id else None
|
||||
|
||||
@staticmethod
|
||||
def resolve_university(obj):
|
||||
return obj.get_university_display()
|
||||
|
||||
@staticmethod
|
||||
def resolve_university_code(obj):
|
||||
return obj.university.code if obj.university_id else None
|
||||
|
||||
@staticmethod
|
||||
def resolve_requires_mobile_verification(obj):
|
||||
return obj.requires_mobile_verification
|
||||
@@ -284,14 +299,42 @@ class UserAuthorizationUpdateSchema(Schema):
|
||||
|
||||
|
||||
class UserUpdateSchema(Schema):
|
||||
username: Optional[str] = None
|
||||
email: Optional[str] = None
|
||||
first_name: Optional[str] = None
|
||||
last_name: Optional[str] = None
|
||||
bio: Optional[str] = None
|
||||
bio: Optional[str] = Field(default=None, max_length=500)
|
||||
year_of_study: Optional[int] = None
|
||||
major: Optional[str] = None
|
||||
university: Optional[str] = None
|
||||
student_id: Optional[str] = None
|
||||
show_public_profile_details: Optional[bool] = None
|
||||
|
||||
|
||||
class PublicProfileEventSchema(Schema):
|
||||
title: str
|
||||
slug: str
|
||||
start_time: datetime
|
||||
image_url: Optional[str] = None
|
||||
participation: Literal["confirmed", "attended"]
|
||||
|
||||
|
||||
class PublicMemberProfileSchema(Schema):
|
||||
username: str
|
||||
first_name: str
|
||||
last_name: str
|
||||
full_name: str
|
||||
profile_picture: Optional[str] = None
|
||||
bio: str = ""
|
||||
details_visible: bool
|
||||
mobile: Optional[str] = None
|
||||
email: Optional[str] = None
|
||||
student_id: Optional[str] = None
|
||||
year_of_study: Optional[int] = None
|
||||
university: Optional[str] = None
|
||||
major: Optional[str] = None
|
||||
badges: List[PublicGamificationBadgeSchema] = []
|
||||
events: List[PublicProfileEventSchema] = []
|
||||
|
||||
|
||||
class TokenSchema(Schema):
|
||||
|
||||
Reference in New Issue
Block a user