本文整理汇总了Python中transforms.dumps函数的典型用法代码示例。如果您正苦于以下问题:Python dumps函数的具体用法?Python dumps怎么用?Python dumps使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dumps函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: main
def main(self, sequence_num):
"""Main method of the deferred task."""
with Namespace(self._namespace):
logging.info('Job started: %s w/ sequence number %d',
self._job_name, sequence_num)
try:
# Check we haven't been canceled before we start.
if self._already_finished(sequence_num):
logging.info(
'Job %s sequence %d already canceled or subsequent '
'run completed; not running this version.',
self._job_name, sequence_num)
return
db.run_in_transaction(DurableJobEntity._start_job,
self._job_name, sequence_num)
result = self.run()
db.run_in_transaction(DurableJobEntity._complete_job,
self._job_name, sequence_num,
transforms.dumps(result))
logging.info('Job completed: %s', self._job_name)
except (Exception, runtime.DeadlineExceededError) as e:
logging.error(traceback.format_exc())
logging.error('Job failed: %s\n%s', self._job_name, e)
db.run_in_transaction(DurableJobEntity._fail_job,
self._job_name, sequence_num,
traceback.format_exc())
raise deferred.PermanentTaskFailure(e)
开发者ID:google,项目名称:coursebuilder-core,代码行数:29,代码来源:jobs.py
示例3: main
def main(self, sequence_num):
"""Main method of the deferred task."""
with Namespace(self._namespace):
logging.info('Job started: %s w/ sequence number %d',
self._job_name, sequence_num)
time_started = time.time()
try:
db.run_in_transaction(DurableJobEntity._start_job,
self._job_name, sequence_num)
result = self.run()
db.run_in_transaction(DurableJobEntity._complete_job,
self._job_name, sequence_num,
transforms.dumps(result),
long(time.time() - time_started))
logging.info('Job completed: %s', self._job_name)
except (Exception, runtime.DeadlineExceededError) as e:
logging.error(traceback.format_exc())
logging.error('Job failed: %s\n%s', self._job_name, e)
db.run_in_transaction(DurableJobEntity._fail_job,
self._job_name, sequence_num,
traceback.format_exc(),
long(time.time() - time_started))
raise deferred.PermanentTaskFailure(e)
开发者ID:UniMOOC,项目名称:gcb-new-module,代码行数:25,代码来源:jobs.py
示例4: main
def main(self):
"""Main method of the deferred task."""
logging.info('Job started: %s', self._job_name)
time_started = time.time()
old_namespace = namespace_manager.get_namespace()
try:
namespace_manager.set_namespace(self._namespace)
try:
db.run_in_transaction(DurableJobEntity._start_job,
self._job_name)
result = self.run()
db.run_in_transaction(DurableJobEntity._complete_job,
self._job_name, transforms.dumps(result),
long(time.time() - time_started))
logging.info('Job completed: %s', self._job_name)
except (Exception, runtime.DeadlineExceededError) as e:
logging.error(traceback.format_exc())
logging.error('Job failed: %s\n%s', self._job_name, e)
db.run_in_transaction(DurableJobEntity._fail_job,
self._job_name, traceback.format_exc(),
long(time.time() - time_started))
raise deferred.PermanentTaskFailure(e)
finally:
namespace_manager.set_namespace(old_namespace)
开发者ID:AppScale,项目名称:coursebuilder,代码行数:25,代码来源:jobs.py
示例5: to_json
def to_json(self):
"""Creates JSON representation of this instance."""
adict = copy.deepcopy(self)
del adict._app_context
return transforms.dumps(
adict,
indent=4, sort_keys=True,
default=lambda o: o.__dict__)
开发者ID:bionicv,项目名称:Learning_analytics_on_GCB,代码行数:8,代码来源:courses.py
示例6: save
def save(cls, dto):
entity = cls._load_entity(dto.id)
if not entity:
entity = cls.ENTITY()
entity.data = transforms.dumps(dto.dict)
entity.put()
MemcacheManager.set(cls._memcache_key(entity.key().id()), entity)
return entity.key().id()
开发者ID:AppScale,项目名称:coursebuilder,代码行数:8,代码来源:models.py
示例7: set_info
def set_info(cls, student, unit_id, info):
st = info.get('start_time', None)
if st:
st = st.strftime(cls.timestamp_format)
info['start_time'] = st
info_ent = StudentPropertyEntity.create(student,
cls.info_tmpl % unit_id)
info_ent.value = transforms.dumps(info)
info_ent.put()
开发者ID:twiffy,项目名称:eabooc,代码行数:9,代码来源:models.py
示例8: add
def add(self, name, data, mime=None):
if not mime:
mime = "unspecified"
name = RE_NON_PRINTABLE.sub("", name)[0:131]
mime = RE_NON_PRINTABLE.sub("", mime)[0:53]
digest = transforms.sha1(data)
d = transforms.dumps(data)
row = u"%s\t%s\t%s\t%s\t%s\t%s\n" % (datetime.datetime.utcnow().isoformat(), mime, name, digest, len(data), d)
self.store(row)
开发者ID:oskarnyqvist,项目名称:barrels,代码行数:11,代码来源:barrel.py
示例9: save_all
def save_all(cls, dtos):
"""Performs a block persist of a list of DTO's."""
entities = []
for dto in dtos:
entity = cls._load_entity(dto.id)
if not entity:
entity = cls.ENTITY()
entity.data = transforms.dumps(dto.dict)
entities.append(entity)
keys = db.put(entities)
for key, entity in zip(keys, entities):
MemcacheManager.set(cls._memcache_key(key.id()), entity)
return [key.id() for key in keys]
开发者ID:AppScale,项目名称:coursebuilder,代码行数:14,代码来源:models.py
示例10: write
def write(cls, unit_id, reviewee_key, contents):
"""Updates or creates a student submission, and returns the key.
Args:
unit_id: string. The id of the unit this submission belongs to.
reviewee_key: db.Key of models.models.Student. The author of the
submission.
contents: object. The contents of the submission, as a Python
object. This will be JSON-transformed before it is stored.
Returns:
db.Key of Submission.
"""
return cls(
unit_id=str(unit_id), reviewee_key=reviewee_key,
contents=transforms.dumps(contents)
).put()
开发者ID:CSCI1200Course,项目名称:csci1200OnlineCourse,代码行数:17,代码来源:student_work.py
示例11: _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
示例12: 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
示例13: 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
示例14: write
def write(cls, unit_id, reviewee_key, contents, instance_id=None):
"""Updates or creates a student submission, and returns the key.
Args:
unit_id: string. The id of the unit this submission belongs to.
reviewee_key: db.Key of models.models.Student. The author of the
submission.
contents: object. The contents of the submission, as a Python
object. This will be JSON-transformed before it is stored.
instance_id: string. The instance id of a component (e.g., file
upload) which submitted the content.
Returns:
db.Key of Submission.
"""
return cls(
unit_id=str(unit_id), reviewee_key=reviewee_key,
contents=transforms.dumps(contents),
instance_id=instance_id,
updated_on=datetime.datetime.utcnow()
).put()
开发者ID:2023SS,项目名称:coursebuilder-core,代码行数:21,代码来源:student_work.py
示例15: build_output
def build_output(root_pipeline_id, results_list, error=None):
return transforms.dumps({
MapReduceJob._OUTPUT_KEY_ROOT_PIPELINE_ID: root_pipeline_id,
MapReduceJob._OUTPUT_KEY_RESULTS: results_list,
MapReduceJob._OUTPUT_KEY_ERROR: error,
})
开发者ID:UniMOOC,项目名称:gcb-new-module,代码行数:6,代码来源:jobs.py
示例16: serialize
def serialize(self):
"""Saves instance to a JSON representation."""
adict = self.to_dict()
json_text = transforms.dumps(adict)
return json_text.encode('utf-8')
开发者ID:bionicv,项目名称:Learning_analytics_on_GCB,代码行数:5,代码来源:courses.py
示例17: write_review
def write_review(
self, unit_id, review_step_key, review_payload, mark_completed):
impl = self._get_impl(unit_id)
return impl.write_review(
review_step_key, transforms.dumps(review_payload),
mark_completed=mark_completed)
开发者ID:danieldalonzo,项目名称:coursebuilder-core,代码行数:6,代码来源:review.py
示例18: get_value_for_datastore
def get_value_for_datastore(self, model):
py_value = super(MoreDifferentIntListProperty, self).get_value_for_datastore(model)
if py_value is None:
py_value = []
return transforms.dumps(py_value)
开发者ID:twiffy,项目名称:eabooc,代码行数:5,代码来源:models.py
注:本文中的transforms.dumps函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论