示例#1
0
def delhost(request, id):
    HostObj = HostInfo.objects.get(id=id)
    HostObj.delete()
    ret = {
        'allServerObj': None,
        'UserInfoObj': None,
        'PageInfo': None,
        'AllCount': None
    }
    page = 1
    allServer = HostInfo.objects.all()
    AllCount = allServer.count()
    ret['AllCount'] = AllCount
    PageObj = Page(AllCount, page, 6)
    allServerObj = allServer[PageObj.begin:PageObj.end]
    pageurl = 'index'
    pageinfo = page_div(page, PageObj.all_page_count, pageurl)
    ret['PageInfo'] = pageinfo
    ret['allServerObj'] = allServerObj
    UserInfoObj = UserInfo.objects.get(
        username=request.session.get('username', None))
    ret['UserInfoObj'] = UserInfoObj
    ret['popover'] = {"id": id, "info": "已经删除主机"}
    return render_to_response('index.html',
                              ret,
                              context_instance=RequestContext(request))
示例#2
0
def clockdwf(page : Page, op) :
    global pfcount
    global dram
    global pcm

    if (page in dram) : #Si la pagina esta en dram 
        if (op == 0) : 
            page.r = 1 #Se cambia el bit R
        else: 
            page.m = page.r = 1 #Se cambia el bit R y M
    elif (page in pcm) : #Si la pagina esta en pcm
        if (op == 0) : 
            page.r = 1 #Se cambia el bit R
        else:
            free_frame_dram()
            dram.append(page) #Se agrega al final de la dram
            page.m = 0 #Se limpia el bit M
            print('\t--- Cambiada a la DRAM ---')
            print(f'\tDRAM: {MAX_DRAM - len(dram)}/{MAX_DRAM} frames disponibles.')
    else: #FALLO DE PÁGINA
        pfcount += 1
        print('\t--- Fallo de Página ---')
        opp = 'Lectura' if op == 0 else 'Escritura'
        print(f'\t--- Operación: {opp}')
        if (op == 0):
            free_frame_pcm() 
            pcm.append(page) #Se agrega al final de la pcm
            page.r = 0 #Se limpia el bit R
            print('\t--- Añadida ala PCM ---')
            print(f'\tPCM: {MAX_PCM - len(pcm)}/{MAX_PCM} frames disponibles.')
        else: #La operacion es escritura
            free_frame_dram()
            dram.append(page) #Se agrega al final de la dram
            page.m = 0 #Se limpia el M
            print('\t--- Añadida a la DRAM ---')
            print(f'\tDRAM: {MAX_DRAM - len(dram)}/{MAX_DRAM} frames disponibles.')
示例#3
0
def index(request,page=1):
    ret = {'ArticleObj':None,'PageInfo':None}
    try:
        page = int(page)
    except Exception:
        page = 1
    AllCount = Article.objects.filter(status='p').all().count()
    PageObj = Page(AllCount,page,6)
    #根据主键序号倒序排列
    ArticleObj = Article.objects.filter(status='p').order_by('-id').all()[PageObj.begin:PageObj.end]
    pageurl = 'index'
    pageinfo = page_div(page, PageObj.all_page_count,pageurl)
    ret['PageInfo'] = pageinfo
    ret['ArticleObj'] = ArticleObj
    
    return render_to_response('index.html',ret,context_instance=RequestContext(request))
示例#4
0
 def get_pages(self, sitemaps: typing.List[str]) -> typing.Iterable[Page]:
     """does the heavy lifting, grabs all sitemaps, parses them into a workable dictionary"""
     for sitemap in sitemaps:
         logger.info("downloading sitemap :" + sitemap)
         r = requests.get(sitemap)
         if "Content-Type" in r.headers and "gz" in r.headers[
                 "Content-Type"]:
             content = gzip.decompress(r.content)
         else:
             content = r.content
         soup = BeautifulSoup(content, "lxml")
         for url in soup.find_all("url"):
             yield Page(
                 url=url.find("loc").text,
                 alts=[
                     HrefLang(href=alt["href"], language=alt["hreflang"])
                     for alt in url.find_all(attrs={"rel": "alternate"})
                 ],
             )
示例#5
0
def searchtag(request,tagname,page=1):
    ret = {'ArticleObj':None,'PageInfo':None,'TagName':None}
    #根据Article对象的tag字段多对多对应TagInfo表的tagname字段
    MatchTagObj = Article.objects.filter(tag__tagname__contains = tagname,status='p')
    #判断如果传进来的tagname查不出结果就返回404
    if not MatchTagObj:
        return HttpResponseNotFound('<h1>Page not found</h1>')
    AllCount = MatchTagObj.all().count()
    #分页为首页
    try:
        page = int(page)
    except Exception:
        page = 1
    PageObj = Page(AllCount,page,4)
    ArticleObj = MatchTagObj.order_by('-id').all()[PageObj.begin:PageObj.end]
    pageurl = 'tag' + '/' + tagname
    pageinfo = page_div(page, PageObj.all_page_count,pageurl)
    ret['PageInfo'] = pageinfo
    ret['ArticleObj'] = ArticleObj
    ret['TagName'] = tagname
    return render_to_response('index.html',ret,context_instance=RequestContext(request))
