def main(web, build): # -------------------------------------------------------------------------- # # 認証 # # 認証失敗 → 認証ページへ転送 m_uno = web.getcookie_secure('admin') if m_uno: # # 成功 # m_uno = int(m_uno) web.uno = m_uno web.user_icon = mf.get_icon(web, web.uno) web.ano = mf.from_uno_getdb_ano(web, web.uno, cookie=False) web.setcookie_secure('admin', str(m_uno), maxage=1800) else: # # 失敗 # return web.redirect('/signin?message=failed') # -------------------------------------------------------------------------- # # 例えば /admin/admin にアクセスがあった場合に次の2行と同等の処理を行う # import admin.admin_foobar # return admin.admin_foobar.main(web, build) # module = web.path[len('/admin/'):].replace('.', '_') module = 'admin.admin_' + (module or 'index') web.log(module, "RED") try: return importlib.import_module(module).main(web, build) except ImportError as e: web.log(e, 'red') # # *.py が無くても HTML テンプレートが存在すればそれを表示する。 # web.statuscode = 404 return build(web, local={}) # # 404 Not Found # web.statuscode = 404 return web.echo()
def main(web, build): # -------------------------------------------------------------------------- # # メモの追加 # if web.get("objectionchange"): # # 状態を更新 # sql = """ UPDATE `significance` SET `state` = %(state)s WHERE `sno` = %(sno)s; """ params = { 'sno': int(web.get("sno")), 'state': int(web.get("memostate")), } web.db.exe(sql, params=params) # # メモを更新 # sql = """ INSERT INTO `significance_memo` VALUES (%(sno)s, %(admin_uno)s, %(memo)s, %(memo_time4)s, %(memocreated_snostate)s) """ params = { 'sno': int(web.get("sno")), 'admin_uno': web.uno, 'memo': str(web.get("memo")), 'memo_time4': web.now4, 'memocreated_snostate': web.get("memostate"), } web.db.exe(sql, params=params) # # リダイレクト用にunoを取得 # sql = """ SELECT `uno` FROM `significance` WHERE `sno` = %(sno)s; """ params = { 'sno': int(web.get("sno")), } uno = web.db.exe(sql, params=params, key=True) joinurl = 'details=' + str(uno) + '&message1=changememo' return web.redirect('/admin/valueweight?details=' + str(uno) + '&message1=changememo') sql = """ SELECT SQL_CALC_FOUND_ROWS `user`.`uno`, `user`.`name0`, `user`.`name1`,`user`.`name2`, `user`.`name3`, `user`.`passhash`, `user`.`created4`, `assign`.`asname`, `icon`.`uno` AS `has_icon` FROM `user` LEFT JOIN `assign` ON `user`.`asno` = `assign`.`asno` LEFT JOIN `icon` ON `icon`.`uno` = `user`.`uno` WHERE `user`.uno = %(uno)s AND `user`.`deleted` = 0;""" params = {'uno': web.get("from")} user = web.db.exe(sql, params=params) sql = """ SELECT CONCAT(name0, name1) AS `fullname`, `asname`, `depth` ,`vuno`,`involvement`.`uno`, `involvement`.`time4`, `involvement`.`deleted` FROM `user` LEFT JOIN `involvement` ON `user`.`uno` = `involvement`.`vuno` LEFT JOIN `assign` USING (`asno`) WHERE (`involvement`.`uno`,`involvement`.`time4`) IN ( SELECT `uno`,MAX(`time4`) AS `time4` FROM `involvement` WHERE `uno` = %(uno)s AND NOT `depth` = 0 GROUP BY `vuno` ) AND NOT `depth` = 0 AND NOT `vuno` = %(uno)s ORDER BY `depth` DESC""" params = {'uno': web.get("from")} involvement_users = web.db.exe(sql, params=params) sumdepth = 0 for k, v in enumerate(involvement_users): sumdepth += v['depth'] # # それぞれのdepthの割合を求める # 同時にvunoの画像も取得 # for k, v in enumerate(involvement_users): if v['depth'] == 0: continue v['parcent'] = round((v['depth'] / sumdepth * 100), 1) icon = matsuoka_func.get_icon(web, int(v['uno'])) v['icon'] = icon['has_icon'] v['icon_uno'] = icon['uno'] sql = """ SELECT CONCAT(name0,name1) AS fullname, `significance_text`, `significance_time4`, `significance_statetext`.`state`, `text` AS `state_text`, `significance`.`sno` FROM `significance` LEFT JOIN `significance_statetext` ON `significance`.`state` = `significance_statetext`.`state` LEFT JOIN `user` ON `user`.`uno` = `significance`.`vuno` WHERE `significance`.`sno` = %(sno)s """ params = { 'sno': web.get("sno"), } significance = web.db.exe(sql, params=params, key=True) significance['significance_time4'] = datetime.datetime.fromtimestamp( int(v['time4'])).strftime('%Y-%m-%d') sql = """ SELECT SQL_CALC_FOUND_ROWS * FROM `significance` LEFT JOIN `significance_memo` ON `significance`.`sno` = `significance_memo`.`sno` LEFT JOIN `user` ON `significance_memo`.`admin_uno` = `user`.`uno` LEFT JOIN `significance_statetext` ON `significance_memo`.`memocreated_snostate` = `significance_statetext`.`state` WHERE `significance`.`sno` = %(sno)s AND `user`.`deleted` =0""" params = { 'sno': web.get("sno"), } found = web.db.exe('SELECT FOUND_ROWS();', params=params, key=True) if found != 0: significance_memo = web.db.exe(sql, params=params) for k, v in enumerate(significance_memo): v['time4'] = datetime.datetime.fromtimestamp(int( v['time4'])).strftime('%Y-%m-%d') else: significance_memo = "NONE" sql = """ SELECT * FROM `significance_statetext` WHERE 1""" state_text = web.db.exe(sql) local = { 'user': user, 'involvement_users': involvement_users, 'significance': significance, 'significance_memo': significance_memo, 'state_text': state_text, 'user_icon': web.user_icon } return build(web, local, \ '/admin/' + web.path.replace('/', '.')[1:] + '.html')
def main(web, build): # -------------------------------------------------------------------------- # # 認証失敗 → 認証ページへ転送 # if web.getcookie_secure('admin'): m_uno = web.getcookie_secure('admin') m_name = 'admin' elif web.getcookie_secure('user'): m_uno = web.getcookie_secure('user') m_name = 'user' else: return web.redirect('/signin?message=failed') if m_uno: # # 成功 # m_uno = int(m_uno) web.uno = m_uno web.user_icon = matsuoka_func.get_icon(web,web.uno) web.ano = matsuoka_func.from_uno_getdb_ano(web,web.uno,False) web.setcookie_secure(m_name, str(m_uno), maxage=1800) else: # # 失敗 # return web.redirect('/signin?message=failed') # -------------------------------------------------------------------------- # # 例えば /user/foobar にアクセスがあった場合に次の2行と同等の処理を行う # import user.user_foobar # return user.user_foobar.main(web, build) # if web.path.startswith('/user'): module = web.path[len('/user/'):].replace('.', '_') module = 'user.user_' + (module or 'index') try: return importlib.import_module(module).main(web, build) except ImportError as e: web.log(e, 'red') # # 404 Not Found # web.statuscode = 404 return web.echo() elif web.path.startswith('/jh'): module = web.path[len('/jh/'):].replace('.', '_') module = 'jh.jh_' + (module or 'index') try: return importlib.import_module(module).main(web, build) except ImportError as e: web.log(e, 'red') # # 404 Not Found # web.statuscode = 404 return web.echo() elif web.path.startswith('/growth'): module = web.path[len('/growth/'):].replace('.', '_') module = 'growth.growth_' + (module or 'index') web.log(module,"RED") try: return importlib.import_module(module).main(web, build) except ImportError as e: web.log(e, 'red') # # 404 Not Found # web.statuscode = 404 return web.echo()
def main(web, build): # # ログイン中のユーザーの画像を取得 # user_icon = matsuoka_func.get_icon(web, web.uno) # # unoから所属する会社を取得 # if web.environ('REQUEST_METHOD') == 'POST': aname = web.post('aname') ano = web.post('ano') sql = """ UPDATE `account` SET `aname` = %(aname)s WHERE `ano` = %(ano)s;""" params = { 'ano': ano, 'aname': aname, } web.db.exe(sql, params=params, key=True) # # cookieからunoを取得 # m_uno = re.match(r'.+\..+\.([0-9]+)', web.cookie('admin')) uno = m_uno.groups()[0] # # unoからuserが所属するaccountを取得 # sql = """ SELECT `account`.`ano`,`account`.`aname` FROM `account` INNER JOIN `user` ON `user`.`ano` = `account`.`ano` WHERE `account`.`deleted` = 0 AND `user`.`uno` = %(uno)s;""" params = { 'uno': uno, } account = web.db.exe(sql, params=params, key=True) sql = """ SELECT `sno` FROM `significance` LEFT JOIN `user` ON `significance`.`uno` = `user`.`uno` WHERE `user`.`ano` = %(ano)s AND `significance`.`state` != 4 AND `user`.`deleted` = 0""" params = { 'ano': account['ano'], } significance = web.db.exe(sql, params=params, key=True) if significance: significance = {'state': True} else: significance = {'state': False} # -------------------------------------------------------------------------- # build # local = { 'item': account, 'significance': significance, 'user_icon': user_icon, } return build(web, local, '/admin/admin.index.html')
def main(web, build): # -------------------------------------------------------------------------- # # updateのページで「はい」を選択すると、cookieに保存されたSQLを実行 # if web.get('send'): # # 値の更新 # if web.getcookie_secure('dsql'): dsql = web.getcookie_secure('dsql') web.db.exe(dsql) web.setcookie_secure('dsql','',maxage=0.1) rsql = web.getcookie_secure('rsql') web.db.exe(rsql) web.setcookie_secure('rsql','',maxage=0.1) return web.redirect("/growth/changestate?message=update") # # 結果の確認画面に表示する処理、postされた内容でSQLを生成しcookieに保存する # sql = """ SELECT `uno`, `vuno`, `hourlywage`, CONCAT(name0, name1) AS fullname, `asname`, `icon`.`uno` AS `has_icon` FROM `salary_evaluation` LEFT JOIN `user` USING (`uno`) LEFT JOIN `icon` USING (`uno`) LEFT JOIN `assign` USING (`ano`) WHERE (`vuno`, `time4`) IN ( SELECT `vuno`, max(`time4`) AS `time4` FROM `salary_evaluation` WHERE `vuno` = %(uno)s GROUP BY `uno` ) AND `salary_evaluation`.`deleted` = 0 GROUP BY `uno` """ params = { 'uno':web.uno } users = web.db.exe(sql, params=params) s_values = {} # salary for k, v in web._post.items(): if re.match(r'salary([0-9]+)', k): # # 正規表現でunoとdepthを取得 # u = re.match(r'salary([0-9]+)', k) uno = int(u.group(1)) # # 空白時はエラーをメッセージで返す # try: salary = int(v) except: return web.redirect("/growth/salary?message =" \ + "notint") # # unoと値をdictで格納する # if uno not in s_values: s_values[uno] = {} s_values[uno] = int(salary) # # depthを更新する用のパラムを生成 # for uno, v in sorted(s_values.items(), key=lambda x: x[1]): s_values[uno] = '(' + str(web.uno) + ", " + str(uno) + ", " \ + str(web.now4) + ", " + str(v) + ", '" + str(0) + "')" # # depthの更新、生成したクエリをcookieに保存 # s_values = ', '.join(s_values.values()) sql = """ INSERT INTO `salary_evaluation` (uno, vuno, time4, hourlywage, deleted) VALUES """ + str(s_values) + ";" web.setcookie_secure('sql', sql, maxage=1800) # # 更新後の数値をリストに格納 # udepth = 0 now_salary = {} # depth for k, v in web._post.items(): if re.match(r'salary([0-9]+)', k): u = re.match(r'salary([0-9]+)', k) uno = int(u.group(1)) salary = int(v) web.log(salary,"BLUE") # # unoを取得 # user = matsuoka_func.get_user(web,uno) apdict = { str(user['uno']):{ 'nowsalary':salary, } } now_salary.update(apdict) if users: # # 100分率用に全員のdepthを合計 # for k, v in enumerate(users): # # 画像の取得 # icon = matsuoka_func.get_icon(web,v['uno']) # # 既に登録されているsalaryを更新する時 # v['now_icon'] = icon['has_icon'] v['now_icon_uno'] = icon['uno'] web.log(now_salary[str(v['vuno'])]['nowsalary'],"RED") v['afterhourlywage'] = now_salary[str(v['vuno'])]['nowsalary'] local = { 'users':users, } return build(web, local, \ '/growth/' + web.path.replace('/', '.')[1:] + '.html')
def main(web, build): # -------------------------------------------------------------------------- # # # #if web.get('valuer'): # vuno = web.get('valuer') # uno = web.uno vuno = 4 uno = 2 if web.get('declaration'): Auser = matsuoka_func.get_user(web,web.uno) Buser = matsuoka_func.get_user(web,vuno) local = { 'Auser' :Auser, 'Buser' :Buser, 'text' :str(web.get('declaration')), 'user_icon' :web.user_icon } return build(web, local,'/user/user.weight.html') if web.get('q'): text = web.get('q') uno = web.get('tgt') vuno = web.get('to') sql = """ SELECT MAX(`time4`) AS `time4` FROM `involvement` WHERE `vuno` = %(vuno)s AND `uno` = %(uno)s AND `deleted` = 0 LIMIT 1 """ params = { 'uno' : uno, 'vuno':vuno, } time4 = web.db.exe(sql, params=params, key=False) nowtime = web.now4 sql1 = """ INSERT INTO `significance` (`uno`, `vuno`, `time4`, `significance_text`, `significance_time4`, `state`) VALUES (%(uno)s, %(vuno)s, %(time4)s, %(text)s, %(nowtime)s, 0); """ sql2 =""" INSERT INTO `significance_memo` (`memo`, `memo_time4`, `memocreated_snostate`) VALUES (%(text)s, %(nowtime)s, 0); """ params = { 'uno' :uno, 'vuno' :vuno, 'time4' :time4, 'text' :str(text), 'nowtime':nowtime } web.db.exe(sql1, params=params) web.db.exe(sql2, params=params) return web.redirect('/user/weight') sql = """ SELECT * FROM `user` LEFT JOIN `assign` USING (`asno`) LEFT JOIN `bind_user_job` USING (`uno`) LEFT JOIN `job` USING (`jno`) WHERE `user`.`uno` = %(vuno)s GROUP BY `jno` """ params = { 'vuno':vuno, } userjob = web.db.exe(sql, params=params) userjob[0]['start'] = 'start' userjob[0]['updated4'] = str(datetime.datetime.fromtimestamp( userjob[0]['updated4']).strftime("%Y/%m/%d")) found_job = len(userjob) sql = """ SELECT SQL_CALC_FOUND_ROWS * FROM `bind_user_job` WHERE jno = %(jno)s """ for k, v in enumerate(userjob): params = { 'jno':v['jno'] } v['havefound'] = web.db.exe('SELECT FOUND_ROWS();',params=params, key=True) v['jupdated4'] = str(datetime.datetime.fromtimestamp( v['job.updated4']).strftime("%Y/%m/%d")) sql = """ SELECT CONCAT(name0, name1) AS `fullname`, `asname`, `depth` ,`vuno`,`involvement`.`uno`, `involvement`.`time4`, `involvement`.`deleted` FROM `user` LEFT JOIN `involvement` ON `user`.`uno` = `involvement`.`uno` LEFT JOIN `assign` USING (`asno`) WHERE (`involvement`.`uno`,`involvement`.`time4`) IN ( SELECT `uno`,MAX(`time4`) AS `time4` FROM `involvement` WHERE `vuno` = %(vuno)s AND `deleted` = 0 GROUP BY `uno` ) AND `involvement`.`vuno` = %(vuno)s AND `involvement`.`deleted` = 0 AND NOT `user`.`uno` = %(vuno)s""" params = { 'vuno':vuno, } involvement = web.db.exe(sql, params=params) if involvement: # # 100分率用に全員のdepthを合計 # sumdepth = 0 for k, v in enumerate(involvement): if v['deleted'] == 0: sumdepth += v['depth'] # # involvementを出力用に書き換え # for k, v in enumerate(involvement): # # 画像の取得 # icon = matsuoka_func.get_icon(web,v['uno']) v['icon'] = icon['has_icon'] v['icon_uno'] = icon['uno'] if v['depth'] != 0: v['parcent'] = round((v['depth'] / sumdepth* 100),1) else: v['parcent'] = 0 local = { 'userjob' :userjob, 'involvement':involvement, 'found_job' :found_job, 'user_icon' :web.user_icon } return build(web, local,'/user/user.weight.html')
def main(web, build): # -------------------------------------------------------------------------- # # 自分を評価する人の割合 # params = {'uno': web.uno} sql1 = """ SELECT SQL_CALC_FOUND_ROWS CONCAT(name0, name1) AS `fullname`, `asname`, `depth` ,`vuno`,`involvement`.`uno`, `involvement`.`time4`, `involvement`.`deleted` FROM `user` LEFT JOIN `involvement` ON `user`.`uno` = `involvement`.`vuno` LEFT JOIN `assign` USING (`asno`) WHERE (`involvement`.`uno`,`involvement`.`time4`) IN ( SELECT `uno`,MAX(`time4`) AS `time4` FROM `involvement` WHERE `uno` = %(uno)s AND NOT `depth` = 0 GROUP BY `uno` ) AND NOT `depth` = 0 ORDER BY `depth` DESC""" involvement_users = web.db.exe(sql1, params=params) # # 自分が評価する人に割合 # sql = """ SELECT SQL_CALC_FOUND_ROWS CONCAT(name0, name1) AS `fullname`, `asname`, `depth` ,`vuno`,`involvement`.`uno`, `involvement`.`time4`, `involvement`.`deleted` FROM `user` LEFT JOIN `involvement` ON `user`.`uno` = `involvement`.`uno` LEFT JOIN `assign` USING (`asno`) WHERE (`involvement`.`vuno`,`involvement`.`time4`) IN ( SELECT `vuno`,MAX(`time4`) AS `time4` FROM `involvement` WHERE `vuno` = %(uno)s AND NOT `depth` = 0 GROUP BY `uno` ) AND NOT `depth` = 0 ORDER BY `depth` DESC""" involvement_users2 = web.db.exe(sql, params=params) # # 100分率用に全員のdepthを合計 # sumdepth = 0 for k, v in enumerate(involvement_users): sumdepth += v['depth'] sumdepth2 = 0 #for k, v in enumerate(involvement_users2): # sumdepth2 += v['depth'] # # それぞれのdepthの割合を求める # 同時にvunoの画像も取得 # for k, v in enumerate(involvement_users): if v['depth'] == 0: continue v['parcent'] = round((v['depth'] / sumdepth * 100), 1) icon = matsuoka_func.get_icon(web, int(v['uno'])) v['icon'] = icon['has_icon'] v['icon_uno'] = icon['uno'] #for k, v in enumerate(involvement_users2): # if v['depth'] == 0: # continue # v['parcent'] = round((v['depth'] / sumdepth2* 100),1) # icon = matsuoka_func.get_icon(web,int(v['uno'])) # v['icon'] = icon['has_icon'] # v['icon_uno'] = icon['uno'] local = { 'involvement_users': involvement_users, 'involvement_users2': involvement_users2, 'user_icon': web.user_icon, } return build(web, local, \ '/growth/' + web.path.replace('/', '.')[1:] + '.html')
def main(web, build): # -------------------------------------------------------------------------- get_uno = web.get('uno') # # ログイン中のユーザーの画像を取得 # login_user_icon = matsuoka_func.get_icon(web, web.uno) # # エラー時の送信メッセージを準備 # message = '?uno=' + str(get_uno) + '&mode=show' # # userの更新 # if web.environ('REQUEST_METHOD') == 'POST': # #パスワードの再設定 # if web.post('passreset'): web.setcookie_secure('user', str(get_uno), maxage=1800) hash = web.cookie('user') web.log(web.cookie('user'), "RED") txt = blossom.read('../template/eml/open.passremind.eml') txt = txt % { 'mailaddr': '*****@*****.**', 'HTTP_HOST': web._environ['HTTP_HOST'], 'uno': get_uno, 'hash': hash } web.log(txt, 'purple') result = blossom.Mail.send(txt) web.log(result, "blue") return web.redirect('/admin/users?message12=passreset') # # 登録内容の変更 # asno = web.post('assign') name0 = web.post('name0') name1 = web.post('name1') # # カタカナ以外が入力されているとFalseが帰ってくる # name2 = matsuoka_func.katakana_validator(web.post('name2')) name3 = matsuoka_func.katakana_validator(web.post('name3')) # # その結果メッセージが送信される # if name2 == False or name3 == False: message += "&message1=name_notkatakana" admin = web.post('admin', 0) mailaddr = web.post('mailaddr') gender = web.post('gender', 0) # # 8桁の数字か確認する、違うならメッセージ送信 # if len(web.post('birthday')) != 8: message += "&message2=birthday_notlen8" if not re.match(r'[0-9]+', web.post('birthday')): message += "&message3=birthday_notnumeric" ba = web.post('birthday') bayear = ba[0:4] bamonth = ba[4:6] baday = ba[6:8] months = re.match('0([0-9])', bamonth) days = re.match('0([0-9])', baday) if months: bamonth = months.group(1) if days: baday = days.group(1) ba = web.post('joinday') jyear = ba[0:4] jmonth = ba[4:6] jday = ba[6:8] jmonths = re.match('0([0-9])', jmonth) jdays = re.match('0([0-9])', jday) birthday = datetime.datetime(int(bayear), int(bamonth), int(baday), 0, 0).strftime('%s') joinday = datetime.datetime(int(jyear), int(jmonth), int(jday), 0, 0).strftime('%s') # # 画像 # icon = web.post('icon') # # エラーがあればまとめて送信 # if re.match('.+&message.+', message): return web.redirect('/admin/user' + str(message)) sql = """ UPDATE `user` SET `name0` = %(name0)s ,`name1` = %(name1)s , `name2` = %(name2)s , `name3` = %(name3)s ,`admin` = %(admin)s , `asno` = %(asno)s, `mailaddr` = %(mailaddr)s, `gender` = %(gender)s ,`birthday` = %(birthday)s ,`joinday` = %(joinday)s WHERE `uno` = %(uno)s; """ params = { 'uno': get_uno, 'name0': name0, 'name1': name1, 'name2': name2, 'name3': name3, 'asno': asno, 'admin': admin, 'mailaddr': mailaddr, 'gender': gender, 'birthday': birthday, 'joinday': joinday, } web.db.exe(sql, params=params, key=False) sql = """ INSERT INTO `icon` SET `name0` = %(name0)s ,`name1` = %(name1)s , `name2` = %(name2)s , `name3` = %(name3)s ,`admin` = %(admin)s , `asno` = %(asno)s, `mailaddr` = %(mailaddr)s, `gender` = %(gender)s ,`birthday` = %(birthday)s ,`joinday` = %(joinday)s WHERE `uno` = %(uno)s; """ return web.redirect('/admin/user?mode=show&uno=' + str(get_uno) + '&message4=change_user') # # admin.usersで名前をクリックした場合 # if web.get('mode') == 'show': # # 画面の仕様が固まり切るまで [*] にしておく # sql = """ SELECT * FROM `user` LEFT JOIN `assign` USING (`asno`) WHERE `uno` = %(uno)s """ params = { 'uno': get_uno, } user = web.db.exe(sql, params=params, key=True) user['birthday'] = datetime.datetime.fromtimestamp( int(user['birthday'])).strftime("%Y%m%d") user['joinday'] = datetime.datetime.fromtimestamp(int( user['joinday'])).strftime("%Y%m%d") sql = """ SELECT `asno`,`asname` FROM `assign` WHERE `ano` = %(ano)s AND NOT `asno` = %(asno)s """ params = {'ano': user['ano'], 'asno': user['asno']} assign = web.db.exe(sql, params=params, key=False) # # 選択したuserのアイコン # user_icon = matsuoka_func.get_icon(web, get_uno) local = { 'user': user, 'assign': assign, 'user_icon': user_icon, 'login_user_icon': login_user_icon, } return build(web, local,'/admin/' \ + web.path.replace('/', '.')[1:] + '.html') # # 削除ボタンを押した場合 # if web.get('mode') == 'delete': if web.uno == int(get_uno): return web.redirect('/admin/users?message11=thisuser') sql = """ UPDATE `user` SET `deleted` = '1' WHERE `uno` = %(uno)s; """ params = { 'uno': get_uno, } # # 削除を実行 # web.db.exe(sql, params=params, key=False) return web.redirect('/admin/users?message7=delete_user') # # 復帰ボタンを押した場合 # if web.get('mode') == 'revive': if web.uno == int(get_uno): return web.redirect('/admin/users?message11=thisuser') sql = """ UPDATE `user` SET `deleted` = '0' WHERE `uno` = %(uno)s; """ params = { 'uno': get_uno, } # # 復帰を実行 # web.db.exe(sql, params=params, key=False) return web.redirect('/admin/users?message8=rivive_user') return web.redirect('/admin/users')
def main(web, build): # -------------------------------------------------------------------------- # # updateのページで「はい」を選択すると、cookieに保存されたSQLを実行 # if web.get('send'): # # 値の更新 # if web.getcookie_secure('dsql'): dsql = web.getcookie_secure('dsql') web.db.exe(dsql) web.setcookie_secure('dsql', '', maxage=0.1) rsql = web.getcookie_secure('rsql') web.db.exe(rsql) web.setcookie_secure('rsql', '', maxage=0.1) return web.redirect("/growth/changestate?message=update") # # 結果の確認画面に表示する処理、postされた内容でSQLを生成しcookieに保存する # sql = """ SELECT * FROM `involvement` LEFT JOIN `user` USING (`uno`) WHERE `involvement`.`deleted` = 0 AND `involvement`.`vuno` = %(uno)s LIMIT 0,20 """ params = { 'uno': web.uno, } farst = web.db.exe(sql, params=params) d_values = {} # depth r_values = {} sumdepth = 0 delete_uno = [] for k, v in web._post.items(): if re.match(r'up([0-9]+)', k): # # 正規表現でunoとdepthを取得 # u = re.match(r'up([0-9]+)', k) uno = int(u.group(1)) # # 空白時はエラーをメッセージで返す # try: depth = int(v) except: return web.redirect("/growth/changestate?message =" \ + "notint") # # unoと値をdictで格納する # if uno not in d_values: d_values[uno] = {} d_values[uno] = int(depth) if uno not in r_values: r_values[uno] = {} r_values[uno] = int(depth) sumdepth += int(depth) # # depthを更新する用のパラムを生成 # for uno, v in sorted(d_values.items(), key=lambda x: x[1]): if d_values[uno] == 0: d_values[uno] = '(' + str(web.uno) + ", " + str(uno) + ", " \ + str(web.now4) + ", " + str(v) + ", '" + str(0) + "')" else: d_values[uno] = '(' + str(web.uno) + ", " + str(uno) + ", " \ + str(web.now4) + ", " + str(v) + ", '" + str(0) + "')" for uno, v in sorted(r_values.items(), key=lambda x: x[1]): sql = """ SELECT `deleted`, max(`time4`) AS `time4`,`json` FROM `role` WHERE `uno` = %(uno)s AND `vuno` = %(vuno)s """ params = { 'uno': uno, 'vuno': web.uno, } rva = web.db.exe(sql, params=params, key=True) if rva: if r_values[uno] == 0 and rva['deleted'] == 1: continue if r_values[uno] != 0 and rva['deleted'] == 0: continue if r_values[uno] == 0: r_values[uno] = '(' + str(web.uno) + ", " + str(uno) + ", " \ + str(web.now4) + ", " + str(rva['json'] or "NULL") + ", '" + str(1) + "')" else: r_values[uno] = '(' + str(web.uno) + ", " + str(uno) + ", " \ + str(web.now4) + ", " + str(rva['json'] or "NULL") + ", '" + str(0) + "')" else: if r_values[uno] == 0: r_values[uno] = '(' + str(web.uno) + ", " + str(uno) + ", " \ + str(web.now4) + ", " + str(rva['json'] or "NULL") + ", '" + str(1) + "')" else: r_values[uno] = '(' + str(web.uno) + ", " + str(uno) + ", " \ + str(web.now4) + ", " + str(rva['json'] or "NULL") + ", '" + str(0) + "')" r2_values = {} for uno, v in r_values.items(): if r_values[uno] == 0: continue r2_values[uno] = r_values[uno] # # depthの更新、生成したクエリをcookieに保存 # d_values = ', '.join(d_values.values()) r_values = ', '.join(r2_values.values()) dsql = """ INSERT INTO `involvement` (uno, vuno, time4, depth, deleted) VALUES """ + str(d_values) + ";" rsql = """ INSERT INTO `role` (uno, vuno, time4, json, deleted) VALUES """ + str(r_values) + ";" web.setcookie_secure('dsql', dsql, maxage=1800) web.setcookie_secure('rsql', rsql, maxage=1800) # # getを元にdepthを計算 # 新規のユーザーや削除されたユーザーもリストに格納する # udepth = 0 now_dpercent = {} # depth now_state = {} # 登録か削除か for k, v in web._post.items(): if re.match(r'up([0-9]+)', k): u = re.match(r'up([0-9]+)', k) uno = int(u.group(1)) udepth = int(v) # # unoを取得 # user = matsuoka_func.get_user(web, uno) if udepth == 0: apdict = { str(user['uno']): { 'parsent': 0, 'nowdepth': udepth, } } statedict = { str(user['uno']): { 'nowstate': 0, } } else: apdict = { str(user['uno']): { 'parsent': round((udepth / sumdepth * 100), 1), 'nowdepth': udepth, } } statedict = { str(user['uno']): { 'nowstate': 1, } } now_dpercent.update(apdict) now_state.update(statedict) # # ユーザー一覧 # sql = """ SELECT CONCAT(name0, name1) AS `fullname`, `asname`, `depth` ,`vuno`,`involvement`.`uno`, `involvement`.`time4`,`involvement`.`deleted` FROM `user` LEFT JOIN `involvement` ON `involvement`.`vuno` = `user`.`uno` LEFT JOIN `assign` USING (`asno`) WHERE (`involvement`.`uno`,`involvement`.`time4`) IN ( SELECT `uno`, MAX(`time4`) FROM `involvement` WHERE `uno` = %(uno)s GROUP BY `uno` )ORDER BY `depth` DESC """ params = {'uno': web.uno} involvement = web.db.exe(sql, params=params) if involvement: # # 100分率用に全員のdepthを合計 # sumdepth = 0 for k, v in enumerate(involvement): if ['depth'] != 0: sumdepth += v['depth'] # # involvementを出力用に書き換え # for k, v in enumerate(involvement): # # 画像の取得 # icon = matsuoka_func.get_icon(web, v['uno']) #if v['depth'] == now_dpercent[str(v['vuno'])]['nowdepth']: # continue # # 既に登録されているdepthを更新する時 # if v['depth'] != 0 and now_state[str(v['vuno'])]['nowstate'] != 0: v['parcent'] = round((v['depth'] / sumdepth * 100), 1) v['oicon'] = icon['has_icon'] v['oicon_uno'] = icon['uno'] v['now_icon'] = icon['has_icon'] v['now_icon_uno'] = icon['uno'] v['now_depth'] = now_dpercent[str(v['vuno'])]['nowdepth'] v['now_parcent'] = now_dpercent[str(v['vuno'])]['parsent'] # # 新たに登録した場合 # if v['depth'] == 0 and now_state[str(v['vuno'])]['nowstate'] != 0: v['depth'] = '新' v['oicon'] = icon['has_icon'] v['oicon_uno'] = icon['uno'] v['now_depth'] = now_dpercent[str(v['vuno'])]['nowdepth'] v['now_parcent'] = now_dpercent[str(v['vuno'])]['parsent'] # # 未登録のままの場合 # if v['depth'] == 0 and now_state[str(v['vuno'])]['nowstate'] == 0: involvement[k]['None'] = "None" continue # # 削除した場合 # if v['depth'] != 0 and now_state[str(v['vuno'])]['nowstate'] == 0: v['now_depth'] = '削' v['parcent'] = now_dpercent[str(v['vuno'])]['parsent'] v['now_icon'] = icon['has_icon'] v['now_icon_uno'] = icon['uno'] if type(v['now_depth']) == int: v['now_icon'] = icon['has_icon'] v['now_icon_uno'] = icon['uno'] # # 最終的なパーセンテージ # sumdepth = 0 for k, v in enumerate(involvement): if v['depth'] == 0: continue if type(v['depth']) == int: sumdepth += v['depth'] for k, v in enumerate(involvement): if v['depth'] == 0: continue if type(v['depth']) == int: v['lastp'] = round((v['depth'] / sumdepth * 100), 1) local = { 'involvement': involvement, } return build(web, local, \ '/growth/' + web.path.replace('/', '.')[1:] + '.html')
def main(web, build): # -------------------------------------------------------------------------- # # 選択したuser情報 # if web.get("details"): # # user情報 # sql = """ SELECT SQL_CALC_FOUND_ROWS `user`.`uno`, `user`.`name0`, `user`.`name1`,`user`.`name2`, `user`.`name3`, `user`.`passhash`, `user`.`created4`, `assign`.`asname`, `icon`.`uno` AS `has_icon` FROM `user` LEFT JOIN `assign` ON `user`.`asno` = `assign`.`asno` LEFT JOIN `icon` ON `icon`.`uno` = `user`.`uno` WHERE `user`.uno = %(uno)s AND `user`.`deleted` = 0;""" params = { 'uno': web.get("details"), } user = web.db.exe(sql, params=params) # # そのuserの関わり合い # sql1 = """ SELECT SQL_CALC_FOUND_ROWS CONCAT(name0, name1) AS `fullname`, `asname`, `depth` ,`vuno`,`involvement`.`uno`, `involvement`.`time4`, `involvement`.`deleted` FROM `user` LEFT JOIN `involvement` ON `user`.`uno` = `involvement`.`vuno` LEFT JOIN `assign` USING (`asno`) WHERE (`involvement`.`uno`,`involvement`.`time4`) IN ( SELECT `uno`,MAX(`time4`) AS `time4` FROM `involvement` WHERE `uno` = %(uno)s AND NOT `depth` = 0 GROUP BY `vuno` ) AND NOT `depth` = 0 AND NOT `vuno` = %(uno)s ORDER BY `depth` DESC""" params = {'uno': web.get("details")} involvement_users = web.db.exe(sql1, params=params) # # 関わり合いがない場合、involvement_usersを送信しない # if not involvement_users: local = { 'user': user, 'user_icon': web.user_icon, } return build(web, local, \ '/admin/' + web.path.replace('/', '.')[1:] + '.html') # # 100分率用に全員のdepthを合計 # sumdepth = 0 for k, v in enumerate(involvement_users): sumdepth += v['depth'] # # それぞれのdepthの割合を求める # 同時にvunoの画像も取得 # for k, v in enumerate(involvement_users): if v['depth'] == 0: continue v['parcent'] = round((v['depth'] / sumdepth * 100), 1) icon = matsuoka_func.get_icon(web, int(v['uno'])) v['icon'] = icon['has_icon'] v['icon_uno'] = icon['uno'] # # 異議 # sql = """ SELECT * FROM `significance` LEFT JOIN `user` ON `user`.`uno` = `significance`.`vuno` LEFT JOIN `icon` ON `icon`.`uno` = `user`.`uno` LEFT JOIN `significance_statetext` ON `significance`.`state` = `significance_statetext`.`state` WHERE `significance`.`uno` = %(uno)s AND `user`.`deleted` =0""" params = { 'uno': web.get("details"), } significance = web.db.exe(sql, params=params) # # 異議が存在しなければスルー # if not significance: local = { 'user': user, 'involvement_users': involvement_users, 'user_icon': web.user_icon, } return build(web, local, \ '/admin/' + web.path.replace('/', '.')[1:] + '.html') # # timestampをUNIXに # for k, v in enumerate(significance): v['time4'] = datetime.datetime.fromtimestamp(int( v['time4'])).strftime('%Y-%m-%d') local = { 'user': user, 'involvement_users': involvement_users, 'significance': significance, 'user_icon': web.user_icon, } return build(web, local, \ '/admin/' + web.path.replace('/', '.')[1:] + '.html') # # 初期画面 # # ページリング # if web.get('page'): page = web.get('page') page = int(page) - int(1) else: page = 0 length = 10 sql_order = "CONCAT(name2, name3) ASC" # # 一覧表示(初期表示、及び検索欄が空白のまま検索した時)、除名リスト(deleted=1)も取得 # if not web.get('q') or web.get('q') == "": search_word = "" sql = """ SELECT SQL_CALC_FOUND_ROWS `user`.`uno`, `user`.`name0`, `user`.`name1`, `user`.`name2`, `user`.`name3`, `user`.`passhash`, `user`.`created4`, `assign`.`asname`, `icon`.`uno` AS `has_icon`, `significance`.`state` FROM `user` LEFT JOIN `significance` ON `significance`.`uno` = `user`.`uno` LEFT JOIN `assign` ON `user`.`asno` = `assign`.`asno` LEFT JOIN `icon` ON `icon`.`uno` = `user`.`uno` WHERE `user`.`deleted` = 0 AND `user`.`ano` = %(ano)s AND `user`.`ano` = %(ano)s ORDER BY """ + sql_order + """ LIMIT """ + str(length * page) + ", " + str(length) + ";" params = { 'ano': web.ano, } users = web.db.exe(sql, params=params, key=False) users_found = web.db.exe('SELECT FOUND_ROWS();', params=params, key=True) # # 検索結果表示 # if web.get('q'): search_word = web.get('q') sql = """ SELECT SQL_CALC_FOUND_ROWS `user`.`uno`, `user`.`name0`, `user`.`name1`,`user`.`name2`, `user`.`name3`, `user`.`passhash`, `user`.`created4`, `assign`.`asname`, `icon`.`uno` AS `has_icon` `significance`.`sno` FROM `user` LEFT JOIN `significance` ON `significance`.`uno` = `user`.`uno` LEFT JOIN `assign` ON `user`.`asno` = `assign`.`asno` LEFT JOIN `icon` ON `icon`.`uno` = `user`.`uno` WHERE (CONCAT(`user`.`name0` ,`user`.`name1` ,`user`.`name2`, `user`.`name3`) LIKE %(search)s) AND `user`.`deleted` = %(deleted)s ORDER BY """ + sql_order + """ LIMIT """ + str(length * page) + ", " + str(length) + ";" params = { 'ano': web.ano, 'search': str('%' + search_word + '%'), } users = web.db.exe(sql, params=params, key=False) users_found = web.db.exe('SELECT FOUND_ROWS();', params=params, key=True) # # 画像とタイムスタンプの変換 # for i, user in enumerate(users): umode = blossom.md5(user['uno'], 16) created4 = user['created4'] user['created4'] = datetime.date.fromtimestamp(created4) #web.log(user['state'],"RED") web.log(user['state'], "RED") if user['state'] == 4 or user['state'] == None: users[i] = { 'uno': user['uno'], 'umode': umode, 'name0': user['name0'], 'name1': user['name1'], 'name2': user['name2'], 'name3': user['name3'], 'created4': user['created4'], 'asname': user['asname'], 'state': bool(False), 'has_icon': bool(user['has_icon']) } else: users[i] = { 'uno': user['uno'], 'umode': umode, 'name0': user['name0'], 'name1': user['name1'], 'name2': user['name2'], 'name3': user['name3'], 'created4': user['created4'], 'asname': user['asname'], 'state': bool(True), 'has_icon': bool(user['has_icon']) } # # pagenav # if web.environ("SERVER_NAME") == "system.nocc.tech": web.url = "https://system.nocc.tech/admin/users" else: web.url = "https://design.nocc.tech/admin/users" pagenav = blossom.pagenav(users_found / length, page) for i, v in enumerate(pagenav): pagenav[i]['href'] = web.urljoin([{'page': v['i'], 'message': None}]) local = { 'user_icon': web.user_icon, 'users': users, 'pagenav': pagenav, 'search_word': search_word, } return build(web, local,'/admin/' \ + web.path.replace('/', '.')[1:] + '.html')
def main(web, build): # ----------------------------------------------------------------------------- # # anoを取得 # ano = mf.from_uno_getdb_ano(web, web.uno, cookie=False) # # 未処理の意義があるかどうか # # # ログイン中のユーザーの画像を取得 # user_icon = mf.get_icon(web, web.uno) # # ページリングの設定 # if web.get('userspage'): userspage_page = web.get('userspage') deletedpage_page = 0 userspage_page = int(userspage_page) - int(1) elif web.get('deletedpage'): deletedpage_page = web.get('deletedpage') userspage_page = 0 deletedpage_page = int(deletedpage_page) - int(1) else: deletedpage_page = 0 userspage_page = 0 length = 10 sql_order = "CONCAT(name2, name3) ASC" # # 一覧表示(初期表示、及び検索欄が空白のまま検索した時)、除名リスト(deleted=1)も取得 # if not web.get('q') or web.get('q') == "": for i in range(2): if i == 0: page = userspage_page else: page = deletedpage_page search_word = "" sql = """ SELECT SQL_CALC_FOUND_ROWS `user`.`uno`, `user`.`name0`, `user`.`name1`, `user`.`name2`, `user`.`name3`, `user`.`passhash`, `user`.`created4`, `assign`.`asname`, `icon`.`uno` AS `has_icon` FROM `user` LEFT JOIN `assign` ON `user`.`asno` = `assign`.`asno` LEFT JOIN `icon` ON `icon`.`uno` = `user`.`uno` WHERE `user`.`deleted` = %(deleted)s AND `user`.`ano` = %(ano)s AND `user`.`ano` = %(ano)s ORDER BY """ + sql_order + """ LIMIT """ + str(length * page) + ", " + str(length) + ";" params = {'ano': ano, 'deleted': i} if i == 0: users = web.db.exe(sql, params=params, key=False) users_found = web.db.exe('SELECT FOUND_ROWS();', params=params, key=True) else: deleted_users = web.db.exe(sql, params=params, key=False) deleted_found = web.db.exe('SELECT FOUND_ROWS();', params=params, key=True) # # 検索結果表示 # if web.get('q'): search_word = web.get('q') for i in range(2): if i == 0: page = userspage_page else: page = deletedpage_page sql = """ SELECT SQL_CALC_FOUND_ROWS `user`.`uno`, `user`.`name0`, `user`.`name1`,`user`.`name2`, `user`.`name3`, `user`.`passhash`, `user`.`created4`, `assign`.`asname`, `icon`.`uno` AS `has_icon` FROM `user` LEFT JOIN `assign` ON `user`.`asno` = `assign`.`asno` LEFT JOIN `icon` ON `icon`.`uno` = `user`.`uno` WHERE (CONCAT(`user`.`name0` ,`user`.`name1` ,`user`.`name2`, `user`.`name3`) LIKE %(search)s) AND `user`.`deleted` = %(deleted)s ORDER BY """ + sql_order + """ LIMIT """ + str(length * page) + ", " + str(length) + ";" params = { 'ano': ano, 'search': str('%' + search_word + '%'), 'deleted': i, } if i == 0: users = web.db.exe(sql, params=params, key=False) users_found = web.db.exe('SELECT FOUND_ROWS();', params=params, key=True) else: deleted_users = web.db.exe(sql, params=params, key=False) deleted_found = web.db.exe('SELECT FOUND_ROWS();', params=params, key=True) # # 画像とタイムスタンプの変換 # for i, user in enumerate(users): umode = blossom.md5(user['uno'], 16) created4 = user['created4'] user['created4'] = datetime.date.fromtimestamp(created4) users[i] = { 'uno': user['uno'], 'umode': umode, 'name0': user['name0'], 'name1': user['name1'], 'name2': user['name2'], 'name3': user['name3'], 'created4': user['created4'], 'asname': user['asname'], 'has_icon': bool(user['has_icon']) } for i, deleted_user in enumerate(deleted_users): umode = blossom.md5(deleted_user, 16) created4 = deleted_user['created4'] deleted_user['created4'] = datetime.date.fromtimestamp(created4) deleted_users[i] = { 'uno': deleted_user['uno'], 'umode': umode, 'name0': deleted_user['name0'], 'name1': deleted_user['name1'], 'name2': deleted_user['name2'], 'name3': deleted_user['name3'], 'created4': deleted_user['created4'], 'asname': deleted_user['asname'], 'has_icon': bool(deleted_user['has_icon']) } # # pagenav # #urlをリセット if web.environ("SERVER_NAME") == "system.nocc.tech": web.url = "https://system.nocc.tech/admin/users" else: web.url = "https://design.nocc.tech/admin/users" users_pagenav = blossom.pagenav(users_found / length, userspage_page) deleted_pagenav = blossom.pagenav(deleted_found / length, deletedpage_page) for i, v in enumerate(users_pagenav): users_pagenav[i]['href'] = web.urljoin([{ 'userspage': v['i'], 'message': None }]) for i, v in enumerate(deleted_pagenav): deleted_pagenav[i]['href'] = web.urljoin([{ 'deletedpage': v['i'], 'message': None }]) web.log(type(users_pagenav), "RED") local = { 'user_icon': user_icon, 'users': users, 'deleted_users': deleted_users, 'users_pagenav': users_pagenav, 'deleted_pagenav': deleted_pagenav, 'search_word': search_word, } return build(web, local,'/admin/' \ + web.path.replace('/', '.')[1:] + '.html')
def main(web, build): # -------------------------------------------------------------------------- # 繋がりのあるユーザー一覧 # sql1 = """ SELECT CONCAT(name0, name1) AS `fullname`, `asname`, `depth`, `vuno`, `involvement`.`uno`, `involvement`.`time4`,`involvement`.`deleted` FROM `user` LEFT JOIN `involvement` ON `user`.`uno` = `involvement`.`vuno` LEFT JOIN `assign` USING (`asno`) WHERE (`involvement`.`uno`,`involvement`.`time4`) IN ( SELECT `uno`,MAX(`time4`) AS `time4` FROM `involvement` WHERE `uno` = %(uno)s """ sql2 = """ GROUP BY `uno` ) AND `user`.`deleted` = 0 ORDER BY `depth` DESC LIMIT 0,20 """ sql = sql1 + sql2 params = {'uno': web.uno} involvement_users = web.db.exe(sql, params=params) # # 全てのユーザー(検索) # if web.get('q'): web.log("OK", "RED") search_word = web.get('q') sql3 = """ GROUP BY `uno` ) AND (CONCAT(`fullname`, `asname`, `depth`) LIKE %(search)s) LIMIT 0,20 """ sql1 += sql3 params = { 'search_word': str('%' + search_word + '%'), } else: # # 全てのユーザー # search_word = "" sql2 = """ GROUP BY `uno` ) AND `vuno` = %(uno)s AND `user`.`deleted` = 0 LIMIT 0,20 """ sql1 += sql2 allusers = web.db.exe(sql1, params=params) # # 画像の取得 # for k, v in enumerate(involvement_users): icon = matsuoka_func.get_icon(web, v['uno']) v['icon'] = icon['has_icon'] v['icon_uno'] = icon['uno'] for k, v in enumerate(allusers): icon = matsuoka_func.get_icon(web, v['uno']) v['icon'] = icon['has_icon'] v['icon_uno'] = icon['uno'] if v['deleted'] == 0: del allusers[k]['deleted'] local = { 'allusers': allusers, 'involvement_users': involvement_users, 'user_icon': web.user_icon, } return build(web, local, \ '/growth/' + web.path.replace('/', '.')[1:] + '.html')