Esempio n. 1
0
def ajax(request):
###########################################

    """
    test_writer = ix.writer()

    test_writer.add_document(term=u"XMM7660 1111 hello world 1111 xmm7360", product=u"XMM7560", url="", description="")

    test_writer.commit()
    results = ix.searcher().find("term", "world")

    print "test for whoosh, results: ",  results
    """
    ################################################
    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: "
        product_list = ['7260', '7360', '7460', '7480', '7560', 'sofia_lte']
        for anyproduct in  product_list:
            match = re.search(anyproduct,  productid )
            if match != None:
                print "match to product: " , match.group(0)
                break
            else:
                print "not match with product: ", anyproduct
        """

        #?? reqproduct = match.group(0)

        temp = str(productid).upper()
        #print "searchindex.lookup(temp):", searchindex.lookup(temp) #searchindex.lookup(terms)

        # first search within whoosh index
        lookup = searchindex.lookup(temp)
        if len(lookup) > 0:
            context['versions'] = []  #empty list, not None, None.append doesn't exist

            for found in lookup:
                #print "type of found: ", type(found) # l
                #print " length of found: ", len(found)

                if found[0] != None:
                    #print "found[0] found:", found[0]
                    #print "found[1] found:", found[1]

                    #reqproduct = found[1]

                    context['versions'].append(found[0]) # Append indicator according to stat

            #print "lookup in whoosh: ", context['versions']

        #if searchindex.lookup(productid) == None:
        #if found['product'] == None:
        else : #len(lookup) == 0: no found in lookup

            reqproduct="xmm"

            product_list = ['7260', '7360', '7460', '7480', '7560', 'sofia_lte']

            for anyproduct in  product_list:
                match = re.search(anyproduct,  productid )
                if match != None:
                    print "match to product: " , match.group(0)
                    reqproduct = reqproduct + str(match.group(0))
                    print "reqproduct= ", reqproduct
                    break
                else:
                    print "not match with product: ", anyproduct

            if reqproduct is "xmm":
                return render(request, 'manifest/ajax_sps_tags.html', [])

            #keyid = str(productid).upper()
            keyid = str(reqproduct).upper() # xmm7360 to XMM7360
            print "now start to search sps with: ", keyid   # grep meaningful product keyword from input

            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: ", versions

            if versions != None:
                #context['latest'] = versions[0]['VersionName']

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

                    if count < max_spstags:
                        searchindex.add_terms( keywords = v['VersionName'], tag=v['VersionName'], product = keyid, url=None,  description=None, explanation=None)
                        count = count +1

                    #if not best and not v['isDraftVersion']:
                    #    best = v['VersionName']

                #print "before create_whoosh, add terms to collector:"
                #print type(searchindex.collector) # list
                if len(searchindex.collector) == 0:
                    print " empty collector !"
                else:
                    #print "type of collector: ", type(searchindex.collector)
                    #print searchindex.collector
                    searchindex.create_whoosh();


                #print "after create_whoosh, collector should be None:", searchindex.collector

                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) + '"'})
Esempio n. 2
0
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) + '"'})
Esempio n. 3
0
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) + '"'})