本文整理汇总了Python中models.User.getByURI方法的典型用法代码示例。如果您正苦于以下问题:Python User.getByURI方法的具体用法?Python User.getByURI怎么用?Python User.getByURI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User
的用法示例。
在下文中一共展示了User.getByURI方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validateTransfer
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import getByURI [as 别名]
def validateTransfer(request):
site_id = request.params.get('site_id','')
newowner = request.POST.get('newowner','').lower()
principal = authenticated_userid(request)
user = User.getByURI(principal)
pol = POLICIES[user.type]
if user.transfers >= pol.transfers:
return {'newowner': "You are not allowed to transfer site."}, None
if newowner == principal:
return {'newowner': "Can't transfer sit to itself."}, None
user = Session.query(User).filter_by(email = newowner).first()
if user is None:
return {'newowner': 'User is not found.'}, None
l = 0
for s in user.sites:
if not s.removed:
l += 1
remaining = POLICIES[user.type].sites - l
if remaining <= 0:
return {'newowner': 'User aready has created maximum number of allowed sites.'}, None
data = {'site': site_id,
'user_id': user.id,
'type': user.type}
return {}, data
示例2: update
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import getByURI [as 别名]
def update(self):
super(MainLayout, self).update()
self.principal = principal = authenticated_userid(self.request)
self.user = User.getByURI(principal)
self.isanon = not self.user
if principal and self.user is None:
headers = forget(self.request)
raise HTTPFound(location='/', headers=headers)
if not self.isanon:
self.membership = self.user.membership_label()
self.policy = POLICIES.get(self.user.type, 0)
if self.user.type in (1, 2):
self.policy_id = self.user.type
else:
self.policy_id = 'free'
price = config.PRICES.get(self.policy.id, 'free')
if price == 'free':
self.price = 'free'
else:
self.price = '$%s'%price
self.removes = self.policy.removes - self.user.removes
self.transfers = self.policy.transfers - self.user.transfers
sites = len([s for s in self.user.sites if not s.removed])
self.sites = self.policy.sites - sites
self.manager = self.user.email in ptah.PTAH_CONFIG.managers
self.principal = self.user.email
示例3: transfer
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import getByURI [as 别名]
def transfer(request):
errors, data = validateTransfer(request)
if errors:
raise HTTPFound(
location="/dashboard.html?message=Can't transfer site.")
site = Session.query(Site).filter_by(id = data['site']).first()
if site is None:
raise HTTPFound(
location="/dashboard.html?message=Can't transfer site.")
principal = authenticated_userid(request)
user = User.getByURI(principal)
if site.user_id != user.id:
raise HTTPFound(
location="/dashboard.html?message=Can't transfer site.")
user.transfers += 1
site.user_id = data['user_id']
# change policy
hosts = [h.host for h in site.hosts]
POLICIES[data['type']].changeHostsPolicy(hosts, site.site_name)
# change owner of new site
if PLOUD.maintence is not None:
PLOUD.maintence.execute(hosts[0], 'ploud-fix-owner')
raise HTTPFound(
location="/dashboard.html?message=Site has been transfered.")
示例4: login
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import getByURI [as 别名]
def login(request):
site_id = request.params.get('site_id', '')
try:
site_id = int(site_id)
except:
raise HTTPFound(location = '/dashboard.html')
site = Session.query(Site).filter_by(id = site_id).first()
if site is None:
raise HTTPFound(
location = "/dashboard.html?message=Can't find site information.")
principal = authenticated_userid(request)
user = User.getByURI(principal)
if user is None:
raise HTTPFound(
location = "/dashboard.html?message=Can't find site information.")
if site.user_id != user.id:
raise HTTPFound(
location = "/dashboard.html?message=Can't find site information.")
data = '%s::%s'%(user.email, user.password)
tid = token.service.generate(LOGIN_TOKEN_TYPE, data)
return HTTPFound(location='http://%s/authToken?token=%s'%(site.hosts[0].host, tid))
示例5: update
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import getByURI [as 别名]
def update(self):
super(FrontendLayout, self).update()
self.principal = principal = authenticated_userid(self.request)
self.user = User.getByURI(principal)
self.isanon = not self.user
if principal and self.user is None:
headers = forget(self.request)
return HTTPFound(location='/', headers=headers)
if not self.isanon:
self.membership = self.user.membership_label()
self.policy = POLICIES.get(self.user.type, 0)
if self.user.type in (1, 2):
self.policy_id = self.user.type
else:
self.policy_id = 'free'
price = config.PRICES.get(self.policy.id, 'free')
if price == 'free':
self.price = 'free'
else:
self.price = '$%s'%price
self.removes = self.policy.removes - self.user.removes
self.transfers = self.policy.transfers - self.user.transfers
sites = len([s for s in self.user.sites if not s.removed])
self.sites = self.policy.sites - sites
MANAGE = ptah.get_settings(ptah.CFG_ID_PTAH, self.request.registry)
self.manager = self.user.email in MANAGE['managers']
self.principal = self.user.email
示例6: update
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import getByURI [as 别名]
def update(self):
uri = authenticated_userid(self.request)
user = User.getByURI(uri)
info = {'email': user.email,
'policy': getattr(user, 'type', 0)}
self.policy = info['policy']
self.user = user
self.isAnon = user is None
return info
示例7: update
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import getByURI [as 别名]
def update(self):
uri = authenticated_userid(self.request)
user = User.getByURI(uri)
if user is not None:
info = {'email': user.email,
'policy': getattr(user, 'type', 0)}
self.policy = info['policy']
else:
info = {'email': 'anonymous subscription',
'policy': 98}
self.user = user
self.isAnon = user is None
return info
示例8: remove
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import getByURI [as 别名]
def remove(request):
site = request.POST.get('site_id')
site = Session.query(Site).filter_by(id = site).first()
if site is None:
raise HTTPFound(location="/dashboard.html?message=Can't find site.")
principal = authenticated_userid(request)
user = User.getByURI(principal)
if site.user_id != user.id:
raise HTTPFound(location="/dashboard.html?message=Can't find site.")
pol = POLICIES[user.type]
if user.removes >= pol.removes:
raise HTTPFound(
location="/dashboard.html?message=You are not allowed to remove site.")
conn = ploud_config.PLOUD_POOL.getconn()
cursor = conn.cursor()
pol.removeSite(site.id, cursor)
site.removed = True
cursor.execute(
"SELECT host FROM vhost WHERE id = %s", (site.id,))
sites = [row[0] for row in cursor.fetchall()]
if sites:
cursor.execute(
"DELETE FROM vhost WHERE id = %s", (site.id,))
removeVirtualHosts(sites)
site.site_name = 'site_for_removing_%s'%site.id
user.removes += 1
cursor.close()
conn.commit()
ploud_config.PLOUD_POOL.putconn(conn)
raise HTTPFound(location="/dashboard.html?message=Site has been removed.")
示例9: update
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import getByURI [as 别名]
def update(self):
request = self.request
self.status = {}
self.message = ''
principal = authenticated_userid(request)
self.user = user = User.getByURI(principal)
# user has been removed
if user is None:
headers = forget(request)
raise HTTPFound(location='/', headers=headers)
self.policy = policy = POLICIES[user.type]
self.allowRemove = user.removes < policy.removes
self.allowTransfer = user.transfers < policy.transfers
self.urls = urls = []
self.stats = stats = {'db': 0, 'bw': 0,
'vhosts': policy.vhosts, 'bots': policy.bots}
host = PLOUD.domain
_site_actions = self._site_actions()
for site in user.sites:
if site.removed:
continue
vhost = Session.query(Host).filter_by(id=site.id).first()
urls.append({'url': 'http://%s.%s/' % (site.site_name, host),
'id': site.id,
'site_name': site.site_name,
'db': '%0.2fMb'%(site.size/1048576.0),
'disabled': site.disabled,
'site_id': site.id,
'hostname' : vhost and vhost.host or None,
'bw': '%0.2fMb'%((site.bwin+site.bwout)/1048576.0),
'actions' : _site_actions[site.site_name]})
stats['db'] = stats['db'] + site.size
stats['bw'] = stats['bw'] + site.bwin + site.bwout
urls = sorted(urls, key=lambda site: site['site_name'])
max_provisioned = policy.sites
self.remaining = max_provisioned - len(urls)
self.allowCreate = bool(self.remaining)
stats['db_pc'] = '%0.1f'%(stats['db'] / (policy.dbsize/100.0))
stats['db'] = '%0.2f Mb'%(stats['db']/1048576.0)
stats['db_to'] = '%d Mb'%(policy.dbsize/1048576)
stats['bw_pc'] = '%0.1f'%(stats['bw'] / (policy.bandwidth/100.0))
stats['bw'] = '%0.2f Mb'%(stats['bw']/1048576.0)
stats['bw_to'] = '%d Mb'%(policy.bandwidth/1048576)
createSite = request.POST.get('form-create-site', None)
if createSite is not None:
self.createSite()
return {'stats': stats, 'urls': urls}
示例10: get_principal
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import getByURI [as 别名]
def get_principal(self, uri):
return User.getByURI(uri)
示例11: update
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import getByURI [as 别名]
def update(self):
request = self.request
site = request.params.get('site')
site = ptah.get_session().query(Site).filter_by(id=site).first()
if site is None:
return HTTPFound(location="/dashboard.html?message=Can't find site.")
self.site = site
self.host = ''
for host in site.hosts:
self.host = host.host
break
principal = authenticated_userid(request)
user = User.getByURI(principal)
if site.user_id != user.id:
return HTTPFound(location="/dashboard.html?message=Can't find site.")
pol = POLICIES[user.type]
if not pol.vhosts:
url = '/dashboard.html?message='
url += 'Virtual hosting is not available for your type of '
url += 'membership.'
return HTTPFound(location=url)
if 'form-change' not in request.POST:
return
hostname = request.POST.get('hostname','').strip().lower()
PLOUD = ptah.get_settings('ploud', self.request.registry)
if hostname.endswith('.%s'%PLOUD['domain']) and \
hostname != '%s.%s'%(site.site_name, PLOUD['domain']):
self.message = "%s domain is not allowed."%PLOUD['domain']
return
if hostname == self.host:
return HTTPFound(location='/dashboard.html?message=Site now has new hostname.')
conn = ploud_config.PLOUD_POOL.getconn()
cursor = conn.cursor()
cursor.execute(
"SELECT host FROM vhost WHERE id = %s", (site.id,))
sites = [row[0] for row in cursor.fetchall()]
if sites:
cursor.execute(
"DELETE FROM vhost WHERE id = %s", (site.id,))
removeVirtualHosts(sites)
cursor.execute("INSERT INTO vhost(id, host) VALUES(%s, %s)",
(site.id, hostname))
addVirtualHosts((str(hostname),), 'plone41')
pol.changeHostsPolicy((hostname,), site.site_name)
cursor.close()
conn.commit()
ploud_config.PLOUD_POOL.getconn(conn)
return HTTPFound(location='/dashboard.html?message=Site now has new hostname.')