コード例 #1
0
 def listCategories():
   globalVars = tools.initApp()
   #for mobile app
   if('api' in request.path and 'uuid' in request.args):
     categories = db.get_categories_for_app(globalVars['arduino_map']['user_id'], session['app_id'])
     data = {}
     data['list_title'] = session['app_name']
     token = models.get_token('guest',flask_login.current_user.id)
     if categories:
       for i in range(len(categories)):
         hasRequest = db.get_request_for_tag(session['app_id'], categories[i]['id'])
         categories[i]['url'] = url_for('locateBooksForTag',tag_id=categories[i]['id'])
         categories[i]['token'] = token
         categories[i]['hasRequest'] = hasRequest
         if categories[i]['color'] is not None:
           colors = categories[i]['color'].split(",")
           categories[i]['red'] = colors[0]
           categories[i]['green'] = colors[1]
           categories[i]['blue'] = colors[2]
       data['elements']=categories
       response = app.response_class(
         response=json.dumps(data),
         mimetype='application/json'
       )
       return response
     else:
       return ('', 204)
   #for web
   else:
     if globalVars['arduino_map'] != None:
       user_id = globalVars['arduino_map']['user_id']
       categories = db.get_categories_for_user(user_id)    
       return render_template('categories.html', user_login=globalVars['user_login'], categories=categories, \
       shelf_infos=globalVars['arduino_map'], uuid_encode=tools.uuid_encode(globalVars['arduino_map']['id_ble']))
     abort(404)
コード例 #2
0
 def listAuthors():
   globalVars = tools.initApp()  
   if globalVars['arduino_map'] != None:
     #for mobile app 
     if('api' in request.path and 'uuid' in request.args):
       data = {}
       token = models.get_token('guest',flask_login.current_user.id)
       data['list_title'] = session['app_name']
       data['elements']=[]
       alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
       for j in range(len(alphabet)):
         '''data['elements'][j]={}
         data['elements'][j]['initial']=alphabet[j]'''
         #print(data)
         items = db.get_authors_for_app(session['app_id'], alphabet[j])
         if items:
           '''set url for authenticate requesting location from app'''
           for i in range(len(items)):
             items[i]['url'] = url_for('locateBooksForTag',tag_id=items[i]['id'])
             items[i]['token'] = token
             hasRequest = db.get_request_for_tag(session['app_id'], items[i]['id'])
             items[i]['hasRequest'] = hasRequest
           #data['elements'][j]['items'] = items
         data['elements'].append({'initial':alphabet[j],'items':items})
       response = app.response_class(
             response=json.dumps(data),
             mimetype='application/json'
       )
       return response
     #for web
     else:
       return render_template('authors.html', user_login=flask_login.current_user.name, db=db, \
           user_id=globalVars['arduino_map']['user_id'], shelf_infos=globalVars['arduino_map'], 
           uuid_encode=tools.uuid_encode(globalVars['arduino_map']['id_ble'])) 
   abort(404)    
コード例 #3
0
def test_bibus_encode():
    data = {'id':1, 'arduino_name':'test module', 'id_ble':'bibus0001', 'nb_lines':3, 'nb_cols':62, 'strip_length':102.5, 'leds_interval':1.66, 'mood_color':'118,43,21'}
    """
    GIVEN a user_app structure
    WHEN an id_ble is base64 encoded
    THEN check id_ble string assertion with decoded data
    """
    uuid = tools.uuid_encode(data['id_ble'])
    id_ble =  tools.uuid_decode(uuid)
    assert id_ble.decode('utf-8') == data['id_ble']
コード例 #4
0
 def listModules(hash_email):
     modules = db.get_arduino_for_api(hash_email)
     data = {}
     if modules:
         data['token'] = models.get_token('guest', modules[0]['email'])
         data['bibus'] = []
         for module in modules:
             data['bibus'].append({
                 'uuid':
                 tools.uuid_encode(module['id_ble']),
                 'name':
                 module['arduino_name']
             })
         response = app.response_class(response=json.dumps(data),
                                       mimetype='application/json')
         return response
     abort(401)
コード例 #5
0
 def listNodesForTag(tag_id):
   globalVars = tools.initApp()
   if globalVars['arduino_map'] != None:
     nodes = db.get_node_for_tag(tag_id, globalVars['arduino_map']['user_id'])
     tag = db.get_tag_by_id(tag_id, globalVars['arduino_map']['user_id'])   
     data = {}
     books = []
     data['list_title'] = tag['tag']
     client = 'server'
     if('token' in request.args):
       client = 'mobile'
     if nodes:
         #for node in nodes:
         for i in range(len(nodes)):
             book = db.get_book(nodes[i]['id_node'], globalVars['arduino_map']['user_id'])
             books.append(book)
             app_modules = db.get_arduino_for_user(flask_login.current_user.id)
             for module in app_modules:
               address = db.get_position_for_book(module['id'], book['id'])
               if address:
                 hasRequest = db.get_request_for_position(module['id'], address['position'], address['row'])
                 books[i]['address'] = address
                 books[i]['arduino_name'] = module['arduino_name']
                 books[i]['uuid_encode'] = tools.uuid_encode(module['id_ble'])
                 books[i]['app_id'] = module['id']
                 books[i]['app_uuid'] = module['uuid']
                 books[i]['app_mac'] = module['mac']
                 books[i]['hasRequest'] = hasRequest
                 if tag['color'] is not None:
                   books[i]['color'] = tag['color']
         data['items'] = books
     #send json when token mode
     if('api' in request.path and 'token' in request.args):
       response = app.response_class(
         response=json.dumps(data),
         mimetype='application/json'
       )
       return response     
     return render_template('tag.html', books=books, user_login=globalVars['user_login'], \
       shelf_infos=globalVars['arduino_map'], tag=tag)
   abort(404)