コード例 #1
0
ファイル: views.py プロジェクト: byronrwth/oc6web
def ajax(request):
###########################################
    max_spstags = 10
    context = {}
    #print "request: " , request
    #print "request.POST: " , request.POST

    #productid = request.POST.get('productid', request.GET.get('productid', '')).strip()
    productid = request.POST.get('productid').strip()
    #print "request has productid: " , productid

    if len(productid) < 3 : # not complete product id 
        print "productid too short ! "
        return render(request, 'manifest/ajax_sps_tags.html', [])

    action = request.POST.get('action', request.GET.get('action', '')).strip()

    if action == 'get_sps_tags' :  

        #context['versions'] = []
        
        keyid = str(productid).upper() # xmm7360 to XMM7360 
        #print "now start to search sps with: ", keyid

        sps = SPS()
        sps.setUserHandle(request.user)
        products = sps.getProductsWithManifestMap()

        #print  products
        '''
        {XMM7460_DPC: 63873, SOFIA_3G: 54272, XMM7272: 62421, ICE7360: 57653, MODEM_DELIVERY_ICE7360: 63768, IA7360: 64000, SOFIA_LTE_ES30_BU: 62330, XMM7360_BU: 62050, XMM7360_V1: 62445, BUTTER_SFLTE: 59430, ICE7360_FB_RFDEV3: 60999, ASU_SF_3GR_MAINT: 61610, ICE7360_FB_PROTO1: 62504, ICE7360_FB_EVT: 65315, SOFIA_LTE: 55571, SOFIA_LTE_M: 63178, SOFIA_LTE_DSDS_BU: 62172, XMM7360_DSDS_3G3G: 62011, ICE7360_FB_PROTO2: 64496, XMM7360_LWA_SW_MODEM: 64777, VZN_SF_LTE: 62521, XMM7360: 56615, XMM7360_ES1_BU: 59266, XMM7360_XG726_BU: 58476, ASU_SF_LTE: 58984, IA7360_SW_MODEM: 64009, MWR_SF_LTE: 61850, FJU_SF_LTE: 59849, ASU_SF_3GR_M: 64801, XMM7480: 63068, SOFIA_LTE_2: 57566, XMM7360_XG726: 57797, SOFIA_LTE_MTBF: 62144, ASU_SF_3GR_CUST_ES2: 62168, MOD_7272M: 61961, ICE7360_FB_PREPROTOMLB: 62092, XMM7560: 63924, XMM7360_LWA: 64521, XMM7460: 53301, ASU_SF_3GR_CUST: 62074}

        '''

        #versions = sps.getVersionsByProductName(product_name, 30)
        # product, number of days
        #versions = sps.getVersionsByProductName("XMM7360", 12) 
        versions = sps.getVersionsByProductName(keyid, 20) 

        #print versions
        '''
        [(Version1){
            VersionId = "43956741"
            VersionName = "XMM7360_1604_3_1602"
            State = "Released"
            ReleaseDate = 2016-01-27 00:00:00
            IsDraftVersion = "Y"
            isDraftVersion = True
            weekNum = "1604"
            isNewWeek = True
            isTarget = False
        }, 
        ......
        '''

        if versions != None:
            #context['latest'] = versions[0]['VersionName']
            context['versions'] = []
            #best = None
            for v in versions:
                context['versions'].append(v['VersionName']) # Append indicator according to state:  + "," + str(0 if v['isDraftVersion'] else 1))
                
                #if not best and not v['isDraftVersion']:
                #    best = v['VersionName']

            if len(context['versions']) > max_spstags:
                context['versions'] = context['versions'][:max_spstags]

        #settings.BASE_DIR = webfe
        #myappdir = os.path.dirname(os.path.abspath(__file__))
        '''
          context['versions'] should be real SPS tags, temporarily saved in product.txt 
        '''
        return render(request, 'manifest/ajax_sps_tags.html', context)
        #return HttpResponse(json.dumps(context), status=200, content_type="application/json")

        
        ''' this is using temp product.txt 
        myappdir = os.path.join(settings.BASE_DIR, "apps/manifest/data/");
        


        myfile = open(myappdir+"product.txt")

        #print(myfile)
        str = myfile.read()
        myfile.close()
        context['versions'] = str.split()
        #print(context['versions'])

        return render(request, 'manifest/ajax_sps_tags.html', context)
        '''

 
    else:
        return render(request, 'manifest/ajax_text.html', {'error_msgs': 'Error: Unsupported action "' + str(action) + '"'})
コード例 #2
0
ファイル: views.py プロジェクト: byronrwth/oc6web
def ajax(request):
###########################################




    ################################################
    max_spstags = 10
    context = {}


    
    productid = request.POST.get('productid').strip()
    print "request has productid: " , productid




    if len(productid) < 3: #7 : # not complete product id 
        #print "productid too short ! "
        return render(request, 'manifest/ajax_sps_tags.html', [])

    action = request.POST.get('action', request.GET.get('action', '')).strip()

    if action == 'get_sps_tags' :  

        #context['versions'] = []
        
        print " search index lookup productid: "
        print searchindex.lookup(productid) #searchindex.lookup(terms)

        keyid = str(productid).upper() # xmm7360 to XMM7360 
        #print "now start to search sps with: ", keyid

        sps = SPS()
        sps.setUserHandle(request.user)
        products = sps.getProductsWithManifestMap()


        #versions = sps.getVersionsByProductName(product_name, 30)
        # product, number of days
        #versions = sps.getVersionsByProductName("XMM7360", 12) 
        versions = sps.getVersionsByProductName(keyid, 20) 
        #print versions

        if versions != None:
            #context['latest'] = versions[0]['VersionName']
            context['versions'] = []
            #best = None
            for v in versions:
                context['versions'].append(v['VersionName']) # Append indicator according to state:  + "," + str(0 if v['isDraftVersion'] else 1))
            
            searchindex.add_terms( keywords = context['versions'][0], url=None, description=None, explanation=None);
                #if not best and not v['isDraftVersion']:
                #    best = v['VersionName']

            if len(context['versions']) > max_spstags:
                context['versions'] = context['versions'][:max_spstags]

        print context
        ''' e.g.
        {'versions': [XMM7360_1604_3_1602, XMM7360_1604_3_1503, XMM7360_01.1605.10, XMM7360_1604_3_1415, XMM7360_1604_3_0903, XMM7360_1604_3_0802, XMM7360_1604_3_0703, XMM7360_1604_3_0602, XMM7360_1604_3_0555, XMM7360_1604_3_0402]}

        '''
        return render(request, 'manifest/ajax_sps_tags.html', context)
        #return HttpResponse(json.dumps(context), status=200, content_type="application/json")


 
    else:
        return render(request, 'manifest/ajax_text.html', {'error_msgs': 'Error: Unsupported action "' + str(action) + '"'})