Browse Source

add get_site_details in wnf

version-14
Pratik Vyas 11 years ago
parent
commit
acddc9bef1
2 changed files with 37 additions and 0 deletions
  1. +19
    -0
      core/doctype/profile/profile.py
  2. +18
    -0
      wnf.py

+ 19
- 0
core/doctype/profile/profile.py View File

@@ -392,3 +392,22 @@ def profile_query(doctype, txt, searchfield, start, page_len, filters):
name asc name asc
limit %(start)s, %(page_len)s""" % {'key': searchfield, 'txt': "%%%s%%" % txt, limit %(start)s, %(page_len)s""" % {'key': searchfield, 'txt': "%%%s%%" % txt,
'mcond':get_match_cond(doctype, searchfield), 'start': start, 'page_len': page_len}) 'mcond':get_match_cond(doctype, searchfield), 'start': start, 'page_len': page_len})

def get_total_users():
total_users = webnotes.conn.sql("""select count(*) from `tabProfile`
where ifnull(enabled, 0) = 1
and docstatus < 2
and name not in ('Administrator', 'Guest')""")
if total_users:
return total_users[0][0]
return 0

def get_active_users():
active_users = webnotes.conn.sql("""select count(*) from `tabProfile`
where ifnull(enabled, 0) = 1
and docstatus < 2
and name not in ('Administrator', 'Guest')
and hour(timediff(now(), last_login)) < 72""")
if active_users:
return active_users[0][0]
return 0

+ 18
- 0
wnf.py View File

@@ -135,6 +135,7 @@ def setup_utilities(parser):
help="Set administrator password") help="Set administrator password")
parser.add_argument("--mysql", action="store_true", help="get mysql shell for a site") parser.add_argument("--mysql", action="store_true", help="get mysql shell for a site")
parser.add_argument("--serve", action="store_true", help="Run development server") parser.add_argument("--serve", action="store_true", help="Run development server")
parser.add_argument("--get_site_details", action="store_true", help="Get site details")
parser.add_argument("--port", default=8000, type=int, help="port for development server") parser.add_argument("--port", default=8000, type=int, help="port for development server")
# clear # clear
@@ -599,6 +600,23 @@ def search_replace_with_prompt(fpath, txt1, txt2, force=False):
with open(fpath, 'w') as f: with open(fpath, 'w') as f:
f.write(''.join(tmp)) f.write(''.join(tmp))
print colored('Updated', 'green') print colored('Updated', 'green')

@cmd
def get_site_details(site=None, verbose=False):
import webnotes
from webnotes.profile import get_system_managers
from core.doctype.profile.profile import get_total_users, get_active_users
webnotes.connect(site=site)
ret = {
'last_backup_on': webnotes.local.conf.last_backup_on,
'active_users': get_active_users(),
'total_users': get_total_users(),
'system_managers': get_system_managers()
}
webnotes.destroy()
if verbose:
print ret
return ret
if __name__=="__main__": if __name__=="__main__":
main() main()

Loading…
Cancel
Save