From 4e6d9ac98fe6a6152f135ef2242ae5aa10c3da05 Mon Sep 17 00:00:00 2001 From: Lucien Christie-Dervaux Date: Sat, 6 May 2017 17:50:55 -0400 Subject: [PATCH 1/6] added new app.py endpoint for a new version of samples with images --- app.py | 57 ++++++++-- templates/sampleimages.html | 207 ++++++++++++++++++++++++++++++++++++ 2 files changed, 256 insertions(+), 8 deletions(-) create mode 100644 templates/sampleimages.html diff --git a/app.py b/app.py index dcb8dc1..3e0c43c 100644 --- a/app.py +++ b/app.py @@ -35,8 +35,8 @@ def index(): @metpet_ui.route("/search/") def search(): - print "search Arguments: ",request.args - print "session data: ", session + print("search Arguments: ",request.args) + print("session data: ", session) #get all filter options from API, use format = json and minimum page sizes to speed it up if request.args.get("resource") == "samples": #resource value set in search_form.html, appends samples.html to bottom of page @@ -132,10 +132,6 @@ def samples(): filters = dict(request.args) tmp_var = 0 - print("tokens") - print(session) - print("Pre-processing filters") - print(filters) for key in filters.keys(): # Key is a map polygon @@ -158,8 +154,7 @@ def samples(): # Turn list into a comma-separated string filters[key] = (',').join([e for e in filters[key] if e and e[0]]) - print("Post-processing filters:") - print(filters) + filters["format"] = "json" samples = {} try: @@ -769,6 +764,52 @@ def test(): ''' return jsonify(results=response.json()) + +@metpet_ui.route("/sampleimages/") +def sample(id): + #headers! to authenticate user during API calls (for private data and to add/edit their samples) + headers = None + if session.get("auth_token", None): + headers = {"Authorization": "Token "+session.get("auth_token")} + + #get the sample the usual way and return error message if something went wrong + sample = get(env("API_HOST")+"samples/"+id+"/", params = {"format": "json"}, headers = headers).json() + if "detail" in sample: + flash(sample["detail"]) + return redirect(url_for("search")) + + #make lat/long and date nice + pos = sample["location_coords"].split(" ") + sample["location_coords"] = [round(float(pos[2].replace(")","")),5), round(float(pos[1].replace("(","")),5)] + if sample["collection_date"]: + sample["collection_date"] = sample["collection_date"][:-10] + + #get subsample and analysis data for tables + subsamples = [] + for s in sample["subsample_ids"]: + subsamples.append(get(env("API_HOST")+"subsamples/"+s, + params = {"fields": "subsample_type,name,id,public_data,owner", "format": "json"}, headers = headers).json()) + for s in subsamples: + s["chemical_analyses"] = get(env("API_HOST")+"chemical_analyses/", + params = {"subsample_ids": s["id"], "fields": "id", "format": "json"}, headers = headers).json()["results"] + + + images = { + + + } + sample["image"] = image + + + return render_template("sample.html", + sample = sample, + subsamples = subsamples, + auth_token = session.get("auth_token",None), + email = session.get("email",None), + name = session.get("name",None) + ) + + if __name__ == "__main__": dotenv.read_dotenv("../app_variables.env") metpet_ui.run(debug = True) diff --git a/templates/sampleimages.html b/templates/sampleimages.html new file mode 100644 index 0000000..eae7d4b --- /dev/null +++ b/templates/sampleimages.html @@ -0,0 +1,207 @@ +{% extends "base.html" %} + +{% block title %} +

+ Sample {{ sample.number }} + {% if auth_token %}Edit Sample{% endif %} +

