You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
""" lrj:
OAuth 认证表单模块
定义OAuth认证过程中使用的Django表单类
"""
from django . contrib . auth . forms import forms
from django . forms import widgets
class RequireEmailForm ( forms . Form ) :
""" lrj:
邮箱补充表单类
当OAuth用户没有提供邮箱时, 用于收集用户邮箱信息
"""
# lrj: 邮箱字段: 必需字段, 标签为'电子邮箱'
email = forms . EmailField ( label = ' 电子邮箱 ' , required = True )
# lrj: OAuth用户ID字段: 隐藏字段, 非必需, 用于关联OAuth用户记录
oauthid = forms . IntegerField ( widget = forms . HiddenInput , required = False )
def __init__ ( self , * args , * * kwargs ) :
""" lrj:
表单初始化方法
自定义表单字段的widget属性, 添加CSS类和占位符
Args:
*args: 位置参数
**kwargs: 关键字参数
"""
#lrj: 调用父类初始化方法
super ( RequireEmailForm , self ) . __init__ ( * args , * * kwargs )
# lrj: 自定义邮箱字段的widget, 添加Bootstrap样式和占位符
self . fields [ ' email ' ] . widget = widgets . EmailInput (
attrs = {
' placeholder ' : " email " , # lrj: 输入框占位符文本
" class " : " form-control " # lrj: Bootstrap表单控件CSS类
} )