From 8d630bd3511da86bf0ef688119b594b0b3267b9e Mon Sep 17 00:00:00 2001 From: Rupika Date: Wed, 13 Feb 2019 16:24:17 -0800 Subject: [PATCH 1/8] hardcoded dummy json input and updated section --- back/backend/views.py | 74 +++++++++++++++++++++++++++++++++++------- back/db.sqlite3 | Bin 105472 -> 105472 bytes 2 files changed, 63 insertions(+), 11 deletions(-) diff --git a/back/backend/views.py b/back/backend/views.py index fa17a1b..f180169 100644 --- a/back/backend/views.py +++ b/back/backend/views.py @@ -3,6 +3,7 @@ from django.http import JsonResponse from .models import * from .policy import pol import os +# import json # function that prints all the reports @@ -57,7 +58,8 @@ def get_fields(s_id): "label": i.label, "type": i.type, "number": i.number, - "value": value + "value": value, + "id": i.id, } # append the fields to array # use copy() to avoid overwriting @@ -154,14 +156,64 @@ def report_detail(request, report_pk): # update a section with new data @api_view(['PUT']) def section(request, report_pk, section_pk): - data = { - "message": "Updated report {0}, section {1}.".format(report_pk, section_pk), - "fields": { - "international": True, - "travel_date": "2012-04-23T18:25:43.511Z", - "fare": "1024.99", - "lowest_fare_screenshot": "image", - } - } + json_input = { + "fields": [ + { + "id": 178, + "value": "2016-05-22", + "type": "date" + }, + { + "id": 179, + "value": "2016-05-22", + "type": "date" + }, + { + "id": 180, + "value": 3.14, + "type": "decimal" + }, + { + "id": 181, + "value": 10000, + "type": "integer" + }, + { + "id": 182, + "value": True, + "type": "boolean" + }, + ] +} - return JsonResponse(data) + ''' + 1) decode JSON object into dictionaries + 2) iterate through fields (for loop)? + 3) in each iteration, check for data type + 4) in the datatype, update the database + 4a) update = field_set.get(id=request.data.id) + 4b) update.data_type = request.data["value"] + ''' + + # print("request data: {}".format(type(request.body))) + # json.loads() + + for v in json_input["fields"]: + update_field = Field.objects.get(id=v["id"]) + + if v["type"] == "boolean": + update_field.data_bool = v["value"] + if v["type"] == "decimal": + update_field.data_decimal = v["value"] + if v["type"] == "date": + update_field.data_date = v["value"] + if v["type"] == "file": + update_field.data_file = v["value"] + if v["type"] == "string": + update_field.data_string = v["value"] + if v["type"] == "integer": + update_field.data_integer = v["value"] + + update_field.save() + + return JsonResponse({"message": "Updated report {0}, section {1}.".format(report_pk, section_pk)}) diff --git a/back/db.sqlite3 b/back/db.sqlite3 index 894a6e76b6ba52528ec81376750c7f6dad32f04f..50db6ebfb3d28517a933f8650b2430a921d3e424 100644 GIT binary patch delta 1858 zcma)6eQZ-z6u;-*ZhhU>!U!9LvaJYYtFY4d`rY9Kf)28_iwP1w9NSy_I?J}U>pC|y z5#IO+F~Z88@foHdhA8MXgNN-z9dY76V1fokAqFyH03o7(A!ZT1uib#CiT-iVueax% z-#uUNY#YhnHjW2|Rt&>NyugV3($C@t{lr+qkM$FK{2it^bs3{@DV~M0uYABT9 zlybfB*1}?&iL-gFR;4{s!Mj14M*F_4x1tn_7Nz4Z1wn~F3KDPBN86^jU|Fip81&DhqHw zA{}Ht`GKs$7jZwy;1l>B8Bk12085+G3(X6NA6mPU9_tnd8;%7d(QsSG=APEB2p{k4 z;M&@HI)j~h)kr#X!K8ejHs_UPdCwwpl^iCYlQ5|wbwr16lAZW09#V?u?#0s3XhnHB zSq@X-aju8DZnwMKR^_MB*~NNFMUWT44&=pS6050FoL{|+mELb_!H`p05VGJg=%q@N zV)>>Xv~@*!{vBn@rOu2gb9om$0?OEh31&sOMesO70?*l6c)P%cgLb#a)56*u4iC%Q zS(n4ghg=@cIu#Q8@E}q%yIcA5%0*K3e|e7osOe=ifD+hINt%l)rzg*S+?*&!d=15I*c2TWk6PdanJ zL5!vKvNZ}NV9Xqe!g^RlIj5mI1dT9*oF@Hb4bjk!9>7s-hr4hbT}6AS+Kg->C-3V5 zqr9ve2C=0>jwfKI{AMeZXdS^=S8{cW{8|iE*#NUE)$&sPRJ0)>&L?QVLbitL z=M3a1B1h?pI7qZ>#K#S&4dfU5z%y?u!iU(^#$Le8nd}Wp|0*wG;?{s%IGw4oY!IV rvNnslSzONaE1=bs5t^GoPmrF_OUhaP1h_|ORkHD2@xgGw)&Ww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YnI?@M@2=;a+;m_S{R4OIn{}qe2~$w%+q1jr4;#XjZYEKBCe*?9DwrN8g-> zJ(cXK9Sz4?DH~FD3LHNlQ3|1I1->CB zj-}$O^!*>I^5DfIC!^1&axb46|@K8g%qwQe2rLD;to~pM7r|KtL8e1K#)C!@2hJN-u z6>6;K!}5)b<+A&C>*VIQTjdK^^|?}8byunV`t2~&s9jC+Sk|PR`TbT{o&yzES%S79 z@;Z5v>}K`nH~Hhd1>S`hpcOReGD Date: Wed, 13 Feb 2019 17:06:58 -0800 Subject: [PATCH 2/8] successfully updates section from the request.data -- dummy JSON in postman --- back/backend/views.py | 45 +----------------------------------------- back/db.sqlite3 | Bin 105472 -> 105472 bytes 2 files changed, 1 insertion(+), 44 deletions(-) diff --git a/back/backend/views.py b/back/backend/views.py index f180169..8cf55ae 100644 --- a/back/backend/views.py +++ b/back/backend/views.py @@ -3,7 +3,6 @@ from django.http import JsonResponse from .models import * from .policy import pol import os -# import json # function that prints all the reports @@ -156,49 +155,7 @@ def report_detail(request, report_pk): # update a section with new data @api_view(['PUT']) def section(request, report_pk, section_pk): - json_input = { - "fields": [ - { - "id": 178, - "value": "2016-05-22", - "type": "date" - }, - { - "id": 179, - "value": "2016-05-22", - "type": "date" - }, - { - "id": 180, - "value": 3.14, - "type": "decimal" - }, - { - "id": 181, - "value": 10000, - "type": "integer" - }, - { - "id": 182, - "value": True, - "type": "boolean" - }, - ] -} - - ''' - 1) decode JSON object into dictionaries - 2) iterate through fields (for loop)? - 3) in each iteration, check for data type - 4) in the datatype, update the database - 4a) update = field_set.get(id=request.data.id) - 4b) update.data_type = request.data["value"] - ''' - - # print("request data: {}".format(type(request.body))) - # json.loads() - - for v in json_input["fields"]: + for v in request.data["fields"]: update_field = Field.objects.get(id=v["id"]) if v["type"] == "boolean": diff --git a/back/db.sqlite3 b/back/db.sqlite3 index 50db6ebfb3d28517a933f8650b2430a921d3e424..9f8e18213a65a0090e546a253ad442f235486114 100644 GIT binary patch delta 243 zcmZqJ!Pc;YZGtr8$%!(~j3*ltwk9wxtX5@UVBlwnXJFpST*2(b%*J$!A)cv|$)8D> z@fzb2#$rYthKCHZCQh{Ew`erwV^C$3=HOsZOp)z|R;z!6zrNGQTXfsMw{^ zZn{nlqxJNHdd86Lnl+5EjO>1mW_%33jMMK$GHOkKSj(tjtl4P7#~=zah688}2cxK4 zVo@qnN@{XuZeos+fuW_YfswAEkxv>>*s{@>k3o}j`u!+I35Arzl2k)WOQ5`|u91;X lN@_u3QAuf0YCK57xY20(#9~HS7LbbR@pX)|mNhWS000_JLc0I} delta 266 zcmZqJ!Pc;YZGtr8hKVxHj2jvgwk9wxtkz&`W8i1dWMEpyRLEq_e1z#A6C>jWMju82 zhRX~K844IQnJbx%8f_T1>(nyFGO{rJWYC)4TgRxz<=1G&$KcB-&A~bSVI-sa^j&p~ z3jF4crhE*lKtT=$MP6Q}>3KDb3ViAUJ~@e%`DLj^#m0?B(XulP%9N6toSB=LeL)9*(yO30=pmZSnzo9P;u>KYmOq@)%k7L}A1rN)CK JmNhWS004J4N2LG& From 11b1de72b37ac76081f6c4a767071bd99e95b3b6 Mon Sep 17 00:00:00 2001 From: Rupika Date: Wed, 13 Feb 2019 17:41:28 -0800 Subject: [PATCH 3/8] revamped update logic -- updated dummy JSON to mirror a full report --- back/backend/views.py | 36 +++++++++++++++++++++--------------- back/db.sqlite3 | Bin 105472 -> 105472 bytes 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/back/backend/views.py b/back/backend/views.py index 8cf55ae..dc6b826 100644 --- a/back/backend/views.py +++ b/back/backend/views.py @@ -155,22 +155,28 @@ def report_detail(request, report_pk): # update a section with new data @api_view(['PUT']) def section(request, report_pk, section_pk): - for v in request.data["fields"]: - update_field = Field.objects.get(id=v["id"]) + # first enter sections + for s in request.data["sections"]: + # check for match + if s["id"] == section_pk: + # begin updating fields + for v in s["fields"]: + update_field = Field.objects.get(id=v["id"]) - if v["type"] == "boolean": - update_field.data_bool = v["value"] - if v["type"] == "decimal": - update_field.data_decimal = v["value"] - if v["type"] == "date": - update_field.data_date = v["value"] - if v["type"] == "file": - update_field.data_file = v["value"] - if v["type"] == "string": - update_field.data_string = v["value"] - if v["type"] == "integer": - update_field.data_integer = v["value"] + if v["type"] == "boolean": + update_field.data_bool = v["value"] + if v["type"] == "decimal": + update_field.data_decimal = v["value"] + if v["type"] == "date": + update_field.data_date = v["value"] + if v["type"] == "file": + update_field.data_file = v["value"] + if v["type"] == "string": + update_field.data_string = v["value"] + if v["type"] == "integer": + update_field.data_integer = v["value"] - update_field.save() + update_field.save() return JsonResponse({"message": "Updated report {0}, section {1}.".format(report_pk, section_pk)}) + diff --git a/back/db.sqlite3 b/back/db.sqlite3 index 9f8e18213a65a0090e546a253ad442f235486114..648001700c0d381b0ad43a87bef2d24c7ed8b0ce 100644 GIT binary patch delta 233 zcmZqJ!Pc;YZGtr8xrs8)jOQ8?wk9wxtgdJ3WZ-AeW@O&VT*2(b%*LS2kifK+$)8D> z@fzb2#$rYthKCHZ7(l?V(S(mdlu??4gI$rAmxEE%EwLz-DJ3;IGdD5Efm3cr;Oka- zBLhQAT>~RsLnEIwkhFQDDIbF>ND~846BDCsNKs;5ab}4^d17V>b7tQ3`Wi-lCUt@B z6KfcMFtPxx(V5;`$Ed;O*J#Ga;0x5qIsIWIqx$q+b&Lw^mW{@I44RzN??*98aHJ%b Xqynuoo32~WXvzX&ZBMIboFxMQ$!a?N delta 197 zcmZqJ!Pc;YZGtr8$%!(~j3*ltwk9wxtX5@UVBlwnXJFpST*2(b%*J$!A)cv|$)8D> z@fzb2#$rYthKCHZCL6L?@>?{T@-e6~N^@{9DDv_$PtUJmRA6R|pRj#m4dV|+7QaR_ zzUjSnj2hDyL^HBZe^$q+V653_!p9&A(!v4M!oeu&mROX^l#-g9nVXnnWMF8iYha{n tXylUy6t-+M=3~(0oPIxwQGz2Su_V>d($aFeZat$Z3y8Hnt)6j~3;^% Date: Wed, 13 Feb 2019 17:43:23 -0800 Subject: [PATCH 4/8] commiting db changes --- back/db.sqlite3 | Bin 105472 -> 105472 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/back/db.sqlite3 b/back/db.sqlite3 index 648001700c0d381b0ad43a87bef2d24c7ed8b0ce..df59c2b7ffeddee4709975fee7c6e2c65907d874 100644 GIT binary patch delta 172 zcmZqJ!Pc;YZGtrK1qKF&bSP$>sA0}{VPnFQ^&Cvh-++P)W}A67{9u;gWZJ^OoXf1t ze23YC=_d1brY%hWm?tq$+N{9g$Fw$5NP66Vi?GiH> HUoZmzpQA9B delta 172 zcmZqJ!Pc;YZGtrKIR*xXbSP$-sA0}{Zezld^&HI1AAy1lNt<~#{9u;gV(MpL&Sh3+ zzQgRnbd#x{c{|eTJ;Hj9;+i|O=c_C0^)IT)F@Gca#w&f6>~lf*nZ z@BTEP$Q1_WE6mG*BD0w%FMk}%!^r%bf%!M{SD+0RK+&hno4-C6+91db Date: Wed, 13 Feb 2019 21:07:53 -0800 Subject: [PATCH 5/8] successfully updates all fields given front end data. PENDING 1) need to tweak DB to accommodate NULL dates 2) insert file logic --- back/backend/views.py | 71 +++++++++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 20 deletions(-) diff --git a/back/backend/views.py b/back/backend/views.py index 140be94..3e256ed 100644 --- a/back/backend/views.py +++ b/back/backend/views.py @@ -155,28 +155,59 @@ def report_detail(request, report_pk): # update a section with new data @api_view(['PUT']) def section(request, report_pk, section_pk): - # first enter sections - for s in request.data["sections"]: - # check for match - if s["id"] == section_pk: - # begin updating fields - for v in s["fields"]: - update_field = Field.objects.get(id=v["id"]) - if v["type"] == "boolean": - update_field.data_bool = v["value"] - if v["type"] == "decimal": - update_field.data_decimal = v["value"] - if v["type"] == "date": - update_field.data_date = v["value"] - if v["type"] == "file": - update_field.data_file = v["value"] - if v["type"] == "string": - update_field.data_string = v["value"] - if v["type"] == "integer": - update_field.data_integer = v["value"] + for key in request.data: + update_field = Field.objects.get(section_id=section_pk, field_name=key) + + if update_field.type == "boolean": + # flight check + if request.data[key] == "on": + update_field.data_bool = True + elif request.data[key] == "off": + update_field.data_bool = False + # everything else + else: + update_field.data_bool = request.data[key] + + if update_field.type == "decimal": + # initialize to 0 + if ( + request.data[key] == "" or + request.data[key] is None + ): + update_field.data_decimal = 0.0 + else: + update_field.data_decimal = request.data[key] + + if update_field.type == "date": + # initialize to today's date + if ( + request.data[key] == "" or + request.data[key] is None + ): + update_field.data_date = datetime.date.today() + # update_field.data_date = None + else: + update_field.data_date = request.data[key] + + if update_field.type == "file": + update_field.data_file = request.data[key] + + if update_field.type == "string": + update_field.data_string = request.data[key] + + if update_field.type == "integer": + # initialize to 0 + if ( + request.data[key] == "" or + request.data[key] is None + ): + update_field.data_integer = 0 + else: + update_field.data_integer = request.data[key] + + update_field.save() - update_field.save() data = { "message": "Updated report {0}, section {1}.".format(report_pk, section_pk), "request.data": request.data From 614f7102bab4e07a5944cd7999303c3b36318059 Mon Sep 17 00:00:00 2001 From: Rupika Date: Wed, 13 Feb 2019 21:17:31 -0800 Subject: [PATCH 6/8] altered data_date to accommodate null date values --- back/backend/models.py | 2 +- back/backend/views.py | 4 ++-- back/db.sqlite3 | Bin 105472 -> 106496 bytes 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/back/backend/models.py b/back/backend/models.py index 557020f..0348d0c 100644 --- a/back/backend/models.py +++ b/back/backend/models.py @@ -34,7 +34,7 @@ class Field(models.Model): completed = models.BooleanField(default=False) data_bool = models.BooleanField(default=False) data_decimal = models.DecimalField(max_digits=9, decimal_places=2, null=True, blank=True) - data_date = models.DateField(default=datetime.date.today) + data_date = models.DateField(null=True, blank=True) data_file = models.FileField(upload_to='uploads/%Y/%m/%d/', max_length=512, null=True, blank=True) data_string = models.TextField(default='', blank=True) data_integer = models.IntegerField(default=0, blank=True) diff --git a/back/backend/views.py b/back/backend/views.py index 3e256ed..ec863ff 100644 --- a/back/backend/views.py +++ b/back/backend/views.py @@ -185,8 +185,8 @@ def section(request, report_pk, section_pk): request.data[key] == "" or request.data[key] is None ): - update_field.data_date = datetime.date.today() - # update_field.data_date = None + # update_field.data_date = datetime.date.today() + update_field.data_date = None else: update_field.data_date = request.data[key] diff --git a/back/db.sqlite3 b/back/db.sqlite3 index df59c2b7ffeddee4709975fee7c6e2c65907d874..7dace4032a417b0a1763b4a3f159693785d3aa2b 100644 GIT binary patch delta 4338 zcmeHK?N3uz7(eG8XbY5zI3x;43u-C0<=)%U(kjaqssk-BsZ7L|dTFmxDXo^`Vxra? zaW5`0vTJhVKDlLCG+8pU#!37#&HS_vZgJVNeK6Uw%q820nJn?cX0n~r-oD)S7W@Nj za!$C1^E}Tvzw`W_mvc*+b9XhDTUI{=08HZ%!b5|{;-b}|e+X=k>#FhBDs*dcrUQM4 zZij`+DQe%Wcng`Ru^I74WYtsXDc%S6qJPoTbVJo+WW`?_H{hw$P*2?ldg{8C zdVqdMXV56((Pp$2Rihi!b?P^C2i-|CdX5s$*K(Tn4b5mkCoOJ=En;=uCHO$RQn%UC zxDJ`ADK0d_$HKuQ5k49QUt-nklxx9YJpF5(b3tsm+=@=4lWEsw9}?dZ$F&Em5ro|b z(m#my`x=Pu0dz0Dy7e~N(cfMTTDHC_tEOq%73AiV@gPex9-3twL6%`0!j^8>tUUqdVB~_1#W8(!2ghL5WrvHAbN%|T0nwvR-9bA)`mBH+RQNUoth*! z73GN~VQpO7JZ^?UzsN1Qqy-L6*0jd7&1N%v`%Q8EwRSiqe)G{QQhn+B%&(2Ok-%b1{u9a~6V%GfSQdiEHAr6wn7ktO5v z$&9G2NEEM?$_5O;t!t63HkqW=`(SIzmcZr;2E1d~K>lbJlaD{nC6eyzZ%%xC1CGb5o}9Euy-yGwxt5tLlwcclz=^05o}8( zuwQ!~u)8u~W9l3gdhyKjcnZIPC-NiAn!sZckArv|#)HFytZl-B{L+2;FJSG$vfOPi z=dN*N-0!!L*wFy?OWFx|=mlS2@HLZSXt(DDUn>R2EMK!Rvk)8!k5&N&;5yZla#9AO;nbh)&r$SfH-l~_l+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ed, 18 insertions(+) create mode 100644 back/backend/migrations/0006_auto_20190213_2113.py diff --git a/back/backend/migrations/0006_auto_20190213_2113.py b/back/backend/migrations/0006_auto_20190213_2113.py new file mode 100644 index 0000000..f472fa1 --- /dev/null +++ b/back/backend/migrations/0006_auto_20190213_2113.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.5 on 2019-02-14 05:13 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('backend', '0005_field_field_name'), + ] + + operations = [ + migrations.AlterField( + model_name='field', + name='data_date', + field=models.DateField(blank=True, null=True), + ), + ] From a2deb2b1bd5fec6bbf69c4b3e5203412a8e531c9 Mon Sep 17 00:00:00 2001 From: Rupika Date: Wed, 13 Feb 2019 23:36:29 -0800 Subject: [PATCH 8/8] updated database with field_type --- .../migrations/0007_merge_20190213_2318.py | 14 ++++++ back/backend/views.py | 41 +++++++++--------- back/db.sqlite3 | Bin 105472 -> 105472 bytes 3 files changed, 35 insertions(+), 20 deletions(-) create mode 100644 back/backend/migrations/0007_merge_20190213_2318.py diff --git a/back/backend/migrations/0007_merge_20190213_2318.py b/back/backend/migrations/0007_merge_20190213_2318.py new file mode 100644 index 0000000..aa0cb2c --- /dev/null +++ b/back/backend/migrations/0007_merge_20190213_2318.py @@ -0,0 +1,14 @@ +# Generated by Django 2.1.5 on 2019-02-14 07:18 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('backend', '0006_auto_20190213_1719'), + ('backend', '0006_auto_20190213_2113'), + ] + + operations = [ + ] diff --git a/back/backend/views.py b/back/backend/views.py index 452ee82..04fc6dd 100644 --- a/back/backend/views.py +++ b/back/backend/views.py @@ -157,59 +157,60 @@ def report_detail(request, report_pk): def section(request, report_pk, section_pk): for key in request.data: - update_field = Field.objects.get(section_id=section_pk, field_name=key) + # get the matching field object + update = Field.objects.get(section_id=section_pk, field_name=key) - if update_field.type == "boolean": + if update.field_type == "boolean": # flight check if request.data[key] == "on": - update_field.data_bool = True + update.data_bool = True elif request.data[key] == "off": - update_field.data_bool = False + update.data_bool = False # everything else else: - update_field.data_bool = request.data[key] + update.data_bool = request.data[key] - if update_field.type == "decimal": + if update.field_type == "decimal": # initialize to 0 if ( request.data[key] == "" or request.data[key] is None ): - update_field.data_decimal = 0.0 + update.data_decimal = 0.0 else: - update_field.data_decimal = request.data[key] + update.data_decimal = request.data[key] - if update_field.type == "date": + if update.field_type == "date": # initialize to today's date if ( request.data[key] == "" or request.data[key] is None ): - # update_field.data_date = datetime.date.today() - update_field.data_date = None + update.data_date = None else: - update_field.data_date = request.data[key] + update.data_date = request.data[key] - if update_field.type == "file": - update_field.data_file = request.data[key] + if update.field_type == "file": + update.data_file = request.data[key] - if update_field.type == "string": - update_field.data_string = request.data[key] + if update.field_type == "string": + update.data_string = request.data[key] - if update_field.type == "integer": + if update.field_type == "integer": # initialize to 0 if ( request.data[key] == "" or request.data[key] is None ): - update_field.data_integer = 0 + update.data_integer = 0 else: - update_field.data_integer = request.data[key] + update.data_integer = request.data[key] - update_field.save() + update.save() data = { "message": "Updated report {0}, section {1}.".format(report_pk, section_pk), + "request_data": request.data } return JsonResponse(data) diff --git a/back/db.sqlite3 b/back/db.sqlite3 index 52e2ecd33b88e7002ab103f534d060a875cfa6ab..df940de7c8c054f4ee96162876249a47ea35ec8b 100644 GIT binary patch delta 3457 zcmeHKOHP5Flh?~(#E0T(ZrE$*{B$c8nNi6 zCT$l?+eyffj=Jm*=%&LYuxx%or|Zmg(oM7KHjBRRHL@ky7S2pN(@hpvwyyP^$ES18 z`Mh(~xpUOHH`JFy2<7$Fi9f%(>kZ;f-!IM%eAi3e$5*uU-DZMnTT%}0QxlF(?&Se0 zL2Gv}!O(t(^ERB`zvn#vQvV<&Kw8YKOT}y|CrgEFDy0;%o1Z>$9zJox;M^%;Nv6FMFzRSMbn4? z++1Q!%B=h3BAXResf}EG8GS27?hIt?DuX;-RisBpD%)xW>N7#{UOhI+pa?yrdv$SI z-!crBeI<*7_!aD+7Mh2fmN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