本文整理汇总了Python中models.models.Student.get_by_email方法的典型用法代码示例。如果您正苦于以下问题:Python Student.get_by_email方法的具体用法?Python Student.get_by_email怎么用?Python Student.get_by_email使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.models.Student
的用法示例。
在下文中一共展示了Student.get_by_email方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models.models import Student [as 别名]
# 或者: from models.models.Student import get_by_email [as 别名]
def post(self):
user = self.personalizePageAndGetUser()
if not user:
self.redirect(users.create_login_url(self.request.uri))
return
if (MAX_CLASS_SIZE and Student.all(keys_only=True).count() >= MAX_CLASS_SIZE):
self.templateValue['course_status'] = 'full'
else:
# Create student record
name = self.request.get('form01')
# create new or re-enroll old student
student = Student.get_by_email(user.email())
if student:
if not student.is_enrolled:
student.is_enrolled = True
student.name = name
else:
student = Student(key_name=user.email(), name=name, is_enrolled=True)
student.put()
# Render registration confirmation page
self.templateValue['navbar'] = {'registration': True}
self.render('confirmation.html')
示例2: get
# 需要导入模块: from models.models import Student [as 别名]
# 或者: from models.models.Student import get_by_email [as 别名]
def get(self):
"""Get a students progress."""
#teachers aren't course admins, so we probably shouldn't check for that
# if not roles.Roles.is_course_admin(self.app_context):
# transforms.send_json_response(self, 401, 'Access denied.', {})
# return
key = self.request.get('student')
errors = []
student = Student.get_by_email(key.strip())
course = self.get_course()
if student:
units = teacher_parsers.StudentProgressTracker.get_detailed_progress(student, course)
else:
errors.append('An error occurred retrieving student data. Contact your course administrator.')
self.validation_error('\n'.join(errors))
return
payload_dict = {
'units': units,
'student_name': student.name,
'student_email': student.email
}
transforms.send_json_response(
self, 200, '', payload_dict=payload_dict,
xsrf_token=crypto.XsrfTokenManager.create_xsrf_token(
self.XSRF_TOKEN))
示例3: post
# 需要导入模块: from models.models import Student [as 别名]
# 或者: from models.models.Student import get_by_email [as 别名]
def post(self):
user = self.personalizePageAndGetUser()
if not user:
self.redirect(users.create_login_url(self.request.uri))
return
# Read in answers
answer = json.dumps(self.request.POST.items())
original_type = self.request.get('assessment_type')
# Check for enrollment status
student = Student.get_by_email(user.email())
if student and student.is_enrolled:
# Log answer submission
logging.info(student.key().name() + ':' + answer)
(student, assessment_type) = self.storeAssessmentTransaction(student.key().name(), original_type, answer)
# Serve the confirmation page
self.templateValue['navbar'] = {'course': True}
self.templateValue['assessment'] = assessment_type
self.templateValue['student_score'] = getScore(student, 'overall_score')
self.render('test_confirmation.html')
else:
self.redirect('/register')
示例4: get
# 需要导入模块: from models.models import Student [as 别名]
# 或者: from models.models.Student import get_by_email [as 别名]
def get(self):
"""Handles GET requests."""
user = self.personalize_page_and_get_user()
student = Student.get_by_email(user.email())
if not user:
self.template_value['loginUrl'] = users.create_login_url('/')
else:
self.template_value['playlist'] = student.playlist
self.template_value['playlist_urls'] = student.playlist_urls
self.template_value['email'] = user.email()
self.template_value['logoutUrl'] = users.create_logout_url('/')
if len(student.playlist) > 0:
#unit_id = str(student.playlist[0][0])
#lesson_id = str(student.playlist[0][2])
self.template_value['start_plist_url'] = str(student.playlist[0]) #('unit?unit=%s&lesson=%s' % (unit_id, lesson_id))
self.template_value['hasList'] = True
else:
self.template_value['hasList'] = False
self.template_value['navbar'] = {'course': True}
self.template_value['units'] = self.get_units()
if user and Student.get_enrolled_student_by_email(user.email()):
self.render('playlist.html')
else:
self.redirect('/preview')
示例5: get
# 需要导入模块: from models.models import Student [as 别名]
# 或者: from models.models.Student import get_by_email [as 别名]
def get(self):
student = Student.get_by_email(self.request.get("img_id"))
if student.avatar:
self.response.headers["Content-Type"] = "image/png"
self.response.out.write(student.avatar)
else:
self.error(404)
示例6: post
# 需要导入模块: from models.models import Student [as 别名]
# 或者: from models.models.Student import get_by_email [as 别名]
def post(self):
"""Handles POST requests."""
user = self.personalize_page_and_get_user()
if not user:
self.redirect(users.create_login_url(self.request.uri))
return
if not self.assert_xsrf_token_or_fail(self.request, 'register-post'):
return
can_register = self.app_context.get_environ(
)['reg_form']['can_register']
if not can_register:
self.template_value['course_status'] = 'full'
else:
name = self.request.get('form01')
surname = self.request.get('form02')
age = self.request.get('form03')
# create new or re-enroll old student
student = Student.get_by_email(user.email())
if not student:
student = Student(key_name=user.email())
student.user_id = user.user_id()
student.is_enrolled = False
student.name = name
student.surname = surname
student.age = age
student.put()
# Render registration confirmation page
self.template_value['navbar'] = {'registration': True}
self.render('confirmation.html')
示例7: update_assessment_transaction
# 需要导入模块: from models.models import Student [as 别名]
# 或者: from models.models.Student import get_by_email [as 别名]
def update_assessment_transaction(
self, email, assessment_type, new_answers, score):
"""Stores answer and updates user scores."""
student = Student.get_by_email(email)
# It may be that old Student entities don't have user_id set; fix it.
if not student.user_id:
student.user_id = self.get_user().user_id()
answers = StudentAnswersEntity.get_by_key_name(student.user_id)
if not answers:
answers = StudentAnswersEntity(key_name=student.user_id)
answers.updated_on = datetime.datetime.now()
utils.set_answer(answers, assessment_type, new_answers)
assessment_type = store_score(student, assessment_type, score)
student.put()
answers.put()
# Also record the event, which is useful for tracking multiple
# submissions and history.
models.EventEntity.record(
'submit-assessment', self.get_user(), json.dumps({
'type': 'assessment-%s' % assessment_type,
'values': new_answers, 'location': 'AnswerHandler'}))
return (student, assessment_type)
示例8: post
# 需要导入模块: from models.models import Student [as 别名]
# 或者: from models.models.Student import get_by_email [as 别名]
def post(self):
"""Handles POST requests."""
user = self.personalize_page_and_get_user()
if not user:
self.redirect(users.create_login_url(self.request.uri))
return
if not self.assert_xsrf_token_or_fail(self.request, "register-post"):
return
can_register = self.app_context.get_environ()["reg_form"]["can_register"]
if not can_register:
self.template_value["course_status"] = "full"
else:
name = self.request.get("form01")
# create new or re-enroll old student
student = Student.get_by_email(user.email())
if not student:
student = Student(key_name=user.email())
student.user_id = user.user_id()
student.is_enrolled = True
student.name = name
student.put()
# Render registration confirmation page
self.template_value["navbar"] = {"registration": True}
self.render("confirmation.html")
示例9: storeAssessmentTransaction
# 需要导入模块: from models.models import Student [as 别名]
# 或者: from models.models.Student import get_by_email [as 别名]
def storeAssessmentTransaction(self, email, original_type, answer):
student = Student.get_by_email(email)
# TODO: considering storing as float for better precision
score = int(round(float(self.request.get('score'))))
assessment_type = storeAssessmentData(student, original_type, score, answer)
student.put()
return (student, assessment_type)
示例10: name
# 需要导入模块: from models.models import Student [as 别名]
# 或者: from models.models.Student import get_by_email [as 别名]
def name(self, email):
name = self._names.get(email, None)
if name:
return name
else:
stud = Student.get_by_email(email)
self._names[email] = stud.name
return stud.name
示例11: get
# 需要导入模块: from models.models import Student [as 别名]
# 或者: from models.models.Student import get_by_email [as 别名]
def get(self):
"""Handles GET requests."""
if not self.personalize_page_and_get_enrolled():
return
user = self.personalize_page_and_get_user()
student = Student.get_by_email(user.email())
playlist = student.playlist
# Extract incoming args
unit_id, lesson_id = extract_unit_and_lesson_id(self)
self.template_value['unit_id'] = unit_id
self.template_value['lesson_id'] = lesson_id
# Set template values for a unit and its lesson entities
for unit in self.get_units():
if unit.unit_id == str(unit_id):
self.template_value['units'] = unit
lessons = self.get_lessons(unit_id)
self.template_value['lessons'] = lessons
# Set template values for nav bar
self.template_value['navbar'] = {'course': True}
# Set template values for back and next nav buttons
if lesson_id == 1:
self.template_value['back_button_url'] = ''
elif lessons[lesson_id - 2].activity:
self.template_value['back_button_url'] = (
'activity?unit=%s&lesson=%s' % (unit_id, lesson_id - 1))
else:
self.template_value['back_button_url'] = (
'unit?unit=%s&lesson=%s' % (unit_id, lesson_id - 1))
if lessons[lesson_id - 1].activity:
self.template_value['playlist_button_url'] = (
'activity?unit=%s&lessons=%s' % (unit_id, lesson_id))
elif playlist[0] != (str(unit_id) + '.' + str(lesson_id)):
self.template_value['playlist_button_url'] = ''
else:
self.template_value['playlist_button_url'] = (
'unit?unit=%s&lesson=%s' % (unit_id, lesson_id + 1))
if lessons[lesson_id - 1].activity:
self.template_value['next_button_url'] = (
'activity?unit=%s&lesson=%s' % (unit_id, lesson_id))
elif lesson_id == len(lessons):
self.template_value['next_button_url'] = ''
else:
self.template_value['next_button_url'] = (
'unit?unit=%s&lesson=%s' % (unit_id, lesson_id + 1))
self.response.out.write(unit_id)
self.response.out.write(lesson_id)
示例12: post_save
# 需要导入模块: from models.models import Student [as 别名]
# 或者: from models.models.Student import get_by_email [as 别名]
def post_save(self):
if not Roles.is_course_admin(self.app_context):
self.abort(403, 'You are not an admin :(')
user = self.personalize_page_and_get_enrolled()
student_email = self.request.GET.get('email', None)
if not student_email:
self.abort(404, 'email= parameter required')
student = Student.get_enrolled_student_by_email(student_email)
if not student:
self.abort(404, Markup('Could not find a student with email "%s"') % student_email)
badge_slug = custom_badge_name(student)
badge = Badge.get_or_insert(badge_slug)
badge_form = BadgeForm(self.request.POST, badge)
comments_form = CommentsForm(self.request.POST)
if not (badge_form.validate() and comments_form.validate()):
self.render_edit(badge_form, comments_form)
return
comments_form.validate()
reviewer = Student.get_by_email(comments_form.review_source.data)
if not reviewer:
comments_form.review_source.errors.append("Could not find a user with that e-mail address")
self.render_edit(badge_form, comments_form)
return
page = WikiPage.get_page(student, unit=UNIT_NUMBER)
if not page:
self.abort(404, Markup('Could not find unit %d wikifolio for student "%s"') % (UNIT_NUMBER, student_email))
old_reviews = Annotation.reviews(whose=student, unit=UNIT_NUMBER).run()
db.delete(old_reviews)
Annotation.review(page, who=reviewer, text=comments_form.public_comments.data)
if not Annotation.endorsements(what=page, who=user).count(limit=1):
Annotation.endorse(page, who=user, optional_done=True)
badge_form.populate_obj(badge)
badge.put()
report = PartReport.on(student, self.get_course(), 4, force_re_run=True, put=False)
for rep in report.unit_reports:
rep._run()
rep.put()
report.slug = badge_slug
report.put()
assertion = Badge.issue(badge, student, put=False)
assertion.evidence = urljoin(self.request.host_url, '/badges/evidence?id=%d' % report.key().id())
assertion.put()
self.response.write(
Markup("Issued badge %s to %s, evidence %s") % (
badge.key().name(), student_email, assertion.evidence))
示例13: get_student_dashboard
# 需要导入模块: from models.models import Student [as 别名]
# 或者: from models.models.Student import get_by_email [as 别名]
def get_student_dashboard(cls, dashboardHandler):
"""Renders Student Dashboard view.
Also gets ALL students in ALL course sections for the registered user to
build a jQuery autocomplete dropdown on the view.
"""
student_email = dashboardHandler.request.get('student') or None #email will be in the request if opened from student list
# view, otherwise it will be None
#need to go through every course section for the current user and get all unique students
students = []
course_sections = teacher_entity.CourseSectionEntity.get_course_sections_for_user()
if course_sections and len(course_sections) > 0:
for course_section in course_sections.values():
if course_section.students and len(course_section.students) > 0:
for student_in_section in course_section.students.values():
if not any(x['user_id'] == student_in_section['user_id'] for x in students):
students.append(student_in_section)
#check to see if we have a student and if we need to get detailed progress
student = None
if student_email:
student = Student.get_by_email(student_email)
if (student):
course = dashboardHandler.get_course()
units = teacher_parsers.StudentProgressTracker.get_detailed_progress(student, course)
scores = teacher_parsers.ActivityScoreParser.get_activity_scores([student.user_id], course)
else:
units = None
scores = None
#render the template for the student dashboard view
main_content = dashboardHandler.get_template(
'student_detailed_progress.html', [TEMPLATES_DIR]).render(
{
'units': units, #unit completion
'student': student, #course defined student object, need email and name
'students': students, #list of students, names and emails, from a course section student list
'scores': scores
})
#call DashboardHandler function to render the page
dashboardHandler.render_page({
'page_title': dashboardHandler.format_title('Student Dashboard'),
'main_content': jinja2.utils.Markup(main_content)
})
示例14: post
# 需要导入模块: from models.models import Student [as 别名]
# 或者: from models.models.Student import get_by_email [as 别名]
def post(self):
"""Handles POST requests"""
user = self.personalize_page_and_get_user()
student = Student.get_by_email(user.email())
playlist = self.request.get_all('plist')
playlist_urls = list(xrange(len(playlist)))
for i in range (0, len(playlist)):
playlist_urls[i] = ('unit?unit=%s&lesson=%s' % (playlist[i][0], playlist[i][2]))
# for i in range (0, 22):
# plist = 'plist' + str(i)
# plist = self.request.get(plist)
# if (plist != ""):
# playlist.append(plist)
student.playlist_urls = playlist_urls
student.playlist = playlist
student.put()
self.redirect('/playlist')
示例15: add_new_teacher_for_user
# 需要导入模块: from models.models import Student [as 别名]
# 或者: from models.models.Student import get_by_email [as 别名]
def add_new_teacher_for_user(cls, email, school, additional_fields, alerts):
student_by_email = Student.get_by_email(email)
if not student_by_email:
alerts.append("This email is not registered as a student for this course")
return None
# assume a new teacher is active by default
teacher = cls._add_new_teacher_for_user(
student_by_email.user_id, email, student_by_email.name, school, True, additional_fields
)
if teacher:
alerts.append("Teacher was successfully registered")
return teacher