Fakultas Ilmu Komputer UI

Skip to content
Snippets Groups Projects
Commit e608c764 authored by Abdul Mughni Wibisono's avatar Abdul Mughni Wibisono
Browse files

Finish create function

parent 08540e8d
Branches
No related tags found
1 merge request!33Finish create function
......@@ -6,15 +6,19 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>Food Ingredient Form</h1>
{% csrf_token %}
<form>
<div>
<label>Food Ingredient Name: </label>
<input type="text">
</div>
<button type="submit">Save</button>
</form>
<div>
<h2>Food Ingredient Form</h2>
<form action="" method="POST">
{% csrf_token %}
<ul>
<li>
<label for="ingredient_name"> Food Ingredient Name: </label>
<input type="text" name="ingredient_name" id="ingredient_name" required>
</li>
</ul>
<button type="submit">Save</button>
</form>
</div>
</body>
</html>
{% endblock %}
\ No newline at end of file
{% extends 'restaurant_base.html' %}
{% extends 'admin_base.html' %}
{% block content %}
<head>
<meta charset="UTF-8">
......@@ -21,14 +21,10 @@
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ i.0 }}</td>
<td><a href = 'delete_ingredient/{{ i.0 }}'><button>Delete</button></a></td>
<!-- <td>
<form method="POST" action="{% url 'delete_ingredient' i.0 %}">
{% csrf_token %}
<button type="submit">Delete</button>
</form>
<td>
<a href = 'delete_ingredient/{{ i.0 }}'><button>Delete</button></a>
</td> -->
</td>
</tr>
{% endfor %}
</table>
......
from django.db import connection
from django.shortcuts import render, redirect
import random, string
def create_ingredient(request):
context = {}
with connection.cursor() as cursor:
cursor.execute("SET SEARCH_PATH TO SIREST")
cursor.execute("""
SELECT name
FROM INGREDIENT
ORDER BY name DESC
""")
ingredient = int(cursor.fetchone()[0]) + 1
context["name"] = ingredient
if request.method == "POST":
name = request.POST.get("name")
random_id = "".join(('I' + random.choice(string.digits)))
ingredient_name = request.POST.get("ingredient_name")
cursor.execute(f"""
INSERT INTO INGREDIENT VALUES
('{name}')
""")
return redirect("/ingredient/")
INSERT INTO INGREDIENT VALUES
('{random_id}', '{ingredient_name}')
""")
return render(request, 'c_ingredient.html', context)
return redirect("/ingredient/")
return render(request, "c_ingredient.html", context)
def read_ingredient(request):
context = {}
......@@ -37,11 +35,27 @@ def read_ingredient(request):
return render(request, 'r_ingredient.html', context)
# def delete_ingredient(request):
# name = request.session["name"]
# with connection.cursor() as cursor:
# cursor.execute("SET SEARCH_PATH TO SIREST")
# cursor.execute(f"""
# DELETE FROM INGREDIENT
# WHERE name = '{name}'""")
# return redirect(f"/ingredient/")
def delete_ingredient(request):
name = request.session["name"]
context = {}
nama = request.session["nama"]
with connection.cursor() as cursor:
cursor.execute("SET SEARCH_PATH TO SIREST")
cursor.execute(f"""
DELETE FROM INGREDIENT
WHERE name = '{name}'""")
return redirect(f"/ingredient/")
\ No newline at end of file
if request.method == "POST":
cursor.execute(f"""
DELETE FROM INGREDIENT
WHERE name = '{nama}'
""")
return redirect("/ingredient/")
return render(request, "r_ingredient.html", context)
\ No newline at end of file
......@@ -12,14 +12,13 @@
{% csrf_token %}
<ul>
<li>
<label for="category">Restaurant Category: </label>
<input type="text" name="category" id="category" required>
<label for="category_name">Restaurant Category: </label>
<input type="text" name="category_name" id="category_name" required>
</li>
</ul>
<button type="submit">Save</button>
</form>
</div>
</body>
</html>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% extends 'admin_base.html' %}
{% block content %}
<head>
<meta charset="UTF-8">
......
from django.db import connection
from django.shortcuts import render, redirect
import random, string
def create_restaurant_category(request):
context = {}
with connection.cursor() as cursor:
cursor.execute("SET SEARCH_PATH TO SIREST")
cursor.execute("""
SELECT name
FROM RESTAURANT_CATEGORY
ORDER BY name DESC
""")
category = int(cursor.fetchone()[0]) + 1
context["name"] = category
if request.method == "POST":
name = request.POST.get("name")
random_id = "".join(('RC' + random.choice(string.digits)))
category_name = request.POST.get("category_name")
cursor.execute(f"""
INSERT INTO RESTAURANT_CATEGORY VALUES
('{name}')
""")
return redirect("/r_restaurant_category/")
INSERT INTO RESTAURANT_CATEGORY VALUES
('{random_id}', '{category_name}')
""")
return redirect("/restaurant_category/")
return render(request, "c_restaurant_category.html", context)
def read_restaurant_category(request):
......@@ -38,10 +36,25 @@ def read_restaurant_category(request):
return render(request, "r_restaurant_category.html", context)
def delete_restaurant_category(request):
name = request.session["name"]
context = {}
name = request.session["nama"]
with connection.cursor() as cursor:
cursor.execute("SET SEARCH_PATH TO SIREST")
cursor.execute(f"""
DELETE FROM RESTAURANT_CATEGORY
WHERE name = '{name}'""")
return redirect(f"/restaurant_category/")
\ No newline at end of file
cursor.execute("""
SELECT DISTINCT RC.Id
FROM RESTAURANT_CATEGORY RC, RESTAURANT R
WHERE RC.Id= R.RCategory
""")
reffered_id = cursor.fetchall()
context["reffered_id"] = reffered_id
if request.method == "POST":
cursor.execute(f"""
DELETE FROM RESTAURANT_CATEGORY
WHERE name = '{name}'
""")
return redirect(f"/restaurant_category/")
return render(request, 'read_restaurant_category.html', context)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment