Skip to content

Commit

Permalink
Creating APIs with the appropriate models
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbilisantosh321 committed Aug 5, 2019
1 parent a431057 commit 0e45a65
Show file tree
Hide file tree
Showing 28 changed files with 1,148 additions and 0 deletions.
8 changes: 8 additions & 0 deletions billing/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.apps import AppConfig


class BillingConfig(AppConfig):
name = 'billing'
9 changes: 9 additions & 0 deletions billing/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.conf.urls import url
from . import views

urlpatterns = [
url(r'^$', views.billinglisting, name="billinglisting"),
url(r'^add$', views.add, name="add"),
url(r'^delete/(?P<id>\w{0,50})/$', views.delete, name="delete"),
url(r'^update/(?P<billingId>\w{0,50})/$', views.update, name="update"),
]
104 changes: 104 additions & 0 deletions billing/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.conf import settings
from django.db.models import Q
from django.core.files.storage import FileSystemStorage
from django.contrib import messages
from django.db import connection


# Create your views here.

def billinglisting(request):
cursor = connection.cursor()
cursor.execute(
"SELECT * FROM billing, booking, room, customer_customer WHERE booking_id = billing_booking_id AND booking_room_id = room_id AND booking_customer_id = customer_id")
billinglist = dictfetchall(cursor)

context = {
"billinglist": billinglist
}

# Message according Billing #
context['heading'] = "Billing Details";
return render(request, 'billing-view.html', context)


def dictfetchall(cursor):
"Return all rows from a cursor as a dict"
columns = [col[0] for col in cursor.description]
return [
dict(zip(columns, row))
for row in cursor.fetchall()
]

def getDropDown(table, condtion):
cursor = connection.cursor()
cursor.execute("SELECT * FROM " + table + " WHERE " + condtion)
dropdownList = dictfetchall(cursor)
return dropdownList;


def getData(id):
cursor = connection.cursor()
cursor.execute("SELECT * FROM billing WHERE billing_id = " + id)
dataList = dictfetchall(cursor)
return dataList[0];

def update(request, billingId):
context = {
"fn": "update",
"bookinglist": getDropDown('booking', 'booking_id'),
"billingDetails": getData(billingId),
"heading": 'Billing Update',
}
if (request.method == "POST"):
cursor = connection.cursor()
cursor.execute("""
UPDATE billing
SET billing_booking_id=%s, billing_date=%s, billing_room_rent=%s, billing_food_bill=%s, billing_laundry_bill=%s, billing_description=%s WHERE billing_id = %s
""", (
request.POST['billing_booking_id'],
request.POST['billing_date'],
request.POST['billing_room_rent'],
request.POST['billing_food_bill'],
request.POST['billing_laundry_bill'],
request.POST['billing_description'],
billingId
))
context["billingDetails"] = getData(billingId)
messages.add_message(request, messages.INFO, "Billing updated succesfully !!!")
return redirect('billinglisting')
else:
return render(request, 'billing.html', context)




def add(request):
context = {
"fn": "add",
"bookinglist": getDropDown('booking', 'booking_id'),
"heading": 'Billing Details'
};
if (request.method == "POST"):
cursor = connection.cursor()
cursor.execute("""
INSERT INTO billing
SET billing_booking_id=%s, billing_date=%s, billing_room_rent=%s, billing_food_bill=%s, billing_laundry_bill=%s, billing_description=%s
""", (
request.POST['billing_booking_id'],
request.POST['billing_date'],
request.POST['billing_room_rent'],
request.POST['billing_food_bill'],
request.POST['billing_laundry_bill'],
request.POST['billing_description']))
return redirect('billinglisting')
return render(request, 'billing.html', context)


def delete(request, id):
cursor = connection.cursor()
sql = 'DELETE FROM billing WHERE billing_id=' + id
cursor.execute(sql)
return redirect('billinglisting')
8 changes: 8 additions & 0 deletions booking/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.apps import AppConfig


