diff options
author | Sam | 2013-12-30 03:45:27 +0000 |
---|---|---|
committer | Sam | 2013-12-30 03:45:27 +0000 |
commit | 957ec58b605af421947335197ed09eddf72479a0 (patch) | |
tree | dede39ac510fc777f4d40cf9efb483b158339b10 /wqflask | |
parent | 51f1049ef5a6b78f02f9fc44e970b80eb64603f1 (diff) | |
download | genenetwork2-957ec58b605af421947335197ed09eddf72479a0.tar.gz |
Collections changes
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/wqflask/collect.py | 36 | ||||
-rw-r--r-- | wqflask/wqflask/model.py | 8 | ||||
-rw-r--r-- | wqflask/wqflask/templates/collections/add.html | 10 | ||||
-rw-r--r-- | wqflask/wqflask/templates/collections/view.html | 1 |
4 files changed, 36 insertions, 19 deletions
diff --git a/wqflask/wqflask/collect.py b/wqflask/wqflask/collect.py index 6ac4abcf..2bf5b602 100644 --- a/wqflask/wqflask/collect.py +++ b/wqflask/wqflask/collect.py @@ -58,25 +58,33 @@ def collections_add(): @app.route("/collections/new") def collections_new(): - print("request.args in collections_new are:", request.args) - if "create_new" in request.args: - return create_new() - elif "add_to_existing" in request.args: - return add_to_existing() - elif "continue" in request.args: - return unnamed() + params = request.args + print("request.args in collections_new are:", params) + + collection_name = params['new_collection'] + + if "create_new" in params: + return create_new(collection_name) + elif "add_to_existing" in params: + return add_traits(params, collection_name) + elif "default" in params: + return add_traits(params, "default") + else: CauseAnError -def unnamed(): - return "unnamed" -def add_to_existing(): - params = request.args +def add_traits(params, collection_name): print("---> params are:", params.keys()) print(" type(params):", type(params)) - uc = model.UserCollection.query.get(params['existing_collection']) + if collection_name=="default": + uc = g.user_session.user_ob.get_collection_by_name("default") + # Doesn't exist so we'll create it + if not uc: + return create_new("default") + else: + uc = model.UserCollection.query.get(params['existing_collection']) members = set(json.loads(uc.members)) len_before = len(members) @@ -114,10 +122,10 @@ def process_traits(unprocessed_traits): traits.add(str(data)) return traits -def create_new(): +def create_new(collection_name): params = request.args uc = model.UserCollection() - uc.name = params['new_collection'] + uc.name = collection_name print("user_session:", g.user_session.__dict__) uc.user = g.user_session.user_id unprocessed_traits = params['traits'] diff --git a/wqflask/wqflask/model.py b/wqflask/wqflask/model.py index b508f18e..192aedd0 100644 --- a/wqflask/wqflask/model.py +++ b/wqflask/wqflask/model.py @@ -57,8 +57,16 @@ class User(Base): user_collections = relationship("UserCollection", order_by="asc(UserCollection.name)", + lazy='dynamic', ) + def get_collection_by_name(self, collection_name): + try: + collect = self.user_collections.filter_by(name=collection_name).one() + except sqlalchemy.orm.exc.NoResultFound: + collect = None + return collect + @property def name_and_org(self): """Nice shortcut for printing out who the user is""" diff --git a/wqflask/wqflask/templates/collections/add.html b/wqflask/wqflask/templates/collections/add.html index 8b6a17a3..c87203b1 100644 --- a/wqflask/wqflask/templates/collections/add.html +++ b/wqflask/wqflask/templates/collections/add.html @@ -1,16 +1,16 @@ <div id="myModal"> <div class="modal-header"> <h3>Add to collection</h3> - <p>You have three choices: Contuine without naming the collection, creating a new named collection, - or adding the traits to an existing collection.</p> + <p>You have three choices: Use your default collection, create a new named collection, + or add the traits to an existing collection.</p> </div> <div class="modal-body"> <form action="/collections/new" data-validate="parsley" id="add_form"> <fieldset> - <legend>Continue without naming collection</legend> - <span class="help-block">Choose this if you don't plan on using the collection again.</span> + <legend>Use your default collection</legend> + <span class="help-block">Choose this if you're in a hurry or don't plan on using the collection again.</span> <span class="help-block"><em></em>If you are unsure this is probably the option you want.</em></span> - <button type="submit" name="continue" class="btn">Continue</button> + <button type="submit" name="default" class="btn">Continue</button> </fieldset> <hr /> diff --git a/wqflask/wqflask/templates/collections/view.html b/wqflask/wqflask/templates/collections/view.html index 0ab004d9..79eeac26 100644 --- a/wqflask/wqflask/templates/collections/view.html +++ b/wqflask/wqflask/templates/collections/view.html @@ -8,6 +8,7 @@ <div class="container"> <div class="page-header"> <h1>Your Collection</h1> + <h2>{{ uc.name }}</h2> </div> <div class="bs-docs-example"> |