Skip to content

Commit

Permalink
Containerized the app and Updated UI
Browse files Browse the repository at this point in the history
  • Loading branch information
gokhanduzel committed Dec 16, 2023
1 parent 1e43372 commit f3e6c40
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 63 deletions.
28 changes: 28 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM python:3.8.2

ENV PYTHONBUFFERED 1
ENV PYTHONWRITEBYTECODE 1

RUN apt-get update \
&& apt-get install -y netcat

ENV APP=/app

# Change the workdir.
WORKDIR $APP

# Install the requirements
COPY requirements.txt $APP

RUN pip3 install -r requirements.txt

# Copy the rest of the files
COPY . $APP

EXPOSE 8000

RUN chmod +x /app/entrypoint.sh

ENTRYPOINT ["/bin/bash","/app/entrypoint.sh"]

CMD ["gunicorn", "--bind", ":8000", "--workers", "3", "djangobackend.wsgi"]
29 changes: 29 additions & 0 deletions server/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
run: dealership
name: dealership
spec:
replicas: 1
selector:
matchLabels:
run: dealership
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
run: dealership
spec:
containers:
- image: us.icr.io/sn-labs-gduzel/dealership:latest
imagePullPolicy: Always
name: dealership
ports:
- containerPort: 8000
protocol: TCP
restartPolicy: Always
17 changes: 11 additions & 6 deletions server/djangoapp/restapis.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ def get_dealer_by_id_from_cf(url, dealer_id):
# Create a get_dealer_reviews_from_cf method to get reviews by dealer id from a cloud function
# - Call get_request() with specified arguments
# - Parse JSON results into a DealerView object list
def get_dealer_reviews_from_cf(url, id):
def get_dealer_reviews_from_cf(url, dealer_id):
results = []
json_result = get_request(url, id=id)
json_result = get_request(url, id=dealer_id)
print(json_result)

if isinstance(json_result, list):
Expand Down Expand Up @@ -172,9 +172,14 @@ def analyze_review_sentiments(dealerreview):
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=dealerreview,features=Features(sentiment=SentimentOptions(targets=[dealerreview]))).get_result()
label=json.dumps(response, indent=2)
label = response['sentiment']['document']['label']
try:
response = natural_language_understanding.analyze( text=dealerreview,features=Features(sentiment=SentimentOptions(targets=[dealerreview]))).get_result()
label=json.dumps(response, indent=2)
label = response['sentiment']['document']['label']

return(label)

return(label)
except:
print("Can't analyze the sentiment")
return 'none'

55 changes: 45 additions & 10 deletions server/djangoapp/templates/djangoapp/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,57 @@
<head>
<meta charset="UTF-8">
<title>About Us</title>
{% load static %}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
</head>

<body>
<section class="container my-5">
<div class="row">
<div class="col-lg-8 mx-auto">
<!--NAVBAR-->
<nav class="navbar navbar-expand-sm navbar-dark bg-dark">
<a class="navbar-brand" href="{% url 'djangoapp:index' %}">Best Cars</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExample04" aria-controls="navbarsExample04" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarsExample04">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="{% url 'djangoapp:about' %}">About Us <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'djangoapp:contact' %}">Contact Us <span class="sr-only">(current)</span></a>
</li>
</ul>
{% if user.is_authenticated %}
<li class="my-2 my-md-0">
<a class="btn btn-link" href="#">{{ user.first_name }}({{ user.username }})</a>
<a class="btn btn-link" href="{% url 'djangoapp:logout' %}">Logout</a>
</li>
{% else %}
<form class="form-inline my-2 my-md-0" action="{% url 'djangoapp:login' %}" method="post">
{% csrf_token %}
<div class="form-group">
<input type="text" class="form-control-sm" placeholder="Username" name="username" >
<input type="password" class="form-control-sm" placeholder="Password" name="psw" >
<button class="btn-sm btn-primary" type="submit">Login</button>
<a class="btn-sm btn-link" href="{% url 'djangoapp:registration' %}">Sign Up</a>
</div>
</form>
{% endif %}
</div>
</nav>
<section class="container my-5">
<div class="row">
<div class="col-lg-8 mx-auto">
<h2 class="text-center mb-4">About Best Cars</h2>
<div class="card" style="width: 36rem;">
<p>Welcome to Best Cars dealership,</p>
<p>home to the best cars in North America</p>
<p>and soon in Canada. We sell domestic and</p>
<p>imported cars at reasonable pricessssss.</p>
<div class="card">
<div class="card-body">
<p class="card-text">Welcome to Best Cars dealership, home to the best cars in North America and soon in Canada.</p>
<p class="card-text">We sell domestic and imported cars at reasonable prices.</p>
</div>
</div>
</div>
</div>
</section>
</div>
</section>
</body>
</html>
8 changes: 4 additions & 4 deletions server/djangoapp/templates/djangoapp/add_review.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ <h3 class="mb-5 mt-3">Add Review for <strong> {{dealer.full_name}} </strong> </h
{% csrf_token %}
<div class="form-group">
<h5>Enter your review here:</h5>
<textarea class="form-control my-2" id="content" name="content" rows="2" required></textarea>
<textarea class="form-control" id="content" name="content" rows="2" required></textarea>
</div>
<div class = "form-check mt-5">
<div class = "form-check mt-3">
<input class="form-check-input" type="checkbox" name="purchasecheck" id="purchasecheck">
<label class="form-check-label">Has purchased car from {{dealer.full_name}} ?</label> <span style="color: gray; font-weight: 300; padding-left: 5px;">(select purchased car information below if checked)</span>
</div>
<div class="form-group">
<div class="form-group mt-3">
<h5 class="my-2">Select your car (Model-Make-Year):</h5>
<select name="car" id="car" class="form-select my-2 mx-2" required>
<select name="car" id="car" class="form-select my-2" required>
{% for car in cars %}
<option selected value={{car.id}}>{{car.name}}-{{car.car_make.name}}-{{ car.year|date:"Y" }}</option>
{% endfor %}
Expand Down
67 changes: 60 additions & 7 deletions server/djangoapp/templates/djangoapp/contact.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,71 @@
<head>
<meta charset="UTF-8">
<title>Contact Us</title>
{% load static %}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
</head>