class BookingConfig(AppConfig):
name = 'booking'
10 changes: 10 additions & 0 deletions booking/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.conf.urls import url
from . import views

urlpatterns = [
url(r'^$', views.bookinglisting, name="bookinglisting"),
url(r'^cancel$', views.cancellisting, name="cancellisting"),
url(r'^add$', views.add, name="add"),
url(r'^delete/(?P<id>\w{0,50})/$', views.delete, name="delete"),
url(r'^update/(?P<bookingId>\w{0,50})/$', views.update, name="update"),
]
124 changes: 124 additions & 0 deletions booking/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.conf import settings
from django.db.models import Q
from django.core.files.storage import FileSystemStorage
from django.contrib import messages
from django.db import connection


# Create your views here.

def bookinglisting(request):
cursor = connection.cursor()
cursor.execute(
"SELECT * FROM booking, customer_customer, room WHERE room_id = booking_room_id AND booking_customer_id = customer_id")
bookinglist = dictfetchall(cursor)

context = {
"bookinglist": bookinglist
}

# Message according Booking #
context['heading'] = "Booking Details";
return render(request, 'booking-view.html', context)

def cancellisting(request):
cursor = connection.cursor()
cursor.execute(
"SELECT * FROM booking, customer_customer, room, status WHERE status_id = booking_status AND room_id = booking_room_id AND booking_customer_id = customer_id AND booking_status = 3")
bookinglist = dictfetchall(cursor)

context = {
"bookinglist": bookinglist
}

# Message according Booking #
context['heading'] = "Booking Details";
return render(request, 'cancel-view.html', context)


def dictfetchall(cursor):
"Return all rows from a cursor as a dict"
columns = [col[0] for col in cursor.description]
return [
dict(zip(columns, row))
for row in cursor.fetchall()
]

def getDropDown(table, condtion):
cursor = connection.cursor()
cursor.execute("SELECT * FROM " + table + " WHERE " + condtion)
dropdownList = dictfetchall(cursor)
return dropdownList;


def getData(id):
cursor = connection.cursor()
cursor.execute("SELECT * FROM booking WHERE booking_id = " + id)
dataList = dictfetchall(cursor)
return dataList[0];

def update(request, bookingId):
context = {
"fn": "update",
"customerlist": getDropDown('customer_customer', 'customer_id'),
"roomlist": getDropDown('room', 'room_id'),
"bookingDetails": getData(bookingId),
"statuslist": getDropDown('status', 'status_id'),
"heading": 'Booking Update',
}
if (request.method == "POST"):
cursor = connection.cursor()
cursor.execute("""
UPDATE booking
SET booking_room_id=%s, booking_customer_id=%s, booking_from_date=%s, booking_to_date=%s, booking_status=%s, booking_amount=%s, booking_description=%s WHERE booking_id = %s
""", (
request.POST['booking_room_id'],
request.POST['booking_customer_id'],
request.POST['booking_from_date'],
request.POST['booking_to_date'],
request.POST['booking_status'],
request.POST['booking_amount'],
request.POST['booking_description'],
bookingId
))
context["bookingDetails"] = getData(bookingId)
messages.add_message(request, messages.INFO, "Booking updated succesfully !!!")
return redirect('bookinglisting')
else:
return render(request, 'booking.html', context)




def add(request):
context = {
"fn": "add",
"customerlist": getDropDown('customer_customer', 'customer_id'),
"statuslist": getDropDown('status', 'status_id'),
"roomlist": getDropDown('room', 'room_id'),
"heading": 'Booking Details'
};
if (request.method == "POST"):
cursor = connection.cursor()
cursor.execute("""
INSERT INTO booking
SET booking_room_id=%s, booking_customer_id=%s, booking_from_date=%s, booking_to_date=%s, booking_status=%s, booking_amount=%s, booking_description=%s
""", (
request.POST['booking_room_id'],
request.POST['booking_customer_id'],
request.POST['booking_from_date'],
request.POST['booking_to_date'],
request.POST['booking_status'],
request.POST['booking_amount'],
request.POST['booking_description']))
return redirect('bookinglisting')
return render(request, 'booking.html', context)


