summaryrefslogtreecommitdiff
path: root/yaksh/models.py
diff options
context:
space:
mode:
authormaheshgudi2017-08-24 16:55:18 +0530
committermaheshgudi2017-08-24 16:55:18 +0530
commit3367cf1bef0b8856972f4e4125322194c699d69e (patch)
tree6a9cc17591b9561b68d2782f742bc886f3360682 /yaksh/models.py
parent6ab383c02085936ecc20ffeb4b9f41ca642256c3 (diff)
downloadonline_test-3367cf1bef0b8856972f4e4125322194c699d69e.tar.gz
online_test-3367cf1bef0b8856972f4e4125322194c699d69e.tar.bz2
online_test-3367cf1bef0b8856972f4e4125322194c699d69e.zip
Adds alphabetical order during yaml serializing
Diffstat (limited to 'yaksh/models.py')
-rw-r--r--yaksh/models.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index b4c665c..cd79268 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
@@ -119,8 +120,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,
+ )
###############################################################################
@@ -510,7 +511,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)