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

Nima #1

Open
wants to merge 4 commits into
base: main
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 modified db_project/api/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file modified db_project/api/__pycache__/views.cpython-310.pyc
Binary file not shown.
296 changes: 296 additions & 0 deletions db_project/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ def get_projects(request):
cursor.execute('SELECT * FROM tbl_cart;')
projects = cursor.fetchall()
cursor.execute('''SHOW columns FROM project.tbl_cart;''')
<<<<<<< HEAD
columns = []
for column in cursor.fetchall():
columns.append(column[0])

return render(request, 'clientarea.html', {'columns': columns, 'projects': projects})


def list_of_products(request):
cursor = connection.cursor()
cursor.execute(
'Select concat(b.title," Code ",a.Id) as list_doreh from tbl_doreh a left join tbl_reshteh b on a.id_reshteh = b.Id; ')
projects = cursor.fetchall()
<<<<<<< Updated upstream
cursor.execute('''SHOW columns FROM tbl_doreh;''')
=======
>>>>>>> 5e077d7a8938f3f44b82e64c6297857552f7b35d
=======
#cursor.execute('''SHOW columns FROM tbl_doreh;''')
>>>>>>> Stashed changes
result = []
columns = []
for column in cursor.fetchall():
Expand Down Expand Up @@ -34,5 +54,281 @@ def list_of_products(request):
# new_item.update({columns[i]: project[i]})
# result.append(new_item)

return render(request, 'clientarea.html', {'columns': ['list_doreh'], 'projects': projects})

<<<<<<< Updated upstream
def list_of_products(request):
cursor = connection.cursor()
cursor.execute('Select concat(b.title," Code ",a.Id) as list_doreh from tbl_doreh a left join tbl_reshteh b on a.id_reshteh = b.Id;')
projects = cursor.fetchall()
cursor.execute('''SHOW columns FROM tbl_doreh;''')
=======
>>>>>>> Stashed changes

def list_of_users(request):
cursor = connection.cursor()
cursor.execute('Select concat(fname," ",lname) as names from tbl_users; ')
projects = cursor.fetchall()
#cursor.execute('''SHOW columns FROM tbl_doreh;''')
result = []
columns = []
for column in cursor.fetchall():
columns.append(column[0])
# for project in projects:
# new_item = dict()
# for i in range(len(columns)):
# new_item.update({columns[i]: project[i]})
# result.append(new_item)

return render(request, 'clientarea.html', {'columns': columns, 'projects': projects})

def list_of_product_types(request):
cursor = connection.cursor()
cursor.execute('Select title from tbl_reshteh; ')
projects = cursor.fetchall()
#cursor.execute('''SHOW columns FROM tbl_doreh;''')
result = []
columns = []
for column in cursor.fetchall():
columns.append(column[0])
# for project in projects:
# new_item = dict()
# for i in range(len(columns)):
# new_item.update({columns[i]: project[i]})
# result.append(new_item)

return render(request, 'clientarea.html', {'columns': columns, 'projects': projects})

def list_of_orders(request):
cursor = connection.cursor()
cursor.execute('Select d.Title,concat(b.fname," ",b.lname) as name,a.date_buy from tbl_buy_doreh a left join tbl_users b on a.id_username = b.username left join tbl_doreh c on a.id_doreh = c.Id left join tbl_reshteh d on d.Id = c.id_reshteh ; ')
projects = cursor.fetchall()
#cursor.execute('''SHOW columns FROM tbl_doreh;''')
result = []
columns = []
for column in cursor.fetchall():
columns.append(column[0])
# for project in projects:
# new_item = dict()
# for i in range(len(columns)):
# new_item.update({columns[i]: project[i]})
# result.append(new_item)

return render(request, 'clientarea.html', {'columns': columns, 'projects': projects})

def list_of_top_10_ussers_all(request):
cursor = connection.cursor()
cursor.execute('Select count(*) as num_buy, a.id_username , concat(b.fname," ",b.lname) as name from tbl_buy_doreh a left join tbl_users b on a.id_username = b.Id group by a.id_username order by count(*) desc Limit 10 ; ')
projects = cursor.fetchall()
#cursor.execute('''SHOW columns FROM tbl_doreh;''')
result = []
columns = []
for column in cursor.fetchall():
columns.append(column[0])
# for project in projects:
# new_item = dict()
# for i in range(len(columns)):
# new_item.update({columns[i]: project[i]})
# result.append(new_item)

