コード例 #1
0
def delete_collection():
    params = request.form
    print("params:", params)
    if g.user_session.logged_in:
        uc_id = params['uc_id']
        if len(uc_id.split(":")) > 1:
            for this_uc_id in uc_id.split(":"):
                uc = model.UserCollection.query.get(this_uc_id)
                collection_name = uc.name
                db_session.delete(uc)
                db_session.commit()
        else:
            uc = model.UserCollection.query.get(uc_id)
            # Todo: For now having the id is good enough since it's so unique
            # But might want to check ownership in the future
            collection_name = uc.name
            db_session.delete(uc)
            db_session.commit()
    else:
        collection_name = params['collection_name']
        user_manager.AnonUser().delete_collection(collection_name)

    flash("We've deleted the collection: {}.".format(collection_name), "alert-info")

    return redirect(url_for('list_collections'))
コード例 #2
0
ファイル: collect.py プロジェクト: gsc0107/genenetwork2
    def __init__(self, collection_name):
        anon_user = user_manager.AnonUser()
        self.key = anon_user.key
        self.name = collection_name
        self.id = None
        self.created_timestamp = datetime.datetime.utcnow().strftime(
            '%b %d %Y %I:%M%p')
        self.changed_timestamp = self.created_timestamp  #ZS: will be updated when changes are made

        #ZS: Find id and set it if the collection doesn't already exist
        if Redis.get(self.key) == "None" or Redis.get(self.key) == None:
            Redis.set(
                self.key, None
            )  #ZS: For some reason I get the error "Operation against a key holding the wrong kind of value" if I don't do this
        else:
            collections_list = json.loads(Redis.get(self.key))
            collection_position = 0  #ZS: Position of collection in collection_list, if it exists
            collection_exists = False
            for i, collection in enumerate(collections_list):
                if collection['name'] == self.name:
                    collection_position = i
                    collection_exists = True
                    self.id = collection['id']
                    break
        if self.id == None:
            self.id = str(uuid.uuid4())
コード例 #3
0
def view_collection():
    params = request.args
    print("PARAMS in view collection:", params)

    if "uc_id" in params:
        uc_id = params['uc_id']
        uc = model.UserCollection.query.get(uc_id)
        traits = json.loads(uc.members)
    else:
        user_collections = json.loads(Redis.get(user_manager.AnonUser().key))
        this_collection = {}
        for collection in user_collections:
            if collection['id'] == params['collection_id']:
                this_collection = collection
                break
        #this_collection = user_collections[params['collection_id']]
        traits = this_collection['members']

    print("in view_collection traits are:", traits)

    trait_obs = []
    json_version = []

    for atrait in traits:
        name, dataset_name = atrait.split(':')
        if dataset_name == "Temp":
            group = name.split("_")[2]
            dataset = create_dataset(dataset_name, dataset_type = "Temp", group_name = group)
            trait_ob = trait.GeneralTrait(name=name, dataset=dataset)
        else:
            dataset = create_dataset(dataset_name)
            trait_ob = trait.GeneralTrait(name=name, dataset=dataset)
            trait_ob = trait.retrieve_trait_info(trait_ob, dataset, get_qtl_info=True)
        trait_obs.append(trait_ob)

        json_version.append(trait.jsonable(trait_ob))

    if "uc_id" in params:
        collection_info = dict(trait_obs=trait_obs,
                               uc = uc)
    else:
        collection_info = dict(trait_obs=trait_obs,
                               collection_name=this_collection['name'])
    if "json" in params:
        print("json_version:", json_version)
        return json.dumps(json_version)
    else:
        return render_template("collections/view.html",
                           **collection_info
                           )
コード例 #4
0
def list_collections():
    params = request.args
    #logger.debug("PARAMS:", params)
    if g.user_session.logged_in:
        user_collections = list(g.user_session.user_collections)
        #logger.debug("user_collections are:", user_collections)
        return render_template("collections/list.html",
                               params = params,
                               collections = user_collections,
                               )
    else:
        anon_collections = user_manager.AnonUser().get_collections()
        #logger.debug("anon_collections are:", anon_collections)
        return render_template("collections/list.html",
                               params = params,
                               collections = anon_collections)
