本文整理汇总了Python中openspending.model.account.Account.by_name方法的典型用法代码示例。如果您正苦于以下问题:Python Account.by_name方法的具体用法?Python Account.by_name怎么用?Python Account.by_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openspending.model.account.Account
的用法示例。
在下文中一共展示了Account.by_name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_new_wrong_user
# 需要导入模块: from openspending.model.account import Account [as 别名]
# 或者: from openspending.model.account.Account import by_name [as 别名]
def test_new_wrong_user(self):
# First we add a Dataset with user 'test_new'
user = Account.by_name('test_new')
assert user.api_key == 'd0610659-627b-4403-8b7f-6e2820ebc95d'
u = url(controller='api/version2', action='create')
params = {
'metadata':
'https://dl.dropbox.com/u/3250791/sample-openspending-model.json',
'csv_file':
'http://mk.ucant.org/info/data/sample-openspending-dataset.csv'
}
apikey_header = 'apikey {0}'.format(user.api_key)
response = self.app.post(u, params, {'Authorization': apikey_header})
assert "200" in response.status
assert Dataset.by_name('openspending-example') is not None
# After that we try to update the Dataset with user 'test_new2'
user = Account.by_name('test_new2')
assert user.api_key == 'c011c340-8dad-419c-8138-1c6ded86ead5'
u = url(controller='api/version2', action='create')
params = {
'metadata':
'https://dl.dropbox.com/u/3250791/sample-openspending-model.json',
'csv_file':
'http://mk.ucant.org/info/data/sample-openspending-dataset.csv'
}
apikey_header = 'apikey {0}'.format(user.api_key)
response = self.app.post(u, params, {'Authorization': apikey_header},
expect_errors=True)
assert '403' in response.status
示例2: test_delete_successfully_loaded_source
# 需要导入模块: from openspending.model.account import Account [as 别名]
# 或者: from openspending.model.account.Account import by_name [as 别名]
def test_delete_successfully_loaded_source(self):
"""
Test source removal with a source that has been successfully loaded.
Removing a source that has been successfully loaded should not be
possible.
"""
# Add and import source without errors.
# The source is added to a dataset called 'test-csv' (but
# we'll just use source.dataset.name in case it changes)
source = csvimport_fixture('successful_import')
source.dataset.managers.append(Account.by_name('test'))
importer = CSVImporter(source)
importer.run()
# Make sure the source is imported
assert db.session.query(Source).filter_by(id=source.id).count() == 1, \
"Import of csv failed. Source not found"
# Delete the source
self.app.post(url(controller='source',
action='delete',
dataset=source.dataset.name,
id=source.id),
extra_environ={'REMOTE_USER': 'test'})
# Check if source has been deleted
assert db.session.query(Source).filter_by(id=source.id).count() == 1, \
"Deleting source succeeded. The source is gone."
示例3: register
# 需要导入模块: from openspending.model.account import Account [as 别名]
# 或者: from openspending.model.account.Account import by_name [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()
示例4: profile
# 需要导入模块: from openspending.model.account import Account [as 别名]
# 或者: from openspending.model.account.Account import by_name [as 别名]
def profile(self, name=None):
"""
Generate a profile page for a user (from the provided name)
"""
# Get the account, if it's none we return a 404
account = Account.by_name(name)
if account is None:
response.status = 404
return None
# Set the account we got as the context variable 'profile'
# Note this is not the same as the context variable 'account'
# which is the account for a logged in user
c.profile = account
# Set a context boo if email/twitter should be shown, it is only shown
# to administrators and to owner (account is same as context account)
show_info = (c.account and c.account.admin) or (c.account == account)
# ..or if the user has chosen to make it public
c.show_email = show_info or account.public_email
c.show_twitter = show_info or account.public_twitter
# Collect and sort the account's datasets and views
c.account_datasets = sorted(account.datasets, key=lambda d: d.label)
c.account_views = sorted(account.views, key=lambda d: d.label)
# Render the profile
return templating.render('account/profile.html')
示例5: test_delete_source
# 需要导入模块: from openspending.model.account import Account [as 别名]
# 或者: from openspending.model.account.Account import by_name [as 别名]
def test_delete_source(self):
"""
Test source removal with a source that includes errors
"""
# Add and import source with errors (we want to remove it)
# The source is added to a dataset called 'test-csv' (but
# we'll just use source.dataset.name in case it changes)
source = csvimport_fixture('import_errors')
source.dataset.managers.append(Account.by_name('test'))
importer = CSVImporter(source)
importer.run()
# Make sure the source is imported
assert db.session.query(Source).filter_by(id=source.id).count() == 1, \
"Import of csv failed. Source not found"
# Delete the source
self.app.post(url(controller='source',
action='delete',
dataset=source.dataset.name,
id=source.id),
extra_environ={'REMOTE_USER': 'test'})
# Check if source has been deleted
assert db.session.query(Source).filter_by(id=source.id).count() == 0, \
"Deleting source unsuccessful. Source still exists."
示例6: create_view
# 需要导入模块: from openspending.model.account import Account [as 别名]
# 或者: from openspending.model.account.Account import by_name [as 别名]
def create_view(dataset, view_config):
"""
Create view for a provided dataset from a view provided as dict
"""
# Check if it exists (if not we create it)
existing = View.by_name(dataset, view_config['name'])
if existing is None:
# Create the view
view = View()
# Set saved configurations
view.widget = view_config['widget']
view.state = view_config['state']
view.name = view_config['name']
view.label = view_config['label']
view.description = view_config['description']
view.public = view_config['public']
# Set the dataset as the current dataset
view.dataset = dataset
# Try and set the account provided but if it doesn't exist
# revert to shell account
view.account = Account.by_name(view_config['account'])
if view.account is None:
view.account = shell_account()
# Commit view to database
db.session.add(view)
db.session.commit()
示例7: setup
# 需要导入模块: from openspending.model.account import Account [as 别名]
# 或者: from openspending.model.account.Account import by_name [as 别名]
def setup(self):
super(TestRunController, self).setup()
self.source = csvimport_fixture('import_errors')
self.source.dataset.managers.append(Account.by_name('test'))
self.importer = CSVImporter(self.source)
self.importer.run()
示例8: shell_account
# 需要导入模块: from openspending.model.account import Account [as 别名]
# 或者: from openspending.model.account.Account import by_name [as 别名]
def shell_account():
account = Account.by_name(SHELL_USER)
if account is not None:
return account
account = Account()
account.name = SHELL_USER
db.session.add(account)
return account
示例9: profile
# 需要导入模块: from openspending.model.account import Account [as 别名]
# 或者: from openspending.model.account.Account import by_name [as 别名]
def profile(self, name=None):
c.config = config
account = Account.by_name(name)
if account is None:
response.status = 404
return None
c.profile = account
c.is_admin = True if (c.account and c.account.admin is True) else False
return render('account/profile.html')
示例10: authenticate
# 需要导入模块: from openspending.model.account import Account [as 别名]
# 或者: from openspending.model.account.Account import by_name [as 别名]
def authenticate(self, environ, identity):
if 'login' not in identity or 'password' not in identity:
return None
account = Account.by_name(identity['login'])
if account is None:
return None
if account.password is None:
return None
if check_password_hash(account.password, identity['password']):
return account.name
return None
示例11: __before__
# 需要导入模块: from openspending.model.account import Account [as 别名]
# 或者: from openspending.model.account.Account import by_name [as 别名]
def __before__(self, action, **params):
account_name = request.environ.get('REMOTE_USER', None)
if account_name:
c.account = Account.by_name(account_name)
else:
c.account = None
i18n.handle_request(request, c)
c._cache_disabled = False
c._must_revalidate = False
c.content_section = c.dataset = None
c.detected_l10n_languages = i18n.get_language_pairs()
示例12: test_new_dataset
# 需要导入模块: from openspending.model.account import Account [as 别名]
# 或者: from openspending.model.account.Account import by_name [as 别名]
def test_new_dataset(self):
user = Account.by_name('test_new')
assert user.api_key == 'd0610659-627b-4403-8b7f-6e2820ebc95d'
u = url(controller='api/version2', action='create')
params = {
'metadata':
'https://dl.dropbox.com/u/3250791/sample-openspending-model.json',
'csv_file':
'http://mk.ucant.org/info/data/sample-openspending-dataset.csv'
}
apikey_header = 'apikey {0}'.format(user.api_key)
response = self.app.post(u, params, {'Authorization': apikey_header})
assert "200" in response.status
assert Dataset.by_name('openspending-example') is not None
示例13: grant_admin
# 需要导入模块: from openspending.model.account import Account [as 别名]
# 或者: from openspending.model.account.Account import by_name [as 别名]
def grant_admin(username):
from openspending.model import meta as db
from openspending.model.account import Account
a = Account.by_name(username)
if a is None:
print "Account `%s` not found." % username
return 1
a.admin = True
db.session.add(a)
db.session.commit()
return 0
示例14: team_update
# 需要导入模块: from openspending.model.account import Account [as 别名]
# 或者: from openspending.model.account.Account import by_name [as 别名]
def team_update(self, dataset, format='html'):
self._get_dataset(dataset)
require.dataset.update(c.dataset)
errors, accounts = {}, []
for account_name in request.params.getall('accounts'):
account = Account.by_name(account_name)
if account is None:
errors[account_name] = _("User account cannot be found.")
else:
accounts.append(account)
if c.account not in accounts:
accounts.append(c.account)
if not len(errors):
c.dataset.managers = accounts
c.dataset.updated_at = datetime.utcnow()
db.session.commit()
h.flash_success(_("The team has been updated."))
return self.team_edit(dataset, errors=errors, accounts=accounts)
示例15: command
# 需要导入模块: from openspending.model.account import Account [as 别名]
# 或者: from openspending.model.account.Account import by_name [as 别名]
def command(self):
super(GrantAdminCommand, self).command()
self._check_args_length(1)
from openspending.model.account import Account
username = self.args[0]
account = Account.by_name(username)
if account is None:
print "Account `%s' not found." % username
return False
roles = set(account["_roles"])
roles |= set([u'admin'])
account["_roles"] = list(roles)
Account.save(account)