Ejemplo n.º 1
0
def genetic():
    f = request.args.get('f')
    a = request.args.get('a')
    k = request.args.get('k')

    fast = json.loads(f)
    keys = json.loads(k)
    att = json.loads(a)

    layout = genetic2.main(fast, att, keys)

    print layout

    l = layout[0][0]

    if session.get("user_id"):
        new_k = Keyboard(name=genName(), user_id=session['user_id'])
        model.session.add(new_k)
        model.session.commit()
        for i in range(len(l)):
            key = Key(kb_id=new_k.id)
            key.location = l[i][0]
            key.values = l[i][1][0] + " " + l[i][1][1]
            qwerty_key = Key.query.get(i + 1)
            key.code = qwerty_key.code
            model.session.add(key)
            new_k.keys.append(key)
        user = User.query.get(session['user_id'])
        a = user.analytics[-1]
        a.kd_id = new_k.id
        print new_k.id
        model.session.commit()

    return jsonify(result=l)
Ejemplo n.º 2
0
 def save_value(self, app_id, key, subkey, value):
     '''
     Saves a value in the database.
     Creates the needed references of key and app if needed.
     
     @param app_id: string The identification of the requesting app
     @param key: string The key that will identify all given values
     @param subkey: string The subkey that identifies this specific value
     @param value: string Value to store
     
     @raise TypeProviderError: Notifies that the given key matches with another ResourceType
     '''
     app = App.get_by(name=app_id)
     if app == None:
         app = App(name=app_id)
     key_db = Key.get_by(name=key,app_name=app_id)
     if key_db == None:
         key_db = Key(name=key,app=app, type_name=self.providerType)
     if key_db.type_name != self.providerType:
         raise TypeProviderError(self.providerType, key_db.type_name)
         
     value_db = Value()
     value_db.key = key_db
     value_db.subkey = subkey
     value_db.value = value
     session.commit()
Ejemplo n.º 3
0
def get_provider_name(app, key):
    '''
    Gets the Provider id from an app key
    '''
    key_stored = Key.get_by(app_name = app, name = key)
    if key_stored == None:
        raise NotExistingProviderError()
    return key_stored.type_name
Ejemplo n.º 4
0
 def get_key(self, app, key):
     '''
     Gets a model.Key object from the database.
     
     @param app: string App id
     @param key: string Key name
     @return: model.Key
     '''
     return Key.get_by(app_name = app, name = key)
Ejemplo n.º 5
0
def admin_llaves():
    keys_list = []
    keys_dict = gpg.list_keys(True)
    for key in keys_dict:
        key_obj = Key(key)
        print(key)
        keys_list.append(key_obj)
    print("keys List: ", keys_list)
    return render_template("admin_llaves.html", message="", keys=keys_list)
Ejemplo n.º 6
0
 def remove_key(self, app_id, key):
     '''
     Removes a key and all their values stored in the database.
     
     @param app_id: string The identification of the requesting app_id
     @param key: string The key that is going to be erased
     '''
     key_db = Key.get_by(name = key, app_name = app_id)
     for value in key_db.values:
         value.delete()
     key_db.delete()
     session.commit()
Ejemplo n.º 7
0
def rename_keyboard(keyboard_id):
    keyboard = Keyboard.query.get(keyboard_id)
    user = User.query.get(session['user_id'])
    new_k = Keyboard(name=keyboard.name, user_id=user.id)
    model.session.add(new_k)
    for key in keyboard.keys:
        new_key = Key(kb_id=new_k.id,
                      location=key.location,
                      values=key.values,
                      code=key.code)
        new_k.keys.append(new_key)
    model.session.commit()
    return jsonify(result="add")
Ejemplo n.º 8
0
    def get(self, category_key_name):
        p = self.GET.get("p")
        p = int(p) if p and p.isdigit() else 1
        
        cate = Key.from_path("Category", category_key_name)
        if not cate:
            #TODO 404
            pass
        
        pager = Post.fetch_page(p, 
                                func=lambda x:x.filter("category =", cate).filter("status =", PostStatus.NORMAL).order("-date_created"),
                                realtime_count=True)

        context = {"pager": pager}
        self.render("index.html", context)
Ejemplo n.º 9
0
def createkey():
    new_app = request.form.get('appname')
    new_apptype = request.form.get('apptype')
    api_key = getmd5(current_user.name + str(new_app))
    api_sercet = getmd5(current_user.password + str(time()))
    try:
        db.session.add(
            Key(current_user.name, new_app, new_apptype, api_key, api_sercet))
        db.session.commit()
        return jsonify({
            'user': current_user.name,
            'app_name': new_app,
            'type': new_apptype,
            'api_key': api_key,
            'api_secret': api_sercet
        })
    except Exception as e:
        raise ApiException(
            message='occur error when creating the api key, please retry')
Ejemplo n.º 10
0
 def _render_key(self, req):
     if req.method == 'POST':
         if req.args.get('new'):
             addr = req.args.get('email')
             if not addr:
                 raise TracError('You must give an email address')
            
             key = Key(self.env, addr)
             if not key.exists:
                 key.save()
             key.notify()
             
             req.hdf['tracbl.key.page'] = 'done'
     else:
         req.hdf['tracbl.key.page'] = 'new'
     return 'tracbl_key.cs', None