本文整理汇总了Python中tiddlyweb.model.tiddler.Tiddler.fields["creation"]方法的典型用法代码示例。如果您正苦于以下问题:Python Tiddler.fields["creation"]方法的具体用法?Python Tiddler.fields["creation"]怎么用?Python Tiddler.fields["creation"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tiddlyweb.model.tiddler.Tiddler
的用法示例。
在下文中一共展示了Tiddler.fields["creation"]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_user
# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import fields["creation"] [as 别名]
def update_user(environ, start_response):
query = environ["tiddlyweb.query"]
store = environ["tiddlyweb.store"]
username = query.get("email", [None])[0]
if not username:
return update_user_form(environ, start_response, message="Must have username/email")
name = query.get("name", [""])[0]
country = query.get("country", [""])[0]
company = query.get("company", [""])[0]
password = query.get("password", [""])[0]
tier = query.get("tier", [""])[0]
expiry = query.get("expiry", ["0"])[0]
now = time.time()
expiry = now + (float(expiry) * 24 * 60 * 60)
user = User(username)
user_new = False
try:
user = store.get(user)
except NoUserError:
user_new = True
roles = [role for role in user.list_roles() if not role.startswith("tier")]
for role in user.list_roles():
user.del_role(role)
roles.append(tier)
for role in roles:
user.add_role(role) # it's a set dupes are handled
if password:
user.set_password(password)
store.put(user)
bag_name = environ["tiddlyweb.config"].get("magicuser.bag", "MAGICUSER")
tiddler = Tiddler(username, bag_name)
tiddler.fields["country"] = country
tiddler.fields["company"] = company
tiddler.fields["name"] = name
# Set the creation and expiration times.
if user_new:
tiddler.fields["creation"] = "%s" % now
tiddler.fields["expiry"] = "%s" % expiry
store.put(tiddler)
# XXX need to go somewhere useful?
# raise HTTP303(server_base_url(environ))
message = "Update successful"
success = True
logging.debug("going to update_user_form with message: " + message)
return update_user_form(environ, start_response, message, success)
示例2: _create_user
# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import fields["creation"] [as 别名]
def _create_user(environ, start_response, creation=0, expiration=0, role="tier1"):
domain = get_domain(environ["HTTP_HOST"])
if creation == 0:
creation = time.time()
store = environ["tiddlyweb.store"]
query = environ["tiddlyweb.query"]
name = query.get("name", [None])[0]
email = query.get("email", [None])[0]
company = query.get("company", [None])[0]
country = query.get("country", [None])[0]
if not (name and email):
# The form has not been filled out
return _user_form(
environ,
start_response,
role=role,
message="Missing Data!",
formdata={"name": name, "email": email, "company": company, "country": country},
)
user = User(email)
try:
user = store.get(user)
# User exists!
return _user_form(
environ,
start_response,
role=role,
message="That account already exists!",
formdata={"name": name, "email": email, "company": company, "country": country},
)
except NoUserError:
password = _random_pass()
user.set_password(password)
user.add_role(role)
store.put(user)
bag_name = environ["tiddlyweb.config"].get("magicuser.bag", "MAGICUSER")
ensure_bag(
bag_name, store, policy_dict={"read": ["NONE"], "write": ["NONE"], "create": ["NONE"], "manage": ["NONE"]}
)
tiddler = Tiddler(email, bag_name)
tiddler.fields["country"] = country
tiddler.fields["company"] = company
tiddler.fields["name"] = name
# Set the creation and expiration times.
now = time.time()
tiddler.fields["creation"] = "%s" % creation
tiddler.fields["expiry"] = "%s" % expiration
store.put(tiddler)
to_address = email
subject = domain + " user info"
body = """
Here's your info:
Username: %s
Password: %s
""" % (
email,
password,
)
query_string = "?email=%s" % to_address
try:
send_email(to_address, subject=subject, body=body, from_="[email protected]" + domain)
query_string += "&success=1&role=%s" % role
raise HTTP303(server_base_url(environ) + "/pages/new_account" + query_string)
except socket.error:
logging.debug("failed to send: %s:%s:%s", to_address, subject, body)
query_string += "&failure=1&role=%s" % role
raise HTTP302(server_base_url(environ) + "/pages/new_account" + query_string)