Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

static pages #133

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
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
3 changes: 0 additions & 3 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ jobs: # list of things to do
uses: actions/setup-node@v3
with:
node-version: 16

- name: Code Checkout
uses: actions/checkout@v3

- name: Install Dependencies
run: npm install
working-directory: functions/sample/nodejs

- name: Code Linting
run: npm run lint
working-directory: functions/sample/nodejs
Expand Down
Binary file added server/db.sqlite3
Binary file not shown.
11 changes: 10 additions & 1 deletion server/djangoapp/admin.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
from django.contrib import admin
# from .models import related models
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)
77 changes: 64 additions & 13 deletions server/djangoapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,75 @@

# 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
# Create a Car Make model
class CarMake(models.Model):
name = models.CharField(max_length=50)
description = models.CharField(max_length=500)

def __str__(self):
return self.name + ": " + self.description



# <HINT> Create a Car Model model
class CarModel(models.Model):
car_make = models.ForeignKey(CarMake, on_delete=models.CASCADE)
name = models.CharField(max_length=50)
dealer_id = models.IntegerField()
car_type = models.CharField(max_length=20, choices=(('SEDAN', 'SEDAN',), ('SUV', 'SUV'), ('HATCHBACK', 'HATCHBACK'),('WAGON', 'WAGON'),('MINIVAN', 'MINIVAN')))
year = models.DateField()

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


# <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):
# Dealer address
self.address = address
# Dealer city
self.city = city
# Dealer Full Name
self.full_name = full_name
# Dealer id
self.id = id
# Location lat
self.lat = lat
# Location long
self.long = long
# Dealer short name
self.short_name = short_name
# Dealer state
self.st = st
# Dealer zip
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):
# Required attributes
self.dealership = dealership
self.name = name
self.purchase = purchase
self.review = review
# Optional attributes
self.purchase_date = ""
self.car_make = ""
self.car_model = ""
self.car_year = ""
self.sentiment = ""
self.id = ""

def __str__(self):
return "Review: " + self.review

def to_json(self):
return json.dumps(self, default=lambda o: o.__dict__,
sort_keys=True, indent=4)
103 changes: 100 additions & 3 deletions server/djangoapp/restapis.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,125 @@
import requests
import json
# import related models here
from .models import CarDealer
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):
api_key = kwargs.get("api_key")
print("GET from {} ".format(url))
try:
if api_key:
params = dict()
params["text"] = kwargs["text"]
params["version"] = kwargs["version"]
params["features"] = kwargs["features"]
params["return_analyzed_text"] = kwargs["return_analyzed_text"]
requests.get(url, params=params, headers={'Content-Type': 'application/json'},
auth=HTTPBasicAuth('apikey', api_key))
else:
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, payload, **kwargs):
print(kwargs)
print("POST to {} ".format(url))
print(payload)
response = requests.post(url, params=kwargs, json=payload)
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["rows"]
# For each dealer object
for dealer in dealers:
# Get its content in `doc` object
dealer_doc = dealer["doc"]
# 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

def get_dealer_by_id_from_cf(url, id):
result = {}
# Call get_request with a URL parameter
json_result = get_request(url, did=id)
if json_result:
# Get the row list in JSON as dealers
dealers = json_result["rows"]
# For each dealer object
dealer = dealers[0]
# Create a CarDealer object with values in `doc` object
dealer_obj = CarDealer(address=dealer["address"], city=dealer["city"], full_name=dealer["full_name"],
id=dealer["id"], lat=dealer["lat"], long=dealer["long"],
short_name=dealer["short_name"],
st=dealer["st"], zip=dealer["zip"])
result = dealer_obj
return result

def get_dealers_by_state_from_cf(url, state, **kwargs):
results = []
# Call get_request with a URL parameter
json_result = get_request(url, state=state)
if json_result:
# Get the row list in JSON as dealers
dealers = json_result["rows"]
# For each dealer object
for dealer in dealers:
dealer_doc = dealer["doc"]
# 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, id):
results = []
# Call get_request with a URL parameter
json_result = get_request(url, did=id)
if json_result:
# Get the row list in JSON as dealers
reviews = json_result["rows"]
# For each dealer object
for review in reviews:
# Create a CarDealer object with values in `doc` object
review_obj = DealerReview(id=review["id"], dealership=review["dealership"], name=review["name"], purchase=review["purchase"],
review=review["review"], purchase_date=review["purchase_date"], car_make=review["car_make"],
car_model=review["car_model"], car_year=review["car_year"], sentiment="")
review_obj.sentiment = analyze_review_sentiments(review_obj.review)
results.append(review_obj)
return results


# Create an `analyze_review_sentiments` method to call Watson NLU and analyze text
Expand Down
49 changes: 49 additions & 0 deletions server/djangoapp/templates/djangoapp/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!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>
<!--Add a nav bar here -->
<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>
<a class="navbar-brand" href="{% url 'djangoapp:index' %}">Dealerships</a>
</div>
<ul class="nav navbar-nav navbar-right">
{% if user.is_authenticated %}
<li>
<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 %}
<li>
<form class="form-inline" action="{% url 'djangoapp:login' %}" method="post">
{% csrf_token %}
<div class="input-group">
<input type="text" class="form-control" placeholder="Username" name="username" >
<input type="password" class="form-control" placeholder="Password" name="psw" >
<button class="btn btn-primary" type="submit">Login</button>
<a class="btn btn-link" href="{% url 'djangoapp:registration' %}">Sign Up</a>
</div>
</form>
</li>
{% endif %}
</ul>
</div>
</nav>
<h1>
Welcome to Best Cars dealership, home to the best cars in North America. We sell domestic and imported cars at reasonable prices.
</h1>
</body>
</html>
55 changes: 55 additions & 0 deletions server/djangoapp/templates/djangoapp/contact.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!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>
<a class="navbar-brand" href="{% url 'djangoapp:index' %}">Dealerships</a>
</div>
<ul class="nav navbar-nav navbar-right">
{% if user.is_authenticated %}
<li>
<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 %}
<li>
<form class="form-inline" action="{% url 'djangoapp:login' %}" method="post">
{% csrf_token %}
<div class="input-group">
<input type="text" class="form-control" placeholder="Username" name="username" >
<input type="password" class="form-control" placeholder="Password" name="psw" >
<button class="btn btn-primary" type="submit">Login</button>
<a class="btn btn-link" href="{% url 'djangoapp:registration' %}">Sign Up</a>
</div>
</form>
</li>
{% endif %}
</ul>
</div>
</nav>
<div class="container">
<p class="contact center">
Contact information
</p>
<div class="contact center">
<ul><b>Phone No:</b> 555 834 6626</ul>
<ul><b>Email:</b> [email protected]"</ul>
<ul><b>Address:</b>1818 West Way Ct.</ul>
</div>
</div>
</body>
</html>
Loading