Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/push-cf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
ibmcloud config --check-version=false
shell: bash
- name: Install CF plugin
run: ibmcloud cf install -f
run: ibmcloud install -f
shell: bash
- name: Log into IBM Cloud
run: |
Expand All @@ -39,8 +39,8 @@ jobs:
run: ibmcloud target --cf-api https://api.$IBM_CLOUD_REGION.cf.cloud.ibm.com -r $IBM_CLOUD_REGION -o $IBM_CLOUD_ORG -s $IBM_CLOUD_SPACE
shell: bash
- name: List all applications
run: ibmcloud cf apps
run: ibmcloud apps
shell: bash
- name: Deploy manifest file
run: ibmcloud cf push -f ./$MANIFEST_NAME
run: ibmcloud push -f ./$MANIFEST_NAME
shell: bash
22 changes: 22 additions & 0 deletions server/djangoapp/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,25 @@
# CarMakeAdmin class with CarModelInline

# Register models here

from django.contrib import admin
from .models import CarMake, CarModel

# Register your models here.

# CarModelInline class
class CarModelInline(admin.StackedInline):
model = CarModel

# CarModelAdmin class
class CarModelAdmin(admin.ModelAdmin):
list_display = ('name',)

# CarMakeAdmin class with CarModelInline
class CarMakeAdmin(admin.ModelAdmin):
inlines = [CarModelInline]
list_display = ('name',)

# Register models here
admin.site.register(CarMake, CarMakeAdmin)
admin.site.register(CarModel, CarModelAdmin)
55 changes: 40 additions & 15 deletions server/djangoapp/models.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,52 @@
from django.db import models
from django.utils.timezone import now


# Create your models here.

# <HINT> Create a Car Make model `class CarMake(models.Model)`:
# - Name
# - Description
# - Any other fields you would like to include in car make model
# - __str__ method to print a car make object
class CarMake(models.Model):
name = models.CharField(max_length=30)
description = models.CharField(max_length=300)

def __str__(self):
return self.name

# <HINT> Create a Car Model model `class CarModel(models.Model):`:
# - Many-To-One relationship to Car Make model (One Car Make has many Car Models, using ForeignKey field)
# - Name
# - Dealer id, used to refer a dealer created in cloudant database
# - Type (CharField with a choices argument to provide limited choices such as Sedan, SUV, WAGON, etc.)
# - Year (DateField)
# - Any other fields you would like to include in car model
# - __str__ method to print a car make object
class CarModel(models.Model):
car_make = models.ForeignKey(CarMake, on_delete=models.CASCADE)
name = models.CharField(max_length=30)
type_c = models.CharField(max_length=10, choices=(('Sedan', 'Sedan',), ('SUV', 'SUV'), ('HATCHBACK', 'HATCHBACK'),('WAGON', 'WAGON')))
dealer_id = models.IntegerField()
year = models.DateField()

def __str__(self):
return self.name

# <HINT> Create a plain Python class `CarDealer` to hold dealer data

# <HINT> Create a plain Python class `CarDealer` to hold dealer data
class CarDealer:
def __init__(self, address, city, full_name, id, lat, long, short_name, st, zip):
self.address = address
self.city = city
self.full_name = full_name
self.id = id
self.lat = lat
self.long = long
self.short_name = short_name
self.st = st
self.zip = zip

def __str__(self):
return "Dealer name: " + self.full_name

# <HINT> Create a plain Python class `DealerReview` to hold review data
class DealerReview:
def __init__(self, dealership, name, purchase, review, purchase_date, car_make, car_model, car_year, sentiment, id):
self.dealership = dealership
self.name = name
self.purchase = purchase
self.review = review
self.purchase_date = purchase_date
self.car_make = car_make
self.car_model = car_model
self.car_year = car_year
self.sentiment = sentiment
self.id = id
95 changes: 89 additions & 6 deletions server/djangoapp/restapis.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,117 @@
import requests
import os
import json
# import related models here
from .models import CarDealer, DealerReview
from requests.auth import HTTPBasicAuth


# Create a `get_request` to make HTTP GET requests
# e.g., response = requests.get(url, params=params, headers={'Content-Type': 'application/json'},
# auth=HTTPBasicAuth('apikey', api_key))
def get_request(url, **kwargs):
print(kwargs)
print("GET from {} ".format(url))
try:
# Call get method of requests library with URL and parameters
response = requests.get(
url, headers={'Content-Type': 'application/json'}, params=kwargs)
except:
# If any error occurs
print("Network exception occurred")
status_code = response.status_code
print("With status {} ".format(status_code))
json_data = json.loads(response.text)
return json_data


# Create a `post_request` to make HTTP POST requests
# e.g., response = requests.post(url, params=kwargs, json=payload)
def post_request(url, json_payload, **kwargs):
print("Payload: ", json_payload, ". Params: ", kwargs)
print(f"POST {url}")
try:
response = requests.post(url, headers={'Content-Type': 'application/json'},
json=json_payload, params=kwargs)
except:
# If any error occurs
print("Network exception occurred")
status_code = response.status_code
print("With status {} ".format(status_code))
json_data = json.loads(response.text)
return json_data


# Create a get_dealers_from_cf method to get dealers from a cloud function
# def get_dealers_from_cf(url, **kwargs):
# - Call get_request() with specified arguments
# - Parse JSON results into a CarDealer object list

