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

changes #148

Open
wants to merge 2 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
Binary file added .github/Open Notebook.onetoc2
Binary file not shown.
Binary file added .github/workflows/Open Notebook.onetoc2
Binary file not shown.
Binary file added Open Notebook.onetoc2
Binary file not shown.
Binary file added cloudant/Open Notebook.onetoc2
Binary file not shown.
Binary file added cloudant/data/Open Notebook.onetoc2
Binary file not shown.
Binary file added functions/Open Notebook.onetoc2
Binary file not shown.
Binary file added functions/sample/Open Notebook.onetoc2
Binary file not shown.
Binary file added functions/sample/nodejs/Open Notebook.onetoc2
Binary file not shown.
Binary file added functions/sample/python/Open Notebook.onetoc2
Binary file not shown.
Binary file added server/Open Notebook.onetoc2
Binary file not shown.
Binary file added server/db.sqlite3
Binary file not shown.
Binary file added server/djangoapp/Open Notebook.onetoc2
Binary file not shown.
Binary file added server/djangoapp/templates/Open Notebook.onetoc2
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions server/djangoapp/templates/djangoapp/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<h1>
Welcome to Best Cars dealership, home to the best cars in North America. We sell domestic and imported cars at reasonable prices.
</h1>
</html>
5 changes: 5 additions & 0 deletions server/djangoapp/templates/djangoapp/contact.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<h1>
Contact Us
</h1>
</html>
79 changes: 79 additions & 0 deletions server/djangoapp/templates/djangoapp/dealer_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,85 @@

<!-- Add reviews as cards -->

<!DOCTYPE html>
<html lang="en">
<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">
</head>

<body>

<!--Add a nav bar here -->
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Dealership Review</a>

<!-- Toggle button for smaller screens -->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ml-auto">
<!-- Conditionally show items based on authentication status -->
{% if user.is_authenticated %}
<li class="nav-item">
<span class="navbar-text">{{ user.first_name|default:user.username }}</span>
</li>
<li class="nav-item">
<form class="form-inline" action="{% url 'djangoapp:logout' %}" method="post">
{% csrf_token %}
<button class="btn btn-outline-danger my-2 my-sm-0" type="submit">Sign Out</button>
</form>
</li>
{% else %}
<li class="nav-item">
<form class="form-inline" action="{% url 'djangoapp:login' %}" method="post">
{% csrf_token %}
<input class="form-control mr-sm-2" type="text" placeholder="Username" name="username">
<input class="form-control mr-sm-2" type="password" placeholder="Password" name="psw">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Login</button>
</form>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'djangoapp:registration' %}">Sign Up</a>
</li>
{% endif %}
</ul>
</div>
</nav>
<!-- Add Dealer Cards
{% if course_list %}
<div class="container"> Style root div with .container class
<div class="card-deck"> Style second div with .card-deck class
{% for course in course_list %}
<div class="card" style="width: 36rem;"> Style third level div with .card class
<img class="card-img-left" src="{{MEDIA_URL}}/{{ course.image }}" width="240px" height="240px"
alt="Course image"> Style card image with .card-img-left class
<div class="card-body bg-light"> Style root div with .card-body and .bg-light class
<h5 class="card-title">{{ course.name }}, <span class="text-success"> Style h5 with .card-title and span with .text-success class
{{ course.total_enrollment}} enrolled</span></h5>
<p class="card-text">{{ course.description}}</p> Style card description with .card-text class
<form action="{% url 'onlinecourse:enroll' course.id %}" method="post">
{% csrf_token %}
<input class="btn btn-primary" type="submit"
value="Enroll"> Style Enroll button with .btn and .btn-primary class
</form>
</div>
</div>
{% endfor %}
</div>
</div>
{% else %}
<p>No courses are available.</p>
{% endif %}-->

</body>

</html>

</body>

</html>
40 changes: 38 additions & 2 deletions server/djangoapp/templates/djangoapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,45 @@
</head>

<body>
<!-- Remove this line the first time you edit this file -->
This is the index page of your Django app!

<!--Add a nav bar here -->
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Dealership Review</a>

<!-- Toggle button for smaller screens -->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ml-auto">
<!-- Conditionally show items based on authentication status -->
{% if user.is_authenticated %}
<li class="nav-item">
<span class="navbar-text">{{ user.first_name|default:user.username }}</span>
</li>
<li class="nav-item">
<form class="form-inline" action="{% url 'djangoapp:logout' %}" method="post">
{% csrf_token %}
<button class="btn btn-outline-danger my-2 my-sm-0" type="submit">Sign Out</button>
</form>
</li>
{% else %}
<li class="nav-item">
<form class="form-inline" action="{% url 'djangoapp:login' %}" method="post">
{% csrf_token %}
<input class="form-control mr-sm-2" type="text" placeholder="Username" name="username">
<input class="form-control mr-sm-2" type="password" placeholder="Password" name="psw">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Login</button>
</form>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'djangoapp:registration' %}">Sign Up</a>
</li>
{% endif %}
</ul>
</div>
</nav>