return render(request, 'clientarea.html', {'columns': columns, 'projects': projects})



def change_users():

html = '''
<div class ='forms01 forms mnforms'>
<div class ='arrow-header'>
<span class ='before-h'><i class='fa fa-user' aria-hidden='true'></i> " + "جست و جو کاربر</span>
<div class ='arrow'></div>
</div>
<div class ='inform-div'>
<a class ='inform-p before-p'>

</a>
</div>
<div class='row-modal' style='margin:5px 0;'>
<div class ='form" + @"' style='display:inline-block;margin-left:2%;'>
<input type = 'text' id='inpmod1' onkeyup='search_user_div()' autocomplete='off' required>
<label class ='label-name'>
<span class ='content-name'>نام کاربری</span>
</label>
</div>
<div class ='form" + @"' style='display:inline-block;margin-left:2%;'>
<input type = 'text' id='inpmod2' onkeyup='search_user_div()' autocomplete='off' required>
<label class ='label-name'>
<span class ='content-name'>نام</span>
</label>
</div>
<div class ='form" + @"' style='display:inline-block;margin-left:2%;'>
<input type = 'text' id='inpmod3' onkeyup='search_user_div()' autocomplete='off' required>
<label class ='label-name'>
<span class ='content-name'>نام خانوادگی</span>
</label>
</div>
<div class ='form" + @"' style='display:inline-block;margin-left:2%;'>
<input type = 'number' id='inpmod4' onkeyup='search_user_div()' autocomplete='off' required>
<label class ='label-name'>
<span class ='content-name'>کد ملی</span>
</label>
</div>
<div class ='form' style='display:inline-block;margin-left:2%;'>
<input type = 'number' id='inpmod5' onkeyup='search_user_div()' autocomplete='off' required>
<label class ='label-name'>
<span class ='content-name'>شماره تلفن</span>
</label>
</div>
<div class='select-div' style='margin:0 2px 0 7px;' ><span class='select-span' >''' + "سطح دسترسی" + "</span>" + '''<select class='classic sp-select' id='inpmod6' onchange='search_user_div()' >
<option value='0'>...</option>
<option value='1'>کاربر</option>
<option value='2'>ادمین</option>
</select>
</div>
<button class='incomp height' onclick='add_change_user()'>جدید</button>
</div>
</br><div id='search_user_div'></div>
<div class ='forgot-div'>
<a class ='forgot-pass' onclick='forgot()'>

</a>
</div>

</div>
''';

def list_of_top_10_users_month(request):
cursor = connection.cursor()
cursor.execute('Select count(*) as num_buy, a.id_username , concat(b.fname," ",b.lname) as name from tbl_buy_doreh a left join tbl_users b on a.id_username = b.Id where a.date_buy >= DATE(NOW() - INTERVAL 1 Month) group by a.id_username order by count(*) desc Limit 10 ;')
projects = cursor.fetchall()
#cursor.execute('''SHOW columns FROM tbl_doreh;''')
result = []
columns = []
for column in cursor.fetchall():
columns.append(column[0])
# for project in projects:
# new_item = dict()
# for i in range(len(columns)):
# new_item.update({columns[i]: project[i]})
# result.append(new_item)

return render(request, 'clientarea.html', {'columns': columns, 'projects': projects})
def list_of_top_10_users_week(request):
cursor = connection.cursor()
cursor.execute('Select count(*) as num_buy, a.id_username , concat(b.fname," ",b.lname) as name from tbl_buy_doreh a left join tbl_users b on a.id_username = b.Id where a.date_buy >= DATE(NOW() - INTERVAL 7 DAY) group by a.id_username order by count(*) desc Limit 10 ;')
projects = cursor.fetchall()
#cursor.execute('''SHOW columns FROM tbl_doreh;''')
result = []
columns = []
for column in cursor.fetchall():
columns.append(column[0])
# for project in projects:
# new_item = dict()
# for i in range(len(columns)):
# new_item.update({columns[i]: project[i]})
# result.append(new_item)

