aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/collect.py10
-rw-r--r--wqflask/wqflask/templates/collections/list.html41
2 files changed, 45 insertions, 6 deletions
diff --git a/wqflask/wqflask/collect.py b/wqflask/wqflask/collect.py
index 9ab40a50..9874b4a4 100644
--- a/wqflask/wqflask/collect.py
+++ b/wqflask/wqflask/collect.py
@@ -73,7 +73,6 @@ def collections_add():
uc_id = g.user_session.add_collection(collection_name, set())
collections = g.user_session.user_collections
- # ZS: One of these might be unnecessary
if 'traits' in request.args:
traits = request.args['traits']
return render_template("collections/add.html",
@@ -127,7 +126,6 @@ def collections_new():
def create_new(collection_name):
params = request.args
-
if "hash" in params:
unprocessed_traits = Redis.get(params['hash'])
Redis.delete(params['hash'])
@@ -238,6 +236,14 @@ def import_collection():
if import_file.filename != '':
file_path = os.path.join(TEMPDIR, import_file.filename)
import_file.save(file_path)
+ collection_csv = open(file_path, "r")
+ traits = [row.strip() for row in collection_csv]
+ os.remove(file_path)
+
+ return json.dumps(traits)
+ else:
+ return render_template(
+ "collections/list.html")
@app.route("/collections/view")
def view_collection():
diff --git a/wqflask/wqflask/templates/collections/list.html b/wqflask/wqflask/templates/collections/list.html
index fb3946fb..6e1261d7 100644
--- a/wqflask/wqflask/templates/collections/list.html
+++ b/wqflask/wqflask/templates/collections/list.html
@@ -22,7 +22,7 @@
<input type="text" id="searchbox" class="form-control" style="width: 200px; display: inline;" placeholder="Search This Table For ...">
<input type="text" id="select_top" class="form-control" style="width: 200px; display: inline;" placeholder="Select Top ...">
<br>
- <form id="collections_form" action="/delete" method="post" enctype="multipart/form-data">
+ <form id="collections_form" action="javascript:void(0);" method="post" enctype="multipart/form-data">
<input type="hidden" name="uc_id" id="uc_id" value="" />
<div style="margin-top: 10px; display: inline-block;"><button class="btn btn-default" id="import_collection" data-url="/collections/import"> Import Collection</button> <input type="file" name="import_file" id="import_file" size="20" style="display: inline-block;"></input></div>
</form>
@@ -69,11 +69,12 @@
{% block js %}
<script language="javascript" type="text/javascript" src="{{ url_for('js', filename='js_alt/timeago.min.js') }}"></script>
- <script type="text/javascript" src="/static/new/javascript/search_results.js"></script>
+ <script language="javascript" type="text/javascript" src="{{ url_for('js', filename='js_alt/md5.min.js') }}"></script>
<script language="javascript" type="text/javascript" src="{{ url_for('js', filename='DataTables/js/jquery.dataTables.min.js') }}"></script>
<script language="javascript" type="text/javascript" src="{{ url_for('js', filename='jszip/jszip.min.js') }}"></script>
<script language="javascript" type="text/javascript" src="{{ url_for('js', filename='DataTablesExtensions/plugins/sorting/natural.js') }}"></script>
<script language="javascript" type="text/javascript" src="{{ url_for('js', filename='DataTablesExtensions/buttons/js/dataTables.buttons.min.js') }}"></script>
+ <script type="text/javascript" src="/static/new/javascript/search_results.js"></script>
<script>
$('#trait_table').dataTable( {
"drawCallback": function( settings ) {
@@ -118,11 +119,43 @@
return $("#collections_form").submit();
};
+ add_collection = function(trait_data, textStatus, jqXHR) {
+ var traits_hash = md5(trait_data.toString());
+
+ $.ajax({
+ type: "POST",
+ url: "/collections/store_trait_list",
+ data: {
+ hash: traits_hash,
+ traits: trait_data.toString()
+ }
+ });
+
+ return $.colorbox({
+ href: "/collections/add?hash=" + traits_hash
+ });
+ }
+
$("#import_collection").on("click", function() {
- url = $(this).data("url")
- submit_special(url)
+ var fd = new FormData();
+ var files = $('#import_file')[0].files;
+ if(files.length > 0){
+ fd.append('import_file', files[0])
+ $.ajax({
+ type: "POST",
+ url: "/collections/import",
+ data: fd,
+ dataType: "json",
+ contentType: false,
+ processData: false,
+ success: add_collection
+ });
+ } else {
+ alert("No file selected")
+ }
});
+
$("#remove_collections").on("click", function() {
url = $(this).data("url")
collections = []