本文整理汇总了Python中openspending.model.account.Account.fullname方法的典型用法代码示例。如果您正苦于以下问题:Python Account.fullname方法的具体用法?Python Account.fullname怎么用?Python Account.fullname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openspending.model.account.Account
的用法示例。
在下文中一共展示了Account.fullname方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
# 需要导入模块: from openspending.model.account import Account [as 别名]
# 或者: from openspending.model.account.Account import fullname [as 别名]
def register(self):
require.account.create()
errors, values = {}, None
if request.method == 'POST':
try:
schema = AccountRegister()
values = request.params
data = schema.deserialize(values)
if Account.by_name(data['name']):
raise colander.Invalid(
AccountRegister.name,
_("Login name already exists, please choose a "
"different one"))
if not data['password1'] == data['password2']:
raise colander.Invalid(AccountRegister.password1, _("Passwords \
don't match!"))
account = Account()
account.name = data['name']
account.fullname = data['fullname']
account.email = data['email']
account.password = generate_password_hash(data['password1'])
db.session.add(account)
db.session.commit()
who_api = get_api(request.environ)
authenticated, headers = who_api.login({
"login": account.name,
"password": data['password1']
})
response.headers.extend(headers)
return redirect("/")
except colander.Invalid, i:
errors = i.asdict()
示例2: make_account
# 需要导入模块: from openspending.model.account import Account [as 别名]
# 或者: from openspending.model.account.Account import fullname [as 别名]
def make_account(name='test', fullname='Test User',
email='[email protected]',
admin=False, verified=True):
from openspending.model.account import Account
# First see if the account already exists and if so, return it
account = Account.by_email(email)
if account:
return account
# Account didn't exist so we create it and return it
account = Account()
account.fullname = fullname
account.email = email
account.admin = admin
account.verified = verified
db.session.add(account)
db.session.commit()
return account
示例3: make_account
# 需要导入模块: from openspending.model.account import Account [as 别名]
# 或者: from openspending.model.account.Account import fullname [as 别名]
def make_account(name='test', fullname='Test User',
email='[email protected]', twitter='testuser',
admin=False):
from openspending.model.account import Account
# First see if the account already exists and if so, return it
account = Account.by_name(name)
if account:
return account
# Account didn't exist so we create it and return it
account = Account()
account.name = name
account.fullname = fullname
account.email = email
account.twitter_handle = twitter
account.admin = admin
db.session.add(account)
db.session.commit()
return account
示例4: register
# 需要导入模块: from openspending.model.account import Account [as 别名]
# 或者: from openspending.model.account.Account import fullname [as 别名]
def register(self):
require.account.create()
c.config = config
self._disable_cache()
errors, values = {}, None
if request.method == 'POST':
try:
schema = AccountRegister()
values = request.params
data = schema.deserialize(values)
if Account.by_name(data['name']):
raise colander.Invalid(
AccountRegister.name,
_("Login name already exists, please choose a "
"different one"))
if not data['password1'] == data['password2']:
raise colander.Invalid(AccountRegister.password1,
_("Passwords don't match!"))
account = Account()
account.name = data['name']
account.fullname = data['fullname']
account.email = data['email']
account.password = generate_password_hash(data['password1'])
db.session.add(account)
db.session.commit()
who_api = get_api(request.environ)
authenticated, headers = who_api.login({
"login": account.name,
"password": data['password1']
})
errors = subscribe_lists(('community', 'developer'), data)
if errors:
h.flash_notice(_("Subscription to the following mailing " +
"lists probably failed: %s.") % ', '.join(errors))
response.headers.extend(headers)
return redirect("/")
except colander.Invalid, i:
errors = i.asdict()
示例5: register
# 需要导入模块: from openspending.model.account import Account [as 别名]
# 或者: from openspending.model.account.Account import fullname [as 别名]
def register():
""" Perform registration of a new user """
errors, values = {}, dict(request.form.items())
try:
# Grab the actual data and validate it
data = AccountRegister().deserialize(values)
#check if email is already registered
# it is, then send the email hash for the login
#check that email is real
#get the domain
print data['email']
if (data['email'].find('@') == -1 or data['email'].find('.') == -1):
raise colander.Invalid(AccountRegister.email,
"You must use a valid USG email address")
domain = data['email'][data['email'].find('@') + 1:]
if 'EMAIL_WHITELIST' not in current_app.config.keys():
raise colander.Invalid(AccountRegister.email,
"System not set correctly. Please contact the administrator.")
domainvalid = False
for domainemail in current_app.config['EMAIL_WHITELIST']:
if domain.lower() == domainemail.lower():
domainvalid = True
if not domainvalid:
raise colander.Invalid(AccountRegister.email,
"Your email is not available for registration. Currently it is only available for US Government emails.")
# Check if the username already exists, return an error if so
if Account.by_email(data['email']):
#resend the hash here to the email and notify the user
raise colander.Invalid(
AccountRegister.email,
"Login Name already exists. Click reset password.")
# Create the account
account = Account()
account.fullname = data['fullname']
account.email = data['email']
db.session.add(account)
db.session.commit()
# Perform a login for the user
#login_user(account, remember=True)
sendhash(account)
# TO DO redirect to email sent page
return redirect(url_for('account.email_message', id=account.id))
except colander.Invalid as i:
errors = i.asdict()
values["csrf_token"] = generate_csrf_token()
return render_template('account/login.jade', form_fill=values,
form_errors=errors)
示例6: register
# 需要导入模块: from openspending.model.account import Account [as 别名]
# 或者: from openspending.model.account.Account import fullname [as 别名]
def register(self):
"""
Perform registration of a new user
"""
# We must allow account creation
require.account.create()
# We add the config as a context variable in case anything happens
# (like with login we need this to allow subscriptions to mailing lists)
c.config = config
# Disable the cache (don't want anything getting in the way)
self._disable_cache()
# Initial values and errors
errors, values = {}, None
# If this is a POST operation somebody is trying to register
if request.method == 'POST':
try:
# Get the account register schema (for validation)
schema = AccountRegister()
# Set values from the request parameters
# (for validation and so we can autofill forms)
values = request.params
# Grab the actual data and validate it
data = schema.deserialize(values)
# Check if the username already exists, return an error if so
if Account.by_name(data['name']):
raise colander.Invalid(
AccountRegister.name,
_("Login name already exists, please choose a "
"different one"))
# Check if passwords match, return error if not
if not data['password1'] == data['password2']:
raise colander.Invalid(AccountRegister.password1,
_("Passwords don't match!"))
# Create the account
account = Account()
# Set username and full name
account.name = data['name']
account.fullname = data['fullname']
# Set email and if email address should be public
account.email = data['email']
account.public_email = data['public_email']
# Hash the password and store the hash
account.password = generate_password_hash(data['password1'])
# Commit the new user account to the database
db.session.add(account)
db.session.commit()
# Perform a login for the user
who_api = get_api(request.environ)
authenticated, headers = who_api.login({
"login": account.name,
"password": data['password1']
})
# Add the login headers
response.headers.extend(headers)
# Subscribe the user to the mailing lists
errors = subscribe_lists(('community', 'developer'), data)
# Notify if the mailing list subscriptions failed
if errors:
h.flash_notice(_("Subscription to the following mailing " +
"lists probably failed: %s.") % ', '.join(errors))
# Registration successful - Redirect to the front page
return redirect("/")
except colander.Invalid, i:
# Mark colander errors
errors = i.asdict()