<body>
<section class="container my-5">
<div class="row">
<div class="col-lg-8 mx-auto">
<!--NAVBAR-->
<nav class="navbar navbar-expand-sm navbar-dark bg-dark">
<a class="navbar-brand" href="{% url 'djangoapp:index' %}">Best Cars</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExample04" aria-controls="navbarsExample04" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarsExample04">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="{% url 'djangoapp:about' %}">About Us <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'djangoapp:contact' %}">Contact Us <span class="sr-only">(current)</span></a>
</li>
</ul>
{% if user.is_authenticated %}
<li class="my-2 my-md-0">
<a class="btn btn-link" href="#">{{ user.first_name }}({{ user.username }})</a>
<a class="btn btn-link" href="{% url 'djangoapp:logout' %}">Logout</a>
</li>
{% else %}
<form class="form-inline my-2 my-md-0" action="{% url 'djangoapp:login' %}" method="post">
{% csrf_token %}
<div class="form-group">
<input type="text" class="form-control-sm" placeholder="Username" name="username" >
<input type="password" class="form-control-sm" placeholder="Password" name="psw" >
<button class="btn-sm btn-primary" type="submit">Login</button>
<a class="btn-sm btn-link" href="{% url 'djangoapp:registration' %}">Sign Up</a>
</div>
</form>
{% endif %}
</div>
</nav>
<section class="container my-5">
<div class="row">
<div class="col-lg-8 mx-auto">
<h2 class="text-center mb-4">Contact Us</h2>
<h5>Phone number: +1 234 567 8910</h5>
<address>Some street number, in the middle of somewhere.</address>
</div>
<div class="row">
<div class="col-md-6">
<h5>Phone number:</h5>
<p>+1 234 567 8910</p>
</div>
<div class="col-md-6">
<h5>Email:</h5>
<p>[email protected]</p>
</div>
</div>
<div class="row">
<div class="col-md-6">
<h5>Address:</h5>
<address>Some street number, in the middle of somewhere.</address>
</div>
<div class="col-md-6">
<h5>Business Hours:</h5>
<p>Monday to Friday: 9 AM - 5 PM<br>Saturday: 10 AM - 2 PM</p>
</div>
</div>
</div>
</section>
</div>
</section>
</body>
</html>
27 changes: 14 additions & 13 deletions server/djangoapp/templates/djangoapp/dealer_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
<body>
<!--NAVBAR-->
<nav class="navbar navbar-expand-sm navbar-dark bg-dark">
<a class="navbar-brand" href="#">Best Cars</a>
<a class="navbar-brand" href="{% url 'djangoapp:index' %}">Best Cars</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExample04" aria-controls="navbarsExample04" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarsExample04">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="about/">About Us <span class="sr-only">(current)</span></a>
<a class="nav-link" href="{% url 'djangoapp:about' %}">About Us <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="contact/">Contact Us <span class="sr-only">(current)</span></a>
<a class="nav-link" href="{% url 'djangoapp:contact' %}">Contact Us <span class="sr-only">(current)</span></a>
</li>
</ul>
{% if user.is_authenticated %}
Expand All @@ -37,7 +37,7 @@
<input type="text" class="form-control-sm" placeholder="Username" name="username" >
<input type="password" class="form-control-sm" placeholder="Password" name="psw" >
<button class="btn-sm btn-primary" type="submit">Login</button>
<a class="btn-sm btn-link" href="registration/">Sign Up</a>
<a class="btn-sm btn-link" href="{% url 'djangoapp:registration' %}">Sign Up</a>
</div>
</form>
{% endif %}
Expand All @@ -54,22 +54,23 @@ <h3> Reviews for <strong> {{ dealer.full_name }} </strong> </h3>
{% for review in reviews_list %}
<div class="card text-dark bg-light mb-3 text-left">
{% if review.sentiment == "positive" %}
<img class="card-img-left" src="{{MEDIA_URL}}/emoji/positive.png" style="height: 70px; width: 70px;"/>
<img class="card-img-top" src="{{MEDIA_URL}}/emoji/positive.png" style="height: 70px; width: 70px;"/>
{% elif review.sentiment == "neutral" %}
<img class="card-img-left" src="{{MEDIA_URL}}/emoji/neutral.png" style="height: 70px; width: 70px;"/>
<img class="card-img-top" src="{{MEDIA_URL}}/emoji/neutral.png" style="height: 70px; width: 70px;"/>
{% elif review.sentiment == "negative" %}
<img class="card-img-left" src="{{MEDIA_URL}}/emoji/negative.png" style="height: 70px; width: 70px;"/>
<img class="card-img-top" src="{{MEDIA_URL}}/emoji/negative.png" style="height: 70px; width: 70px;"/>
{% else %}
<img class="card-img-left" src="{{MEDIA_URL}}/emoji/neutral.png" style="height: 70px; width: 70px;"/>
<img class="card-img-top" src="{{MEDIA_URL}}/emoji/neutral.png" style="height: 70px; width: 70px;"/>
{% endif %}

