Skip to content

Commit e5ccc33

Browse files
committed
remove Raw-SQL queryies
1 parent 1d4779e commit e5ccc33

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

app.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -856,16 +856,12 @@ def today(self):
856856
return res
857857

858858
def appointed(self):
859-
list = SaleInstallment.raw("SELECT * ,datediff(date,curdate()) as 'deadline' FROM `saleinstallment` WHERE (dateback is null) having deadline < 5 order by deadline asc")
860-
count = 0
861-
for li in list:
862-
count += 1
863-
# try:
864-
# list = SaleInstallment.raw("SELECT * ,datediff(date,curdate()) as 'deadline' FROM `saleinstallment` WHERE (dateback is null) having deadline < 1000 order by deadline asc")
865-
# res = list.count()
866-
# print(res)
867-
# except:
868-
# res = 0
859+
today = datetime.today()
860+
enddate = today + timedelta(days=7)
861+
count = SaleInstallment.select()\
862+
.where((SaleInstallment.dateback.is_null()) & (SaleInstallment.date > enddate))\
863+
.count()
864+
869865
return count
870866

871867
class StorageChange(BaseModel):
@@ -1070,12 +1066,15 @@ class Dashboard(Template):
10701066
def Process(self,section):
10711067

10721068
if section == 'instulments':
1073-
insts = SaleInstallment.raw("SELECT * ,datediff(date,curdate()) as 'deadline' FROM `saleinstallment` WHERE (dateback is null) having deadline < 5 order by deadline asc")
1069+
today = datetime.today()
1070+
enddate = today + timedelta(days=7)
1071+
insts = SaleInstallment.select()\
1072+
.where((SaleInstallment.dateback.is_null(True))&(SaleInstallment.date < enddate))
10741073
i = 1
10751074
for inst in insts:
10761075
inst.index = i
10771076
i += 1
1078-
self.RenderFile('dashboard/instulments.htm',{'insts':insts,'_':config.i18n})
1077+
self.RenderFile('dashboard/instulments.htm',{'insts':insts,'_':config.i18n,'today':today})
10791078

10801079
elif section == 'charts':
10811080
users = User.select()

database.db

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)