Skip to content
Merged
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
5 changes: 4 additions & 1 deletion AppStore/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@

urlpatterns = [
path('admin/', admin.site.urls),
path('', app.views.index, name='index'),
##path('', app.views.index, name='index'),
path('add', app.views.add, name='add'),
path('view/<str:id>', app.views.view, name='view'),
path('edit/<str:id>', app.views.edit, name='edit'),
path('login/<str:id>', app.views.login, name='login'),
path('index_products/<str:id>', app.views.index_products, name='products'),
path('', app.views.purchase, name='purchase'),
]
Binary file added app/static/app/images.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 0 additions & 10 deletions app/templates/app/Login.html

This file was deleted.

34 changes: 34 additions & 0 deletions app/templates/app/index_products.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% load static %}
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Products Listing</title>
</head>
<body>
<img src="{% static 'app/images/images.png' %}" width="10%" alt="App Logo"/><br/>
<h2>The Makan Network</h2>
<a href="add">Register</a>
<br/>
<a href="login">Login</a>
<br/><br/>
<table border=1>
<thead>
<th>ID</th>
<th>Product Name</th>
<th>Price</th>
<th>Description</th>
</thead>
{% for product in product %}
<tr>
<td> {{ product.5 }} </td>
<td> {{ product.0 }} </td>
<td> {{ product.1 }} </td>
<td> {{ product.2 }} </td>
<td>
<a href="purchase/{{ product.5 }}"><button>purchase</button></a>
</td>
<tr>
{% endfor %}
</table>
</body>
</html>
2 changes: 1 addition & 1 deletion app/templates/app/index_user_admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<body>
<h2>Customers in the App Store</h2>
<img src="{% static 'app/images/nus.jpg' %}" width="10%" alt="NUS logo"/><br/>
<a href="add">New customer</a>
<a href="add">New User</a>
<br/><br/>
<table border=1>
<thead>
Expand Down
26 changes: 26 additions & 0 deletions app/templates/app/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% load static %}
<html>
<head>
<meta charset="UTF-8">
<title>Login</title>
</head>
<body>
<img src="{% static 'app/images/images.png' %}" width="10%" alt="App Logo"/><br/>
<h2>Login</h2>
<a href="/index_product">Back to home</a>
<a href="/add">Register</a>

