From 5f44a594d138715091b865f39e8c8e74cc42f595 Mon Sep 17 00:00:00 2001 From: Roalndo Date: Sat, 23 Mar 2013 22:24:57 -0400 Subject: [PATCH] Many changes to clean up flow and allow people to restart, change params without F5/Ctrl-R --- flaskapp.py | 18 +++++++++++------- migra.py | 30 ++++++++++++++---------------- migrastorage.py | 6 +++--- static/css/migra.css | 20 +++++++++++++++----- static/js/migra.js | 36 ++++++++++++++++++++++++++++-------- templates/index.html | 24 +++++++++++++++++++----- 6 files changed, 90 insertions(+), 44 deletions(-) diff --git a/flaskapp.py b/flaskapp.py index e85c5d5..e2dbcd9 100755 --- a/flaskapp.py +++ b/flaskapp.py @@ -33,22 +33,26 @@ def index(): @app.route('/upload',methods=['POST']) def upload(): """ Get the file and the search term from the upload, turn it into a gedcom, do something with this """ - query = request.form['q'] file = request.files['gedcom'] - #uploads not permitted in Heroku. Need to send this over to amazon. For now this will have to do. if file and __allowed_file(file.filename): - ( fullDict, filteredList ) = migra.processGedcom(file,query) - session['key'] = fileStorage().store_file(fullDict) - return jsonresponse({'people':filteredList,'parameters':{'query':query}}) + all = migra.processGedcom(file) + k = session.get('key',None) + session['key'] = fileStorage().store_file(all,k) + return jsonresponse({'count': len(all.keys())}) else: raise MigraError, ('File not allowed') - + +@app.route('/filter',methods=['GET','POST']) +def filter(): + q = request.form['q'] + d = fileStorage().get_file(session['key']) + return jsonresponse({'people': migra.filter ( d, q )}) + @app.route('/walk',methods=['GET','POST']) def walk(): """Now we have to find our file and send it to gedcom -- unless we can attach the gedcom created earlier via session!""" d = fileStorage().get_file(session['key']) - return jsonresponse( migra.walk(d,request.form['i'],request.form['d']) ) @app.route('/cache',methods=['POST']) diff --git a/migra.py b/migra.py index cadf7aa..7c2e8db 100755 --- a/migra.py +++ b/migra.py @@ -170,21 +170,20 @@ def get_place(cls, i): return best @classmethod - def buildListOfIndividuals(cls,l,q): - import sys - people = [] - + def filterList(cls,d,q): if not q: sys.stderr.write ( 'No query string received.\n' ) - q = q.lower() + q = q.lower().split() filtered = [] - for p in l: - uname = unicode(p.name(),'utf-8').lower() - if ( uname.find(q) >= 0 ): - filtered.append ( p ) + for id in d.keys(): + uname = d[id]['name'].lower() + for qt in q: + if ( uname.find(qt) >= 0 ): + filtered.append ( d[id] ) + break - return sorted(filtered, key=lambda person: person.name() ) + return sorted(filtered, key=lambda person: person['name'] ) class MigraError(Exception): def __init__ ( self, value ): @@ -268,7 +267,7 @@ class Migra: def __init__(self): MigraGeocoder() - def processGedcom ( self, file, query ): + def processGedcom ( self, file ): #the calling function will have gotten the file from the web server and done something with it. #based upon its framework it probably will have saved the file, but who knows? what we need to do: #turn the file into a Gedcom object and then return a reference to it and a reference to the @@ -280,18 +279,17 @@ def processGedcom ( self, file, query ): else: g = Gedcom(file) - full = [] dict = {} for i in g.element_list(): if i.individual(): p = MigraPerson(i) dict[i.pointer()] = p - full.append ( p ) - - filtered = MigraHelper.buildListOfIndividuals(full,query) - return (dict, filtered) + return dict + def filter ( self, dict, query ): + return MigraHelper.filterList(dict,query) + def walk ( self, dict, id, depth ): '''Given a full list of all people, and a focal node, and a depth, tell the walker to walk back as far as it can ''' walker = MigraWalker(dict,id,int(depth)) diff --git a/migrastorage.py b/migrastorage.py index a48d9fe..6060307 100644 --- a/migrastorage.py +++ b/migrastorage.py @@ -10,7 +10,7 @@ def fileStorage(): class LocalFileStorage: @classmethod - def store_file(cls,d): + def store_file(cls,d,k): """ Given a dict of all of the people in our gedcom, store it somewhere, and then pass back an identifier that will make it easy to find on the second pass.""" from tempfile import NamedTemporaryFile @@ -68,8 +68,8 @@ def test_key(cls,k=None): return k @classmethod - def store_file(cls,d): - awsKey = cls.__key() + def store_file(cls,d,k=None): + awsKey = cls.__key(k) awsKey.set_contents_from_string(json.dumps(d,indent=4,cls=MigraPersonEncoder)) return awsKey.key diff --git a/static/css/migra.css b/static/css/migra.css index 0527eba..a2ce68c 100644 --- a/static/css/migra.css +++ b/static/css/migra.css @@ -30,9 +30,17 @@ html, body { width: 100%; } +#buttons { + margin: 0 0 0.5em 0; + padding: 0.5em 0 0.5em 0; +} + .pseudobutton { +// margin: 0.5em; + color: black; padding: 0.5em; - border: solid #888888 1px; + background-color: #9966ff; + border: solid #ff7700 2px; } #map_canvas { @@ -75,14 +83,15 @@ fieldset label { .dialog { position: relative; width: 500px; - margin: 10% auto 0px auto ; + margin: 10% auto 0px auto; padding: 25px; - background: #9966ff; -webkit-border-radius: 25px; -moz-border-radius: 25px; border-radius: 25px; box-shadow: 0 0 25px #d0d0d0; - opacity: 0.8; + background-color: #9966ff; + opacity: 1 !important; + z-index: 5; } .dialog fieldset { @@ -107,13 +116,14 @@ fieldset label { #overlay { display: block; position: fixed; - z-index: 9999; + z-index: 9998; left: 0; top: 0; width: 100%; min-height: 100% !important; height: 100% !important; max-height: 100% !important; + background-color:rgba(0, 0, 0, 0.5); } #spinner{ diff --git a/static/js/migra.js b/static/js/migra.js index f324177..7fee03f 100644 --- a/static/js/migra.js +++ b/static/js/migra.js @@ -19,7 +19,7 @@ if (!String.prototype.repeat) { } } -MigraForms = { View: 1, UploadForm: 2, WalkForm: 3 }; +MigraForms = { View: 1, UploadForm: 2, FilterForm: 3, WalkForm: 4 }; function initialize() { @@ -434,7 +434,6 @@ function clearMap() } Window.clusterer.clearMarkers(); - Window.data.people = []; Window.data.addresses = []; @@ -446,12 +445,21 @@ function addEventListeners() //When our forms are submitted we want to process their forms. When those are done we want to do things. $('#upload_form').submit(function (e) { Window.stat.actionStart("Uploading data"); + processForm(this, e,function (result) { + Window.stat.actionEnd("Data uploaded"); + showForm(MigraForms.FilterForm); + }); + }); + + //When our forms are submitted we want to process their forms. When those are done we want to do things. + $('#filter_form').submit(function (e) { + Window.stat.actionStart("Filtering list of individuals"); processForm(this, e,function (result) { buildPeopleList(result); Window.stat.actionEnd("List of people built"); }); }); - + $('#walk_form').submit(function (e) { Window.stat.actionStart("Walking the genealogy"); processForm(this, e,function (result) { @@ -466,12 +474,11 @@ function addEventListeners() $('#btn_restart').click(function(e) { //Might need to clean up data - showForm(MigraForms.UploadForm); }); $('#btn_choose').click(function(e) { - showForm(MigraForms.WalkForm); + showForm(MigraForms.FilterForm); }); } @@ -479,23 +486,34 @@ function addEventListeners() function showForm ( n ) { //there are three + if ( n == MigraForms.View ) { $('#overlay').hide(); - $('#walk_form_wrapper').hide(); $('#upload_form_wrapper').hide(); + $('#filter_form_wrapper').hide(); + $('#walk_form_wrapper').hide(); } else if ( n == MigraForms.UploadForm ) { $('#overlay').show(); - $('#walk_form_wrapper').hide(); $('#upload_form_wrapper').show(); + $('#filter_form_wrapper').hide(); + $('#walk_form_wrapper').hide(); } else if ( n == MigraForms.WalkForm ) { $('#overlay').show(); + $('#upload_form_wrapper').hide(); + $('#filter_form_wrapper').hide(); $('#walk_form_wrapper').show(); + } + else if ( n == MigraForms.FilterForm ) + { + $('#overlay').show(); $('#upload_form_wrapper').hide(); + $('#filter_form_wrapper').show(); + $('#walk_form_wrapper').hide(); } else { @@ -550,7 +568,9 @@ function buildPeopleList(httpData) var value = ""; var i = 0; Window.options = httpData.parameters; - //$('#sid').val(httpData.sid); + + $('#i_select').empty(); + if ( httpData.people.length > 0 ) { //We have found at least one match. diff --git a/templates/index.html b/templates/index.html index 6d24bff..8c2ed2c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -17,7 +17,7 @@