本文整理汇总了Python中util.get_current_user函数的典型用法代码示例。如果您正苦于以下问题:Python get_current_user函数的具体用法?Python get_current_user怎么用?Python get_current_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_current_user函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
def post(self):
greeting = Greeting()
if util.get_current_user():
greeting.author = util.get_current_user()
greeting.content = self.request.get('content')
greeting.put()
self.redirect('/')
示例2: clear_question_answers_for_current_user
def clear_question_answers_for_current_user(s_question_id):
user = util.get_current_user()
if not user:
return
question_id = -1
try:
question_id = int(s_question_id)
except:
return
if question_id < 0:
return
question = models_discussion.Feedback.get_by_id(question_id)
if not question:
return;
user_data = models.UserData.get_or_insert_for(user)
feedback_keys = question.children_keys()
for key in feedback_keys:
notifications = models_discussion.FeedbackNotification.gql("WHERE user = :1 AND feedback = :2", user, key)
if notifications.count():
db.delete(notifications)
user_data.count_feedback_notification = -1
user_data.put()
示例3: get
def get(self):
user = util.get_current_user()
coach_email = "Not signed in. Please sign in to see your Coach ID."
if user:
coach_email = user.email()
self.render_template('about/faq.html', {"selected_id": "faq", "approx_vid_count": consts.APPROX_VID_COUNT, "coach_email": coach_email})
示例4: get
def get(self):
user = util.get_current_user()
# This if/then clause just makes sure that the user is logged in
if user:
question_key = self.request.get('question_key')
if question_key:
question = db.get(question_key)
bc = breadcrumb(question.subject)
root = Subject.gql('WHERE parent_subject=:1', None).get()
subjects = Subject.gql('WHERE parent_subject = :1', root)
greeting = 'user: %s [<a href="%s">sign out</a>]' % (user.nickname(), users.create_logout_url('/'))
template_values = {
'question': question,
'subjects': subjects,
'greeting': greeting,
'current_url': self.request.uri,
'breadcrumb': bc,
}
path = os.path.join(os.path.dirname(__file__), 'viewquestion.html')
self.response.out.write(template.render(path, template_values))
else:
self.redirect(util.create_login_url(self.request.uri))
示例5: post
def post(self):
user = util.get_current_user()
if not user:
self.redirect(util.create_login_url(self.request.uri))
return
if not is_honeypot_empty(self.request):
# Honeypot caught a spammer (in case this is ever public or spammers
# have google accounts)!
return
question_text = self.request.get("question_text")
video_key = self.request.get("video_key")
playlist_key = self.request.get("playlist_key")
video = db.get(video_key)
if question_text and video:
if len(question_text) > 500:
question_text = question_text[0:500] # max question length, also limited by client
question = models_discussion.Feedback()
question.author = user
question.content = question_text
question.targets = [video.key()]
question.types = [models_discussion.FeedbackType.Question]
db.put(question)
self.redirect("/discussion/pagequestions?video_key=%s&playlist_key=%s&page=0" % (video_key, playlist_key))
示例6: post
def post(self):
user = util.get_current_user()
if not user:
self.redirect(util.create_login_url(self.request.uri))
return
if not is_honeypot_empty(self.request):
# Honeypot caught a spammer (in case this is ever public or spammers
# have google accounts)!
return
comment_text = self.request.get("comment_text")
comments_hidden = self.request.get("comments_hidden")
video_key = self.request.get("video_key")
playlist_key = self.request.get("playlist_key")
video = db.get(video_key)
if comment_text and video:
if len(comment_text) > 300:
comment_text = comment_text[0:300] # max comment length, also limited by client
comment = models_discussion.Feedback()
comment.author = user
comment.content = comment_text
comment.targets = [video.key()]
comment.types = [models_discussion.FeedbackType.Comment]
db.put(comment)
self.redirect("/discussion/pagecomments?video_key=%s&playlist_key=%s&page=0&comments_hidden=%s" % (video_key, playlist_key, comments_hidden))
示例7: video_comments_context
def video_comments_context(video, playlist, page=0, comments_hidden=True):
if page > 0:
comments_hidden = False # Never hide questions if specifying specific page
else:
page = 1
limit_per_page = 10
limit_initially_visible = 3 if comments_hidden else limit_per_page
comments_query = models_discussion.Feedback.gql("WHERE types = :1 AND targets = :2 AND deleted = :3 ORDER BY date DESC", models_discussion.FeedbackType.Comment, video.key(), False)
count_total = comments_query.count()
comments = comments_query.fetch(limit_per_page, (page - 1) * limit_per_page)
count_page = len(comments)
pages_total = max(1, ((count_total - 1) / limit_per_page) + 1)
return {
"user": util.get_current_user(),
"is_mod": is_current_user_moderator(),
"video": video,
"playlist": playlist,
"comments": comments,
"count_total": count_total,
"comments_hidden": count_page > limit_initially_visible,
"limit_initially_visible": limit_initially_visible,
"pages": range(1, pages_total + 1),
"pages_total": pages_total,
"prev_page_1_based": page - 1,
"current_page_1_based": page,
"next_page_1_based": page + 1,
"show_page_controls": pages_total > 1,
"login_url": util.create_login_url("/video?v=%s" % video.youtube_id)
}
示例8: get_for_current_user
def get_for_current_user():
user = util.get_current_user()
if user is not None:
user_data = UserData.get_for(user)
if user_data is not None:
return user_data
return UserData()
示例9: get_user_badges
def get_user_badges(user = None):
if not user:
user = util.get_current_user()
user_badges = []
user_badges_dict = {}
if user:
user_badges = models_badges.UserBadge.get_for(user)
badges_dict = all_badges_dict()
user_badge_last = None
for user_badge in user_badges:
if user_badge_last and user_badge_last.badge_name == user_badge.badge_name:
user_badge_last.count += 1
if user_badge_last.count > 1:
user_badge_last.list_context_names_hidden.append(user_badge.target_context_name)
else:
user_badge_last.list_context_names.append(user_badge.target_context_name)
else:
user_badge.badge = badges_dict.get(user_badge.badge_name)
user_badge.count = 1
user_badge.list_context_names = [user_badge.target_context_name]
user_badge.list_context_names_hidden = []
user_badge_last = user_badge
user_badges_dict[user_badge.badge_name] = True
possible_badges = all_badges()
for badge in possible_badges:
badge.is_owned = user_badges_dict.has_key(badge.name)
user_badges = sorted(filter(lambda user_badge: hasattr(user_badge, "badge") and user_badge.badge is not None, user_badges), reverse=True, key=lambda user_badge:user_badge.date)
possible_badges = sorted(possible_badges, key=lambda badge:badge.badge_category)
user_badges_normal = filter(lambda user_badge: user_badge.badge.badge_category != badges.BadgeCategory.MASTER, user_badges)
user_badges_master = filter(lambda user_badge: user_badge.badge.badge_category == badges.BadgeCategory.MASTER, user_badges)
user_badges_diamond = filter(lambda user_badge: user_badge.badge.badge_category == badges.BadgeCategory.DIAMOND, user_badges)
user_badges_platinum = filter(lambda user_badge: user_badge.badge.badge_category == badges.BadgeCategory.PLATINUM, user_badges)
user_badges_gold = filter(lambda user_badge: user_badge.badge.badge_category == badges.BadgeCategory.GOLD, user_badges)
user_badges_silver = filter(lambda user_badge: user_badge.badge.badge_category == badges.BadgeCategory.SILVER, user_badges)
user_badges_bronze = filter(lambda user_badge: user_badge.badge.badge_category == badges.BadgeCategory.BRONZE, user_badges)
bronze_badges = sorted(filter(lambda badge:badge.badge_category == badges.BadgeCategory.BRONZE, possible_badges), key=lambda badge:badge.points or sys.maxint)
silver_badges = sorted(filter(lambda badge:badge.badge_category == badges.BadgeCategory.SILVER, possible_badges), key=lambda badge:badge.points or sys.maxint)
gold_badges = sorted(filter(lambda badge:badge.badge_category == badges.BadgeCategory.GOLD, possible_badges), key=lambda badge:badge.points or sys.maxint)
platinum_badges = sorted(filter(lambda badge:badge.badge_category == badges.BadgeCategory.PLATINUM, possible_badges), key=lambda badge:badge.points or sys.maxint)
diamond_badges = sorted(filter(lambda badge:badge.badge_category == badges.BadgeCategory.DIAMOND, possible_badges), key=lambda badge:badge.points or sys.maxint)
master_badges = sorted(filter(lambda badge:badge.badge_category == badges.BadgeCategory.MASTER, possible_badges), key=lambda badge:badge.points or sys.maxint)
return { 'possible_badges': possible_badges,
'user_badges': user_badges,
'user_badges_normal': user_badges_normal,
'user_badges_master': user_badges_master,
"badge_collections": [bronze_badges, silver_badges, gold_badges, platinum_badges, diamond_badges, master_badges],
'bronze_badges': user_badges_bronze,
'silver_badges': user_badges_silver,
'gold_badges': user_badges_gold,
'platinum_badges': user_badges_platinum,
'diamond_badges': user_badges_diamond, }
示例10: signature
def signature(target=None, verb=None):
return {
"target": target,
"verb": verb,
"is_mod": is_current_user_moderator(),
"is_author": target and target.author == util.get_current_user()
}
示例11: get
def get(self):
user = util.get_current_user()
if user:
coach = user
coach_email = self.request_string("coach_email")
if users.is_current_user_admin() and coach_email:
# Site administrators can look at any class profile
coach = users.User(email=coach_email)
user_data_coach = models.UserData.get_or_insert_for(coach)
students_data = user_data_coach.get_students_data()
class_points = 0
if students_data:
class_points = reduce(lambda a,b: a + b, map(lambda student_data: student_data.points, students_data))
dict_students = map(lambda student_data: {
"email": student_data.user.email(),
"nickname": util.get_nickname_for(student_data.user),
}, students_data)
selected_graph_type = self.request_string("selected_graph_type") or ClassProgressReportGraph.GRAPH_TYPE
initial_graph_url = "/profile/graph/%s?coach_email=%s&%s" % (selected_graph_type, urllib.quote(coach.email()), urllib.unquote(self.request_string("graph_query_params", default="")))
# Sort students alphabetically and sort into 4 chunked up columns for easy table html
dict_students_sorted = sorted(dict_students, key=lambda dict_student:dict_student["nickname"])
students_per_row = 4
students_per_col = max(1, len(dict_students_sorted) / students_per_row)
list_cols = [[], [], [], []]
list_students_columnized = []
for ix in range(0, len(dict_students_sorted)):
dict_student = dict_students_sorted[ix]
list_cols[(ix / students_per_col) % students_per_row].append(dict_student)
for ix in range(0, len(dict_students_sorted)):
dict_student = list_cols[ix % students_per_row][(ix / students_per_row) % students_per_col]
list_students_columnized.append(dict_student)
template_values = {
'coach': coach,
'coach_email': coach.email(),
'coach_nickname': util.get_nickname_for(coach),
'dict_students': dict_students,
'students_per_row': students_per_row,
'list_students_columnized': list_students_columnized,
'count_students': len(dict_students),
'class_points': class_points,
'selected_graph_type': selected_graph_type,
'initial_graph_url': initial_graph_url,
'exercises': models.Exercise.get_all_use_cache(),
'is_profile_empty': len(dict_students) <= 0,
'selected_nav_link': 'coach',
}
self.render_template('viewclassprofile.html', template_values)
else:
self.redirect(util.create_login_url(self.request.uri))
示例12: post
def post(self):
user = util.get_current_user()
if user:
lat = self.request_float("lat")
lng = self.request_float("lng")
zoom = self.request_int("zoom")
user_data = UserData.get_or_insert_for(user)
user_data.map_coords = serializeMapCoords(lat, lng, zoom)
user_data.put()
示例13: post
def post(self):
user = util.get_current_user()
if user is None:
self.redirect(util.create_login_url(self.request.uri))
return
user_data = UserData.get_or_insert_for(user)
coach_email = self.request.get('coach').lower()
user_data.coaches.append(coach_email)
user_data.put()
self.redirect("/coaches")
示例14: video_qa_context
def video_qa_context(video, playlist=None, page=0, qa_expand_id=None):
limit_per_page = 5
if qa_expand_id:
# If we're showing an initially expanded question,
# make sure we're on the correct page
question = models_discussion.Feedback.get_by_id(qa_expand_id)
if question:
question_preceding_query = models_discussion.Feedback.gql("WHERE types = :1 AND targets = :2 AND deleted = :3 AND date > :4 ORDER BY date DESC", models_discussion.FeedbackType.Question, video.key(), False, question.date)
count_preceding = question_preceding_query.count()
page = 1 + (count_preceding / limit_per_page)
if page <= 0:
page = 1
question_query = models_discussion.Feedback.gql("WHERE types = :1 AND targets = :2 AND deleted = :3 ORDER BY date DESC", models_discussion.FeedbackType.Question, video.key(), False)
answer_query = models_discussion.Feedback.gql("WHERE types = :1 AND targets = :2 AND deleted = :3 ORDER BY date", models_discussion.FeedbackType.Answer, video.key(), False)
count_total = question_query.count()
questions = question_query.fetch(limit_per_page, (page - 1) * limit_per_page)
dict_questions = {}
# Store each question in this page in a dict for answer population
for question in questions:
dict_questions[question.key()] = question
# Just grab all answers for this video and cache in page's questions
for answer in answer_query:
# Grab the key only for each answer, don't run a full gql query on the ReferenceProperty
question_key = answer.parent_key()
if (dict_questions.has_key(question_key)):
question = dict_questions[question_key]
question.children_cache.append(answer)
count_page = len(questions)
pages_total = max(1, ((count_total - 1) / limit_per_page) + 1)
return {
"user": util.get_current_user(),
"is_mod": is_current_user_moderator(),
"video": video,
"playlist": playlist,
"questions": questions,
"count_total": count_total,
"pages": range(1, pages_total + 1),
"pages_total": pages_total,
"prev_page_1_based": page - 1,
"current_page_1_based": page,
"next_page_1_based": page + 1,
"show_page_controls": pages_total > 1,
"qa_expand_id": qa_expand_id,
"issue_labels": ('Component-Videos,Video-%s' % video.youtube_id),
"login_url": util.create_login_url("/video?v=%s" % video.youtube_id)
}
示例15: get
def get(self):
user = util.get_current_user()
user_data = UserData.get_for_current_user()
logout_url = users.create_logout_url(self.request.uri)
template_values = qa.add_template_values({'App': App,
'points': user_data.points,
'username': user and user.nickname() or "",
'login_url': util.create_login_url(self.request.uri),
'student_email' : self.request.get('student_email'),
'logout_url': logout_url},
self.request)
path = os.path.join(os.path.dirname(__file__), 'import.html')
self.response.out.write(template.render(path, template_values))