+{% endblock %} + +{% block body %} +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Owner{% if sample.owner %}{{ sample.owner.name }}{% endif %}
IGSN{% if sample.sesar_number %}{{ sample.sesar_number }}{% endif %}
Aliases{% if sample.aliases %}{% for a in sample.aliases %}{% if loop.index0 > 0 %}, {% endif %}{{ a }}{% endfor %}{% endif %}
Date Collected{% if sample.collection_date %}{{ sample.collection_date }}{% endif %}
Rock Type{% if sample.rock_type %}{{ sample.rock_type.name }}{% endif %}
Public{% if sample.public_data %}Yes{% else %}No{% endif %}
Latitude{% if sample.location_coords %}{{ sample.location_coords.0 }}{% endif %}
Longitude{% if sample.location_coords %}{{ sample.location_coords.1 }}{% endif %}
Country{% if sample.country %}{{ sample.country }}{% endif %}
Collector{% if sample.collector_name %}{{ sample.collector_name }}{% endif %}
Present Location{% if sample.location_name %}{{ sample.location_name }}{% endif %}
Regions{% if sample.regions %}{% for r in sample.regions %}{% if loop.index0 > 0 %}, {% endif %}{{ r }}{% endfor %}{% endif %}
Metamorphic Regions{% if sample.metamorphic_regions %}{% for r in sample.metamorphic_regions %}{% if loop.index0 > 0 %}, {% endif %}{{ r.name }}{% endfor %}{% endif %}
Metamorphic Grades{% if sample.metamorphic_grades %}{% for g in sample.metamorphic_grades %}{% if loop.index0 > 0 %}, {% endif %}{{ g.name }}{% endfor %}{% endif %}
Publication References + {% if sample.references %}{% for r in sample.references %} + {{ r.name }} + {% if r.title %}   + + + + + + + + +
Title: + + {% if r.title %}{{ r.title }}{% endif %} +
Authors:{% if r.first_author %}{{ r.first_author }}{% endif %}{% if r.second_authors %}, {{ r.second_authors }}{% endif %}
Journal:{% if r.journal_name %}{{ r.journal_name }}{% endif %}
Text:{% if r.full_text %}{{ r.full_text }}{% endif %}

+ {% endif %} + {% endfor %}{% endif %} +
Description{% if sample.description %}{{ sample.description }}{% endif %}
Minerals{% if sample.minerals %}{% for m in sample.minerals %}{% if loop.index0 > 0 %}, {% endif %}{{ m.name }}{% endfor %}{% endif %}
+
+ +
+ +
+
+

Sample Images

+ + + + + + + {% if sample.images %}{% for image in sample.images %} + + + + + {% endfor %}{% endif %} + +
Thumbnail + Type +
+ + + + {{ image.image_type }}
+
+ +
+

Subsamples{% if auth_token %}Add Subsample{% endif %}

+
+ + + + + + + + + + + + + + {% for subsample in subsamples %} + + + + + + + + + + {% endfor %} + +
NamePublicTypeImage CountChemical Analysis CountOwnerImage Map
{{ subsample.name }}{{ subsample.public_data }}{{ subsample.subsample_type.name }}{{ subsample.image_count }}{{ subsample.chemical_analyses|length }}{{ sample.owner.name }} --
+
+ + + + + + + +{% endblock %} From b5686f7bbfb340ef902816a27c770959b6fd6b0b Mon Sep 17 00:00:00 2001 From: Lucien Christie-Dervaux Date: Sat, 6 May 2017 20:03:45 -0400 Subject: [PATCH 2/6] got basic design down for sliding deck of sample images --- app.py | 15 ++++---- templates/sampleimages.html | 69 ++++++++++++++++++++++++++++++++++--- 2 files changed, 74 insertions(+), 10 deletions(-) diff --git a/app.py b/app.py index 3e0c43c..e177423 100644 --- a/app.py +++ b/app.py @@ -766,7 +766,7 @@ def test(): @metpet_ui.route("/sampleimages/") -def sample(id): +def sampleimages(id): #headers! to authenticate user during API calls (for private data and to add/edit their samples) headers = None if session.get("auth_token", None): @@ -794,14 +794,17 @@ def sample(id): params = {"subsample_ids": s["id"], "fields": "id", "format": "json"}, headers = headers).json()["results"] - images = { - + images = [{"url":"http://www.cs.rpi.edu/~sibel/transfer/metpetdb/mon1B-1%20pts.jpg"}, + {"url":"http://www.cs.rpi.edu/~sibel/transfer/metpetdb/mon1C-1%20pts.jpg"}, + {"url":"http://www.cs.rpi.edu/~sibel/transfer/metpetdb/mon2A1-1%20pts.jpg"}] - } - sample["image"] = image + + sample["images"] = images - return render_template("sample.html", + print sample + + return render_template("sampleimages.html", sample = sample, subsamples = subsamples, auth_token = session.get("auth_token",None), diff --git a/templates/sampleimages.html b/templates/sampleimages.html index eae7d4b..60b30eb 100644 --- a/templates/sampleimages.html +++ b/templates/sampleimages.html @@ -1,4 +1,5 @@ {% extends "base.html" %} + {% block title %}

