本文整理汇总了Python中model.User.get方法的典型用法代码示例。如果您正苦于以下问题:Python User.get方法的具体用法?Python User.get怎么用?Python User.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: profile_get
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get [as 别名]
def profile_get(username):
"""
Show user's profile with at most recent 10 tweets
:param username: username of the user
:type username: string
:rtype: profile page of the user
Note:
Need to check whether authenticated or not
if so add an profile edit button
if not follow button or followed status
Use 'action' param to judge whether to update profile or password
if it is 'profile', show profile update form
if it is 'password', show password update form
"""
user = User.get(username)
ownername = request.get_cookie('username', secret=COOKIES_SECRET)
owner = User.get(ownername)
action = request.GET.get('action', '')
if ownername == username:
if action == 'profile':
return template('profile_update', user=user)
elif action == 'password':
return template('password_update', user=user)
tweets = user.get_tweets()
isfollow = owner.isfollow(username)
return template('profile', user=user, owner=owner, tweets=tweets,
isfollow=isfollow)
示例2: main
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get [as 别名]
def main():
"""docstring for main"""
username_list = {}
data = file("data/petster-hamster/ent.petster-hamster")
for item in data.readlines():
if not item.startswith("%"):
res = INFO_PATTERN.findall(item)
info = dict(zip(KEYS, res))
username_list[info["id"]] = info["username"]
user = User(info)
user.add()
data.close()
data = file("data/petster-hamster/out.petster-hamster")
for item in data.readlines():
# print repr(item)
# raw_input()
if not item.startswith("%"):
uid1, uid2 = item.strip().split(" ")
# print repr(uid1), repr(uid2)
# raw_input()
username1 = username_list[uid1]
username2 = username_list[uid2]
user1 = User.get(username1)
user2 = User.get(username2)
user1.follow(username2)
user2.follow(username1)
data.close()
示例3: profile_post
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get [as 别名]
def profile_post(username):
"""
Update user's profile or password
:param username: username of the user
:type username: string
:rtype: profile page of the user
Note:
Use 'action' param to judge whether to update profile or password
"""
user = User.get(username)
ownername = request.get_cookie('username', secret=COOKIES_SECRET)
owner = User.get(ownername)
action = request.GET.get('action', '')
if ownername == username:
if action == 'profile':
avatar = request.files.avatar
if avatar and avatar.file:
avatar_new = 'images/%s' % username
avatar_file = file(avatar_new, 'w')
print >> avatar_file, avatar.file.read()
avatar_file.close()
res, msg = user.update(
name=request.forms.name,
gender=request.forms.gender,
hometown=request.forms.hometown,
)
elif action == 'password':
old_pw = request.forms.get('old_pw')
new_pw1 = request.forms.get('new_pw1')
new_pw2 = request.forms.get('new_pw2')
res, msg = user.update_password(old_pw, new_pw1, new_pw2)
elif action == 'tweet':
res, msg = Tweet.add(
username = username,
text = request.forms.text,
created_at =
datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
)
if res:
redirect('/%s/' % username)
else:
return template('%s_update' % action, user=user, msg=msg,
ownername=ownername)
elif action == 'follow':
owner.follow(username)
elif action == 'unfollow':
owner.unfollow(username)
redirect('/%s/' % username)
示例4: userUpdate
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get [as 别名]
def userUpdate(self, **kw):
field = str(kw['field'])
type = kw['type']
id = cherrypy.session['current_user']
if type == 'string':
value = str(kw['value'])
elif type == 'int':
value = int(kw['value'])
elif type == 'date':
value = str(kw['value'])
User.get(id).__setattr__(field, value)
return dict()
示例5: get
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get [as 别名]
def get(self):
if not isUserAdmin(self):
self.session[LOGIN_NEXT_PAGE_KEY] = self.URL
self.redirect("/")
return
userKey = self.request.get("userKey")
if (userKey != None and userKey != ""):
user = None
try:
user = User.get(userKey)
except BadKeyError:
pass
if user != None:
weeks = user.weeks
mondays = {}
for week in weeks:
if not mondays.has_key(week.monday):
mondays[week.monday] = week.monday
orderedMondays = sorted(mondays.keys())
template_values = {
'user':user,
'mondays':orderedMondays
}
template = jinja_environment.get_template('templates/admin/userWeeksList.html')
userName = ""
if user.familyName!= None:
userName = userName + user.familyName
if user.familyName!= None and user.givenName!=None:
userName = userName + " "
if user.givenName!=None:
userName = userName + user.givenName
if len(userName) == 0:
userName = "ISMERETLEN"
self.printPage(userName + " rendelései", template.render(template_values), False, False)
示例6: get
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get [as 别名]
def get(self):
if(not isUserAdmin(self)):
self.session[LOGIN_NEXT_PAGE_KEY] = self.URL
self.redirect("/")
return
userKey = self.request.get("userKey")
if (userKey != None and userKey != ""):
user = None
try:
user = User.get(userKey)
except BadKeyError:
pass
if user != None:
template_values = {
"user":user,
}
template = jinja_environment.get_template('templates/userOverview.html')
userName = ""
if (user.familyName != None):
userName = userName + user.familyName
if (user.familyName != None) and (user.givenName != None):
userName = userName + " "
if (user.givenName != None):
userName = userName + user.givenName
if userName == "":
userName = "UNKNOWN"
self.printPage(userName, template.render(template_values), False, False)
else:
template_values = {
"title":"Nincs ilyen felhasznalo",
"message":"Menj vissza, probald meg megegyszer."
}
template = jinja_environment.get_template('templates/staticMessage.html')
self.printPage("User hiba", template.render(template_values), False, False)
示例7: post
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get [as 别名]
def post(self):
userid = self.request.get("userid")
password = self.request.get("userid")
user = User.get(userid)
user.set_password(self.request.get("password")) #set password. need encrypt.
user.put()
return True
示例8: get
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get [as 别名]
def get(self):
if not isUserAdmin(self):
self.session[LOGIN_NEXT_PAGE_KEY] = self.URL
self.redirect("/")
return
userKey = self.request.get('userKey')
orders = None
user = None
if userKey != None and userKey != '':
user = User.get(userKey)
if user != None:
orders = user.webshopOrders
if orders == None:
orders = WebshopOrderItem.all().order("-orderDate")
orderedOrders = sorted(orders, key=lambda order: order.orderDate, reverse=True)
orders = []
for order in orderedOrders:
order.addressString = order.address.zipNumCode + " " + order.address.street + " " + order.address.streetNumber
order.price = order.item.price * order.orderQuantity
orders.append(order)
template_values = {
'orders':orders
}
if user != None:
template_values['user'] = user
template = jinja_environment.get_template('templates/webshop/usersOrders.html')
self.printPage("Rendelések", template.render(template_values), True, True)
示例9: isUserLoggedIn
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get [as 别名]
def isUserLoggedIn(handler):
userKey = handler.session.get(USER_KEY,None)
if (userKey != None):
#If session has a user key, than return logged in
return User.get(userKey)!=None
else:
return False
示例10: post
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get [as 别名]
def post(self):
if(not isUserAdmin(self)):
self.session[LOGIN_NEXT_PAGE_KEY] = self.URL
self.redirect("/")
return
admin = getUser(self)
userKey = self.request.get("userKey")
user = User.get(userKey)
taskId = self.request.get("taskId")
actualTime = datetime.datetime.now(timeZone)
taskList = user.taskList
newTaskList = []
doneTask = None
for task in taskList:
if task.encode('ascii','ignore').startswith(str(taskId) + " "):
doneTask = task
else:
newTaskList.append(task)
if doneTask != None:
actualTime = datetime.datetime.now(timeZone)
parts = doneTask.split(" ", 4)
updatedTaskString = parts[0] + " " + parts[1] + " " + actualTime.strftime("%Y-%m-%d_%H:%M") + " " + str(admin.key()) + " " + parts[4]
doneTasks = user.doneTasks
doneTasks.append(updatedTaskString)
user.taskList = newTaskList
user.doneTasks = doneTasks
user.put()
self.redirect(CRMUserDetails.URL + "?userKey=" + str(user.key()))
示例11: get
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get [as 别名]
def get(self, error_msg=None):
user = sessions.Session().get_current_user()
template_values = {
"temp_user": User.get(str(user.key())),
"error": error_msg
}
self.generate('user/user_profile.html',template_values)
示例12: profile_post
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get [as 别名]
def profile_post(username):
"""
Update user's profile or password
:param username: username of the user
:type username: string
:rtype: profile page of the user
Note:
Use 'action' param to judge whether to update profile or password
"""
user = User.get(username)
ownername = request.get_cookie("username", secret=COOKIES_SECRET)
owner = User.get(ownername)
action = request.GET.get("action", "")
if ownername == username:
if action == "profile":
avatar = request.files.avatar
username_new = request.forms.username or username
avatar_new = user.avatar
if avatar and avatar.file:
avatar_new = "images/avatar_%s%s" % (username, os.path.splitext(avatar.filename)[-1])
avatar_file = file(avatar_new, "w")
print >> avatar_file, avatar.file.read()
avatar_file.close()
res, msg = user.update(username_new, avatar_new)
return template("profile_update", user=user, msg=msg)
elif action == "password":
old_pw = request.forms.get("old_pw")
new_pw1 = request.forms.get("new_pw1")
new_pw2 = request.forms.get("new_pw2")
res, msg = user.update_password(old_pw, new_pw1, new_pw2)
return template("password_update", user=user, msg=msg)
elif action == "tweet":
param = {
"username": username,
"text": request.forms.text,
"created_at": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
}
res, msg = Tweet.add(**param)
return template("tweet_update", user=user, tweet_msg=msg)
elif action == "follow":
owner.follow(username)
elif action == "unfollow":
owner.unfollow(username)
redirect("/%s/" % username)
示例13: before_request
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get [as 别名]
def before_request():
model.db.connect()
uid = session.get("user_id")
if uid:
try:
g.user = User.get(User.id == uid)
except peewee.DoesNotExist, e:
session.pop("user_id")
示例14: user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get [as 别名]
def user(self):
userid = unauthenticated_userid(self)
if userid is not None:
try:
return User.get(userid)
except pycassa.NotFoundException:
return None
return None
示例15: get
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get [as 别名]
def get(self):
if(not isUserAdmin(self)):
self.session[LOGIN_NEXT_PAGE_KEY] = self.URL
self.redirect("/")
return
userKey = self.request.get("userKey")
user = User.get(userKey)
processedHistory = []
for entry in user.contactHistory:
parts = entry.split(" ", 3)
processedEntry = {}
processedEntry['date'] = parts[1]
processedEntry['admin'] = User.get(parts[2])
processedEntry['message'] = parts[3]
processedHistory.append(processedEntry)
user.processedHistory = sorted(processedHistory, key=lambda entry:entry['date'], reverse = True)
processedTasks = []
for entry in user.taskList:
parts = entry.split(" ", 4)
processedEntry = {}
processedEntry['id'] = parts[0]
processedEntry['date'] = parts[1]
processedEntry['doneDate'] = parts[2]
processedEntry['admin'] = User.get(parts[3])
processedEntry['message'] = parts[4]
processedTasks.append(processedEntry)
user.processedTasks = sorted(processedTasks, key=lambda entry:entry['date'], reverse = True)
processedDoneTasks = []
for entry in user.doneTasks:
parts = entry.split(" ", 4)
processedEntry = {}
processedEntry['id'] = parts[0]
processedEntry['date'] = parts[1]
processedEntry['doneDate'] = parts[2]
processedEntry['admin'] = User.get(parts[3])
processedEntry['message'] = parts[4]
processedDoneTasks.append(processedEntry)
user.processedDoneTasks = sorted(processedDoneTasks, key=lambda entry:entry['date'], reverse = True)
template_values={
'user': user,
}
template = jinja_environment.get_template('templates/crm/userOverview.html')
self.printPage("Felhasznaló reszletei", template.render(template_values), False, False)