def deletedoreh(data): try: conadmin().deletefrom('doreh', 'id={id}'.format(id=data)).runquery() return True except Exception as error: return {"error": error}
def addnewdoreh(data): try: conadmin().insertinto('doreh', tuple([*data]), tuple(data.values())).runquery() return True except Exception as error: return {"error": error}
def userlevelset(data): try: conadmin().insertinto('level', tuple([*data]), tuple(data.values())).runquery() return True except Exception as error: return {"error": error}
def updatedoreh(data): try: conadmin().updateit( 'doreh', data['newdata'], "id={id}".format(id=data['condition'])).runquery() return True except Exception as error: return {"error": error}
def addusertodoreh(data): users = [str(key) for key, value in data.items() if value == 'on'] try: for item in users: conadmin().insertinto( 'classregister', "(userid,doreh)", "({thisitem}, {doreh})".format(doreh=data['doreh'], thisitem=item)).runquery() return True except Exception as error: return {"error": error}
def selectuserswaitinglevel(): return conadmin().select( """ user."melli-code", user.name, user.fname, user.grade, user.tel, user.address, level.mellicode """, 'user').joinit('LEFT', 'level', ' level.mellicode = user."melli-code"').where( ' level.mellicode IS NULL').fetchall()
def show_admin(): # data = request.headers.get('Authorization') # data = "TOKEN123" # واکشی اطلاعات مورد نیاز صفحه داشبورد content = { 'manager': current_user.username, 'user': mydb.selectuserswaitinglevel(), 'doreh': conadmin().select('*', 'doreh').where("date > '{todey}'".format( todey=JalaliDate.today())).orderby('id', 'DESC').fetchall() } # چک میشود اگر توکن ارسالی توسط کاربری معتبر است یا خیر # if str(data) == "TOKEN123": return render_template('admin/dashboard.html', content=content)
def selectalldoreh(): return conadmin().select('*', 'doreh').orderby('id', 'DESC').fetchall()
def selectalluser(): return conadmin().select('*', 'user').fetchall()