本文整理汇总了Python中models.UserData类的典型用法代码示例。如果您正苦于以下问题:Python UserData类的具体用法?Python UserData怎么用?Python UserData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
def get(self):
coach = UserData.current()
if coach:
user_override = self.request_user_data("coach_email")
if user_override and user_override.are_students_visible_to(coach):
# Only allow looking at a student list other than your own
# if you are a dev, admin, or coworker.
coach = user_override
student_lists = StudentList.get_for_coach(coach.key())
student_lists_list = [{
'key': 'allstudents',
'name': 'כל התלמידים'.decode("utf8"),
}];
for student_list in student_lists:
student_lists_list.append({
'key': str(student_list.key()),
'name': student_list.name,
})
list_id, _ = get_last_student_list(self, student_lists, coach==UserData.current())
current_list = None
for student_list in student_lists_list:
if student_list['key'] == list_id:
current_list = student_list
selected_graph_type = self.request_string("selected_graph_type") or ClassProgressReportGraph.GRAPH_TYPE
if selected_graph_type == 'progressreport' or selected_graph_type == 'goals': # TomY This is temporary until all the graphs are API calls
initial_graph_url = "/api/v1/user/students/%s?coach_email=%s&%s" % (selected_graph_type, urllib.quote(coach.email), urllib.unquote(self.request_string("graph_query_params", default="")))
else:
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="")))
initial_graph_url += 'list_id=%s' % list_id
exercises = models.Exercise.get_all_use_cache()
exercises.sort(key=lambda ex: ex.display_name)
template_values = {
'user_data_coach': coach,
'coach_email': coach.email,
'list_id': list_id,
'student_list': current_list,
'student_lists': student_lists_list,
'student_lists_json': json.dumps(student_lists_list),
'coach_nickname': coach.nickname,
'selected_graph_type': selected_graph_type,
'initial_graph_url': initial_graph_url,
'exercises': exercises,
'is_profile_empty': not coach.has_students(),
'selected_nav_link': 'coach',
"view": self.request_string("view", default=""),
'stats_charts_class': 'coach-view',
}
self.render_jinja2_template('viewclassprofile.html', template_values)
else:
self.redirect(util.create_login_url(self.request.uri))
示例2: get
def get(self):
student = UserData.current() or UserData.pre_phantom()
user_override = self.request_student_user_data(legacy=True)
if user_override and user_override.key_email != student.key_email:
if not user_override.is_visible_to(student):
# If current user isn't an admin or student's coach, they can't
# look at anything other than their own profile.
self.redirect("/profile")
return
else:
# Allow access to this student's profile
student = user_override
user_badges = util_badges.get_user_badges(student)
selected_graph_type = (self.request_string("selected_graph_type") or
ActivityGraph.GRAPH_TYPE)
# TODO: deal with this one-off hackery. Some graphs use the API
# to fetch data, instead of the /profile/graph methods.
if selected_graph_type == "exerciseprogress":
initial_graph_url = ("/api/v1/user/exercises?email=%s" %
urllib.quote(student.email))
elif selected_graph_type == "goals":
initial_graph_url = ("/api/v1/user/goals?email=%s" %
urllib.quote(student.email))
else:
initial_graph_url = "/profile/graph/%s?student_email=%s&%s" % (
selected_graph_type,
urllib.quote(student.email),
urllib.unquote(self.request_string("graph_query_params",
default="")))
tz_offset = self.request_int("tz_offset", default=0)
template_values = {
'student_email': student.email,
'student_nickname': student.nickname,
'selected_graph_type': selected_graph_type,
'initial_graph_url': initial_graph_url,
'tz_offset': tz_offset,
'student_points': student.points,
'count_videos': models.Setting.count_videos(),
'count_videos_completed': student.get_videos_completed(),
'count_exercises': models.Exercise.get_count(),
'count_exercises_proficient': len(student.all_proficient_exercises),
'badge_collections': user_badges['badge_collections'],
'user_badges_bronze': user_badges['bronze_badges'],
'user_badges_silver': user_badges['silver_badges'],
'user_badges_gold': user_badges['gold_badges'],
'user_badges_platinum': user_badges['platinum_badges'],
'user_badges_diamond': user_badges['diamond_badges'],
'user_badges_master': user_badges['user_badges_master'],
'user_badges': [user_badges['bronze_badges'], user_badges['silver_badges'], user_badges['gold_badges'], user_badges['platinum_badges'], user_badges['diamond_badges'],user_badges['user_badges_master']],
'user_data_student': student,
"show_badge_frequencies": self.request_bool("show_badge_frequencies", default=False),
"view": self.request_string("view", default=""),
}
self.render_jinja2_template('viewprofile.html', template_values)
示例3: setUp
def setUp(self):
self.sel = WebDriver()
# Create a user and an org
self.user = UserData.createUser('a', 'b','[email protected]', 'pw')
theOrg = OrgData.createOrg("theOrg")
self.user.org = theOrg
self.user.save()
self.user = UserData.createUser('d', 'e','[email protected]', 'pw')
self.user.org = theOrg
self.user.save()
示例4: get
def get(self):
student = UserData.current() or UserData.pre_phantom()
user_override = self.request_user_data("student_email")
if user_override and user_override.key_email != student.key_email:
if not user_override.is_visible_to(student):
# If current user isn't an admin or student's coach, they can't look at anything other than their own profile.
self.redirect("/profile?k")
return
else:
# Allow access to this student's profile
student = user_override
user_badges = util_badges.get_user_badges(student)
selected_graph_type = self.request_string("selected_graph_type") or ActivityGraph.GRAPH_TYPE
initial_graph_url = "/profile/graph/%s?student_email=%s&%s" % (
selected_graph_type,
urllib.quote(student.email),
urllib.unquote(self.request_string("graph_query_params", default="")),
)
tz_offset = self.request_int("tz_offset", default=0)
template_values = {
"student_nickname": student.nickname,
"selected_graph_type": selected_graph_type,
"initial_graph_url": initial_graph_url,
"tz_offset": tz_offset,
"student_points": student.points,
"count_videos": models.Setting.count_videos(),
"count_videos_completed": student.get_videos_completed(),
"count_exercises": models.Exercise.get_count(),
"count_exercises_proficient": len(student.all_proficient_exercises),
"badge_collections": user_badges["badge_collections"],
"user_badges_bronze": user_badges["bronze_badges"],
"user_badges_silver": user_badges["silver_badges"],
"user_badges_gold": user_badges["gold_badges"],
"user_badges_platinum": user_badges["platinum_badges"],
"user_badges_diamond": user_badges["diamond_badges"],
"user_badges_master": user_badges["user_badges_master"],
"user_badges": [
user_badges["bronze_badges"],
user_badges["silver_badges"],
user_badges["gold_badges"],
user_badges["platinum_badges"],
user_badges["diamond_badges"],
user_badges["user_badges_master"],
],
"user_data_student": student,
"show_badge_frequencies": self.request_bool("show_badge_frequencies", default=False),
"view": self.request_string("view", default=""),
}
self.render_jinja2_template("viewprofile.html", template_values)
示例5: get
def get(self):
user = users.get_current_user()
day_time = datetime.today() - timedelta(1)
query = UserData.gql("WHERE user = :1", user)
thisUser = query.get()
if thisUser is None:
thisUser = UserData(user=user, lastemail=day_time, Number_Tiles=0)
thisUser.put()
N_tiles = 0
else:
N_tiles = thisUser.Number_Tiles
self.response.write(N_tiles)
示例6: get_profile_target_user_data
def get_profile_target_user_data(self):
student = UserData.current() or UserData.pre_phantom()
if student:
user_override = self.request_user_data("student_email")
if user_override and user_override.key_email != student.key_email:
if not user_override.is_visible_to(student):
# If current user isn't an admin or student's coach, they can't look at anything other than their own profile.
student = None
else:
# Allow access to this student's profile
student = user_override
return student
示例7: post
def post(self):
"""Handle a POST from the login form.
This happens when the user attempts to login with an identifier (email
or username) and password.
"""
cont = self.request_continue_url()
# Authenticate via username or email + password
identifier = self.request_string('identifier')
password = self.request_string('password')
if not identifier or not password:
errors = {}
if not identifier: errors['noemail'] = True
if not password: errors['nopassword'] = True
self.render_json({'errors': errors})
return
user_data = UserData.get_from_username_or_email(identifier.strip())
if not user_data or not user_data.validate_password(password):
errors = {}
errors['badlogin'] = True
# TODO(benkomalo): IP-based throttling of failed logins?
self.render_json({'errors': errors})
return
# Successful login
Login.return_login_json(self, user_data, cont)
示例8: can_control_gandalf
def can_control_gandalf():
"""CUSTOMIZE can_control_gandalf however you want to specify
whether or not the currently-logged-in user has access
to Gandalf dashboard."
"""
user_data = UserData.current(bust_cache=True)
return users.is_current_user_admin() or (user_data and user_data.developer)
示例9: post
def post(self):
x = int(self.request.get('x'))
y = int(self.request.get('y'))
currentdaytime = datetime.today()
query = Claim.gql("WHERE x = :1 AND y = :2", x, y)
Claim_itterator = query.iter(produce_cursors=True)
for claim in Claim_itterator:
query2 = UserData.gql("WHERE user = :1", claim.user)
thisUser = query2.get()
if thisUser.lastemail < currentdaytime - timedelta(1):
message = mail.EmailMessage()
message.sender = ("http://infinitegraffitiwall.appspot.com/ " +
"Tile Claim Service <[email protected]>")
message.to = claim.user.email()
message.subject = ("A Tile that you have claimed " +
"has been changed today.")
message.body = ("""
A Tile that you have claimed has been changed today.
Tile coordinates """ + str(x) + "," + str(y) + """.
Link to location: http://infinitegraffitiwall.appspot.com/@""" +
str(x) + "," + str(y))
message.send()
thisUser.lastemail = currentdaytime
thisUser.put()
示例10: get
def get(self,site_key):
# Get the file by the provided key name
user_data = UserData.get_by_key_name(site_key)
if not user_data:
return self.error(404)
blob_info = user_data.blob_info
# Figure out hostname so we can give 'full links'
host_name = '/'.join([k for k in self.request.url.split('/')[:3]])
# Build the response
resp = {
'name':blob_info.filename,
'creation':blob_info.creation.strftime("%Y-%m-%d %H:%M:%S"),
'download_url':'%s/%s' % (host_name,site_key),
'url':'%s/%s' % (host_name,site_key),
'type':blob_info.content_type,
'size':blob_info.size,
'size_in_kb':(blob_info.size)/1024,
'info_url':'%s/i/%s' % (host_name,site_key),
'thumbnail_url': get_serving_url(blob_info) if blob_info.content_type in IMAGE_MIMETYPES else ''
}
if self.request.get('format') == 'json':
# If the requested format is json render to json
return self.response.out.write(json.dumps(resp))
else:
# Otherwise render to html
self.response.out.write(template.render('templates/viewer.html', resp))
示例11: post
def post(self):
template_values = {}
user_data = UserData.current()
status_file = StringIO.StringIO(self.request_string("status_file"))
reader = csv.reader(status_file)
student_list = []
for line in reader:
student_email = line[0]
student_status = line[1]
student_comment = line[2]
student = SummerStudent.all().filter("email =", student_email).get()
if student is None:
logging.error("Student %s not found" % student_email)
continue
student.application_status = student_status
student.comment = student_comment
if student_status == "Accepted":
student.accepted = True
student_list.append(student)
db.put(student_list)
self.response.out.write("OK")
self.response.set_status(200)
示例12: post
def post(self):
format = self.request.get('format','html')
try:
user_upload = UserData.create(self.get_uploads()[0])
except IndexError:
self.error(404)
self.redirect('/i/%s?format=%s' % (user_upload.key().name(),format))
示例13: get
def get(self):
user_data = UserData.current()
if not user_data:
self.redirect(util.create_login_url(self.request.uri))
return
accept_coach = self.request_bool("accept", default = False)
user_data_coach = self.request_user_data("coach_email")
user_data_student = self.request_user_data('student_email')
if bool(user_data_coach) == bool(user_data_student):
raise Exception('must provide coach_email xor student_email')
if user_data_coach:
user_data_student = user_data
elif user_data_student:
user_data_coach = user_data
if user_data_coach and not user_data_student.is_coached_by(user_data_coach):
coach_request = CoachRequest.get_for(user_data_coach, user_data_student)
if coach_request:
coach_request.delete()
if user_data.key_email == user_data_student.key_email and accept_coach:
user_data_student.coaches.append(user_data_coach.key_email)
user_data_student.put()
if not self.is_ajax_request():
self.redirect("/coaches")
示例14: _consume_auth_token
def _consume_auth_token(self):
"""Check to see if a valid auth token is specified as a param
in the request, so it can be converted into a cookie
and used as the identifier for the current and future requests.
"""
auth_stamp = self.request_string("auth")
if auth_stamp:
# If an auth stamp is provided, it means they logged in using
# a password via HTTPS, and it has redirected here to postlogin
# to set the auth cookie from that token. We can't rely on
# UserData.current() yet since no cookies have yet been set.
token = AuthToken.for_value(auth_stamp)
if not token:
logging.error("Invalid authentication token specified")
else:
user_data = UserData.get_from_user_id(token.user_id)
if not user_data or not token.is_valid(user_data):
logging.error("Invalid authentication token specified")
else:
# Good auth stamp - set the cookie for the user, which
# will also set it for this request.
auth.cookies.set_auth_cookie(self, user_data, token)
return True
return False
示例15: render_login_outer
def render_login_outer(self):
"""Render the login page.
Note that part of the contents of this page is hosted on an iframe
and rendered by this same RequestHandler (render_login_form)
"""
cont = self.request_continue_url()
direct = self.request_bool('direct', default=False)
user_data = UserData.current()
if user_data and not user_data.is_phantom:
# Don't let users see the login page if they're already logged in.
# This avoids dangerous edge cases in which users have conflicting
# Google/FB cookies, and google.appengine.api.users.get_current_user
# returns a different user than the actual person logged in.
self.redirect(cont)
return
template_values = {
'continue': cont,
'direct': direct,
'google_url': users.create_login_url(cont),
}
self.render_jinja2_template('login.html', template_values)