コード例 #5
0
def view_collection():
    params = request.args

    if g.user_session.logged_in and "uc_id" in params:
        uc_id = params['uc_id']
        uc = (collection for collection in g.user_session.user_collections if collection["id"] == uc_id).next()
        traits = uc["members"]
    else:
        user_collections = json.loads(Redis.get(user_manager.AnonUser().key))
        this_collection = {}
        for collection in user_collections:
            if collection['id'] == params['collection_id']:
                this_collection = collection
                break

        traits = this_collection['members']

    trait_obs = []
    json_version = []

    for atrait in traits:
        name, dataset_name = atrait.split(':')
        if dataset_name == "Temp":
            group = name.split("_")[2]
            dataset = create_dataset(dataset_name, dataset_type = "Temp", group_name = group)
            trait_ob = trait.GeneralTrait(name=name, dataset=dataset)
        else:
            dataset = create_dataset(dataset_name)
            trait_ob = trait.GeneralTrait(name=name, dataset=dataset)
            trait_ob = trait.retrieve_trait_info(trait_ob, dataset, get_qtl_info=True)
        trait_obs.append(trait_ob)

        json_version.append(trait.jsonable(trait_ob))

    if "uc_id" in params:
        collection_info = dict(trait_obs=trait_obs,
                               uc = uc)
    else:
        collection_info = dict(trait_obs=trait_obs,
                               collection_name=this_collection['name'])
    if "json" in params:
        return json.dumps(json_version)
    else:
        return render_template("collections/view.html",
                           **collection_info
                           )
コード例 #6
0
def collections_add():
    traits=request.args['traits']

    if g.user_session.logged_in:
        user_collections = g.user_session.user_collections
        #logger.debug("user_collections are:", user_collections)
        return render_template("collections/add.html",
                               traits = traits,
                               collections = user_collections,
                               )
    else:
        anon_collections = user_manager.AnonUser().get_collections()
        collection_names = []
        for collection in anon_collections:
            collection_names.append({'id':collection['id'], 'name':collection['name']})
        return render_template("collections/add.html",
                                traits = traits,
                                collections = collection_names,
                              )
コード例 #7
0
def create_new(collection_name):
    params = request.args

    unprocessed_traits = params['traits']
    traits = process_traits(unprocessed_traits)

    if g.user_session.logged_in:
        uc = model.UserCollection()
        uc.name = collection_name
        print("user_session:", g.user_session.__dict__)
        uc.user = g.user_session.user_id
        uc.members = json.dumps(list(traits))
        db_session.add(uc)
        db_session.commit()
        return redirect(url_for('view_collection', uc_id=uc.id))
    else:
        current_collections = user_manager.AnonUser().get_collections()
        ac = AnonCollection(collection_name)
        ac.changed_timestamp = datetime.datetime.utcnow().strftime('%b %d %Y %I:%M%p')
        ac.add_traits(params)
        return redirect(url_for('view_collection', collection_id=ac.id))
コード例 #8
0
def delete_collection():
    params = request.form
    if g.user_session.logged_in:
        uc_id = params['uc_id']
        if len(uc_id.split(":")) > 1:
            for this_uc_id in uc_id.split(":"):
                collection_name = g.user_session.delete_collection(this_uc_id)
        else:
            collection_name = g.user_session.delete_collection(uc_id)
    else:
        if "collection_name" in params:
            collection_name = params['collection_name']
        else:
            for this_collection in params['uc_id'].split(":"):
                user_manager.AnonUser().delete_collection(this_collection)

    if len(uc_id.split(":")) > 1:
        flash("We've deleted the selected collections.", "alert-info")
    else:
        flash("We've deleted the collection: {}.".format(collection_name), "alert-info")

    return redirect(url_for('list_collections'))
コード例 #9
0
ファイル: collect.py プロジェクト: Brainiarc7/genenetwork2
 def __init__(self):
     self.anon_user = user_manager.AnonUser()
     self.key = "anon_collection:v5:{}".format(self.anon_user.anon_id)