From a20e6a5b2877e5b74c5cb66fb8b071b2b043b47d Mon Sep 17 00:00:00 2001 From: cnscwong Date: Sat, 13 Jan 2024 10:05:39 -0500 Subject: [PATCH] Added review page --- functions/get-dealership.js | 2 +- server/db.sqlite3 | Bin 143360 -> 143360 bytes server/djangoapp/restapis.py | 2 +- .../templates/djangoapp/add_review.html | 54 +++++++++++++++++- .../templates/djangoapp/dealer_details.html | 54 +++++++++++++++++- server/djangoapp/views.py | 44 ++++++++------ 6 files changed, 131 insertions(+), 25 deletions(-) diff --git a/functions/get-dealership.js b/functions/get-dealership.js index 52ae09f5c4..300e70899e 100644 --- a/functions/get-dealership.js +++ b/functions/get-dealership.js @@ -44,7 +44,7 @@ app.get('/dealerships/get', (req, res) => { const queryOptions = { selector, - limit: 10, // Limit the number of documents returned to 10 + limit: 20, // Limit the number of documents returned to 10 }; db.find(queryOptions, (err, body) => { diff --git a/server/db.sqlite3 b/server/db.sqlite3 index 1969354de6a722793436f101ddaa2cd5a5c558c7..40ae7ad7c188acc25de2fd62a5cdc48e9c734c4b 100644 GIT binary patch delta 661 zcmaiyyKdTG7>04&N>LgL<#u#j47HHEY zTbrR{r|eP0zy);Z)*A>zlpEbcB&ddc-WKE5s<~xjS zgkk7+x?mDT?NKkG=cZLt8p~myQ%hYuJ1J*5y;QElfDj~83M*!X$m>)dms@R@3pC16 z_N#GrVv0rxkGdUcZhmdY^CYvKIxutfzxor7us?Za2b%qyUAnh?q8W(X&Q-_)s zz>=Dl(q6ef5Dnv~$VIj-63wb4dxe?Vb5!d9WCXE7D0XSkhhj5tHEJ+y0p2wH6!7G3 ziAj|^M2jzaa+Fs?CeUUR&klG{Qwj$TYt1ut(Jb|aDbGqxDI^J!#tDFvaQAO{Bn??= zvT;v}ILn8wW78vdqLWT{lpHw5(Cq{vG=rmQr%mV-af2;ZQ<30gIyhC=`(zgM48KMP z<$)6N_D~qTQM+0rasx$qEDJf4xP>KC43%JL3MP}w%P%jGEfhPAVQXxKoi3laAF$jr zR6_0=4E-It%Xi~=eZE?sBhO#|Vw}aWYwRm_wtTSojJ?`HIpmhtpI^GE1O3nWAMK6R J^$%o+_z8=-(Om!l delta 118 zcmV-+0Ez#A;0S==2#^~Aa*-TE0dlcm&TbDdI65*mIxsaZG%`0gF*UP2Z^s}A0S?;$ z4%-d2v4N`%0s$tmfg%C3+ny-_2mue=01w;`x3dv|t`7kvk%1wD+^@IXuK_4P2mue` Y01x61!?O{9x(@*#kwF``;{O32Ff}qL)&Kwi diff --git a/server/djangoapp/restapis.py b/server/djangoapp/restapis.py index f6e2a40714..db3c975ed3 100644 --- a/server/djangoapp/restapis.py +++ b/server/djangoapp/restapis.py @@ -74,7 +74,7 @@ def analyze_review_sentiments(text): authenticator = IAMAuthenticator(api_key) natural_language_understanding = NaturalLanguageUnderstandingV1(version='2021-08-01',authenticator=authenticator) natural_language_understanding.set_service_url(url) - response = natural_language_understanding.analyze( text=text,features=Features(sentiment=SentimentOptions(targets=[text]))).get_result() + response = natural_language_understanding.analyze( text=text + "hello hello hello",features=Features(sentiment=SentimentOptions(targets=[text + "hello hello hello"]))).get_result() label=json.dumps(response, indent=2) label = response['sentiment']['document']['label'] diff --git a/server/djangoapp/templates/djangoapp/add_review.html b/server/djangoapp/templates/djangoapp/add_review.html index 768ddf508c..f4a2244510 100644 --- a/server/djangoapp/templates/djangoapp/add_review.html +++ b/server/djangoapp/templates/djangoapp/add_review.html @@ -11,6 +11,58 @@ - + + +

Add Review

+
+ {% csrf_token %} +
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
\ No newline at end of file diff --git a/server/djangoapp/templates/djangoapp/dealer_details.html b/server/djangoapp/templates/djangoapp/dealer_details.html index 4cf4ad700e..e316ec20ab 100644 --- a/server/djangoapp/templates/djangoapp/dealer_details.html +++ b/server/djangoapp/templates/djangoapp/dealer_details.html @@ -9,9 +9,57 @@ - - - + +

Reviews

+
+ {% for review in reviews %} +
+ {% if review.sentiment == 'positive' %} + + {% elif review.sentiment == 'negative' %} + + {% else %} + + {% endif %} +
+
{{review.car_model}}, {{review.car_make}}
+
{{review.car_year}}
+

{{review.review}}

+
+
+ {% endfor %} +
diff --git a/server/djangoapp/views.py b/server/djangoapp/views.py index 2e003d7e6f..fc6ab7352c 100644 --- a/server/djangoapp/views.py +++ b/server/djangoapp/views.py @@ -90,28 +90,34 @@ def get_dealer_details(request, dealer_id): if request.method == "GET": url = f"https://cncw18-5000.theiadockernext-0-labs-prod-theiak8s-4-tor01.proxy.cognitiveclass.ai/api/get_reviews?id={dealer_id}" reviews = get_dealer_reviews_from_cf(url) - text = ' '.join([f"{review.review}: {review.sentiment}" for review in reviews]) - return HttpResponse(text) + context["dealer_id"] = dealer_id + context["reviews"] = reviews + return render(request, 'djangoapp/dealer_details.html', context) def add_review(request, dealer_id): if request.user.is_authenticated: - url = "https://cncw18-5000.theiadockernext-0-labs-prod-theiak8s-4-tor01.proxy.cognitiveclass.ai/api/post_review" - review = { - "id": 1114, - "name": "Upkar Lidder", - "dealership": dealer_id, - "review": "Great service!", - "purchase": False, - "another": "field", - "purchase_date": "02/16/2021", - "car_make": "Audi", - "car_model": "Car", - "car_year": 2021 - } - json_payload = {} - json_payload["review"] = review - res = post_request(url, json_payload, dealerId=dealer_id) - return HttpResponse(res["message"]) + if request.method == "GET": + context = {} + context["dealer_id"] = dealer_id + return render(request, 'djangoapp/add_review.html', context) + elif request.method == "POST": + url = "https://cncw18-5000.theiadockernext-0-labs-prod-theiak8s-4-tor01.proxy.cognitiveclass.ai/api/post_review" + review = { + "id": 1114, + "name": "Upkar Lidder", + "dealership": dealer_id, + "review": "Great service!", + "purchase": False, + "another": "field", + "purchase_date": "02/16/2021", + "car_make": "Audi", + "car_model": "Car", + "car_year": 2021 + } + json_payload = {} + json_payload["review"] = review + res = post_request(url, json_payload, dealerId=dealer_id) + return HttpResponse(res["message"]) else: context = {} context['message'] = "You must be logged in to post a review"