def resolution(request): id = request.POST.get("id", None) type = request.POST.get("type", None) content = request.POST.get("content", None) _type = ['mayor', 'gwh', 'develop'] if request.user.has_perm("QieGaoWorld." + _type[int(type)]): demand = Demand.objects.get(id=id) if demand.status in [2, 3]: return HttpResponse(dialog('failed', 'danger', '当前状态无法发表决议')) resolution = Resolution.objects.filter(user_id=request.user.id, demand_id=demand.id, type=type) if len(resolution) == 0: resolution = Resolution(user_id=request.user.id, type=type, content=content, demand_id=demand.id) else: resolution = resolution[0] resolution.content = content resolution.save() return HttpResponse(dialog('ok', 'success', '成功')) else: return HttpResponse(dialog('failed', 'danger', '权限不足'))
def auto_login(request): token = str(request.GET.get("token", None)) user = User.objects.filter(token_expired_time__gte=int(time.time()), token=token) print(user) if len(user) == 0: return HttpResponse(dialog('failed', 'danger', '用户名或密码错误')) else: user = user[0] # 登录成功后 data={} data["is_login"] = True data['username'] = user.username data['nickname'] = user.nickname data['qqnumber'] = user.qqnumber data['usrgroup'] = user.usrgroup data['id'] = user.id data['register_time'] = user.register_time data['avatar'] = user.avatar # data.set_expiry(3600) # 1小时有效期 return HttpResponse(dialog('ok', 'success', '登录成功',data))
def animals_del(request): try: id_ = int(request.POST.get('id', None)) username = request.session.get('username', None) except ValueError: return HttpResponse(dialog('failed', 'danger', '参数错误')) try: obj = DeclareAnimals.objects.get(id=id_) # 1、检查是否是当前用户的状态为“审核不通过”的建筑 if not (obj.username == username or ('%op%' in request.session.get('permissions', '%default%'))): return HttpResponse(dialog('failed', 'danger', '可能这个牌照不属于你!')) obj.delete() common.logs( "用户:%s(%d) 删除了牌照:%s(id:%s,user:%s)" % (request.session['username'], request.session['id'], obj.license, obj.id, obj.username), "动物牌照管理") return HttpResponse(dialog('ok', 'success', '更新动物牌照成功!刷新页面生效!')) except MultipleObjectsReturned as e: logging.error(e) return HttpResponse(dialog('failed', 'danger', '内部错误,请联系管理员')) except ObjectDoesNotExist: return HttpResponse(dialog('failed', 'danger', '可能这个牌照不属于你!'))
def icon_edit(request): name = request.POST.get("name", "") if name == "": return HttpResponse(dialog('failed', 'danger', '请填写名称!')) code = request.POST.get("code", "") if code == "": return HttpResponse(dialog('failed', 'danger', '请填写标识!')) icon = request.POST.get("icon", "") if icon == "": return HttpResponse(dialog('failed', 'danger', '请填写静态图!')) gif = request.POST.get("gif", "") if gif == "": return HttpResponse(dialog('failed', 'danger', '请填写动态图!')) _id = request.POST.get("id", "") if _id == "": info = Icon(name=name, status=1, gif=gif, icon=icon, code=code) else: info = Icon.objects.get(id=_id) info.name = name info.gif = gif info.icon = icon info.code = code info.save() return HttpResponse(dialog('ok', 'success', '保存成功!'))
def task_change_status(request): try: id_ = int(request.POST.get('id', None)) new_status = int(request.POST.get('status', None)) username = request.session.get('username', None) except ValueError: return HttpResponse(dialog('failed', 'danger', '参数错误')) try: obj = Task.objects.get(id=id_) # 1、检查是否是当前用户的状态为“审核通过”的建筑,再检查修改状态是否为“正在建设”和“完工” 如果不是,检查是否是管理员 if (obj.username != username ) : return HttpResponse(dialog('failed', 'danger', '可能这个任务不属于你!')) old_status=obj.status obj.status = new_status obj.save() return HttpResponse(dialog('ok', 'success', '更新任务状态成功!刷新页面生效!')) except MultipleObjectsReturned as e: logging.error(e) return HttpResponse(dialog('failed', 'danger', '内部错误,请联系管理员')) except ObjectDoesNotExist: return HttpResponse(dialog('failed', 'danger', '可能这个任务不属于你!'))
def rarity_edit(request): name = request.POST.get("name", "") if name == "": return HttpResponse(dialog('failed', 'danger', '请填写名称!')) chance = request.POST.get("chance", 0) color = request.POST.get("color", "") # number=request.POST.get("number","") if chance == "": return HttpResponse(dialog('failed', 'danger', '请填写爆率!')) if color == "": return HttpResponse(dialog('failed', 'danger', '请填写颜色!')) commands = request.POST.get("commands", "") catch_announce = request.POST.get("catch_announce", 0) if (catch_announce == ''): catch_announce = 0 _id = request.POST.get("id", "") if _id == "": info = Rarity(name=name, status=1, chance=chance, color=color, commands=commands, catch_announce=catch_announce) else: info = Rarity.objects.get(id=_id) info.name = name info.chance = chance info.color = color info.commands = commands info.catch_announce = catch_announce info.save() return HttpResponse(dialog('ok', 'success', '保存成功!'))
def chapter_add(request): # try: arg_list = {'name', 'summary', 'book_id', 'type'} lis = {key: str(request.POST.get(key, '')).strip() for key in arg_list} lis['time'] = int(time.time()) _id = request.POST.get("id", None) for l in lis: if len(str(lis[l])) == 0: return HttpResponse(dialog('failed', 'danger', '%s为空!请检查!' % l)) # lis['pic_perspective'] = str(request.POST.get('pic_perspective', '')).strip() if (lis['type'] == 0): lis['show_time'] = int(time.time()) else: lis['show_time'] = 0 if _id == None or len(_id) == 0: obj = CmsChapter(title=lis['name'], content=lis['summary'], status=1, show_time=lis['show_time'], time=lis['time'], book_id=lis['book_id']) else: obj = CmsChapter.objects.get(id=_id) obj.title = lis['name'] obj.content = lis['summary'] obj.save() return HttpResponse(dialog('ok', 'success', '添加成功'))
def reward_del(request): if "%op%" not in request.session.get('permissions', ''): return HttpResponse(dialog('failed', 'danger', '权限不足!')) id = request.POST.get('id', None) reward = Reward.objects.get(id=id) reward.delete() return HttpResponse(dialog('ok', 'success', '删除成功!'))
def match_del(request): if "%op%" not in request.session.get('permissions', ''): return HttpResponse(dialog('failed', 'danger', '权限不足!')) id = request.POST.get('id', None) info = FishMatch.objects.get(id=id) info.delete() return HttpResponse(dialog('ok', 'success', '删除成功!'))
def upload_building_picture(request, upload_type): file_obj = request.FILES["files[]"] file_name = str(file_obj) pos = file_name.rfind(".") if pos == -1: return HttpResponse(dialog('failed', 'danger', '文件类型错误')) suffix = file_name[pos:] # 取出后缀名 allowed_type = [".jpg", ".png", ".jpeg", ".gif"] flag = False for eachType in allowed_type: if suffix.lower() == eachType: flag = True break if flag: try: u = str(uuid.uuid1()) save_path = "buildings/%s/%s" % (upload_type, u + ".png") # thumb_path = "buildings/%s/%s_thumb" % (upload_type, u )+ ".jpg" path = default_storage.save(save_path, ContentFile(file_obj.read())) # path_thu = default_storage.save(thumb_path, ContentFile(file_obj.read())) tmp_file = os.path.join(settings.MEDIA_ROOT, path) # thu_file = os.path.join(settings.MEDIA_ROOT, path_thu) im = Image.open(tmp_file) width, height = im.size # resize 一下,破坏PE文件后面的附属信息(防止被当作图床) out = im.resize((width - 1, height - 1), Image.ANTIALIAS) out.save(tmp_file) # make_thumb(tmp_file, thu_file) # if width < height: # print("resize") # out = im.resize((width, width), Image.ANTIALIAS) # out.save(tmp_file) # else: # out = im.resize((height, height), Image.ANTIALIAS) # out.save(tmp_file) except Exception as e: logging.error(e) return HttpResponse(dialog('failed', 'danger', '文件类型错误,请联系管理员')) return HttpResponse( dialog('ok', 'success', '修改成功', {'url': "static/media/%s" % save_path})) else: return HttpResponse(dialog('failed', 'danger', '文件类型错误'))
def add(request): title = request.POST.get("title", None) content = request.POST.get("content", None) if len(title) <= 0 or len(content) <= 0: return HttpResponse(dialog('failed', 'danger', '标题或内容不能为空')) demand = Demand(title=title, details=content, user_id=request.session['id']) demand.save() return HttpResponse(dialog('ok', 'success', '创建成功'))
def avatar_update(request, new_avatar_url): username = request.session.get('username', "N/A") try: obj = User.objects.filter(username=username) except MultipleObjectsReturned: return HttpResponse(dialog('failed', 'danger', '内部错误,请联系管理员')) if len(obj) == 0: return HttpResponse(dialog('failed', 'danger', '更新头像失败')) obj[0].avatar = new_avatar_url obj[0].save() request.session['avatar'] = new_avatar_url
def reward_status(request): if "%op%" not in request.session.get('permissions', ''): return HttpResponse(dialog('failed', 'danger', '权限不足!')) status = str(request.POST.get('status', None)) id = request.POST.get('id', None) menu = Reward.objects.get(id=id) if (status == "True"): menu.status = False else: menu.status = True menu.save() return HttpResponse(dialog('ok', 'success', 'ok!'))
def pool_status(request): if "%op%" not in request.session.get('permissions', ''): return HttpResponse(dialog('failed', 'danger', '权限不足!')) status = str(request.POST.get('status', None)) id = request.POST.get('id', None) info = FishPool.objects.get(id=id) if (status == "True"): info.status = False else: info.status = True info.save() return HttpResponse(dialog('ok', 'success', 'ok!'))
def task_add(request): try: title=request.POST.get('title',None) content=request.POST.get("content",None) except ValueError: return HttpResponse(dialog('failed', 'danger', '参数错误')) if title == None : return HttpResponse(dialog('failed', 'danger', '请填写标题')) if content == None : return HttpResponse(dialog('failed', 'danger', '请填写任务详情')) menu=Task(title=title,username=(request.session['username']),content=content,status=0) menu.save() return HttpResponse(dialog('ok', 'success', '任务发布成功!'))
def pond_edit(request): name = request.POST.get("name", "") if name == "": return HttpResponse(dialog('failed', 'danger', '请填写名称!')) _id = request.POST.get("id", "") if _id == "": info = FishPond(name=name, status=1) else: info = FishPond.objects.get(id=_id) info.name = name info.save() return HttpResponse(dialog('ok', 'success', '保存成功!'))
def chapter_change_show_time(request): try: _id = request.POST.get("id", None) _time = request.POST.get("time", None) if _id == None or len(_id) <= 0: return HttpResponse(dialog('failed', 'danger', '参数错误')) book = CmsChapter.objects.get(id=_id) if book == None: return HttpResponse(dialog('failed', 'danger', '章节不存在!')) book.show_time = time.mktime(time.strptime( _time, "%Y-%m-%d %H:%M:%S")) - 28800 book.save() return HttpResponse(dialog('ok', 'success', '编辑成功')) except Exception as e: return HttpResponse(dialog('failed', 'danger', '内部错误,请联系管理员'))
def chapter_info(request): _id = request.POST.get("id", None) if _id == None or len(_id) <= 0: return HttpResponse(dialog('failed', 'danger', '参数错误')) book = CmsChapter.objects.get(id=_id) if book == None: return HttpResponse(dialog('failed', 'danger', '章节不存在!')) return HttpResponse( json.dumps({ "id": book.id, "name": book.title, "summary": book.content, "status": "ok" }))
def fish_edit(request): name = request.POST.get("name", "") if name == "": return HttpResponse(dialog('failed', 'danger', '请填写名称!')) min = request.POST.get("min", "") max = request.POST.get("max", "") rarity_id = request.POST.get("rarity", "") if min == "" or max == "": return HttpResponse(dialog('failed', 'danger', '请填写尺寸范围!')) if rarity_id == "": return HttpResponse(dialog('failed', 'danger', '请选择稀有度!')) pond_id = request.POST.get("pond", "") # if min == "" or max == "": # return HttpResponse(dialog('failed', 'danger', '请填写尺寸范围!')) icon_id = request.POST.get("icon", "") if icon_id == "": return HttpResponse(dialog('failed', 'danger', '请选择图标!')) # icon=Icon.objects.get(id=icon_id); commands = request.POST.get("commands", "") icons = request.POST.get("icons", "") conditions = request.POST.get("conditions", 0) _id = request.POST.get("id", "") if _id == "": info = Fish(name=name, status=1, min=min, max=max, commands=commands, rarity_id=rarity_id, icon_id=icon_id, conditions=conditions, pond_id=pond_id, icons=icons) else: info = Fish.objects.get(id=_id) info.name = name info.conditions = conditions info.icon_id = icon_id info.commands = commands info.rarity_id = rarity_id info.max = max info.min = min info.pond_id = pond_id info.icons = icons info.save() return HttpResponse(dialog('ok', 'success', '保存成功!'))
def announcement_delete(request): if '%announcement_delete%' not in request.session.get( 'permissions', '%default%'): return HttpResponse(dialog('failed', 'danger', '权限不足')) id = str(request.POST.get('id', '')).strip() try: obj = Announcement.objects.get(id=id) obj.visible = False obj.save() return HttpResponse(dialog('ok', 'success', '删除成功')) except ObjectDoesNotExist: return HttpResponse(dialog('failed', 'danger', '公告ID不存在')) except MultipleObjectsReturned: return HttpResponse(dialog('failed', 'danger', '内部错误,请联系管理员')) pass
def group_info(request): _id = request.POST.get("id", None) if _id == None: return HttpResponse(dialog('ok', 'danger', '参数错误')) per = Permission.objects.all() type = ContentType.objects.all() group = Group.objects.get(id=_id) m = [] # group_per= cursor = connection.cursor() cursor.execute("select * from auth_group_permissions where group_id=" + _id + "") row = cursor.fetchall() group_per = [] for i in range(0, len(row)): if row[i][2] not in group_per: group_per.append(row[i][2]) # print(group_per) return render(request, "dashboard/system/group_info.html", { "per": per, "gp": group_per, "mode": m, "type": type, "group": group })
def problem_edit(request): id = request.POST.get("id", None) name = request.POST.get("name", "分页符") _type = request.POST.get("type", None) type_list = Conf.objects.get(key="wenjuan_type") type_list = json.loads(type_list.content) problem_list_obj = Conf.objects.get(key="problem_list") problem_list = json.loads(problem_list_obj.content) for i in range(0, len(type_list)): if _type == type_list[i]: _type = i break if id == "": wj = Problem(dry=name, type=_type, status=True) wj.save() logging.error(sort) problem_list.append(str(wj.id)) problem_list_obj.content = json.dumps(problem_list) problem_list_obj.save() # ["1","2","3","4","5","7","8"] else: wj = Problem.objects.get(id=id) wj.dry = name wj.type = _type wj.save() return HttpResponse(dialog('ok', 'success', '编辑成功!'))
def buildings_add(request): try: arg_list = { 'name', 'summary', 'coordinate', 'area', 'predict_start_time', 'predict_end_time', 'type', 'pic_plan' } lis = {key: str(request.POST.get(key, '')).strip() for key in arg_list} lis['declare_time'] = int(time.time()) lis['username'] = request.session.get('username', None) for l in lis: if len(str(lis[l])) == 0: return HttpResponse(dialog('failed', 'danger', '%s为空!请检查!' % l)) lis['pic_perspective'] = str(request.POST.get('pic_perspective', '')).strip() obj = DeclareBuildings( declare_time=lis['declare_time'], username=lis['username'], coordinate=lis['coordinate'], area=lis['area'], # concept=lis['pic_concept'], concept='', plan=lis['pic_plan'], name=lis['name'], # english_name=lis['english_name'], english_name='', summary=lis['summary'], detail='', perspective=lis['pic_perspective'], predict_start_time=time.mktime( time.strptime(lis['predict_start_time'], "%Y-%m-%d")), predict_end_time=time.mktime( time.strptime(lis['predict_end_time'], "%Y-%m-%d")), actually_end_time=0, status=3, type=int(str(lis['type'])), ) obj.save() return HttpResponse(dialog('ok', 'success', '登记成功!请开始你的表演吧!')) except ValueError as e: print(e) return HttpResponse(dialog('failed', 'danger', '数值错误')) except Exception as e: logging.error(e) return HttpResponse(dialog('failed', 'danger', '内部错误,请联系管理员'))
def menu_edit(request): id= request.POST.get('id',None) name=request.POST.get('name',None) url=request.POST.get('url',None) _type=request.POST.get("type",None) if(id==""): men=Menu.objects.filter(name=name) if(men): return HttpResponse(dialog('failed', 'danger', '该菜单名已被使用!')) menu=Menu(name=name,url=url,status=True,type=_type,parent=0) else: menu=Menu.objects.get(id=id) menu.name=name menu.url=url menu.save() return HttpResponse(dialog('ok', 'success', '编辑成功!'))
def whitelist_add(request): if "%whitelist%" not in request.session['permissions']: return HttpResponse(dialog('failed', 'danger', '权限不足')) name = str(request.POST.get('name', None)) white_list = whitelist(request) if (name in white_list): return HttpResponse(dialog('failed', 'danger', '该用户已存在')) if (re.match(r'[0-9a-z]+', name) == None): return HttpResponse(dialog('failed', 'danger', '该用户id格式错误')) with open(parameter.SPIGOT_PATH + "/plugins/WhiteList/config.yml", "a") as w: w.write("\n - " + name) return HttpResponse(dialog('ok', 'success', '添加成功!')) return HttpResponse(dialog('failed', 'error', '添加失败!'))
def para_edit(request): id= request.POST.get('id',None) name=request.POST.get('name',None) key=request.POST.get('key',None) content=request.POST.get("content",None) if(id==""): para=Conf.objects.filter(key=key) if(para): return HttpResponse(dialog('failed', 'danger', '该key已被使用!')) para=Conf(name=name,key=key,content=content) else: para=Conf.objects.get(id=id) para.name=name para.key=key para.content=content para.save() return HttpResponse(dialog('ok', 'success', '编辑成功!'))
def test(request): content_type = ContentType.objects.get_for_id(27) Permission.objects.create(codename='test', name="检测权限专用", content_type=content_type) # Permission.objects.create(codename='mayor',name="市长决议",content_type=content_type) # Permission.objects.create(codename='gwh',name="糕委会决议",content_type=content_type) # Permission.objects.create(codename='develop',name="开发反馈",content_type=content_type) return HttpResponse(dialog('ok', 'success', '成功', {}))
def whitelist_del(request): if "%whitelist%" not in request.session['permissions']: return HttpResponse(dialog('failed', 'danger', '权限不足')) name = str(request.POST.get('name', None)) # white_list=whitelist() # if(name not in white_list): # return HttpResponse(dialog('failed', 'danger', '该用户不存在')) with open(parameter.SPIGOT_PATH + "/plugins/WhiteList/config.yml", "r") as r: fs = r.readlines() with open(parameter.SPIGOT_PATH + "/plugins/WhiteList/config.yml", "w") as w: for f in fs: if ("- " + name not in f): w.write(f) return HttpResponse(dialog('ok', 'success', '删除成功!'))
def problem_del(requerst): id = requerst.POST.get("id", None) ProblemInfo.objects.filter(problem_id=id).delete() Problem.objects.get(id=id).delete() problem_list_obj = Conf.objects.get(key="problem_list") problem_list = json.loads(problem_list_obj.content) problem_list.remove(str(id)) problem_list_obj.content = json.dumps(problem_list) problem_list_obj.save() return HttpResponse(dialog('ok', 'success', '删除成功!'))
def message_star(request): status = str(request.POST.get('status', None)) id = request.POST.get('id', None) menu = Message.objects.get(id=id) if (status == "True"): menu.status = False else: menu.status = True menu.save() return HttpResponse(dialog('ok', 'success', 'ok!'))