return render(request, 'clientarea.html', {'columns': columns, 'projects': projects})

def list_of_top_sold_product_week(request):
cursor = connection.cursor()
cursor.execute('Select count(*) as times_bought , c.Title from tbl_buy_doreh a left join tbl_doreh b on a.id_doreh = b.Id left join tbl_reshteh c on c.Id = b.id_reshteh where a.date_buy >= DATE(NOW() - INTERVAL 7 Day) group by a.id_doreh order by count(*) desc;')
projects = cursor.fetchall()
#cursor.execute('''SHOW columns FROM tbl_doreh;''')
result = []
columns = []
for column in cursor.fetchall():
columns.append(column[0])
# for project in projects:
# new_item = dict()
# for i in range(len(columns)):
# new_item.update({columns[i]: project[i]})
# result.append(new_item)

return render(request, 'clientarea.html', {'columns': columns, 'projects': projects})

def list_of_top_sold_procut_month(request):
cursor = connection.cursor()
cursor.execute('Select count(*) as times_bought , c.Title from tbl_buy_doreh a left join tbl_doreh b on a.id_doreh = b.Id left join tbl_reshteh c on c.Id = b.id_reshteh where a.date_buy >= DATE(NOW() - INTERVAL 1 Month) group by a.id_doreh order by count(*) desc; ')
projects = cursor.fetchall()
#cursor.execute('''SHOW columns FROM tbl_doreh;''')
result = []
columns = []
for column in cursor.fetchall():
columns.append(column[0])
# for project in projects:
# new_item = dict()
# for i in range(len(columns)):
# new_item.update({columns[i]: project[i]})
# result.append(new_item)

return render(request, 'clientarea.html', {'columns': columns, 'projects': projects})

def list_of_special_offers(request):
cursor = connection.cursor()
cursor.execute('Select c.title , a.discount2 as off_percentage from tbl_buy_doreh a left join tbl_doreh b on a.id_doreh = b.Id left join tbl_reshteh c on c.Id = b.id_reshteh where a.discount2 >= (a.fee*15/100);')
projects = cursor.fetchall()
#cursor.execute('''SHOW columns FROM tbl_doreh;''')
result = []
columns = []
for column in cursor.fetchall():
columns.append(column[0])
# for project in projects:
# new_item = dict()
# for i in range(len(columns)):
# new_item.update({columns[i]: project[i]})
# result.append(new_item)

return render(request, 'clientarea.html', {'columns': columns, 'projects': projects})

def list_of_providersof_product_admin(request):
cursor = connection.cursor()
cursor.execute('Select concat(a.Id," name ",c.title," offered by ",b.name) as offerd_by from tbl_doreh a left join tbl_institute b on a.Id = b.id_doreh left join tbl_reshteh c on a.id_reshteh = c.Title;')
projects = cursor.fetchall()
#cursor.execute('''SHOW columns FROM tbl_doreh;''')
result = []
columns = []
for column in cursor.fetchall():
columns.append(column[0])
# for project in projects:
# new_item = dict()
# for i in range(len(columns)):
# new_item.update({columns[i]: project[i]})
# result.append(new_item)

return render(request, 'clientarea.html', {'columns': columns, 'projects': projects})

def list_of_providersof_product_admin_2(request):
cursor = connection.cursor()
cursor.execute('Select concat(a.Id," name ",c.title," offered by ",b.name) as offerd_by from tbl_institute b left join tbl_doreh a on a.Id = b.id_doreh left join tbl_reshteh c on a.id_reshteh = c.Title where c.Id = '';')
projects = cursor.fetchall()
#cursor.execute('''SHOW columns FROM tbl_doreh;''')
result = []
columns = []
for column in cursor.fetchall():
columns.append(column[0])
# for project in projects:
# new_item = dict()
# for i in range(len(columns)):
# new_item.update({columns[i]: project[i]})
# result.append(new_item)

return render(request, 'clientarea.html', {'columns': columns, 'projects': projects})