def get_dealers_from_cf(url, **kwargs):
results = []
# Call get_request with a URL parameter
json_result = get_request(url)
if json_result:
# Get the row list in JSON as dealers
dealers = json_result["entries"]
# For each dealer object
for dealer_doc in dealers:
# Create a CarDealer object with values in `doc` object
dealer_obj = CarDealer(
address=dealer_doc["address"],
city=dealer_doc["city"],
full_name=dealer_doc["full_name"],
id=dealer_doc["id"],
lat=dealer_doc["lat"],
long=dealer_doc["long"],
short_name=dealer_doc["short_name"],
st=dealer_doc["st"],
zip=dealer_doc["zip"],
)
results.append(dealer_obj)
return results

# Create a get_dealer_reviews_from_cf method to get reviews by dealer id from a cloud function
# def get_dealer_by_id_from_cf(url, dealerId):
# - Call get_request() with specified arguments
# - Parse JSON results into a DealerView object list


def get_dealer_reviews_from_cf(url, dealerId):
results = []
# Call get_request with a URL parameter
json_result = get_request(url)
if json_result:
# Get the row list in JSON as dealers
reviews = json_result["entries"]
# For each dealer object
for review_doc in reviews:
# Create a CarDealer object with values in `doc` object
review_obj = DealerReview(
dealership=review_doc["dealership"],
name=review_doc["name"],
purchase=review_doc["purchase"],
review=review_doc["review"],
purchase_date=review_doc["purchase_date"],
car_make=review_doc["car_make"],
car_model=review_doc["car_model"],
car_year=review_doc["car_year"],
sentiment=analyze_review_sentiments(review_doc["review"]),
id=review_doc["id"],
)
results.append(review_obj)
return results


# Create an `analyze_review_sentiments` method to call Watson NLU and analyze text
# def analyze_review_sentiments(text):
# - Call get_request() with specified arguments
# - Get the returned sentiment label such as Positive or Negative



def analyze_review_sentiments(text):
URL = 'https://api.us-east.natural-language-understanding.watson.cloud.ibm.com/instances/4c1dae76-d689-45e0-8340-f55e03dccfc0'
API_KEY = os.getenv('NLU_API_KEY')
params = json.dumps({"text": text, "features": {"sentiment": {}}})
response = requests.post(
URL, data=params, headers={'Content-Type': 'application/json'}, auth=HTTPBasicAuth('apikey', API_KEY)
)
try:
return response.json()['sentiment']['document']['label']
except KeyError:
return 'neutral'
33 changes: 33 additions & 0 deletions server/djangoapp/templates/djangoapp/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>Dealership Review</title>
<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>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link href="https://unpkg.com/[email protected]/dist/bootstrap-table.min.css" rel="stylesheet">
<script src="https://unpkg.com/[email protected]/dist/bootstrap-table.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/extensions/filter-control/bootstrap-table-filter-control.min.js"></script>

</head>

<body>
<nav class="navbar navbar-light bg-light">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="{% url 'djangoapp:about' %}">About Us</a>
<a class="navbar-brand" href="{% url 'djangoapp:contact' %}">Contact Us</a>
</div>

</div>
</nav>

<p class="lead mt-5 text-center">
Welcome to Best Cars dealership, home to the best cars in North America. We sell domestic and imported cars at reasonable prices.
</p>
</body>

</html>
45 changes: 41 additions & 4 deletions server/djangoapp/templates/djangoapp/add_review.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,53 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
{% load static %}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/css/bootstrap-datepicker.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/css/bootstrap-datepicker.css"
rel="stylesheet">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/js/bootstrap-datepicker.js"></script>

</head>
<body>

<body>
<!--Add review form here -->
</body>
</html>
<div class="container">
<form action="/djangoapp/dealer/{{dealer.id}}/add_review" method="post">
{% csrf_token %}
<div class="form-group">
<label for="content">Enter the review content:</label>
<textarea class="form-control" id="content" name="content" rows="2" required></textarea>
</div>
<div class="form-group form-check">
<input class="form-check-input" type="checkbox" name="purchasecheck" id="purchasecheck">
<label for="purchasecheck">Has purchased the car from {{dealer.full_name}}? (select purchased car
information below if checked)</label>
</div>
<div class="form-group">
<label for="car">Select your car (model-make-year):</label>
<select name="car" id="car" class="form-select" required>
{% for car in cars %}
<option selected value={{car.id}}>{{car.name}}-{{car.car_make.name}}-{{ car.year|date:"Y" }}
</option>
{% endfor %}
</select>
</div>
<div class="form-group" data-provide="datepicker">
<label for="purchasedate">Select your purchase date:</label>
<input class="form-control" type="text" name="purchasedate" id="purchasedate">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</body>
<script type="text/javascript">
$('.date-own').datepicker({
format: 'mm/dd/yyyy'
});
</script>

</html>
41 changes: 41 additions & 0 deletions server/djangoapp/templates/djangoapp/contact.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>Dealership Review</title>
<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>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link href="https://unpkg.com/[email protected]/dist/bootstrap-table.min.css" rel="stylesheet">
<script src="https://unpkg.com/[email protected]/dist/bootstrap-table.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/extensions/filter-control/bootstrap-table-filter-control.min.js"></script>

</head>

<body>
<nav class="navbar navbar-light bg-light">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="{% url 'djangoapp:about' %}">About Us</a>
<a class="navbar-brand" href="{% url 'djangoapp:contact' %}">Contact Us</a>
</div>

</div>
</nav>
<div class="container">
<p class="mt-5 h1 text-center">
Contacts information
</p>
<div class="mt-5 h1 text-center">
<ul><b>Phone No:</b> 555 555 5555</ul>
<ul><b>Email:</b>
<a text="[email protected]">[email protected]</a>
</ul>
<ul><b>Personel:</b><a>Tyler</a></ul>
</div>
</div>
</body>

</html>
Loading