本文整理汇总了Python中application.models.User.save方法的典型用法代码示例。如果您正苦于以下问题:Python User.save方法的具体用法?Python User.save怎么用?Python User.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类application.models.User
的用法示例。
在下文中一共展示了User.save方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from application.models import User [as 别名]
# 或者: from application.models.User import save [as 别名]
def create(self):
data = json.loads(request.data)
if "mail" not in data:
abort(400)
u = users.User(data["mail"])
a = User(role="editor", user=u)
a.save()
return Response(a.as_json(), mimetype="application/json")
示例2: create
# 需要导入模块: from application.models import User [as 别名]
# 或者: from application.models.User import save [as 别名]
def create(self):
data = json.loads(request.data)
if 'mail' not in data:
abort(400)
u = users.User(data['mail'])
a = User(role='editor',
user=u)
a.save();
return Response(a.as_json(), mimetype='application/json')
示例3: setUp
# 需要导入模块: from application.models import User [as 别名]
# 或者: from application.models.User import save [as 别名]
def setUp(self):
self.app = application.app
bcrypt = Bcrypt(self.app)
# forcibly reconnect to testing db
connection.disconnect()
self.app.config['MONGO_CONFIG']['db_name'] = 'pipeline_testing'
self.connection = connect(
self.app.config['MONGO_CONFIG']['db_name']
, host=self.app.config['MONGO_CONFIG']['host']
, port=int(self.app.config['MONGO_CONFIG']['port'])
)
# drop any lingering test dbs
self.connection.drop_database(
self.app.config['MONGO_CONFIG']['db_name'])
member_user = User(
admin_rights = False
, email = '[email protected]'
, email_confirmation_code = 'goodday'
, email_confirmed = True
, last_login_time = datetime.datetime.utcnow()
, password_hash = bcrypt.generate_password_hash('hola!')
, registration_time = datetime.datetime.utcnow()
, verified = True)
member_user.save()
''' create a test org
'''
test_org = Organization(
label = 'best-org'
, name = 'best org')
test_org.save()
# save membership
member_user.update(push__organizations = test_org)
''' create a test project
'''
test_project = Project(
creation_time = datetime.datetime.utcnow()
, label = 'best-project'
, name = 'best project'
, organization = test_org)
test_project.save()
test_org.update(push__projects=test_project)
''' create a data-less upload
'''
'''
示例4: register
# 需要导入模块: from application.models import User [as 别名]
# 或者: from application.models.User import save [as 别名]
def register(request):
if request.method == "POST":
uf = UserForm(request.POST)
if uf.is_valid():
#获取表单信息
username = uf.cleaned_data['address']
#headImg = uf.cleaned_data['headImg']
#写入数据库
user = User()
user.username = username
#user.headImg = headImg
user.save()
return HttpResponse('upload ok!')
else:
uf = UserForm()
return render_to_response('register.html',{'uf':uf})
示例5: save
# 需要导入模块: from application.models import User [as 别名]
# 或者: from application.models.User import save [as 别名]
def save(self, User):
User.country = self.cleaned_data["country"]
User.postal_code = self.cleaned_data["postal_code"]
User.user_type = self.cleaned_data["user_type"]
User.save()
if User.user_type == "Teacher":
teacher_instance = teacher()
teacher_instance.most_recent_job_title = self.cleaned_data["most_recent_job_title"]
teacher_instance.subjects = self.cleaned_data["subjects"]
teacher_instance.user_id = User
teacher_instance.save()
elif User.user_type == "Student":
student_instance = student()
student_instance.user_id = User
student_instance.School_University = self.cleaned_data["institution"]
student_instance.save()
示例6: setUp
# 需要导入模块: from application.models import User [as 别名]
# 或者: from application.models.User import save [as 别名]
def setUp(self):
self.app = application.app
bcrypt = Bcrypt(self.app)
# forcibly reconnect to testing db
connection.disconnect()
self.app.config['MONGO_CONFIG']['db_name'] = 'pipeline_testing'
mongo_config = self.app.config['MONGO_CONFIG']
mongodb_uri = 'mongodb://'
if mongo_config['dbuser'] and mongo_config['dbpassword']:
mongodb_uri += '%s:%[email protected]' % (mongo_config['dbuser']
, mongo_config['dbpassword'])
mongodb_uri += '%s/%s' % (mongo_config['hosts'], mongo_config['db_name'])
self.connection = connect(mongo_config['db_name'], host=mongodb_uri)
# drop any lingering test dbs
self.connection.drop_database(
self.app.config['MONGO_CONFIG']['db_name'])
''' create test user
'''
member_user = User(
admin_rights = False
, email = '[email protected]'
, email_confirmation_code = 'goodday'
, email_confirmed = True
, last_login_time = datetime.utcnow()
, password_hash = bcrypt.generate_password_hash('hola!')
, registration_time = datetime.utcnow()
, verified = True)
member_user.save()
''' create test org
'''
test_org = Organization(
label = 'euro-water'
, name = 'Euro Water')
test_org.save()
# save membership
member_user.update(push__organizations = test_org)
''' create test headers
'''
date_header = Header(data_type = 'datetime', name = 'date',
label = 'date')
date_header.save()
pH_header = Header(data_type = 'number', name = 'pH', label = 'pH')
pH_header.save()
city_header = Header(data_type = 'string', name = 'city',
label = 'city')
city_header.save()
headers = [date_header, pH_header, city_header]
# save ref to this header for later test
self.date_header_id = date_header.id
''' create test project
'''
test_project = Project(
creation_time = datetime.utcnow()
, label = 'water-quality'
, name = 'water quality'
, ordered_schema = headers
, organization = test_org)
test_project.save()
test_org.update(push__projects=test_project)
''' update the headers with a ref to the project
'''
for header in headers:
header.update(set__project = test_project)
''' create test datapoints
'''
test_data = [
{'date': datetime(2012, 3, 4), 'pH': 2.2, 'city': 'Madrid'}
, {'date': datetime(2012, 3, 5), 'pH': 3, 'city': 'Paris'}
, {'date': datetime(2012, 3, 6), 'pH': 4, 'city': 'London'}
, {'date': datetime(2012, 3, 6), 'pH': 3, 'city': 'London'}
, {'date': datetime(2012, 3, 6), 'pH': None, 'city': 'London'}
]
for datapoint in test_data:
new_entry = Entry(
project = test_project
, unique = True
, values = datapoint)
new_entry.save()
示例7: setUp
# 需要导入模块: from application.models import User [as 别名]
# 或者: from application.models.User import save [as 别名]
def setUp(self):
self.app = application.app
bcrypt = Bcrypt(self.app)
# forcibly reconnect to testing db
connection.disconnect()
self.app.config['MONGO_CONFIG']['db_name'] = 'pipeline_testing'
mongo_config = self.app.config['MONGO_CONFIG']
mongodb_uri = 'mongodb://'
if mongo_config['dbuser'] and mongo_config['dbpassword']:
mongodb_uri += '%s:%[email protected]' % (mongo_config['dbuser']
, mongo_config['dbpassword'])
mongodb_uri += '%s/%s' % (mongo_config['hosts'], mongo_config['db_name'])
self.connection = connect(mongo_config['db_name'], host=mongodb_uri)
# drop any lingering test dbs
self.connection.drop_database(
self.app.config['MONGO_CONFIG']['db_name'])
admin_user = User(
admin_rights = True
, email = '[email protected]'
, email_confirmation_code = 'goodday'
, email_confirmed = True
, last_login_time = datetime.datetime.utcnow()
, password_hash = bcrypt.generate_password_hash('hola!')
, registration_time = datetime.datetime.utcnow()
, verified = True)
admin_user.save()
# same as verified but will push into an org for membership
member_user = User(
admin_rights = False
, email = '[email protected]'
, email_confirmation_code = 'goodday'
, email_confirmed = True
, last_login_time = datetime.datetime.utcnow()
, password_hash = bcrypt.generate_password_hash('hola!')
, registration_time = datetime.datetime.utcnow()
, verified = True)
member_user.save()
verified_user = User(
admin_rights = False
, email = '[email protected]'
, email_confirmation_code = 'goodday'
, email_confirmed = True
, last_login_time = datetime.datetime.utcnow()
, password_hash = bcrypt.generate_password_hash('hola!')
, registration_time = datetime.datetime.utcnow()
, verified = True)
verified_user.save()
unverified_user = User(
admin_rights = False
, email = '[email protected]'
, email_confirmation_code = 'goodday'
, email_confirmed = True
, last_login_time = datetime.datetime.utcnow()
, password_hash = bcrypt.generate_password_hash('hola!')
, registration_time = datetime.datetime.utcnow()
, verified = False)
unverified_user.save()
''' create a test org
'''
test_org = Organization(
label = 'best-org'
, name = 'best org')
test_org.save()
# save membership
member_user.update(push__organizations = test_org)
''' create a test project
'''
test_project = Project(
creation_time = datetime.datetime.utcnow()
, label = 'best-project'
, name = 'best project'
, organization = test_org)
test_project.save()
test_org.update(push__projects=test_project)