diff options
author | mahesh | 2017-08-24 23:29:30 +0530 |
---|---|---|
committer | mahesh | 2017-08-24 23:29:30 +0530 |
commit | eb90ab2fbc1bf86c1549e391aa6cc461aaea699d (patch) | |
tree | dcbd32edb6866e3b45da2fc5977bba3d40c98a2e /yaksh | |
parent | 751dc83729e5bf57b2dd1a2798bb7b527a2e3584 (diff) | |
parent | 3367cf1bef0b8856972f4e4125322194c699d69e (diff) | |
download | online_test-eb90ab2fbc1bf86c1549e391aa6cc461aaea699d.tar.gz online_test-eb90ab2fbc1bf86c1549e391aa6cc461aaea699d.tar.bz2 online_test-eb90ab2fbc1bf86c1549e391aa6cc461aaea699d.zip |
Merge branch 'yaml_questions' of https://github.com/maheshgudi/online_test into yaml_questions
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/models.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index d9218ef..044a164 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -3,6 +3,7 @@ from datetime import datetime, timedelta import json import ruamel.yaml from ruamel.yaml.scalarstring import PreservedScalarString +from ruamel.yaml.comments import CommentedMap from random import sample from collections import Counter from django.db import models @@ -114,8 +115,8 @@ def dict_to_yaml(dictionary, path_to_file=None): ruamel.yaml.round_trip_dump(dictionary, yaml_file, default_flow_style=False, explicit_start=True, - allow_unicode=True - ) + allow_unicode=True, + ) ############################################################################### @@ -505,7 +506,8 @@ class Question(models.Model): tmp_file_path = tempfile.mkdtemp() yaml_path = os.path.join(tmp_file_path, "questions_dump.yaml") for elem in q_dict: - dict_to_yaml(elem, yaml_path) + commented_map = CommentedMap(sorted(elem.items(), key=lambda x:x[0])) + dict_to_yaml(commented_map, yaml_path) zip_file.write(yaml_path, os.path.basename(yaml_path)) zip_file.close() shutil.rmtree(tmp_file_path) |