<!--Add a dealer table here -->

Expand Down
13 changes: 13 additions & 0 deletions server/djangoapp/templates/djangoapp/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<form action="{% url 'djangoapp:login' %}" method="post">
{% csrf_token %}
<div class="container">
<h1>Login</h1>
<label for="username"><b>User Name</b></label>
<input type="text" placeholder="Enter User Name: " name="username" required>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password: " name="psw" required>
<div>
<button class="button" type="submit">Login</button>
</div>
</div>
</form>
19 changes: 18 additions & 1 deletion server/djangoapp/templates/djangoapp/registration.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<!--Add a registration form here -->
<form action="{% url 'djangoapp:registration' %}" method="post">
<div class="container">
<h1>Sign Up</h1>
<hr>
<label for="username"><b>User Name</b></label><br>
<input type="text" placeholder="Enter User Name: " name="username" required><br>
<label for="firstname"><b>First Name</b></label><br>
<input type="text" placeholder="Enter First Name: " name="firstname" required><br>
<label for="lastname"><b>Last Name</b></label><br>
<input type="text" placeholder="Enter Last Name: " name="lastname" required><br>
<label for="psw"><b>Password</b></label><br>
<input type="password" placeholder="Enter Password: " name="psw" required><br>
<div>
{% csrf_token %}
<br><button class="button" type="submit">Sign Up</button>
</div>
</div>
</form>
</body>
</html>
6 changes: 5 additions & 1 deletion server/djangoapp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@
# view refers to the view function
# name the URL

# path for about view
path(route='about/', view=views.about, name='about'),

# path for contact us view
path(route='contact/', view=views.contact, name='contact'),

# path for registration
path('registration/', views.registration_request, name='registration'),

# path for login
path('login/', views.login_request, name='login'),

# path for logout
path('logout/', views.logout_request, name='logout'),

path(route='', view=views.get_dealerships, name='index'),

Expand Down
73 changes: 64 additions & 9 deletions server/djangoapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,79 @@


# Create an `about` view to render a static about page
# def about(request):
# ...
def about(request):
context = {}
if request.method == "GET":
return render(request, 'djangoapp/about.html', context)


# Create a `contact` view to return a static contact page
#def contact(request):
def contact(request):
context = {}
if request.method == "GET":
return render(request, 'djangoapp/contact.html', context)

# Create a `login_request` view to handle sign in request
# def login_request(request):
# ...
def login_request(request):
context = {}
# Handles POST request
if request.method == "POST":
# Get username and password from request.POST dictionary
username = request.POST['username']
password = request.POST['psw']
# Try to check if provide credential can be authenticated
user = authenticate(username=username, password=password)
if user is not None:
# If user is valid, call login method to login current user
login(request, user)
return redirect('djangoapp:index')
else:
# If not, return to login page again
return render(request, 'djangoapp/user_login.html', context)
else:
return render(request, 'djangoapp/user_login.html', context)

# Create a `logout_request` view to handle sign out request
# def logout_request(request):
# ...

def logout_request(request):
# Get the user object based on session id in request
print("Log out the user `{}`".format(request.user.username))
# Logout user in the request
logout(request)
# Redirect user back to course list view
return redirect('djangoapp:index')

# Create a `registration_request` view to handle sign up request
# def registration_request(request):
# ...
def registration_request(request):
context = {}
# If it is a GET request, just render the registration page
if request.method == 'GET':
return render(request, 'djangoapp/registration.html', context)
# If it is a POST request
elif request.method == 'POST':
# Get user information from request.POST
username = request.POST['username']
password = request.POST['psw']
first_name = request.POST['firstname']
last_name = request.POST['lastname']
user_exist = False
try:
# Check if user already exists
User.objects.get(username=username)
user_exist = True
except:
# If not, simply log this is a new user
logger.debug("{} is new user".format(username))
# If it is a new user
if not user_exist:
# Create user in auth_user table
user = User.objects.create_user(username=username, first_name=first_name, last_name=last_name,
password=password)
# Login the user and redirect to course list page
login(request, user)
return redirect("djangoapp:index")
else:
return render(request, 'djangoapp/registration.html', context)

# Update the `get_dealerships` view to render the index page with a list of dealerships
def get_dealerships(request):
Expand Down
Binary file added server/djangobackend/Open Notebook.onetoc2
Binary file not shown.
Binary file added server/static/Open Notebook.onetoc2
Binary file not shown.
Binary file added server/static/admin/Open Notebook.onetoc2
Binary file not shown.
Binary file added server/static/admin/css/Open Notebook.onetoc2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added server/static/admin/fonts/Open Notebook.onetoc2
Binary file not shown.
Binary file added server/static/admin/img/Open Notebook.onetoc2
Binary file not shown.
Binary file added server/static/admin/img/gis/Open Notebook.onetoc2
Binary file not shown.
Binary file added server/static/admin/js/Open Notebook.onetoc2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added server/static/media/Open Notebook.onetoc2
Binary file not shown.
Binary file added server/static/media/emoji/Open Notebook.onetoc2
Binary file not shown.