def maps_list(request): operation = request.POST.get("type", "user") if 'all' in operation and "%op%" in request.session.get("permissions", ""): _type = "all" maps = Maps.objects.order_by("-id") else: _type = "user" maps = Maps.objects.filter( username=request.session.get('username', None)).order_by("-id") page = request.POST.get("page", 1) paginator = Paginator(maps, 25) maps = paginator.get_page(page) # maps=sorted(maps, key=lambda a: a.declare_time, reverse=True) for i in range(0, len(maps)): maps[i].nickname = username_get_nickname(maps[i].username) if maps[i].status: maps[i].status_label = 'uk-label-success' maps[i].status_text = '已领取' else: maps[i].status_label = '' maps[i].status_text = '未领取' return render( request, 'dashboard/declaration/maps_list.html', { 'permissions': request.session['permissions'], 'list': maps, "page": common.page("declare/maps_list", maps, _type) })
def user_center(request): announcements = announcement_list(request) MC_SERVER = Conf.objects.get(key="MC_SERVER").content na = len(DeclareAnimals.objects.all()) nb = len(DeclareBuildings.objects.all()) nc = len(Cases.objects.all()) try: from mcstatus import MinecraftServer server = MinecraftServer.lookup(MC_SERVER) status = server.status() mot = status.description['text'] motd = str(mot) pos = motd.find('§') while pos != -1: motd = motd[:pos] + motd[pos + 2:] pos = motd.find('§') fav = status.favicon opn = status.players.online user = [] if status.players.sample is not None: for e in status.players.sample: user.append({ 'name': e.name, 'id': e.id, "nickname": username_get_nickname(e.name) }) context = { 'favicon': fav, 'server_address': MC_SERVER, 'online_players_list': user, 'online_players_number': opn, 'number_buildings': nb, 'number_animals': na, 'number_cases': nc, 'permissions': request.session.get("permissions", ""), 'announcements': announcements, "latency": status.latency } except Exception as e: context = { 'favicon': '', 'server_address': MC_SERVER, 'online_players_list': [], 'online_players_number': '超时', 'number_buildings': nb, 'number_animals': na, 'number_cases': nc, 'permissions': request.session.get("permissions", ""), 'announcements': announcements, "latency": -1 } return render(request, "dashboard/user_center.html", context)
def buildings_detail(request): error_msg = '<div class="uk-modal-header"><h2 class="uk-modal-title" style="color: #cc3947">%s</h2></div>' if '%declaration_watch%' not in request.session.get('permissions', ''): return HttpResponse(error_msg % "您没有查看建筑详情的权限!") try: id_ = int(request.GET.get('id', None)) except ValueError: return HttpResponse(error_msg % "参数错误!") try: obj = DeclareBuildings.objects.get(id=id_) obj.declare_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(obj.declare_time))) obj.predict_start_time = time.strftime( "%Y-%m-%d", time.localtime(int(obj.predict_start_time))) obj.predict_end_time = time.strftime( "%Y-%m-%d", time.localtime(int(obj.predict_end_time))) obj.nickname = username_get_nickname(obj.username) if obj.type == 0: obj.type = '公共建筑' else: obj.type = '私有建筑' if obj.status == 0: obj.status_label = 'uk-label-warning' obj.status_text = '审核挂起' elif obj.status == 1: obj.status_label = 'uk-label-warning' obj.status_text = '正在审核' elif obj.status == 2: obj.status_label = 'uk-label-danger' obj.status_text = '审核不通过' elif obj.status == 3: obj.status_label = '' obj.status_text = '审核通过' elif obj.status == 4: obj.status_label = '' obj.status_text = '正在建设' elif obj.status == 5: obj.status_label = 'uk-label-success' obj.status_text = '完工' return render(request, "dashboard/declaration/building_detail.html", {'building': obj}) except MultipleObjectsReturned as e: logging.error(e) return HttpResponse(error_msg % "内部错误,请联系管理员!") except ObjectDoesNotExist: return HttpResponse(error_msg % "建筑不存在!")
def task_list(request,_all=False): if _all: task=Task.objects.all() else: task=Task.objects.filter(username=request.session['username']) for i in range(0,len(task)) : if task[i].status == 0: task[i].status_label="uk-label-success" task[i].status_text="悬赏中" elif task[i].status == 1: task[i].status_label="uk-label-warning" task[i].status_text="已完成" else: task[i].status_label="uk-label-danger" task[i].status_text="已结束" task[i].nickname=username_get_nickname(task[i].username) return task
def animals_add(request): try: declare_time = int(time.time()) username = request.session.get('username', None) license_ = str(request.POST.get('license', None)).strip() feature = str(request.POST.get('feature', None)).strip() if len(license_) == 0: return HttpResponse(dialog('failed', 'danger', '牌照号不能为空')) if len(feature) == 0: return HttpResponse(dialog('failed', 'danger', '特征不能为空')) try: binding = int(str(request.POST.get('binding', None)).strip()) status = int(str(request.POST.get('status', None)).strip()) except ValueError: return HttpResponse(dialog('failed', 'danger', '数值错误')) if animals_check_license_exist(license_): return HttpResponse(dialog('failed', 'danger', '牌照已存在')) if binding == 0: binding = username_get_nickname(username) else: binding = '公共' logging.debug("binding: " + binding) logging.debug("license: " + license_) logging.debug("feature: " + feature) logging.debug("status: " + str(status)) obj = DeclareAnimals(declare_time=declare_time, username=username, binding=binding, license=license_, feature=feature, status=status) obj.save() return HttpResponse(dialog('ok', 'success', '更新成功')) except Exception as e: logging.error(e) return HttpResponse(dialog('failed', 'danger', '内部错误,请联系管理员'))
def logs_list(request): _list = Signin.objects.order_by("-time") page = request.POST.get("page", 1) paginator = Paginator(_list, 25) _list = paginator.get_page(page) for i in range(0, len(_list)): # _list[i].localtime=datetime.utcfromtimestamp(_list[i].time).replace(tzinfo=timezone(timedelta(hours=8))).strftime('%Y-%m-%d %H:%M:%S') _list[i].localtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(_list[i].time)) _list[i].nickname = username_get_nickname(_list[i].username) context = { 'permissions': request.session['permissions'], "list": _list, "page": common.page("signin/logs_list", _list) } return render(request, "dashboard/signin/logs_list.html", context)
def animals_list(request): global animals operation = request.POST.get("type", "user") if 'all' in operation: animals = DeclareAnimals.objects.order_by("-declare_time").all() elif 'user' in operation: animals = DeclareAnimals.objects.order_by("-declare_time").filter( username=request.session.get('username', None)) # 按照时间由新到旧排序 # animals = sorted(animals, key=lambda a: a.declare_time, reverse=True) page = request.POST.get("page", 1) paginator = Paginator(animals, 25) animals = paginator.get_page(page) for i in range(0, len(animals)): animals[i].declare_time = time.strftime( "%Y-%m-%d %H:%M:%S", time.localtime(animals[i].declare_time)) animals[i].nickname = username_get_nickname(animals[i].username) if animals[i].status == 0: animals[i].status_label = '' animals[i].status_text = '未知' elif animals[i].status == 1: animals[i].status_label = 'uk-label-success' animals[i].status_text = '存活' elif animals[i].status == 2: animals[i].status_label = 'uk-label-warning' animals[i].status_text = '丢失' elif animals[i].status == 3: animals[i].status_label = 'uk-label-danger' animals[i].status_text = '死亡' return render( request, 'dashboard/declaration/animals_list.html', { 'permissions': request.session['permissions'], 'animals': animals, "page": common.page("declare/animals_list", animals, operation) })
def buildings_list(request): # global buildings operation = request.POST.get("type", "user") username = request.GET.get("username", "") if 'all' in operation: if (username == ""): buildings = DeclareBuildings.objects.order_by( "-declare_time").all() else: buildings = DeclareBuildings.objects.order_by( "-declare_time").filter(username=username) elif 'user' in operation: buildings = DeclareBuildings.objects.order_by("-declare_time").filter( username=request.session.get('username', None)) # 按照时间由新到旧排序 # buildings = sorted(buildings, key=lambda b: b.declare_time, reverse=True) page = request.POST.get("page", 1) paginator = Paginator(buildings, 25) buildings = paginator.get_page(page) for i in range(0, len(buildings)): buildings[i].declare_time = time.strftime( "%Y-%m-%d", time.localtime(buildings[i].declare_time)) buildings[i].nickname = username_get_nickname(buildings[i].username) buildings[i].predict_start_time = time.strftime( "%Y-%m-%d", time.localtime(buildings[i].predict_start_time)) buildings[i].predict_end_time = time.strftime( "%Y-%m-%d", time.localtime(buildings[i].predict_end_time)) # 设置logo为缩略图的路径 # logo = buildings[i].concept # pos = logo.rfind(".") # if pos == -1: # return [] # buildings[i].logo = logo[:pos] + '_thumb' + logo[pos:] # # 如果缩略图不存在,我们创建 # if not os.path.exists(buildings[i].logo): # make_thumb(buildings[i].concept, buildings[i].logo) if buildings[i].status == 0: buildings[i].status_label = 'uk-label-warning' buildings[i].status_text = '审核挂起' elif buildings[i].status == 1: buildings[i].status_label = 'uk-label-warning' buildings[i].status_text = '正在审核' elif buildings[i].status == 2: buildings[i].status_label = 'uk-label-danger' buildings[i].status_text = '审核不通过' elif buildings[i].status == 3: buildings[i].status_label = '' buildings[i].status_text = '审核通过' elif buildings[i].status == 4: buildings[i].status_label = '' buildings[i].status_text = '正在建设' elif buildings[i].status == 5: buildings[i].status_label = 'uk-label-success' buildings[i].status_text = '完工' elif buildings[i].status == 6: buildings[i].status_label = 'uk-label-danger' buildings[i].status_text = '弃坑' # return buildings return render( request, 'dashboard/declaration/building_list.html', { 'permissions': request.session['permissions'], 'buildings': buildings, "user": user.user_list(request), "default": username, "page": common.page("declare/buildings_list", buildings, operation) })