def list_of_cheapest_providerof_products_admin(request):
cursor = connection.cursor()
cursor.execute('Select concat(a.Id," name ",c.title," offered by ",b.name," for the cheapest price") as offerd_by from tbl_institute b left join tbl_doreh a on a.Id = b.id_doreh left join tbl_reshteh c on a.id_reshteh = c.Title where c.Id = '' order by a.fee desc LIMIT 1;')
projects = cursor.fetchall()
#cursor.execute('''SHOW columns FROM tbl_doreh;''')
result = []
columns = []
for column in cursor.fetchall():
columns.append(column[0])
# for project in projects:
# new_item = dict()
# for i in range(len(columns)):
# new_item.update({columns[i]: project[i]})
# result.append(new_item)

return render(request, 'clientarea.html', {'columns': columns, 'projects': projects})

Binary file modified db_project/users/__pycache__/urls.cpython-310.pyc
Binary file not shown.
47 changes: 47 additions & 0 deletions phase3_queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,58 @@ Select count(*) as times_bought , c.Title from tbl_buy_doreh a left join tbl_dor
# 6th query top sold products of month
Select count(*) as times_bought , c.Title from tbl_buy_doreh a left join tbl_doreh b on a.id_doreh = b.Id left join tbl_reshteh c on c.Id = b.id_reshteh where a.date_buy >= DATE(NOW() - INTERVAL 1 Month) group by a.id_doreh order by count(*) desc;

# 7th query list of special offers (stuff with more than 15% off)
Select c.title , a.discount2 as off_percentage from tbl_buy_doreh a left join tbl_doreh b on a.id_doreh = b.Id left join tbl_reshteh c on c.Id = b.id_reshteh where a.discount2 >= (a.fee*15/100);

# 8th query list of providers of a product for admin
Select concat(a.Id," name ",c.title," offered by ",b.name) as offerd_by from tbl_doreh a left join tbl_institute b on a.Id = b.id_doreh left join tbl_reshteh c on a.id_reshteh = c.Title;

# 9th query list of providers of a product for admin
Select concat(a.Id," name ",c.title," offered by ",b.name) as offerd_by from tbl_institute b left join tbl_doreh a on a.Id = b.id_doreh left join tbl_reshteh c on a.id_reshteh = c.Title where c.Id = '';

# 9th query showing the cheapest provider of an item for admin
Select concat(a.Id," name ",c.title," offered by ",b.name," for the cheapest price") as offerd_by from tbl_institute b left join tbl_doreh a on a.Id = b.id_doreh left join tbl_reshteh c on a.id_reshteh = c.Title where c.Id = '' order by a.fee desc LIMIT 1;

# 10th query list of last 10 orders of a user
#select * from tbl_buy_doreh a1 left join tbl_users a2 on a2.Id=a1.id_username order by a1.adate desc limit 10
Select * from tbl_buy_doreh where id_username = 1 order by Id desc limit 10 ;
Select * from tbl_buy_doreh a left join tbl_users b on a.id_username = b.Id where a.id_username=1 order by a.date_buy desc limit 10;

# 11th query list of comments for a given product
# select top 3 * from tbl_comments where id_buy_doreh=@v1
CREATE TABLE `tbl_comment` (
`Id` int(11) NOT NULL,
`comment` varchar(2000) DEFAULT NULL,
`id_username` int(20) DEFAULT NULL,
`score` int(20) DEFAULT NULL,
`id_doreh` int(20) DEFAULT NULL,
`adate` datetime default null,
PRIMARY KEY (`Id`),
Foreign Key (`id_username`) REFERENCES tbl_users(Id),
Foreign Key (`id_doreh`) REFERENCES tbl_doreh(Id)
);

Select * from tbl_comments where id_buy_doreh = '' limit 3;

# 12th query top 3 comments which gave the best score to product
select * from tbl_comments where id_buy_doreh=@v1 order by score limit 3;

# 13th query top 3 comments which gave the worst score to product
select * from tbl_comments where id_buy_doreh=@v1 order by score desc limit 3;

# 14th query showing the amount of sale of a product to admin
select Id,count(*) as buy_number from tbl_buy_doreh group by Id;

# 15th query showing the average sale of store to admin
select avg(fee),month(date_buy),year(date_buy) from tbl_buy_doreh group by month(date_buy),year(date_buy);

# 16th query users of a given city
select * from tbl_users group by city;


# 17th query providers of a given city
alter table tbl_institute add column `city` varchar(20);
select * from tbl_institute group by city;