<div class="card-body bg-light">
<h6 class="card-title">Username: {{review.name}}</h5>
{% if review.purchase %}
<h5 class="card-title">{{review.car_make}}</h5>
<h5 class="card-title">{{review.car_model}}</h5>
<h5 class="card-title">{{review.purchase_date}}</h5>
<h5 class="card-title">Make: {{review.car_make}}</h5>
<h5 class="card-title">Model: {{review.car_model}}</h5>
<h5 class="card-title">Review: {{review.purchase_date}}</h5>
{% else %}
<h5 class="card-title">Reviewer did not buy any car</h5>
<h6 class="card-title">Reviewer did not buy any car</h5>
{% endif %}
<label class="card-title">{{review.review}}</label>
</div>
Expand All @@ -88,4 +89,4 @@ <h5 class="card-title">No reviews yet</h5>
</div>
</body>

</html>
</html>
11 changes: 6 additions & 5 deletions server/djangoapp/templates/djangoapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8">
<title>Dealership Review</title>
{% load static %}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
Expand All @@ -16,24 +17,24 @@
<body>
<!--NAVBAR-->
<nav class="navbar navbar-expand-sm navbar-dark bg-dark">
<a class="navbar-brand" href="#">Best Cars</a>
<a class="navbar-brand" href="{% url 'djangoapp:index' %}">Best Cars</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExample04" aria-controls="navbarsExample04" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarsExample04">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="about/">About Us <span class="sr-only">(current)</span></a>
<a class="nav-link" href="{% url 'djangoapp:about' %}">About Us <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="contact/">Contact Us <span class="sr-only">(current)</span></a>
<a class="nav-link" href="{% url 'djangoapp:contact' %}">Contact Us <span class="sr-only">(current)</span></a>
</li>
</ul>
{% if user.is_authenticated %}
<li class="my-2 my-md-0">
<a class="btn btn-link" href="#">{{ user.first_name }}({{ user.username }})</a>
<a class="btn btn-link" href="logout/">Logout</a>
<a class="btn btn-link" href="{% url 'djangoapp:logout' %}">Logout</a>
</li>
{% else %}
<form class="form-inline my-2 my-md-0" action="{% url 'djangoapp:login' %}" method="post">
Expand All @@ -42,7 +43,7 @@
<input type="text" class="form-control-sm" placeholder="Username" name="username" >
<input type="password" class="form-control-sm" placeholder="Password" name="psw" >
<button class="btn-sm btn-primary" type="submit">Login</button>
<a class="btn-sm btn-link" href="registration/">Sign Up</a>
<a class="btn-sm btn-link" href="{% url 'djangoapp:registration' %}">Sign Up</a>
</div>
</form>
{% endif %}
Expand Down
Loading

0 comments on commit f3e6c40

Please sign in to comment.