Skip to content

Commit

Permalink
Many changes to clean up flow and allow people to restart, change par…
Browse files Browse the repository at this point in the history
…ams without F5/Ctrl-R
  • Loading branch information
rolando3 committed Mar 24, 2013
1 parent ec8ab96 commit 5f44a59
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 44 deletions.
18 changes: 11 additions & 7 deletions flaskapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
30 changes: 14 additions & 16 deletions migra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ):
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions migrastorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 15 additions & 5 deletions static/css/migra.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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{
Expand Down
36 changes: 28 additions & 8 deletions static/js/migra.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -434,7 +434,6 @@ function clearMap()
}

Window.clusterer.clearMarkers();

Window.data.people = [];
Window.data.addresses = [];

Expand All @@ -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) {
Expand All @@ -466,36 +474,46 @@ 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);
});

}

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
{
Expand Down Expand Up @@ -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.
Expand Down
24 changes: 19 additions & 5 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div id="header"><h1>Migra ancestry mapping</h1></div>
<div id="map_canvas"></div>
<div id="footer">
<div id="buttons" style="display: none">
<div id="buttons">
<a id="btn_restart" href="#" class="pseudobutton">Upload a new file</a>
<a id="btn_choose" href="#" class="pseudobutton">Choose a new focus</a>
</div>
Expand Down Expand Up @@ -56,10 +56,6 @@
<dd>
<input type="file" required name="gedcom" id="gedcom" />
</dd>
<dt><label for="q_input" id="q_label" >Search</label></dt>
<dd>
<input name="q" id="q_input" placeholder="Search term" />
</dd>
</dl>
<input type="submit" />
</fieldset>
Expand All @@ -71,6 +67,24 @@
</p>
</form>
</div>
<div id="filter_form_wrapper" class="dialog" style="display: none;" >
<form id="filter_form" action="/filter" >
<fieldset>
<legend>Filter the target file</legend>
<dl class="formfields">
<dt><label for="q_input" id="q_label" >Search</label></dt>
<dd>
<input name="q" id="q_input" placeholder="Search term" />
</dd>
</dl>
<input type="submit" />
</fieldset>
<p style="font-size: 75%">
To map you will need to find a <q>focal</q> individual in your Gedcom.
Search for their name here.
</p>
</form>
</div>
<div id="walk_form_wrapper" class="dialog" style="display: none;">
<form id="walk_form" action="/walk" >
<!--
Expand Down

0 comments on commit 5f44a59

Please sign in to comment.