@@ -104,6 +105,51 @@


+ +{% if sample.images %} + + +{% endif %} + + + +

Subsamples{% if auth_token %}Add Subsample{% endif %}

@@ -166,8 +217,18 @@

Subsamples{% if auth_token %} Date: Sat, 6 May 2017 20:04:14 -0400 Subject: [PATCH 3/6] deleted pdf --- templates/MetPetDB (URP).pdf | Bin 7951 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 templates/MetPetDB (URP).pdf diff --git a/templates/MetPetDB (URP).pdf b/templates/MetPetDB (URP).pdf deleted file mode 100644 index 636f0eb28973c8e254f17db73799aaa31ae62404..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7951 zcmcgxZFAeW5&o`UfwGrMn%I=x$=vi5Ntv9JUfqdvnZ(o1ebPWAB+(`bmVj*QT>bYx z3lJ12$%!KC8c#Ij0=w8Z>>D3nF!7*89xE11xDw%9XKBD*tXi$d7i^Ns=$7e3r-DF( z`KwWju`fI;0C;?4$~=YnBAbYktyWkBRx)LLq32^QZ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+IXlWw{R4CjS}&iiBZDZ%J%9J88_-2+>DufH7+*4JJ+J`Bj+ z|GjSfN4O}IH}}khmwM*20k49<2GrgOGaT3^bukxN67iJ1g%d7SqA;<;C}4Y|8~yGi ze#HwP1J6}egF(`=QI!Uj9yhX0}>EIxo&`ZLSY6vBxE?Zy?!VWo9q%$Zu>$R5aEbb7MWB z{)-Sc)AOB}E}S*KUo4a;p(BwYs|?Mr`EKEYRbYb^rup?vX$7Ygee05Rj=*Gxlyc zlDjFL0!y(9uKb2Sgj^N5&{3R+k<5Aos!j=MN_tI+T=mYwpTbw$@NE|A<4sHFf;cZ! zIFoXg3SK129E7Sv_3+laQExD9QnDOQQEcHO3ceQ^Ua3ZLPd{{A!`BTjcj5*@t6~%c`_xh5s$8ic+rG5IMDqm-Xbz zj%LHN)#|m~htcWRHlEYQ)*UZdw!A>6D#{_^GP4>9NfRMP#vk%or#kh7nFo*sD^5}b zi$o{**zvolgfy+} z#R=T8f)`RjJu+{IZcJ%~KtG7js2T-SHJ$GVFO8PDei@tuFN4$#z}*7g4F?&&6>GNM z-+>Al3ZFh}K~7jjo}?wFjIj0*J*OsZ0mVvG8}xe!f6--<&ua3OwS5x`Vl3ow{2@`0 z6pFFupRl$Wnjqx4lRMoCpLsG6pBGk1ok|*esF8)Lv$eb!r- Date: Sat, 6 May 2017 20:05:59 -0400 Subject: [PATCH 4/6] slight cosmetic changes --- templates/sampleimages.html | 79 +++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/templates/sampleimages.html b/templates/sampleimages.html index 60b30eb..f8ee2ee 100644 --- a/templates/sampleimages.html +++ b/templates/sampleimages.html @@ -105,49 +105,52 @@


+
+

Sample Images

+ {% if sample.images %} +

Sample Images

@@ -152,35 +158,6 @@

Sample Images

- - -

Subsamples{% if auth_token %}Add Subsample{% endif %}

@@ -218,21 +195,7 @@

Subsamples{% if auth_token %}