<p style="color:red">{{ status|safe }}</p>
<!-- Create a Form -->
<form method="POST">
<!-- Security token by Django -->
{% csrf_token %}
<!-- form -->
<div id="div_id_user_id" class="control-group"> <label for="id_user_id" class="control-label requiredField">
User Id<span class="asteriskField">*</span> </label> <div class="controls"> <input type="text" name="User Id" maxlength="64" class="textinput textInput" required="" id="id_user_id"> </div> </div> <div id="div_id_password" class="control-group"> <label for="id_password" class="control-label requiredField">
Password<span class="asteriskField">*</span> </label> <div class="controls"> <input type="text" name="Password" maxlength="64" class="textinput textInput" required="" id="id_password"> </div> </div>
<br>
<button type="submit" value="Login">login</button>
</form>
</body>
</html>
8 changes: 4 additions & 4 deletions app/templates/app/new_user.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ <h2>New User</h2>
<!-- Security token by Django -->
{% csrf_token %}
<!-- form -->
<div id="div_id_first_name" class="control-group"> <label for="id_first_name" class="control-label requiredField">
First name<span class="asteriskField">*</span> </label> <div class="controls"> <input type="text" name="first_name" maxlength="64" class="textinput textInput" required="" id="id_first_name"> </div> </div> <div id="div_id_last_name" class="control-group"> <label for="id_last_name" class="control-label requiredField">
Last name<span class="asteriskField">*</span> </label> <div class="controls"> <input type="text" name="last_name" maxlength="64" class="textinput textInput" required="" id="id_last_name"> </div> </div> <div id="div_id_email" class="control-group"> <label for="id_email" class="control-label requiredField">
Email<span class="asteriskField">*</span> </label> <div class="controls"> <input type="text" name="email" maxlength="64" class="textinput textInput" required="" id="id_email"> </div> </div> <div id="div_id_dob" class="control-group"> <label for="id_dob" class="control-label requiredField">
<div id="div_id_user_id" class="control-group"> <label for="id_user_id" class="control-label requiredField">
User Id<span class="asteriskField">*</span> </label> <div class="controls"> <input type="text" name="User Id" maxlength="64" class="textinput textInput" required="" id="id_user_id"> </div> </div> <div id="div_id_password" class="control-group"> <label for="id_password" class="control-label requiredField">
Password<span class="asteriskField">*</span> </label> <div class="controls"> <input type="text" name="Password" maxlength="64" class="textinput textInput" required="" id="id_password"> </div> </div> <div id="div_id_phone_num" class="control-group"> <label for="id_phone_num" class="control-label requiredField">
Phone number<span class="asteriskField">*</span> </label> <div class="controls"> <input type="text" name="Phone Number" maxlength="64" class="textinput textInput" required="" id="id_phone_num"> </div> </div> <div id="div_id_dob" class="control-group"> <label for="id_dob" class="control-label requiredField">
Date of birth (yyyy-mm-dd)<span class="asteriskField">*</span> </label> <div class="controls"> <input type="text" name="dob" class="dateinput" required="" id="id_dob"> </div> </div> <div id="div_id_since" class="control-group"> <label for="id_since" class="control-label requiredField">
Since (yyyy-mm-dd)<span class="asteriskField">*</span> </label> <div class="controls"> <input type="text" name="since" class="dateinput" required="" id="id_since"> </div> </div> <div id="div_id_customerid" class="control-group"> <label for="id_customerid" class="control-label requiredField">
Customerid<span class="asteriskField">*</span> </label> <div class="controls"> <input type="text" name="customerid" maxlength="16" class="textinput textInput" required="" id="id_customerid"> </div> </div> <div id="div_id_country" class="control-group"> <label for="id_country" class="control-label requiredField">
Expand Down
42 changes: 42 additions & 0 deletions app/templates/app/purchase.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Purchase</title>
</head>
<body>
<table border=1>
<thead>
<th>ID</th>
<th>Product Name</th>
<th>Allergen Notice</th>
<th>Price</th>
<th>Description</th>
<th>Category</th>
<th>Min Orders</th>
</thead>
{% for cust in records %}
<tr>
<td> {{ cust.5 }} </td>
<td> {{ cust.0 }} </td>
<td> {{ cust.1 }} </td>
<td> {{ cust.2 }} </td>
<td> {{ cust.3 }} </td>
<td> {{ cust.4 }} </td>
<td> {{ cust.6 }} </td>
<td>
<p style="color:red">{{ status|safe }}</p>
<!-- Create a Form -->
<form method="POST">
<!-- Security token by Django -->
{% csrf_token %}
<!-- form -->
<div id="div_id_quantity" class="control-group"> <label for="id_quantity" class="control-label requiredField">
Quantity<span class="asteriskField">*</span> </label> <div class="controls"> <input type="text" name="Quantity" maxlength="64" class="textinput textInput" required="" id="id_quantity"> </div> </div>
</form>
</td>
</tr>
</table>
<br>
<button type="submit" value="Buy">Buy</button>
</body>
</html>
52 changes: 51 additions & 1 deletion app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,54 @@ def edit(request, id):
context["obj"] = obj
context["status"] = status

return render(request, "app/edit_admin.html", context)
return render(request, "app/edit_admin.html", context)

# Create your views here.
def login(request):
"""Shows the login page"""
context = {}
status = ''

if request.POST:
## Check if customerid is already in the table
with connection.cursor() as cursor:

cursor.execute("SELECT * FROM customers WHERE customerid = %s", [request.POST['customerid']])
customer = cursor.fetchone()
## No customer with same id
if customer == None:
##TODO: date validation
cursor.execute("INSERT INTO customers VALUES (%s, %s, %s, %s, %s, %s, %s)"
, [request.POST['first_name'], request.POST['last_name'], request.POST['email'],
request.POST['dob'] , request.POST['since'], request.POST['customerid'], request.POST['country'] ])
return redirect('index')
else:
status = 'Your User Id and Password is incorrect' % (request.POST['customerid'])

return render(request, 'app/login.html', context)


# Create your views here.
def index_products(request):
"""Shows the product listing page"""

## Use raw query to get all objects
with connection.cursor() as cursor:
cursor.execute("SELECT * FROM product_listings ORDER BY productid")
customers = cursor.fetchall()

result_dict = {'records': product_listings}

return render(request, 'app/index_products.html', result_dict)

def purchase(request):
"""Shows the main page"""

## Use raw query to get all objects
with connection.cursor() as cursor:
cursor.execute("SELECT * FROM customers ORDER BY customerid")
customers = cursor.fetchall()

result_dict = {'records': customers}

return render(request, 'app/purchase.html', result_dict)