|
@@ -0,0 +1,626 @@
|
|
|
+#coding=utf-8
|
|
|
+'''
|
|
|
+'''
|
|
|
+import random
|
|
|
+import os,re
|
|
|
+import json,time,datetime
|
|
|
+import shutil
|
|
|
+import tempfile
|
|
|
+import zipfile
|
|
|
+from docxtpl import DocxTemplate,InlineImage
|
|
|
+from docx.shared import Mm
|
|
|
+from django.db import transaction
|
|
|
+from django.conf import settings
|
|
|
+import common.models as cm
|
|
|
+import common.error_info as ce
|
|
|
+import common.common_functions as ccf
|
|
|
+import common.common_control as ccc
|
|
|
+from utils.exceltool import ExcelTool
|
|
|
+from utils.exceltool import ExcelTool
|
|
|
+from utils.aestool import aescbc
|
|
|
+from django.db.models import Q
|
|
|
+from PIL import Image
|
|
|
+from PIL import Image,ImageDraw,ImageFont
|
|
|
+from utils.jgpush import send_notification_by_registration_ids
|
|
|
+import string
|
|
|
+
|
|
|
+import xlrd
|
|
|
+import xlwt
|
|
|
+from xlutils.copy import copy
|
|
|
+from xltpl.writer import BookWriter
|
|
|
+from utils.qrcodetool import gen_cus_qrcode_img
|
|
|
+from utils.upload_to_oss import TedOSS
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+def add_model(cls,**kwargs):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ model_name = re.search(r'.*\.(\w+)View',str(cls.__class__)).groups()[0]
|
|
|
+ model = getattr(cm,model_name)
|
|
|
+ obj = model.objects.create(**kwargs)
|
|
|
+ return obj.id
|
|
|
+
|
|
|
+def update_model(cls,**kwargs):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ model_name = re.search(r'.*\.(\w+)View',str(cls.__class__)).groups()[0]
|
|
|
+ model = getattr(cm,model_name)
|
|
|
+ id = kwargs.pop("id")
|
|
|
+ rst = model.objects.filter(id=id).update(**kwargs)
|
|
|
+ return rst
|
|
|
+
|
|
|
+def delete_model(cls,**kwargs):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ model_name = re.search(r'.*\.(\w+)View',str(cls.__class__)).groups()[0]
|
|
|
+ model = getattr(cm,model_name)
|
|
|
+ ids = str(kwargs.get("id")).split(",")
|
|
|
+ rst = model.objects.filter(id__in=ids).delete()
|
|
|
+ return ids
|
|
|
+
|
|
|
+def get_model_detail_info(cls,**kwargs):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ model_name = re.search(r'.*\.(\w+)View',str(cls.__class__)).groups()[0]
|
|
|
+ model = getattr(cm,model_name)
|
|
|
+ id = kwargs.get("id")
|
|
|
+ rst = list(model.objects.filter(id=id).values())
|
|
|
+ rst = rst[0] if rst else {}
|
|
|
+ if model_name == "Hotel":
|
|
|
+ rooms = list(cm.Room.objects.filter(hotel_id=id).values())
|
|
|
+ for r in rooms:
|
|
|
+ print r["imgs"],11111111111111
|
|
|
+ img = json.loads(r["imgs"])[0] if r["imgs"] else ""
|
|
|
+ r["img"] = img
|
|
|
+ rst["rooms"] = rooms
|
|
|
+ return rst
|
|
|
+
|
|
|
+def get_list_info(cls,**kwargs):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ model_name = re.search(r'.*\.(\w+)ListView',str(cls.__class__)).groups()[0]
|
|
|
+ model = getattr(cm,model_name)
|
|
|
+ qset = model.objects.all()
|
|
|
+ if kwargs.get("name"):
|
|
|
+ qset = qset.filter(name__icontains=kwargs.get("name"))
|
|
|
+ data = list(qset.values())
|
|
|
+ if model_name == "Conference":
|
|
|
+ for item in data:
|
|
|
+ item["conference_img"] = cm.Conference.objects.filter(id=item["conference_id"]).first().img
|
|
|
+ if model_name == "Signup":
|
|
|
+ for item in data:
|
|
|
+ item["conference_img"] = cm.Conference.objects.filter(id=item["conference_id"]).first().img
|
|
|
+ if model_name == "Hotel":
|
|
|
+ for item in data:
|
|
|
+ pass
|
|
|
+ #imgs = json.loads(item["imgs"]) if item["imgs"] else []
|
|
|
+ #item["img"] = imgs[0] if imgs else ""
|
|
|
+ page = int(kwargs.get("page",0))
|
|
|
+ page_size = int(kwargs.get("page_size",20))
|
|
|
+ if page and page_size:
|
|
|
+ total,data = ccf.get_page_list(data,page,page_size)
|
|
|
+ return (total,data)
|
|
|
+ else:
|
|
|
+ return len(data),data
|
|
|
+
|
|
|
+ return rst
|
|
|
+
|
|
|
+
|
|
|
+def login_user(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ info = request.json
|
|
|
+ username = info.get('username')
|
|
|
+ password = info.get('password')
|
|
|
+ registration_id = info.get('registration_id')
|
|
|
+ if not username or not password:
|
|
|
+ raise ce.TipException(u"账户或密码不能为空!")
|
|
|
+
|
|
|
+ user = cm.StaffUser.objects.filter(username=username).first()
|
|
|
+ if user:
|
|
|
+ if registration_id:
|
|
|
+ user.registration_id = registration_id
|
|
|
+ user.save()
|
|
|
+ if user.password != ccf.make_password(password):
|
|
|
+ raise ce.TipException(u"账号或密码错误!")
|
|
|
+ tstr = "{}_{}_{}{}".format(user.id,3,time.time(),random.randint(100000,999999))
|
|
|
+ token = aescbc.encrypt(tstr)
|
|
|
+ if user.utype == u"岗位级":
|
|
|
+ return {"id":user.id,"token":token,"utype":3,"role":1}
|
|
|
+ if user.utype == u"部门级":
|
|
|
+ return {"id":user.id,"token":token,"utype":3,"role":2}
|
|
|
+ if user.utype == u"公司级":
|
|
|
+ return {"id":user.id,"token":token,"utype":3,"role":3}
|
|
|
+
|
|
|
+ else:
|
|
|
+ user = cm.Goverment.objects.filter(username=username).first()
|
|
|
+ if user:
|
|
|
+ if user.password != ccf.make_password(password):
|
|
|
+ raise ce.TipException(u"账号或密码错误!")
|
|
|
+ tstr = "{}_{}_{}{}".format(user.id,1,time.time(),random.randint(100000,999999))
|
|
|
+ token = aescbc.encrypt(tstr)
|
|
|
+ return {"id":user.id,"token":token,"utype":1}
|
|
|
+ else:
|
|
|
+ user = cm.EnterPrise.objects.filter(username=username).first()
|
|
|
+ if user:
|
|
|
+ if user.password != ccf.make_password(password):
|
|
|
+ raise ce.TipException(u"账号或密码错误!")
|
|
|
+ tstr = "{}_{}_{}{}".format(user.id,2,time.time(),random.randint(100000,999999))
|
|
|
+ token = aescbc.encrypt(tstr)
|
|
|
+ return {"id":user.id,"token":token,"utype":2}
|
|
|
+
|
|
|
+ raise ce.TipException(u"账号或密码错误!")
|
|
|
+
|
|
|
+def get_index_banners(request):
|
|
|
+ """首页banner
|
|
|
+ """
|
|
|
+ ret = {}
|
|
|
+ ret["banners"] = list(cm.Banners.objects.values())
|
|
|
+ return ret
|
|
|
+
|
|
|
+def get_index_journals(request):
|
|
|
+ """首页全刊数据
|
|
|
+ """
|
|
|
+ ret = []
|
|
|
+ capts = string.ascii_uppercase
|
|
|
+ for c in capts:
|
|
|
+ journals = list(cm.Journal.objects.all().order_by("-ctime").values(
|
|
|
+ "name","img","wxcode","publishingUnit","editor","ename","id"))
|
|
|
+ #ret["journals"] = journals
|
|
|
+ journals = list(filter(lambda x:x["ename"].startswith(c),journals))
|
|
|
+ if journals:
|
|
|
+ ret.append({"lower":c.lower(),"name":c,"journals":journals})
|
|
|
+ return ret
|
|
|
+
|
|
|
+def get_index_organizers(request):
|
|
|
+ """首页主办单位
|
|
|
+ """
|
|
|
+ ret = {}
|
|
|
+ qdata = request.json
|
|
|
+ qset = cm.Organizer.objects.all().order_by("-order")
|
|
|
+ #分页
|
|
|
+ page = qdata.get("page",1)
|
|
|
+ page_size = qdata.get("page_size",20)
|
|
|
+ total,qset = ccc.get_page_qset(qset,page,page_size)
|
|
|
+
|
|
|
+ data = list(qset.values())
|
|
|
+ for d in data:
|
|
|
+ journal_ids = list(cm.JournalOrganizer.objects.filter(organizer_id=d["id"]).values_list("journal_id",flat=True))
|
|
|
+ journals = list(cm.Journal.objects.filter(id__in=journal_ids)[:3].values("id","name","desc"))
|
|
|
+ d["journals"] = journals
|
|
|
+ d["total_journal"] = len(journals)
|
|
|
+ if d["order"] > 0:
|
|
|
+ d["istop"] = 1
|
|
|
+ else:
|
|
|
+ d["istop"] = 0
|
|
|
+ return {"total":total,"list":data}
|
|
|
+
|
|
|
+def get_index_subjects(request):
|
|
|
+ """首页领域期刊
|
|
|
+ """
|
|
|
+ ret = {}
|
|
|
+ qdata = request.json
|
|
|
+ qset = cm.Subject.objects.all().order_by("-ctime")
|
|
|
+ #分页
|
|
|
+ page = qdata.get("page",1)
|
|
|
+ page_size = qdata.get("page_size",20)
|
|
|
+ total,qset = ccc.get_page_qset(qset,page,page_size)
|
|
|
+
|
|
|
+ data = list(qset.values())
|
|
|
+ for d in data:
|
|
|
+ d["total_journal"] = cm.Journal.objects.filter(subject_id=d["id"]).count()
|
|
|
+ d["journals"] = list(cm.Journal.objects.filter(subject_id=d["id"]).values())
|
|
|
+ if d["order"] > 0:
|
|
|
+ d["istop"] = 1
|
|
|
+ else:
|
|
|
+ d["istop"] = 0
|
|
|
+ return {"total":total,"list":data}
|
|
|
+
|
|
|
+
|
|
|
+def get_article_list(request):
|
|
|
+ """获取文章列表
|
|
|
+ """
|
|
|
+ qdata = request.json
|
|
|
+ qset = cm.Article.objects.all().order_by("-ctime")
|
|
|
+ if qdata.get("keyword"):
|
|
|
+ keyword = qdata.get("keyword")
|
|
|
+ qset = qset.filter(Q(name__icontains=keyword)|Q(desc__icontains=keyword))
|
|
|
+ if qdata.get("order_by"):
|
|
|
+ qset = qset.order_by("%s" % qdata.get("order_by"))
|
|
|
+ #分页
|
|
|
+ page = qdata.get("page",1)
|
|
|
+ page_size = qdata.get("page_size",20)
|
|
|
+ total,qset = ccc.get_page_qset(qset,page,page_size)
|
|
|
+
|
|
|
+ data = list(qset.values("id","name","img","author","desc","publish_time"))
|
|
|
+ return {"total":total,"list":data}
|
|
|
+
|
|
|
+def get_journals_list(request):
|
|
|
+ """获取期刊列表
|
|
|
+ """
|
|
|
+ qdata = request.json
|
|
|
+ qset = cm.Journal.objects.all().order_by("-ctime")
|
|
|
+ if qdata.get("keyword"):
|
|
|
+ keyword = qdata.get("keyword")
|
|
|
+ qset = qset.filter(Q(name__icontains=keyword)|Q(desc__icontains=keyword))
|
|
|
+ if qdata.get("subject_id"):
|
|
|
+ qset = qset.filter(subject_id=qdata.get("subject_id"))
|
|
|
+ #分页
|
|
|
+ page = qdata.get("page",1)
|
|
|
+ page_size = qdata.get("page_size",20)
|
|
|
+ total,qset = ccc.get_page_qset(qset,page,page_size)
|
|
|
+
|
|
|
+ data = list(qset.values("id","name","img","editor","desc","wxcode"))
|
|
|
+ for item in data:
|
|
|
+ organizers_ids = list(cm.JournalOrganizer.objects.filter(journal_id=item["id"]).values_list("organizer_id",flat=True))
|
|
|
+ organizers = list(cm.Organizer.objects.filter(id__in=organizers_ids).values_list("name",flat=True))
|
|
|
+ item["organizers"] = ",".join(organizers)
|
|
|
+ return {"total":total,"list":data}
|
|
|
+
|
|
|
+def get_activity_list(request):
|
|
|
+ """获取活动列表
|
|
|
+ """
|
|
|
+ qdata = request.json
|
|
|
+ qset = cm.Activity.objects.all().order_by("-ctime")
|
|
|
+ if qdata.get("keyword"):
|
|
|
+ keyword = qdata.get("keyword")
|
|
|
+ qset = qset.filter(Q(name__icontains=keyword)|Q(desc__icontains=keyword))
|
|
|
+ if qdata.get("order_by"):
|
|
|
+ qset = qset.order_by("%s" % qdata.get("order_by"))
|
|
|
+ if qdata.get("type"):
|
|
|
+ now_time = datetime.datetime.now()
|
|
|
+ if qdata.get("type") == "pre":
|
|
|
+ cm.Activity.objects.filter(begin_time__gte=now_time)
|
|
|
+ else:
|
|
|
+ cm.Activity.objects.filter(end_time__lte=now_time)
|
|
|
+ #分页
|
|
|
+ page = qdata.get("page",1)
|
|
|
+ page_size = qdata.get("page_size",20)
|
|
|
+ total,qset = ccc.get_page_qset(qset,page,page_size)
|
|
|
+
|
|
|
+ data = list(qset.values("id","name","img","desc","begin_time","journal_id","speaker"))
|
|
|
+ for item in data:
|
|
|
+ item["publish_unit"] = u"测试发布单位"
|
|
|
+ if item["speaker"]:
|
|
|
+ item["speaker"] = ",".join([x["name"] for x in json.loads(item["speaker"])])
|
|
|
+ return {"total":total,"list":data}
|
|
|
+
|
|
|
+
|
|
|
+def get_search_default(request):
|
|
|
+ """获取搜索页默认数据
|
|
|
+ """
|
|
|
+ navs = [
|
|
|
+ {"name":u"主办单位","value":"organizer"},
|
|
|
+ {"name":u"文章","value":"article"},
|
|
|
+ {"name":u"学术会议","value":"conference"},
|
|
|
+ {"name":u"期刊","value":"journal"},
|
|
|
+ {"name":u"学科","value":"subject"}
|
|
|
+ ]
|
|
|
+ history = ["光电","物理","中国","成都"]
|
|
|
+ cold_keyword = ["物理","国际"]
|
|
|
+ hot_keyword = ["中国","地理","成都","国际","学院"]
|
|
|
+
|
|
|
+ return {"navs":navs,"history":history,"cold_keyword":cold_keyword,"hot_keyword":hot_keyword}
|
|
|
+
|
|
|
+
|
|
|
+def search(request):
|
|
|
+ """搜索
|
|
|
+ """
|
|
|
+ ret = []
|
|
|
+ qdata = request.json
|
|
|
+ if qdata.get("type"):
|
|
|
+ _type = qdata.get("type")
|
|
|
+ if _type == "organizer":
|
|
|
+ qset = cm.Organizer.objects.filter(Q(name__icontains=keyword)|Q(desc__icontains=keyword))
|
|
|
+ data = list(qset.values("id","name","img","desc"))
|
|
|
+ ret.append({"name":u"相关主办方","value":"organizer","list":data})
|
|
|
+ if _type == "article":
|
|
|
+ qset = cm.Article.objects.filter(Q(name__icontains=keyword)|Q(desc__icontains=keyword))
|
|
|
+ data = list(qset.values("id","name","img","desc"))
|
|
|
+ ret.append({"name":u"相关文章","value":"article","list":data})
|
|
|
+ if _type == "conference":
|
|
|
+ qset = cm.Conference.objects.filter(Q(name__icontains=keyword)|Q(desc__icontains=keyword))
|
|
|
+ data = list(qset.values("id","name","img","desc"))
|
|
|
+ ret.append({"name":u"相关学术会议","value":"conference","list":data})
|
|
|
+ if _type == "journal":
|
|
|
+ qset = cm.Journal.objects.filter(Q(name__icontains=keyword)|Q(desc__icontains=keyword))
|
|
|
+ data = list(qset.values("id","name","img","desc"))
|
|
|
+ ret.append({"name":u"相关期刊","value":"journal","list":data})
|
|
|
+ if _type == "subject":
|
|
|
+ qset = cm.Subject.objects.filter(Q(name__icontains=keyword)|Q(desc__icontains=keyword))
|
|
|
+ data = list(qset.values("id","name","desc"))
|
|
|
+ ret.append({"name":u"相关学科","value":"subject","list":data})
|
|
|
+ else:
|
|
|
+ keyword = qdata.get("keyword")
|
|
|
+ #主办单位
|
|
|
+ orgset = cm.Organizer.objects.filter(Q(name__icontains=keyword)|Q(desc__icontains=keyword))
|
|
|
+ orgdata = list(orgset.values("id","name","img","desc"))
|
|
|
+ ret.append({"name":u"相关主办方","value":"organizer","list":orgdata})
|
|
|
+ #文章
|
|
|
+ artset = cm.Article.objects.filter(Q(name__icontains=keyword)|Q(desc__icontains=keyword))
|
|
|
+ artdata = list(orgset.values("id","name","img","desc"))
|
|
|
+ ret.append({"name":u"相关文章","value":"article","list":artdata})
|
|
|
+ #会议
|
|
|
+ conset = cm.Conference.objects.filter(Q(name__icontains=keyword)|Q(desc__icontains=keyword))
|
|
|
+ condata = list(conset.values("id","name","img","desc"))
|
|
|
+ ret.append({"name":u"相关学术会议","value":"conference","list":condata})
|
|
|
+ #期刊
|
|
|
+ jourset = cm.Journal.objects.filter(Q(name__icontains=keyword)|Q(desc__icontains=keyword))
|
|
|
+ jourdata = list(conset.values("id","name","img","desc"))
|
|
|
+ ret.append({"name":u"相关期刊","value":"journal","list":jourdata})
|
|
|
+ #学科
|
|
|
+ subset = cm.Subject.objects.filter(Q(name__icontains=keyword)|Q(desc__icontains=keyword))
|
|
|
+ subdata = list(subset.values("id","name","desc"))
|
|
|
+ ret.append({"name":u"相关学科","value":"subject","list":subdata})
|
|
|
+
|
|
|
+ return ret
|
|
|
+
|
|
|
+
|
|
|
+def recommend(request):
|
|
|
+ """推荐
|
|
|
+ """
|
|
|
+ ret = {}
|
|
|
+ #活动推荐
|
|
|
+ artset = cm.Activity.objects.all().order_by("-id")
|
|
|
+ data = list(artset.values("id","name","img","desc","begin_time","speaker"))
|
|
|
+ for item in data:
|
|
|
+ item["publish_unit"] = u"测试发布单位"
|
|
|
+ if item["speaker"]:
|
|
|
+ item["speaker"] = ",".join([x["name"] for x in json.loads(item["speaker"])])
|
|
|
+ ret["article"] = data
|
|
|
+ #热门活动
|
|
|
+ artset = cm.Conference.objects.all().order_by("-id")[:3]
|
|
|
+ act = list(artset.values("id","name","img","desc","begin_time","organizer_id"))
|
|
|
+ for item in act:
|
|
|
+ item["organizer_name"] = cm.Organizer.objects.filter(id=item["organizer_id"]).first().name
|
|
|
+ ret["hot_act"] = act
|
|
|
+ #活动预告
|
|
|
+ artset = cm.Activity.objects.all().order_by("-id")[:3]
|
|
|
+ act = list(artset.values("id","name","img","desc","begin_time","speaker"))
|
|
|
+ for item in act:
|
|
|
+ item["publish_unit"] = u"测试发布单位"
|
|
|
+ if item["speaker"]:
|
|
|
+ item["speaker"] = ",".join([x["name"] for x in json.loads(item["speaker"])])
|
|
|
+ ret["pre_act"] = act
|
|
|
+ #活动回顾
|
|
|
+ artset = cm.Activity.objects.all().order_by("-id")[:3]
|
|
|
+ act = list(artset.values("id","name","img","desc","begin_time","speaker"))
|
|
|
+ for item in act:
|
|
|
+ item["publish_unit"] = u"测试发布单位"
|
|
|
+ if item["speaker"]:
|
|
|
+ item["speaker"] = ",".join([x["name"] for x in json.loads(item["speaker"])])
|
|
|
+ ret["over_act"] = act
|
|
|
+ return ret
|
|
|
+
|
|
|
+
|
|
|
+def get_conference_list(request):
|
|
|
+ """获取会议列表
|
|
|
+ """
|
|
|
+ qdata = request.json
|
|
|
+ qset = cm.Conference.objects.all().order_by("-ctime")
|
|
|
+ if qdata.get("keyword"):
|
|
|
+ keyword = qdata.get("keyword")
|
|
|
+ qset = qset.filter(Q(name__icontains=keyword)|Q(desc__icontains=keyword))
|
|
|
+ if qdata.get("order_by"):
|
|
|
+ qset = qset.order_by("%s" % qdata.get("order_by"))
|
|
|
+ #分页
|
|
|
+ page = qdata.get("page",1)
|
|
|
+ page_size = qdata.get("page_size",20)
|
|
|
+ total,qset = ccc.get_page_qset(qset,page,page_size)
|
|
|
+
|
|
|
+ data = list(qset.values("id","name","img","desc","begin_time","organizer_id"))
|
|
|
+ for item in data:
|
|
|
+ item["organizer_name"] = cm.Organizer.objects.filter(id=item["organizer_id"]).first().name
|
|
|
+ return {"total":total,"list":data}
|
|
|
+
|
|
|
+
|
|
|
+def get_detail_info(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ ret = {}
|
|
|
+ qdata = request.json
|
|
|
+ _id = qdata.get("id")
|
|
|
+ _type = qdata.get("type")
|
|
|
+ uid = qdata.get("uid")
|
|
|
+ print _id,_type,uid
|
|
|
+ if _type == "organizer":
|
|
|
+ qset = cm.Organizer.objects.filter(id=_id)
|
|
|
+ data = list(qset.values())
|
|
|
+ ret = data[0] if data else {}
|
|
|
+ if _type == "article":
|
|
|
+ qset = cm.Article.objects.filter(id=_id)
|
|
|
+ data = list(qset.values())
|
|
|
+ ret = data[0] if data else {}
|
|
|
+ if cm.Collection.objects.filter(target_id=_id,target_type=_type,user_id=uid):
|
|
|
+ ret["is_collected"] = 1
|
|
|
+ else:
|
|
|
+ ret["is_collected"] = 0
|
|
|
+ ret["journal_name"] = cm.Journal.objects.filter(id=ret["journal_id"]).first().name
|
|
|
+ if _type == "conference":
|
|
|
+ qset = cm.Conference.objects.filter(id=_id)
|
|
|
+ data = list(qset.values())
|
|
|
+ ret = data[0] if data else {}
|
|
|
+ ret["organizer_info"] = cm.Organizer.objects.filter(id=ret["organizer_id"]).values("name","desc").first()
|
|
|
+ if ret["is_signup"]:
|
|
|
+ ret["signup_fields"] = json.loads(ret["signup_fields"])
|
|
|
+ if ret["speaker"]:
|
|
|
+ ret["speaker"] = ",".join([x["name"] for x in json.loads(ret["speaker"])])
|
|
|
+ if cm.Collection.objects.filter(target_id=_id,target_type=_type,user_id=uid):
|
|
|
+ ret["is_collected"] = 1
|
|
|
+ else:
|
|
|
+ ret["is_collected"] = 0
|
|
|
+ if _type == "journal":
|
|
|
+ qset = cm.Journal.objects.filter(id=_id)
|
|
|
+ data = list(qset.values())
|
|
|
+ ret = data[0] if data else {}
|
|
|
+ ret["articles"] = list(cm.Article.objects.filter(journal_id=_id)[:3].values())
|
|
|
+ #活动预告
|
|
|
+ now_time = datetime.datetime.now()
|
|
|
+ pre_activitys = list(cm.Activity.objects.filter(journal_id=_id,begin_time__gte=now_time)[:3].values())
|
|
|
+ #活动回顾
|
|
|
+ over_activitys = list(cm.Activity.objects.filter(journal_id=_id,end_time__lte=now_time)[:3].values())
|
|
|
+ for item in pre_activitys:
|
|
|
+ item["publish_unit"] = u"测试发布单位"
|
|
|
+ if item["speaker"]:
|
|
|
+ item["speaker"] = ",".join([x["name"] for x in json.loads(item["speaker"])])
|
|
|
+ for item in over_activitys:
|
|
|
+ item["publish_unit"] = u"测试发布单位"
|
|
|
+ if item["speaker"]:
|
|
|
+ item["speaker"] = ",".join([x["name"] for x in json.loads(item["speaker"])])
|
|
|
+ ret["pre_activitys"] = pre_activitys
|
|
|
+ ret["over_activitys"] = over_activitys
|
|
|
+ if _type == "activity":
|
|
|
+ qset = cm.Activity.objects.filter(id=_id)
|
|
|
+ data = list(qset.values())
|
|
|
+ ret = data[0] if data else {}
|
|
|
+ ret["publish_unit"] = u"测试发布单位"
|
|
|
+ ret["hold_unit"] = u"主办方"
|
|
|
+ ret["assist_unit"] = u"测试协办单位"
|
|
|
+ if ret["speaker"]:
|
|
|
+ ret["speaker"] = ",".join([x["name"] for x in json.loads(ret["speaker"])])
|
|
|
+ if _type == "subject":
|
|
|
+ qset = cm.Subject.objects.filter(id=_id)
|
|
|
+ data = list(qset.values())
|
|
|
+ ret = data[0] if data else {}
|
|
|
+
|
|
|
+ return ret
|
|
|
+
|
|
|
+
|
|
|
+def collect(request):
|
|
|
+ """收藏
|
|
|
+ """
|
|
|
+ qdata = request.json
|
|
|
+ #uid = request.user.id
|
|
|
+ uid = qdata.get("uid")
|
|
|
+ _id = qdata.get("id")
|
|
|
+ _type = qdata.get("type")
|
|
|
+ action= qdata.get("action")
|
|
|
+ if action == "cancel":
|
|
|
+ cm.Collection.objects.filter(target_id=_id,target_type=_type).delete()
|
|
|
+ else:
|
|
|
+ cm.Collection.objects.create(**{
|
|
|
+ "target_id":_id,"target_type":_type,"user_id":uid})
|
|
|
+
|
|
|
+ return True
|
|
|
+
|
|
|
+
|
|
|
+def index_totop(request):
|
|
|
+ """首页单位和领域置顶操作
|
|
|
+ """
|
|
|
+ qdata = request.json
|
|
|
+ _id = qdata.get("id")
|
|
|
+ _type = qdata.get("type")
|
|
|
+ action = qdata.get("action")
|
|
|
+ if _type == "cancel":
|
|
|
+ if _type == "organizer":
|
|
|
+ cm.Organizer.objects.filter(id=_id).update(order=0)
|
|
|
+ if _type == "subject":
|
|
|
+ cm.Subject.objects.filter(id=_id).update(order=0)
|
|
|
+ else:
|
|
|
+ if _type == "organizer":
|
|
|
+ max = cm.Organizer.objects.all().order_by("-order").first().order
|
|
|
+ cm.Organizer.objects.filter(id=_id).update(order=max+1)
|
|
|
+ if _type == "subject":
|
|
|
+ cm.Subject.objects.filter(id=_id).update(order=0)
|
|
|
+ max = cm.Subject.objects.all().order_by("-order").first().order
|
|
|
+ cm.Subject.objects.filter(id=_id).update(order=max+1)
|
|
|
+
|
|
|
+
|
|
|
+def get_user_collection(request):
|
|
|
+ """获取用户收藏
|
|
|
+ """
|
|
|
+ qdata = request.json
|
|
|
+ uid = qdata.get("uid")
|
|
|
+ qset = cm.Collection.objects.filter(user_id=uid)
|
|
|
+ #分页
|
|
|
+ page = qdata.get("page",1)
|
|
|
+ page_size = qdata.get("page_size",20)
|
|
|
+ total,qset = ccc.get_page_qset(qset,page,page_size)
|
|
|
+
|
|
|
+ data = list(qset.values())
|
|
|
+ for item in data:
|
|
|
+ _id = item["target_id"]
|
|
|
+ if item["target_type"] == "article":
|
|
|
+ article = cm.Article.objects.filter(id=_id).values("id","name","img","author","publish_time","desc").first()
|
|
|
+ item.update(article)
|
|
|
+ else:
|
|
|
+ article = cm.Conference.objects.filter(id=_id).values("id","name","img","address","begin_time","desc").first()
|
|
|
+ item.update(article)
|
|
|
+
|
|
|
+ return {"total":total,"list":data}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+def do_signup(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ qdata = request.json
|
|
|
+ need_params = ["conference_id","conference_name","name","sex","age","job",
|
|
|
+ "title","is_caos","organizer_unit","phone","email"]
|
|
|
+ vals = ccf.get_need_params(*need_params,**qdata)
|
|
|
+ vals["user_id"] = qdata.get("uid")
|
|
|
+ obj = cm.Signup.objects.create(**vals)
|
|
|
+ return obj.id
|
|
|
+
|
|
|
+
|
|
|
+def update_signup(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ qdata = request.json
|
|
|
+ need_params = ["proof_img","paytype","billtype","billhead","billno",
|
|
|
+ "billaddress","billphone","billbank","billbankno","hotel_id","room_id",
|
|
|
+ "room_nums","room_stime","room_etime"]
|
|
|
+ vals = ccf.get_need_params(*need_params,**qdata)
|
|
|
+ id = qdata.get("id")
|
|
|
+ cm.Signup.objects.filter(id=id).update(**vals)
|
|
|
+ obj = cm.Signup.objects.filter(id=id).first()
|
|
|
+ if vals.get("proof_img") and vals.get("paytype"):
|
|
|
+ obj.signup_status = 1
|
|
|
+ if vals.get("hotel_id") and vals.get("room_id"):
|
|
|
+ obj.signup_status = 3
|
|
|
+ #生成核销二维码
|
|
|
+ url = settings.HOST+"/xcx/verify?sid=%s" % obj.id
|
|
|
+ imgname = gen_cus_qrcode_img(url,"/tmp/signup_%s.png" % obj.id)
|
|
|
+ oss = TedOSS()
|
|
|
+ verify_qrcode = oss.upload_from_local(imgname,"zky/signup_%s.png"%obj.id)
|
|
|
+ obj.verify_qrcode = verify_qrcode
|
|
|
+ obj.save()
|
|
|
+ return True
|
|
|
+
|
|
|
+
|
|
|
+def get_organiztion_list(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ data = [
|
|
|
+ {
|
|
|
+ "name":u"成都分院",
|
|
|
+ "value":"成都分院",
|
|
|
+ "children":[
|
|
|
+ {"name":u"成都光电研究所","value":u"成都光电研究所","children":[
|
|
|
+ {"name":u"光学学报","value":u"光学学报","children":[]}
|
|
|
+ ]} ]} ,
|
|
|
+ {
|
|
|
+ "name":u"成都分院",
|
|
|
+ "value":"成都分院",
|
|
|
+ "children":[
|
|
|
+ {"name":u"成都光电研究所","value":u"成都光电研究所","children":[
|
|
|
+ {"name":u"光学学报","value":u"光学学报","children":[]}
|
|
|
+ ]} ]}
|
|
|
+
|
|
|
+ ]
|
|
|
+
|
|
|
+ return data
|
|
|
+
|
|
|
+
|
|
|
+def verify_signup(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ qdata = request.json
|
|
|
+ need_params = ["sid","uid"]
|
|
|
+ vals = ccf.get_need_params(*need_params,**qdata)
|
|
|
+ id = qdata.get("sid")
|
|
|
+ obj = cm.Signup.objects.filter(id=id).update(signup_status=4)
|
|
|
+ return True
|
|
|
+
|
|
|
+
|