本文整理汇总了Python中transforms.loads函数的典型用法代码示例。如果您正苦于以下问题:Python loads函数的具体用法?Python loads怎么用?Python loads使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了loads函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _update_global_profile_attributes
def _update_global_profile_attributes(
cls,
profile,
email=None,
legal_name=None,
nick_name=None,
date_of_birth=None,
is_enrolled=None,
final_grade=None,
course_info=None,
):
"""Modifies various attributes of Student's Global Profile."""
# TODO(psimakov): update of email does not work for student
if email is not None:
profile.email = email
if legal_name is not None:
profile.legal_name = legal_name
if nick_name is not None:
profile.nick_name = nick_name
if date_of_birth is not None:
profile.date_of_birth = date_of_birth
if not (is_enrolled is None and final_grade is None and course_info is None):
# Defer to avoid circular import.
# pylint: disable-msg=g-import-not-at-top
from controllers import sites
course = sites.get_course_for_current_request()
course_namespace = course.get_namespace_name()
if is_enrolled is not None:
enrollment_dict = transforms.loads(profile.enrollment_info)
enrollment_dict[course_namespace] = is_enrolled
profile.enrollment_info = transforms.dumps(enrollment_dict)
if final_grade is not None or course_info is not None:
course_info_dict = {}
if profile.course_info:
course_info_dict = transforms.loads(profile.course_info)
if course_namespace in course_info_dict.keys():
info = course_info_dict[course_namespace]
else:
info = {}
if final_grade:
info["final_grade"] = final_grade
if course_info:
info["info"] = course_info
course_info_dict[course_namespace] = info
profile.course_info = transforms.dumps(course_info_dict)
开发者ID:reachedu14,项目名称:traininginstitute,代码行数:53,代码来源:models.py
示例2: get_all_scores
def get_all_scores(self, student):
"""Gets all score data for a student.
Args:
student: the student whose scores should be retrieved.
Returns:
an array of dicts, each representing an assessment. Each dict has
the keys 'id', 'title', 'weight' and 'score' (if available),
representing the unit id, the assessment title, the weight
contributed by the assessment to the final score, and the
assessment score.
"""
assessment_list = self.get_assessment_list()
scores = transforms.loads(student.scores) if student.scores else {}
assessment_score_list = []
for unit in assessment_list:
# Compute the weight for this assessment.
weight = 0
if hasattr(unit, 'weight'):
weight = unit.weight
elif unit.unit_id in DEFAULT_LEGACY_ASSESSMENT_WEIGHTS:
weight = DEFAULT_LEGACY_ASSESSMENT_WEIGHTS[unit.unit_id]
assessment_score_list.append({
'id': str(unit.unit_id),
'title': unit.title,
'weight': weight,
'score': (scores[str(unit.unit_id)]
if str(unit.unit_id) in scores else 0),
})
return assessment_score_list
开发者ID:bionicv,项目名称:Learning_analytics_on_GCB,代码行数:34,代码来源:courses.py
示例3: deserialize
def deserialize(self, binary_data):
"""Loads instance from a JSON representation."""
json_text = binary_data.decode('utf-8')
adict = transforms.loads(json_text)
if not self.version == adict.get('version'):
raise Exception('Expected version %s, found %s.' % (
self.version, adict.get('version')))
self._from_dict(adict)
开发者ID:bionicv,项目名称:Learning_analytics_on_GCB,代码行数:8,代码来源:courses.py
示例4: get_status_url
def get_status_url(job, namespace, xsrf_token):
if not job.output:
return None
content = transforms.loads(job.output)
pipeline_id = content[MapReduceJob._OUTPUT_KEY_ROOT_PIPELINE_ID]
return ('/mapreduce/ui/pipeline/status?' +
urllib.urlencode({'root': pipeline_id,
'namespace': namespace,
'xsrf_token': xsrf_token}))
开发者ID:UniMOOC,项目名称:gcb-new-module,代码行数:9,代码来源:jobs.py
示例5: filter
def filter(self, fun=None):
if not fun:
fun = lambda x: True
try:
with io.open(self.filename, "r") as f:
for line in f:
meta, raw, comment = self.parse_line(line)
if not meta:
continue
if fun(meta):
yield (meta, transforms.loads(raw))
except IOError:
pass
开发者ID:oskarnyqvist,项目名称:barrels,代码行数:13,代码来源:barrel.py
示例6: _add_new_student_for_current_user
def _add_new_student_for_current_user(
cls, user_id, email, nick_name, additional_fields):
"""Create new or re-enroll old student."""
# create profile if does not exist
profile = cls._get_profile_by_user_id(user_id)
if not profile:
profile = cls._add_new_profile(user_id, email)
# create new student or re-enroll existing
student = Student.get_by_email(email)
if not student:
# TODO(psimakov): we must move to user_id as a key
student = Student(key_name=email)
# update profile
cls._update_attributes(
profile, student, nick_name=nick_name, is_enrolled=True)
# update student
student.user_id = user_id
student.additional_fields = additional_fields
# CGL-MOOC-Builder starts: additional data fields for a student
additional_data = transforms.loads(additional_fields)
for st in additional_data:
if st[0] == 'age':
student.age = st[1]
elif st[0] == 'city':
student.city = st[1]
elif st[0] == 'state':
student.state = st[1]
elif st[0] == 'country':
student.country = st[1]
elif st[0] == 'education':
student.education = st[1]
elif st[0] == 'profession':
student.profession = st[1]
elif st[0] == 'organization':
student.organization = st[1]
elif st[0] == 'motivation':
student.motivation = st[1]
elif st[0] == 'referral':
student.referral = st[1]
elif st[0] == 'privacy':
student.privacy = st[1]
# CGL-MOOC-Builder ends
# put both
cls._put_profile(profile)
student.put()
开发者ID:cglmoocs,项目名称:cgl-mooc-builder,代码行数:51,代码来源:models.py
示例7: get_info
def get_info(cls, student, unit_id):
info_ent = StudentPropertyEntity.get(student,
cls.info_tmpl % unit_id)
if not info_ent:
return {
'tries_left': TRIES_ALLOWED_ON_EXAMS.value,
'start_time': None,
}
info = transforms.loads(info_ent.value)
if info['start_time']:
info['start_time'] = datetime.datetime.strptime(
info['start_time'],
cls.timestamp_format)
return info
开发者ID:twiffy,项目名称:eabooc,代码行数:15,代码来源:models.py
示例8: set_answer
def set_answer(answers, assessment_name, answer):
"""Stores the answer array for the given student and assessment.
The caller must call answers.put() to commit.
This does not do any type-checking on 'answer'; it just stores whatever
is passed in.
Args:
answers: the StudentAnswers entity in which the answer should be stored.
assessment_name: the name of the assessment.
answer: an array containing the student's answers.
"""
if not answers.data:
score_dict = {}
else:
score_dict = transforms.loads(answers.data)
score_dict[assessment_name] = answer
answers.data = transforms.dumps(score_dict)
开发者ID:MaxSchumacher,项目名称:coursebuilder,代码行数:18,代码来源:utils.py
示例9: _set_entity_value
def _set_entity_value(self, student_property, key, value):
"""Sets the integer value of a student property.
Note: this method does not commit the change. The calling method should
call put() on the StudentPropertyEntity.
Args:
student_property: the StudentPropertyEntity
key: the student property whose value should be incremented
value: the value to increment this property by
"""
try:
progress_dict = transforms.loads(student_property.value)
except (AttributeError, TypeError):
progress_dict = {}
progress_dict[key] = value
student_property.value = transforms.dumps(progress_dict)
开发者ID:CSavvy,项目名称:coursebuilder,代码行数:18,代码来源:progress.py
示例10: set_score
def set_score(student, assessment_name, score):
"""Stores the score for the given student and assessment.
The caller must call student.put() to commit.
This does not do any type-checking on 'score'; it just stores whatever
is passed in.
Args:
student: the student whose answer should be stored.
assessment_name: the name of the assessment.
score: the student's score.
"""
if not student.scores:
score_dict = {}
else:
score_dict = transforms.loads(student.scores)
score_dict[assessment_name] = score
student.scores = transforms.dumps(score_dict)
开发者ID:MaxSchumacher,项目名称:coursebuilder,代码行数:18,代码来源:utils.py
示例11: get_reviews_by_keys
def get_reviews_by_keys(
self, unit_id, review_keys, handle_empty_keys=False):
"""Gets a list of reviews, given their review keys.
If handle_empty_keys is True, then no error is thrown on supplied keys
that are None; the elements in the result list corresponding to those
keys simply return None. This usually arises when this method is called
immediately after get_review_steps_by_keys().
Args:
unit_id: string. Id of the unit to get the reviews for.
review_keys: [db.Key of peer.ReviewStep]. May include None, if
handle_empty_keys is True.
handle_empty_keys: if True, the return value contains None for keys
that are None. If False, the method throws if empty keys are
supplied.
Returns:
List with the same number of elements as review_keys. It contains:
- the JSON-decoded contents of the review corresponding to that
review_key, or
- None if either:
- no review has been submitted for that review key, or
- handle_empty_keys == True and the review_key is None.
"""
impl = self._get_impl(unit_id)
reviews = []
if not handle_empty_keys:
reviews = impl.get_reviews_by_keys(review_keys)
else:
nonempty_review_indices = []
nonempty_review_keys = []
for idx, review_key in enumerate(review_keys):
if review_key is not None:
nonempty_review_indices.append(idx)
nonempty_review_keys.append(review_key)
tmp_reviews = impl.get_reviews_by_keys(nonempty_review_keys)
reviews = [None] * len(review_keys)
for (i, idx) in enumerate(nonempty_review_indices):
reviews[idx] = tmp_reviews[i]
return [(transforms.loads(rev.contents) if rev else None)
for rev in reviews]
开发者ID:danieldalonzo,项目名称:coursebuilder-core,代码行数:44,代码来源:review.py
示例12: get_error_message
def get_error_message(job):
if not job.output:
return None
content = transforms.loads(job.output)
return content[MapReduceJob._OUTPUT_KEY_ERROR]
开发者ID:UniMOOC,项目名称:gcb-new-module,代码行数:5,代码来源:jobs.py
示例13: get_results
def get_results(job):
if not job.output:
return None
content = transforms.loads(job.output)
return content[MapReduceJob._OUTPUT_KEY_RESULTS]
开发者ID:UniMOOC,项目名称:gcb-new-module,代码行数:5,代码来源:jobs.py
示例14: get_root_pipeline_id
def get_root_pipeline_id(job):
if not job or not job.output:
return None
content = transforms.loads(job.output)
return content[MapReduceJob._OUTPUT_KEY_ROOT_PIPELINE_ID]
开发者ID:UniMOOC,项目名称:gcb-new-module,代码行数:5,代码来源:jobs.py
示例15: get_contents_by_key
def get_contents_by_key(cls, submission_key):
"""Returns the contents of a submission, given a db.Key."""
submission = entities.get(submission_key)
return transforms.loads(submission.contents) if submission else None
开发者ID:2023SS,项目名称:coursebuilder-core,代码行数:4,代码来源:student_work.py
示例16: get_all
def get_all(cls):
entities = cls.ENTITY.all().fetch(1000)
return [
cls.DTO(e.key().id(), transforms.loads(e.data)) for e in entities]
开发者ID:AppScale,项目名称:coursebuilder,代码行数:4,代码来源:models.py
示例17: _get_entity_value
def _get_entity_value(self, progress, event_key):
if not progress.value:
return None
return transforms.loads(progress.value).get(event_key)
开发者ID:CSavvy,项目名称:coursebuilder,代码行数:4,代码来源:progress.py
示例18: get_score
def get_score(self, student, assessment_id):
"""Gets a student's score for a particular assessment."""
assert self.is_valid_assessment_id(assessment_id)
scores = transforms.loads(student.scores) if student.scores else {}
return scores.get(assessment_id) if scores else None
开发者ID:bionicv,项目名称:Learning_analytics_on_GCB,代码行数:5,代码来源:courses.py
示例19: load
def load(cls, obj_id):
entity = cls._load_entity(obj_id)
if entity:
return cls.DTO(obj_id, transforms.loads(entity.data))
else:
return None
开发者ID:AppScale,项目名称:coursebuilder,代码行数:6,代码来源:models.py
示例20: make_value_from_datastore
def make_value_from_datastore(self, db_value):
if type(db_value) is list:
return db_value
elif not db_value:
return []
return transforms.loads(db_value)
开发者ID:twiffy,项目名称:eabooc,代码行数:6,代码来源:models.py
注:本文中的transforms.loads函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论