💕💕作者:计算机源码社
💕💕个人简介:本人七年开发经验,擅长Java、微信小程序、Python、Android等,大家有这一块的问题可以一起交流!
💕💕学习资料、程序开发、技术解答、代码讲解、文档报告
1、绪论
1.1 项目背景
随着信息化时代的到来,管理系统都趋向于智能化、系统化,基于Python学生社团招新系统也不例外,学生社团招新系统是一款线上管理系统,旨在丰富学生用户的课余生活,学生用户可以在系统中查看学生社团的相关活动信息、发表意见看法、申请加入社团群体等。让学生通过参与开展的活动来使得自己的校园生活更加的充实,锻炼了学生的社交能力,提升自我,更是营造活跃的校园氛围,构建浓厚的校园文化气息。
随着规模的扩大,越来越多的学生加入社团,每一项都离不开社团干部的管理,这就使得社团的管理工作变得越来越吃力。工作量的增大让社团的管理带来了很多不必要的工作麻烦,例如工作分配不均匀,重复做同一件事情等。为了解决这一难题,帮助各大校园社团脱离这个现状,可以设计一个基于Python高校社团管理系统来进行规范的管理。将各社团内的成员的信息录入系统中,存储到数据库内,将每一项活动申请都做成线上的模式,节省了大量的时间,提高了工作的效率,为社团的活动以及社团的招新开展提供了一个有效的平台。
1.2 项目现状
随着教育事业的发展以及高校生源的扩充,越来越多的学生进入大学学习。在大学里也有着各种各样的校园组织,例如校园学生会、社团、大学生联合会等组织。大学里学习的不仅仅是专业知识,还考验学生各方面的做事能力、为人处世的能力,而加入这些组织是锻炼学生各方面综合素质发展的最佳途径。在校园中,学生可以充分利用可与时间,加入感兴趣的社团,可以展现自己的才艺获得自信,还可以促进人与人之间的交流。学校也非常重视校园的各项组织活动,很希望学生能够通过自主的能力去学习去锻炼去丰富自己的大学生活。但由于学校的学生数量庞大,有时会出现管理不到位的情况,因此结合网络平台的帮助来管理各组织内的干部,能让组织的管理更有条理,更加规范。
2、核心功能模块
基于Python社团招新系统采用Django技术,MySQL数据库进行设计,系统有学生用户、社团成员、管理员这三类角色,主要实现首页、公告信息、招新、论坛、社团活动、个人中心、场地申请、场地管理、活动申请、活动管理、竞选干部、选票管理、加入社团申请管理、社团成员管理等。通过这个系统能够满足校园内社团管理社团成员以及社团招新、社团活动这些的管理功能。
3、项目展示
3.1 查看社团公告信息
3.2 社团招新信息
3.3 申请
3.4 查看申请情况
3.5 通过申请
3.6 社团活动管理
3.7 社团干部竞选
3.8 竞选投票
4、 核心代码
# 判断当前表的表属性isAdmin,为真则是管理员表
# 当表属性isAdmin=”是”,刷出来的用户表也是管理员,即page和list可以查看所有人的考试记录(同时应用于其他表)
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
# 当前表也是有管理员权限的表
if __isAdmin__ == "是":
if req_dict.get("userid"):
del req_dict["userid"]
else:
#非管理员权限的表,判断当前表字段名是否有userid
if tablename!="users" and 'zhaoxinxinxi'[:7]!='discuss'and "userid" in zhaoxinxinxi.getallcolumn(zhaoxinxinxi,zhaoxinxinxi):
req_dict["userid"] = request.session.get("params").get("id")
#当列属性authTable有值(某个用户表)[该列的列名必须和该用户表的登陆字段名一致],则对应的表有个隐藏属性authTable为”是”,那么该用户查看该表信息时,只能查看自己的
try:
__authTables__=zhaoxinxinxi.__authTables__
except:
__authTables__=None
if __authTables__!=None and __authTables__!={}:
try:
del req_dict['userid']
except:
pass
for authColumn,authTable in __authTables__.items():
if authTable==tablename:
params = request.session.get("params")
req_dict[authColumn]=params.get(authColumn)
break
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] =zhaoxinxinxi.page(zhaoxinxinxi, zhaoxinxinxi, req_dict, request)
return JsonResponse(msg)
def zhaoxinxinxi_autoSort(request):
'''
.智能推荐功能(表属性:[intelRecom(是/否)],新增clicktime[前端不显示该字段]字段(调用info/detail接口的时候更新),按clicktime排序查询)
主要信息列表(如商品列表,新闻列表)中使用,显示最近点击的或最新添加的5条记录就行
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
if "clicknum" in zhaoxinxinxi.getallcolumn(zhaoxinxinxi,zhaoxinxinxi):
req_dict['sort']='clicknum'
else:
req_dict['sort']='clicktime'
req_dict['order']='desc'
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = zhaoxinxinxi.page(zhaoxinxinxi,zhaoxinxinxi, req_dict)
return JsonResponse(msg)
def zhaoxinxinxi_list(request):
'''
前台分页
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= zhaoxinxinxi.getallcolumn( zhaoxinxinxi, zhaoxinxinxi)
#表属性[foreEndList]前台list:和后台默认的list列表页相似,只是摆在前台,否:指没有此页,是:表示有此页(不需要登陆即可查看),前要登:表示有此页且需要登陆后才能查看
try:
__foreEndList__=zhaoxinxinxi.__foreEndList__
except:
__foreEndList__=None
if __foreEndList__=="前要登":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#forrEndListAuth
try:
__foreEndListAuth__=zhaoxinxinxi.__foreEndListAuth__
except:
__foreEndListAuth__=None
#authSeparate
try:
__authSeparate__=zhaoxinxinxi.__authSeparate__
except:
__authSeparate__=None
if __foreEndListAuth__ =="是" and __authSeparate__=="是":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict['userid']=request.session.get("params",{"id":0}).get("id")
tablename = request.session.get("tablename")
if tablename == "users" and req_dict.get("userid") != None:#判断是否存在userid列名
del req_dict["userid"]
else:
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
if __isAdmin__ == "是":
if req_dict.get("userid"):
del req_dict["userid"]
else:
#非管理员权限的表,判断当前表字段名是否有userid
if "userid" in columns:
try:
pass
# 本接口可以匿名访问,所以try判断是否为匿名
#req_dict['userid']=request.session.get("params").get("id")
except:
pass
#当列属性authTable有值(某个用户表)[该列的列名必须和该用户表的登陆字段名一致],则对应的表有个隐藏属性authTable为”是”,那么该用户查看该表信息时,只能查看自己的
try:
__authTables__=zhaoxinxinxi.__authTables__
except:
__authTables__=None
if __authTables__!=None and __authTables__!={} and __foreEndListAuth__=="是":
try:
del req_dict['userid']
except:
pass
for authColumn,authTable in __authTables__.items():
if authTable==tablename:
params = request.session.get("params")
req_dict[authColumn]=params.get(authColumn)
break
if zhaoxinxinxi.__tablename__[:7]=="discuss":
try:
del req_dict['userid']
except:
pass
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = zhaoxinxinxi.page(zhaoxinxinxi, zhaoxinxinxi, req_dict)
return JsonResponse(msg)
def zhaoxinxinxi_save(request):
'''
后台新增
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
if 'clicktime' in req_dict.keys():
del req_dict['clicktime']
tablename=request.session.get("tablename")
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
#获取全部列名
columns= zhaoxinxinxi.getallcolumn( zhaoxinxinxi, zhaoxinxinxi)
if tablename!='users' and req_dict.get("userid")!=None and 'userid' in columns and __isAdmin__!='是':
params=request.session.get("params")
req_dict['userid']=params.get('id')
error= zhaoxinxinxi.createbyreq(zhaoxinxinxi,zhaoxinxinxi, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def zhaoxinxinxi_add(request):
'''
前台新增
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= zhaoxinxinxi.getallcolumn( zhaoxinxinxi, zhaoxinxinxi)
try:
__authSeparate__=zhaoxinxinxi.__authSeparate__
except:
__authSeparate__=None
if __authSeparate__=="是":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
try:
__foreEndListAuth__=zhaoxinxinxi.__foreEndListAuth__
except:
__foreEndListAuth__=None
if __foreEndListAuth__ and __foreEndListAuth__!="否":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict['userid']=request.session.get("params").get("id")
error= zhaoxinxinxi.createbyreq(zhaoxinxinxi,zhaoxinxinxi, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def zhaoxinxinxi_thumbsup(request,id_):
'''
点赞:表属性thumbsUp[是/否],刷表新增thumbsupnum赞和crazilynum踩字段,
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
id_=int(id_)
type_=int(req_dict.get("type",0))
rets=zhaoxinxinxi.getbyid(zhaoxinxinxi,zhaoxinxinxi,id_)
update_dict={
"id":id_,
}
if type_==1:#赞
update_dict["thumbsupnum"]=int(rets[0].get('thumbsupnum'))+1
elif type_==2:#踩
update_dict["crazilynum"]=int(rets[0].get('crazilynum'))+1
error = zhaoxinxinxi.updatebyparams(zhaoxinxinxi,zhaoxinxinxi, update_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def zhaoxinxinxi_info(request,id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data = zhaoxinxinxi.getbyid(zhaoxinxinxi,zhaoxinxinxi, int(id_))
if len(data)>0:
msg['data']=data[0]
#浏览点击次数
try:
__browseClick__= zhaoxinxinxi.__browseClick__
except:
__browseClick__=None
if __browseClick__=="是" and "clicknum" in zhaoxinxinxi.getallcolumn(zhaoxinxinxi,zhaoxinxinxi):
try:
clicknum=int(data[0].get("clicknum",0))+1
except:
clicknum=0+1
click_dict={"id":int(id_),"clicknum":clicknum}
ret=zhaoxinxinxi.updatebyparams(zhaoxinxinxi,zhaoxinxinxi,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = ret
return JsonResponse(msg)
def zhaoxinxinxi_detail(request,id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data =zhaoxinxinxi.getbyid(zhaoxinxinxi,zhaoxinxinxi, int(id_))
if len(data)>0:
msg['data']=data[0]
#浏览点击次数
try:
__browseClick__= zhaoxinxinxi.__browseClick__
except:
__browseClick__=None
if __browseClick__=="是" and "clicknum" in zhaoxinxinxi.getallcolumn(zhaoxinxinxi,zhaoxinxinxi):
try:
clicknum=int(data[0].get("clicknum",0))+1
except:
clicknum=0+1
click_dict={"id":int(id_),"clicknum":clicknum}
ret=zhaoxinxinxi.updatebyparams(zhaoxinxinxi,zhaoxinxinxi,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = retfo
return JsonResponse(msg)
def zhaoxinxinxi_update(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
if req_dict.get("mima") and req_dict.get("password"):
if "mima" not in zhaoxinxinxi.getallcolumn(zhaoxinxinxi,zhaoxinxinxi) :
del req_dict["mima"]
if "password" not in zhaoxinxinxi.getallcolumn(zhaoxinxinxi,zhaoxinxinxi) :
del req_dict["password"]
try:
del req_dict["clicknum"]
except:
pass
error = zhaoxinxinxi.updatebyparams(zhaoxinxinxi, zhaoxinxinxi, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def zhaoxinxinxi_delete(request):
'''
批量删除
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
error=zhaoxinxinxi.deletes(zhaoxinxinxi,
zhaoxinxinxi,
req_dict.get("ids")
)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def zhaoxinxinxi_vote(request,id_):
'''
浏览点击次数(表属性[browseClick:是/否],点击字段(clicknum),调用info/detail接口的时候后端自动+1)、投票功能(表属性[vote:是/否],投票字段(votenum),调用vote接口后端votenum+1)
统计商品或新闻的点击次数;提供新闻的投票功能
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code}
data= zhaoxinxinxi.getbyid(zhaoxinxinxi, zhaoxinxinxi, int(id_))
for i in data:
votenum=i.get('votenum')
if votenum!=None:
params={"id":int(id_),"votenum":votenum+1}
error=zhaoxinxinxi.updatebyparams(zhaoxinxinxi,zhaoxinxinxi,params)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def zhaoxinxinxi_importExcel(request):
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": "成功", "data": {}}
excel_file = request.FILES.get("file", "")
file_type = excel_file.name.split('.')[1]
if file_type in ['xlsx', 'xls']:
data = xlrd.open_workbook(filename=None, file_contents=excel_file.read())
table = data.sheets()[0]
rows = table.nrows
try:
for row in range(1, rows):
row_values = table.row_values(row)
req_dict = {}
zhaoxinxinxi.createbyreq(zhaoxinxinxi, zhaoxinxinxi, req_dict)
except:
pass
else:
msg.code = 500
msg.msg = "文件类型错误"
return JsonResponse(msg)
def zhaoxinxinxi_sendemail(request):
if request.method in ["POST", "GET"]:
req_dict = request.session.get("req_dict")
code = random.sample(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], 4)
to = []
to.append(req_dict['email'])
send_mail('用户注册', '您的注册验证码是【'+''.join(code)+'】,请不要把验证码泄漏给其他人,如非本人请勿操作。', 'yclw9@qq.com', to, fail_silently = False)
cursor = connection.cursor()
cursor.execute("insert into emailregistercode(email,role,code) values('"+req_dict['email']+"','用户','"+''.join(code)+"')")
msg = {
"msg": "发送成功",
"code": 0
}
return JsonResponse(msg)
def zhaoxinxinxi_autoSort2(request):
if request.method in ["POST", "GET"]:
req_dict = request.session.get("req_dict")
cursor = connection.cursor()
leixing = set()
try:
cursor.execute("select inteltype from storeup where userid = %d"%(request.session.get("params").get("id"))+" and tablename = 'zhaoxinxinxi' order by addtime desc")
rows = cursor.fetchall()
for row in rows:
for item in row:
if item != None:
leixing.add(item)
except:
leixing = set()
L = []
cursor.execute("select * from zhaoxinxinxi where $intelRecomColumn in ('%s"%("','").join(leixing)+"') union all select * from zhaoxinxinxi where $intelRecomColumn not in('%s"%("','").join(leixing)+"')")
desc = cursor.description
data_dict = [dict(zip([col[0] for col in desc], row)) for row in cursor.fetchall()]
for online_dict in data_dict:
for key in online_dict:
if 'datetime.datetime' in str(type(online_dict[key])):
online_dict[key] = online_dict[key].strftime(
"%Y-%m-%d %H:%M:%S")
else:
pass
L.append(online_dict)
return JsonResponse({"code": 0, "msg": '', "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":5,"list": L[0:6]}})
def zhaoxinxinxi_value(request, xColumnName, yColumnName, timeStatType):
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": "成功", "data": {}}
where = ' where 1 = 1 '
token = request.META.get('HTTP_TOKEN')
decode_str = eval(base64.b64decode(token).decode("utf8"))
if decode_str['tablename'] != 'users':
where = where + " and shetuanzhanghao ='{0}' ".format(decode_str['params']['shetuanzhanghao'])
token = request.META.get('HTTP_TOKEN')
decode_str = eval(base64.b64decode(token).decode("utf8"))
if decode_str['tablename'] != 'users':
where = where + " and buzhangzhanghao ='{0}' ".format(decode_str['params']['buzhangzhanghao'])
sql = ''
if timeStatType == '日':
sql = "SELECT DATE_FORMAT({0}, '%Y-%m-%d') {0}, sum({1}) total FROM zhaoxinxinxi {2} GROUP BY DATE_FORMAT({0}, '%Y-%m-%d')".format(xColumnName, yColumnName, where, '%Y-%m-%d')
if timeStatType == '月':
sql = "SELECT DATE_FORMAT({0}, '%Y-%m') {0}, sum({1}) total FROM zhaoxinxinxi {2} GROUP BY DATE_FORMAT({0}, '%Y-%m')".format(xColumnName, yColumnName, where, '%Y-%m')
if timeStatType == '年':
sql = "SELECT DATE_FORMAT({0}, '%Y') {0}, sum({1}) total FROM zhaoxinxinxi {2} GROUP BY DATE_FORMAT({0}, '%Y')".format(xColumnName, yColumnName, where, '%Y')
L = []
cursor = connection.cursor()
cursor.execute(sql)
desc = cursor.description
data_dict = [dict(zip([col[0] for col in desc], row)) for row in cursor.fetchall()]
for online_dict in data_dict:
for key in online_dict:
if 'datetime.datetime' in str(type(online_dict[key])):
online_dict[key] = online_dict[key].strftime(
"%Y-%m-%d %H:%M:%S")
else:
pass
L.append(online_dict)
msg['data'] = L
return JsonResponse(msg)
def zhaoxinxinxi_o_value(request, xColumnName, yColumnName):
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": "成功", "data": {}}
where = ' where 1 = 1 '
token = request.META.get('HTTP_TOKEN')
decode_str = eval(base64.b64decode(token).decode("utf8"))
if decode_str['tablename'] != 'users':
where = where + " and shetuanzhanghao ='{0}' ".format(decode_str['params']['shetuanzhanghao'])
token = request.META.get('HTTP_TOKEN')
decode_str = eval(base64.b64decode(token).decode("utf8"))
if decode_str['tablename'] != 'users':
where = where + " and buzhangzhanghao ='{0}' ".format(decode_str['params']['buzhangzhanghao'])
sql = "SELECT {0}, sum({1}) AS total FROM zhaoxinxinxi {2} GROUP BY {0}".format(xColumnName, yColumnName, where)
L = []
cursor = connection.cursor()
cursor.execute(sql)
desc = cursor.description
data_dict = [dict(zip([col[0] for col in desc], row)) for row in cursor.fetchall()]
for online_dict in data_dict:
for key in online_dict:
if 'datetime.datetime' in str(type(online_dict[key])):
online_dict[key] = online_dict[key].strftime(
"%Y-%m-%d %H:%M:%S")
else:
pass
L.append(online_dict)
msg['data'] = L
return JsonResponse(msg)
def zhaoxinxinxi_alipay(request):
if request.method in ["POST", "GET"]:
alipay = AliPay(
appid=settings.ALIPAY_APP_ID,
app_notify_url=None,
app_private_key_string=settings.APP_PRIVATE_KEY_STRING,
alipay_public_key_string=settings.ALIPAY_PUBLIC_KEY_STRING,
sign_type=settings.ALIPAY_SIGN_TYPE,
debug=True,
config=AliPayConfig(timeout=15)
)
req_dict = request.session.get("req_dict")
order_string = alipay.api_alipay_trade_page_pay(
out_trade_no=req_dict['tradeno'],
total_amount=req_dict['totalamount'],
subject=req_dict['subject'],
return_url='http://localhost:8080/django577ux/zhaoxinxinxi/notify',
#notify_url=''
)
pay_url = 'https://openapi.alipaydev.com/gateway.do?' + order_string
pay_url = '<form name="punchout_form" method="post" action="{0}"><input type="hidden" name="biz_content" ><input type="submit" value="立即支付" style="display: none"></form>'.format(pay_url)
return JsonResponse({'code': 0, "data": pay_url})
def zhaoxinxinxi_notify(request):
if request.method in ["POST", "GET"]:
req_dict = request.session.get("req_dict")
out_trade_no = req_dict['out_trade_no']
cursor = connection.cursor()
return redirect('http://localhost:8080/django577ux/admin/dist/index.html#/zhaoxinxinxi')