本文整理汇总了Python中models.UserData类的典型用法代码示例。如果您正苦于以下问题:Python UserData类的具体用法?Python UserData怎么用?Python UserData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserData类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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))
开发者ID:di445,项目名称:server,代码行数:58,代码来源:util_profile.py
示例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)
开发者ID:KhanWorld,项目名称:KhanAcademy,代码行数:58,代码来源:util_profile.py
示例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()
开发者ID:jab0ii,项目名称:pgfwd,代码行数:11,代码来源:ui_tests.py
示例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)
开发者ID:avh4,项目名称:khan-academy,代码行数:52,代码来源:util_profile.py
示例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)
开发者ID:Gaurav0,项目名称:InfiniteGraffitiWall,代码行数:13,代码来源:main.py
示例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
开发者ID:avh4,项目名称:khan-academy,代码行数:14,代码来源:util_profile.py
示例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)
开发者ID:PaulWagener,项目名称:khan-website,代码行数:29,代码来源:login.py
示例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)
开发者ID:KhanWorld,项目名称:KhanAcademy,代码行数:7,代码来源:config.py
示例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()
开发者ID:Gaurav0,项目名称:InfiniteGraffitiWall,代码行数:26,代码来源:main.py
示例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))
开发者ID:topher515,项目名称:sharewithme,代码行数:30,代码来源:views.py
示例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)
开发者ID:hebkhan,项目名称:server,代码行数:28,代码来源:__init__.py
示例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))
开发者ID:topher515,项目名称:sharewithme,代码行数:7,代码来源:views.py
示例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")
开发者ID:avh4,项目名称:khan-academy,代码行数:30,代码来源:coaches.py
示例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
开发者ID:PaulWagener,项目名称:khan-website,代码行数:25,代码来源:login.py
示例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)
开发者ID:PaulWagener,项目名称:khan-website,代码行数:25,代码来源:login.py
示例16: basic_auth_required
def basic_auth_required(self, include_viewers=False):
# scheme = os.environ.get('wsgi.url_scheme')
# if scheme != 'https':
# # Basic auth should be done via https only
# return False
auth = os.environ.get("HTTP_AUTHORIZATION", None)
auth_msg = 'Basic realm="%s on AppEngine"' % self.reponame
if not auth:
# lacking auth info
self.response.headers["WWW-Authenticate"] = auth_msg
return False
(basic, _, auth) = auth.partition(" ")
if basic != "Basic":
# Mechanism is not Basic.
self.response.headers["WWW-Authenticate"] = auth_msg
return False
(username, _, password) = base64.b64decode(auth).partition(":")
if username.find("@") < 0:
username += "@gmail.com"
userdata = UserData.get_by_key_name("user_" + username)
if not userdata or str(userdata.passphrase) != str(password):
# passphrase mismatch.
self.response.headers["WWW-Authenticate"] = auth_msg
return False
if not self.repo.check_user_perm(userdata.key(), include_viewers):
# Userdata mismatch.
self.response.headers["WWW-Authenticate"] = auth_msg
return False
# Otherwise, valid user.
logging.info("%s pushed into %s." % (username, self.reponame))
return True
开发者ID:pombredanne,项目名称:SmartNotes,代码行数:31,代码来源:hgapp_mod.py
示例17: setUp
def setUp(self):
testOrg = OrgData(orgName='Test org',
status=1)
testOrg.pk = 9
testOrg.save()
self.testUser = UserData.createUser('Test', 'Tester',
'[email protected]', 'pw')
self.testUser.org = testOrg
self.testUser.apiKey = 'TESTAPIKEY8'
self.testUser.save()
self.hierarchy = '{"numLevels":1,"levels":{"0":{"timeout":30,\
"users":[' + str(self.testUser.pk) + ']}}}'
testContactMethod = ContactMethodData(user=self.testUser,
contactType='email',
contactData='[email protected]',
priority=0)
testContactMethod.pk = 7
testContactMethod.save()
self.client = Client()
log = self.client.login(username='[email protected]',
password='pw')
s = self.client.session
s['swag'] = 41
s.save()
开发者ID:jab0ii,项目名称:pgfwd,代码行数:30,代码来源:tests_func.py
示例18: test_APILogin
def test_APILogin(self):
self.testUserL = UserData.createUser('Test', 'Tester',
'[email protected]', 'pw')
self.testUserL.apiKey = 'TESTAPIKEY9'
self.testUserL.save()
testContactMethod = ContactMethodData(user=self.testUserL,
contactType='email',
contactData='[email protected]',
priority=0)
testContactMethod.pk = 11
testContactMethod.save()
userPCMDict = self.testUserL.toUserPCM().toDict()
postData = json.dumps({'username':'[email protected]',
'password':'pw'})
response = self.client.post(APP_URL + '/API/login',
postData, content_type = "application/json")
responses = {'userPCM': userPCMDict,
'error': None}
self.assertEqual(responses, json.loads(response.content))
开发者ID:jab0ii,项目名称:pgfwd,代码行数:25,代码来源:tests_func.py
示例19: post
def post(self):
custom_badge_name = self.request_string("name", default="")
custom_badges = CustomBadge.all()
custom_badge_awarded = None
emails_awarded = []
for custom_badge in custom_badges:
if custom_badge.name == custom_badge_name:
custom_badge_awarded = custom_badge
if custom_badge_awarded:
# Award badges and show successful email addresses
emails_newlines = self.request_string("emails", default="")
emails = emails_newlines.split()
emails = map(lambda email: email.strip(), emails)
for email in emails:
user_data = UserData.get_from_user_input_email(email)
if user_data:
if not custom_badge_awarded.is_already_owned_by(user_data):
custom_badge_awarded.award_to(user_data)
user_data.put()
emails_awarded.append(email)
template_values = {
"custom_badges": CustomBadge.all(),
"custom_badge_awarded": custom_badge_awarded,
"emails_awarded": emails_awarded
}
self.render_jinja2_template("badges/award_custom_badge.html", template_values)
开发者ID:di445,项目名称:server,代码行数:31,代码来源:custom_badges.py
示例20: post
def post(self):
params = self.request.params
if not 'domain' in params:
self.abort(404)
domain = get_domain_or_404(params['domain'])
if 'from' in params and 'firstvisit' in params:
if params['from'] == 'inside' and params['firstvisit'] == 'true':
# maybe use a transaction for these two independent database
# operations? maybe not: it doesn't really matter if an entity of
# UserData could be put while Domain failed or vice versa.
domain.increment_counter()
UserData.add(self.request, params['domain'])
# explicit request to have content-type application/json
self.response.headers['Content-Type'] = 'application/json'
self.response.write(domain.get_json())
开发者ID:sebtesobe,项目名称:clickcounter-backend,代码行数:17,代码来源:handlers.py
注:本文中的models.UserData类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论