示例#6
0
def batchdelhost(request):
    if request.method == 'POST':
        #根据传进来的主机id批量删除数据库对象
        ret = {
            'allServerObj': None,
            'UserInfoObj': None,
            'PageInfo': None,
            'AllCount': None
        }
        tmpmeminfo = request.POST.getlist("checkboxdel[]", None)
        if tmpmeminfo:
            for i in tmpmeminfo:
                HostObj = HostInfo.objects.get(id=i)
                HostObj.delete()
            ids = ",".join(tmpmeminfo)
            ret['popover'] = {"id": ids, "info": "已经删除主机"}
        else:
            ret['popover'] = {"id": "", "info": "没有选中可删除的主机"}
        page = 1
        allServer = HostInfo.objects.all()
        AllCount = allServer.count()
        ret['AllCount'] = AllCount
        PageObj = Page(AllCount, page, 6)
        allServerObj = allServer[PageObj.begin:PageObj.end]
        pageurl = 'index'
        pageinfo = page_div(page, PageObj.all_page_count, pageurl)
        ret['PageInfo'] = pageinfo
        ret['allServerObj'] = allServerObj
        UserInfoObj = UserInfo.objects.get(
            username=request.session.get('username', None))
        ret['UserInfoObj'] = UserInfoObj
        return render_to_response('index.html',
                                  ret,
                                  context_instance=RequestContext(request))
    else:
        return HttpResponseNotFound('<h1>Page not found</h1>')
示例#7
0
def index(request, page=1):
    ret = {
        'allServerObj': None,
        'UserInfoObj': None,
        'PageInfo': None,
        'AllCount': None
    }
    try:
        page = int(page)
    except Exception:
        page = 1
    if request.method == 'GET':
        #查询页面的分页显示
        if request.GET.get('issearch', None):
            searchos = request.GET.get('searchos', None)
            searchhostname = request.GET.get('searchhostname', None)
            searchsn = request.GET.get('searchsn', None)
            searchpublish = request.GET.get('searchpublish', None)
            searchip = request.GET.get('searchip', None)
            tmpstarttime = request.GET.get('searchstarttime', None)
            tmpendtime = request.GET.get('searchendtime', None)
            Qset = {}
            Qset['searchos'] = searchos
            Qset['searchhostname'] = searchhostname
            Qset['searchsn'] = searchsn
            Qset['searchpublish'] = searchpublish
            Qset['searchip'] = searchip
            Qset['tmpstarttime'] = tmpstarttime
            Qset['tmpendtime'] = tmpendtime

            #判断是否输入了开始时间,没输入或输入非法则默认为1970.01.01
            try:
                searchstarttime = datetime.datetime.strptime(
                    tmpstarttime, '%Y-%m-%d')
            except:
                searchstarttime = datetime.datetime(1970, 1, 1)
            #判断是否输入了结束时间或输入非法,没输入或输入非法则默认为现在
            try:
                searchendtime = datetime.datetime.strptime(
                    tmpendtime, '%Y-%m-%d')
            except:
                searchendtime = datetime.datetime.now()
            allServer = HostInfo.objects(
                Q(os__contains=searchos)
                & Q(networkinfo__addrlst__contains=searchip)
                & Q(hostname__contains=searchhostname)
                & Q(ispublish__contains=searchpublish)
                & Q(hardwareinfo__SN__contains=searchsn)
                & Q(timestamp__gte=searchstarttime)
                & Q(timestamp__lte=searchendtime))
            AllCount = allServer.count()
            ret['AllCount'] = AllCount
            PageObj = Page(AllCount, page, 6)
            allServerObj = allServer[PageObj.begin:PageObj.end]
            pageurl = 'index'
            querycondition = request.META.get("QUERY_STRING", None)
            pageinfo = query_page_div(page, PageObj.all_page_count, pageurl,
                                      querycondition)
            ret['PageInfo'] = pageinfo
            ret['allServerObj'] = allServerObj
            UserInfoObj = UserInfo.objects.get(
                username=request.session.get('username', None))
            ret['UserInfoObj'] = UserInfoObj
            ret['Qset'] = Qset
            return render_to_response('index.html',
                                      ret,
                                      context_instance=RequestContext(request))
        #正常主页的分页显示
        else:
            allServer = HostInfo.objects.all()
            AllCount = allServer.count()
            ret['AllCount'] = AllCount
            PageObj = Page(AllCount, page, 6)
            allServerObj = allServer[PageObj.begin:PageObj.end]
            pageurl = 'index'
            pageinfo = page_div(page, PageObj.all_page_count, pageurl)
            ret['PageInfo'] = pageinfo
            ret['allServerObj'] = allServerObj
            UserInfoObj = UserInfo.objects.get(
                username=request.session.get('username', None))
            ret['UserInfoObj'] = UserInfoObj
            return render_to_response('index.html',
                                      ret,
                                      context_instance=RequestContext(request))
    else:
        return HttpResponse("this is a web page , please use metod GET")