Ver código fonte

[minor] add system manager, webnotes.conn.count

version-14
Anand Doshi 11 anos atrás
pai
commit
18f2629eab
5 arquivos alterados com 50 adições e 25 exclusões
  1. +16
    -8
      webnotes/__init__.py
  2. +10
    -0
      webnotes/db.py
  3. +17
    -0
      webnotes/profile.py
  4. +6
    -0
      webnotes/utils/__init__.py
  5. +1
    -17
      wnf.py

+ 16
- 8
webnotes/__init__.py Ver arquivo

@@ -557,15 +557,23 @@ def get_conf(site):
site_config = _dict({})
conf = site_config.update(conf.__dict__)
if conf.sites_dir and site:
conf_path = os.path.join(get_site_base_path(sites_dir=conf.sites_dir, hostname=site), 'site_config.json')
if os.path.exists(conf_path):
with open(conf_path, 'r') as f:
site_config.update(json.load(f))
site_config['site'] = site
return site_config

else:
out = get_site_config(conf.sites_dir, site)
if not out:
raise NotFound()
site_config.update(out)
site_config['site'] = site
return site_config

else:
return conf

def get_site_config(sites_dir, site):
conf_path = get_conf_path(sites_dir, site)
if os.path.exists(conf_path):
with open(conf_path, 'r') as f:
return json.load(f)

def get_conf_path(sites_dir, site):
return os.path.join(get_site_base_path(sites_dir=sites_dir,
hostname=site), 'site_config.json')

+ 10
- 0
webnotes/db.py Ver arquivo

@@ -467,6 +467,16 @@ class Database:
except:
return None
def count(self, dt, filters=None):
if filters:
conditions, filters = self.build_conditions(filters)
return webnotes.conn.sql("""select count(*)
from `tab%s` where %s""" % (dt, conditions), filters)[0][0]
else:
return webnotes.conn.sql("""select count(*)
from `tab%s`""" % (dt,))[0][0]
def get_table_columns(self, doctype):
return [r[0] for r in self.sql("DESC `tab%s`" % doctype)]



+ 17
- 0
webnotes/profile.py Ver arquivo

@@ -179,3 +179,20 @@ def add_role(profile, role):
"role": role
})
profile_wrapper.save()

def add_system_manager(email, first_name=None, last_name=None):
# add profile
profile = webnotes.new_bean("Profile")
profile.doc.fields.update({
"name": email,
"email": email,
"enabled": 1,
"first_name": first_name or email,
"last_name": last_name
})
profile.insert()
# add roles
roles = webnotes.conn.sql_list("""select name from `tabRole`
where name not in ("Administrator", "Guest", "All")""")
profile.make_controller().add_roles(*roles)

+ 6
- 0
webnotes/utils/__init__.py Ver arquivo

@@ -838,6 +838,12 @@ def get_site_base_path(sites_dir=None, hostname=None):
def get_site_path(*path):
return get_path(base=get_site_base_path(), *path)
def get_files_path():
return get_site_path(webnotes.conf.files_path)

def get_backups_path():
return get_site_path(webnotes.conf.backup_path)
def get_url(uri=None):
url = get_request_site_address()
if not url or "localhost" in url:


+ 1
- 17
wnf.py Ver arquivo

@@ -219,23 +219,7 @@ def install_fixtures(site=None):
@cmd
def add_system_manager(email, first_name=None, last_name=None, site=None):
webnotes.connect(site=site)
# add profile
profile = webnotes.new_bean("Profile")
profile.doc.fields.update({
"name": email,
"email": email,
"enabled": 1,
"first_name": first_name or email,
"last_name": last_name
})
profile.insert()
# add roles
roles = webnotes.conn.sql_list("""select name from `tabRole`
where name not in ("Administrator", "Guest", "All")""")
profile.make_controller().add_roles(*roles)

webnotes.profile.add_system_manager(email, first_name, last_name)
webnotes.conn.commit()

@cmd


Carregando…
Cancelar
Salvar