def delete(request, id):
cursor = connection.cursor()
sql = 'DELETE FROM booking WHERE booking_id=' + id
cursor.execute(sql)
return redirect('bookinglisting')
8 changes: 8 additions & 0 deletions cleaning/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.apps import AppConfig


class CleaningConfig(AppConfig):
name = 'cleaning'
9 changes: 9 additions & 0 deletions cleaning/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.conf.urls import url
from . import views

urlpatterns = [
url(r'^$', views.cleaninglisting, name="cleaninglisting"),
url(r'^add$', views.add, name="add"),
url(r'^delete/(?P<id>\w{0,50})/$', views.delete, name="delete"),
url(r'^update/(?P<cleaningId>\w{0,50})/$', views.update, name="update"),
]
98 changes: 98 additions & 0 deletions cleaning/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.conf import settings
from django.db.models import Q
from django.core.files.storage import FileSystemStorage
from django.contrib import messages
from django.db import connection


# Create your views here.

def cleaninglisting(request):
cursor = connection.cursor()
cursor.execute(
"SELECT * FROM cleaning, room WHERE room_id = cleaning_room_id")
cleaninglist = dictfetchall(cursor)

context = {
"cleaninglist": cleaninglist
}

# Message according Cleaning #
context['heading'] = "Cleaning Details";
return render(request, 'cleaning-view.html', context)


def dictfetchall(cursor):
"Return all rows from a cursor as a dict"
columns = [col[0] for col in cursor.description]
return [
dict(zip(columns, row))
for row in cursor.fetchall()
]

def getDropDown(table, condtion):
cursor = connection.cursor()
cursor.execute("SELECT * FROM " + table + " WHERE " + condtion)
dropdownList = dictfetchall(cursor)
return dropdownList;


def getData(id):
cursor = connection.cursor()
cursor.execute("SELECT * FROM cleaning WHERE cleaning_id = " + id)
dataList = dictfetchall(cursor)
return dataList[0];

def update(request, cleaningId):
context = {
"fn": "update",
"roomlist": getDropDown('room', 'room_id'),
"cleaningDetails": getData(cleaningId),
"heading": 'Cleaning Update',
}
if (request.method == "POST"):
cursor = connection.cursor()
cursor.execute("""
UPDATE cleaning
SET cleaning_room_id=%s, cleaning_date=%s, cleaning_description=%s WHERE cleaning_id = %s
""", (
request.POST['cleaning_room_id'],
request.POST['cleaning_date'],
request.POST['cleaning_description'],
cleaningId
))
context["cleaningDetails"] = getData(cleaningId)
messages.add_message(request, messages.INFO, "Cleaning updated succesfully !!!")
return redirect('cleaninglisting')
else:
return render(request, 'cleaning.html', context)




def add(request):
context = {
"fn": "add",
"roomlist": getDropDown('room', 'room_id'),
"heading": 'Cleaning Details'
};
if (request.method == "POST"):
cursor = connection.cursor()
cursor.execute("""
INSERT INTO cleaning
SET cleaning_room_id=%s, cleaning_date=%s, cleaning_description=%s
""", (
request.POST['cleaning_room_id'],
request.POST['cleaning_date'],
request.POST['cleaning_description']))
return redirect('cleaninglisting')
return render(request, 'cleaning.html', context)


def delete(request, id):
cursor = connection.cursor()
sql = 'DELETE FROM cleaning WHERE cleaning_id=' + id
cursor.execute(sql)
return redirect('cleaninglisting')
8 changes: 8 additions & 0 deletions customer/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.apps import AppConfig


class CustomerConfig(AppConfig):
name = 'customer'
Loading

0 comments on commit 0e45a65

Please sign in to comment.