本文整理汇总了Python中models.Profile.owner方法的典型用法代码示例。如果您正苦于以下问题:Python Profile.owner方法的具体用法?Python Profile.owner怎么用?Python Profile.owner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Profile
的用法示例。
在下文中一共展示了Profile.owner方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: v1_profiles_json
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import owner [as 别名]
def v1_profiles_json(request):
if request.method == "POST":
action = request.POST["action"]
current_device = cache.get('%s:preferred_device' % (request.session['username'],), None)
current_presence = cache.get('%s:presence' % (request.session["username"],), 10)
if action == "remember":
if "id" in request.POST and request.POST["id"] != "":
obj = get_object_or_404(Profile, id=request.POST["id"])
else:
obj = Profile()
obj.owner = request.session["username"]
obj.name = request.POST["name"]
obj.latitude = request.POST["latitude"]
obj.longitude = request.POST["longitude"]
obj.accuracy = int(request.POST["accuracy"])
obj.presence = current_presence if request.POST["presence_id"] == "current" else request.POST["presence_id"]
obj.device = current_device if request.POST["device_id"] == "current" else request.POST["device_id"]
obj.save()
elif action == "delete":
obj = get_object_or_404(Profile, id=request.POST["id"])
obj.delete()
PRESENCE_MAP = {
1: "Do Not Disturb",
2: "Be Right Back",
3: "Unavailable",
4: "Busy",
5: "In A Meeting",
10: "Available",
}
DEVICE_MAP = {
'devices-device1': 'Home',
'devices-device2': 'Work',
'devices-device3': 'Meeting room',
'devices-device4': 'Voicemail'
}
profiles = [{
'id': p.id,
'name': p.name,
'latitude': float(p.latitude),
'longitude': float(p.longitude),
'accuracy': p.accuracy,
'presence_id': p.presence,
'presence_name': PRESENCE_MAP[int(p.presence)],
'device_id': p.device,
'device_name': DEVICE_MAP[p.device]
} for p in Profile.objects.filter(owner=request.session["username"])]
return {"success": True, "profiles": profiles}
示例2: get
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import owner [as 别名]
def get(self, profile_id):
viewer = self.user_model
q = User.query(User.username == profile_id)
user = q.get()
profile = Profile.query(Profile.owner == user.key).get()
#if profile isn't created, create one
if not profile:
profile = Profile()
profile.owner = user.key
profile.about = "I'm new to Techeria. Add me!"
profile.put()
TutorPosts = RequestPost.query(RequestPost.requester == profile_id).fetch()
user.jobpostings = len(TutorPosts)
# for starring and stuff
starQry = RequestPost.query(RequestPost.payment_is_done == True)
tutors_who_can_rate = []
tutees_who_can_rate = []
for a in starQry:
tutors_who_can_rate.append(a.final_provider)
tutees_who_can_rate.append(a.requester)
#Get Notifications
notifications = NotifiedMessage.query(NotifiedMessage.person_reference == viewer.username).fetch(10)
notis_count = len(notifications)
trl = Transaction.query()
transactions_list = []
for oneTransaction in trl:
if viewer.username in oneTransaction.testPeoplewhocanseethis:
transactions_list.append(oneTransaction)
#Get Emails
msg_count = viewer.msg_count
posts_that_are_paid = RequestPost.query(RequestPost.payment_is_done == True).fetch()
posts_tutors_applied_to = RequestPost.query().fetch()
#payments history
#for onePaid in PaidPosts:
#if onePaid.final_provider == user.username:
#posts_that_are_paid = PaidPosts
skill_list = []
endorsements = Endorsement.query(Endorsement.endorsee == user.key).fetch()
endorsement_details = EndorsementDetails.query(EndorsementDetails.endorsee == user.key).fetch()
user.endorsement_count = len(endorsement_details)
for skill in user.skills:
skill = skill.get()
if skill is not None:
endorsement_list = []
endorsement_list.append(skill)
#Get endorsement messages
#Add number #
count = 0
for x in endorsements:
if x.skill == skill.key:
count=x.endorsement_count
endorsement_list.append(count)
skill_list.append(endorsement_list)
connection_list = []
"""Get friend count """
counter = 0
for connection in user.friends:
connection = User.get_by_id(connection.id())
counter+=1
user.friend_count = counter
user.put()
# Get Nested Comments
comments = Comment.query(Comment.root==True, ndb.OR(Comment.recipient_key == user.key, Comment.sender_key == user.key)).order(-Comment.time).fetch(100)
index = 0
while index < len(comments):
children = Comment.query(Comment.parent == comments[index].key).fetch()
index += 1
comments[index:index] = children
if user:
self.response.out.write(template.render('views/profile.html',
{'user':user,
'comments': comments,
'viewer':viewer,
'skills':skill_list,
'profile':profile,
'endorsements':endorsement_details,
'TutorPosts': TutorPosts,
'posts_tutors_applied_to': posts_tutors_applied_to,
'posts_that_are_paid': posts_that_are_paid,
'notifications': notifications,
'notis_count': notis_count,
'transactions_list': transactions_list,
'tutors_who_can_rate': tutors_who_can_rate,
'tutees_who_can_rate': tutees_who_can_rate,
'msg_count': msg_count
}))
示例3: get
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import owner [as 别名]
def get(self, profile_id):
viewer = self.user_model
q = User.query(User.username == profile_id)
user = q.get()
profile = Profile.query(Profile.owner == user.key).get()
#if profile isn't created, create one
if not profile:
profile = Profile()
profile.owner = user.key
profile.about = "I'm new to Techeria. Add me!"
profile.put()
TutorPosts = RequestPost.query(RequestPost.requester == profile_id).fetch()
user.jobpostings = len(TutorPosts)
#posts_tutors_applied_to = []
posts_tutors_applied_to = ""
AllPosts = RequestPost.query()
for onePost in AllPosts:
if user.username in onePost.list_of_applicants:
posts_tutors_applied_to = RequestPost.query().fetch()
user.jobsapplied = len(posts_tutors_applied_to)
skill_list = []
endorsements = Endorsement.query(Endorsement.endorsee == user.key).fetch()
endorsement_details = EndorsementDetails.query(EndorsementDetails.endorsee == user.key).fetch()
user.endorsement_count = len(endorsement_details)
for skill in user.skills:
skill = skill.get()
if skill is not None:
endorsement_list = []
endorsement_list.append(skill)
#Get endorsement messages
#Add number #
count = 0
for x in endorsements:
if x.skill == skill.key:
count=x.endorsement_count
endorsement_list.append(count)
skill_list.append(endorsement_list)
connection_list = []
"""Get friend count """
counter = 0
for connection in user.friends:
connection = User.get_by_id(connection.id())
counter+=1
user.friend_count = counter
user.put()
# Get Nested Comments
comments = Comment.query(Comment.root==True, ndb.OR(Comment.recipient_key == user.key, Comment.sender_key == user.key)).order(-Comment.time).fetch(100)
index = 0
while index < len(comments):
children = Comment.query(Comment.parent == comments[index].key).fetch()
index += 1
comments[index:index] = children
if user:
self.response.out.write(template.render('views/profile.html',
{'user':user, 'comments': comments,
'viewer':viewer, 'skills':skill_list, 'profile':profile, 'endorsements':endorsement_details,
'TutorPosts': TutorPosts, 'posts_tutors_applied_to': posts_tutors_applied_to
}))
示例4: get
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import owner [as 别名]
def get(self, profile_id):
viewer = self.user_model
get_notifications(viewer)
viewer.last_check =datetime.datetime.now() - datetime.timedelta(hours=8)
viewer.put()
# Get profile info
profile_owner = User.query(User.username == profile_id).get()
profile = Profile.query(Profile.owner == profile_owner.key).get()
if not profile:
# If profile isn't created, instantiate
new_profile = Profile()
new_profile.owner = profile_owner.key
new_profile.about_me = "I love to eat food"
new_profile.put()
current_date = datetime.datetime.now() - datetime.timedelta(hours=8)
# Get profile history
history = Request.query(Request.start_time <= current_date, Request.sender == profile_owner.key).order(Request.start_time)
# Get Request regarding the user
reqs = []
timeline_requests = []
waiting_requests = []
my_reqs = []
fired_requests = []
table_reqs = []
pending_requests = []
accepted_requests = []
completed_reqs = []
alloted_time = current_date + datetime.timedelta(minutes=20)
# Get all requests where profile owner is foodie and expert
available_requests = Request.query(Request.start_time >= alloted_time).order(Request.start_time)
my_reqs = Request.query(ndb.OR(Request.sender==profile_owner.key, Request.recipient == profile_owner.key), Request.start_time >= alloted_time).order(Request.start_time).fetch()
dead_reqs = Request.query(ndb.OR(Request.sender==profile_owner.key, Request.recipient == profile_owner.key), Request.start_time <= alloted_time).order(Request.start_time).fetch()
# Get all pending request that user has bid on
for request in available_requests:
# Get all requests you didn't send
if request.sender != profile_owner.key:
# Request not accepted yet
if request.recipient == None:
# Check for bidders
for bid in request.bidders:
bid = bid.get()
if bid.name == profile_owner.username:
# Bid by user
pending_requests.append(request)
table_requests = my_reqs[:] + dead_reqs[:] + pending_requests[:]
table_requests = sorted(table_requests, key=lambda x: x.start_time, reverse=True)
waiting_requests = [x for x in table_requests if x.status == "waiting for a bid"]
accepted_requests = [x for x in table_requests if x.status == "accepted"]
timeline_requests = table_requests
pending_requests = [x for x in timeline_requests if x.status == "pending"]
pending_requests = sorted(pending_requests, key = lambda x: x.start_time, reverse=True)
timeline_requests = [x for x in timeline_requests if x.status != "waiting for a bid"]
timeline_requests = [x for x in timeline_requests if x.status != "pending"]
timeline_requests = [x for x in timeline_requests if x.status != "dead"]
timeline_requests = [x for x in timeline_requests if x.status != "accepted"]
timeline_comments = []
for r in timeline_requests:
c = Endorsement.query(Endorsement.request == r.key).fetch()
if c:
timeline_comments.append(c)
else:
timeline_comments.append("None")
timeline_requests = zip(timeline_requests, timeline_comments)
completed_requests = [x for x in timeline_requests if x[0].status == "complete"]
fired_requests = [x for x in timeline_requests if x[0].status == "fired"]
self.response.out.write(template.render('views/profile.html',
{'owner':profile_owner, 'profile':profile, 'history': history, 'user': viewer, 'timeline_requests': timeline_requests,
'pending_requests': pending_requests, 'accepted_requests': accepted_requests, 'completed_requests': completed_requests,
'waiting_requests': waiting_requests, 'fired_requests': fired_requests}))