From 0081adff364c92bde2258ab64fbfcd3373bf067a Mon Sep 17 00:00:00 2001 From: Khanh Ngo Date: Tue, 4 Sep 2018 08:57:41 +0700 Subject: [PATCH] Sort record list alphabetically if python version < 3.6 --- app/models.py | 15 ++++++++++++--- app/templates/admin_setting_pdns.html | 2 +- .../1274ed462010_remove_all_settings_in_the_db.py | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/models.py b/app/models.py index 812fff4..4ce23c4 100644 --- a/app/models.py +++ b/app/models.py @@ -1,4 +1,6 @@ +import sys import os +import re import ldap import ldap.filter import base64 @@ -6,7 +8,6 @@ import bcrypt import itertools import traceback import pyotp -import re import dns.reversename import dns.inet import dns.name @@ -1924,12 +1925,20 @@ class Setting(db.Model): def get_forward_records_allow_to_edit(self): records = self.get('forward_records_allow_edit') f_records = literal_eval(records) if isinstance(records, str) else records - return [r for r in f_records if f_records[r]] + r_name = [r for r in f_records if f_records[r]] + # Sort alphabetically if python version is smaller than 3.6 + if sys.version_info[0] < 3 or (sys.version_info[0] == 3 and sys.version_info[1] < 6): + r_name.sort() + return r_name def get_reverse_records_allow_to_edit(self): records = self.get('reverse_records_allow_edit') r_records = literal_eval(records) if isinstance(records, str) else records - return [r for r in r_records if r_records[r]] + r_name = [r for r in r_records if r_records[r]] + # Sort alphabetically if python version is smaller than 3.6 + if sys.version_info[0] < 3 or (sys.version_info[0] == 3 and sys.version_info[1] < 6): + r_name.sort() + return r_name class DomainTemplate(db.Model): diff --git a/app/templates/admin_setting_pdns.html b/app/templates/admin_setting_pdns.html index 528b73c..3310680 100644 --- a/app/templates/admin_setting_pdns.html +++ b/app/templates/admin_setting_pdns.html @@ -41,7 +41,7 @@
- +
diff --git a/migrations/versions/1274ed462010_remove_all_settings_in_the_db.py b/migrations/versions/1274ed462010_remove_all_settings_in_the_db.py index 9c3b7da..f1f54e4 100644 --- a/migrations/versions/1274ed462010_remove_all_settings_in_the_db.py +++ b/migrations/versions/1274ed462010_remove_all_settings_in_the_db.py @@ -1,4 +1,4 @@ -"""Change setting.value data type +"""Remove all setting in the DB Revision ID: 31a4ed468b18 Revises: 4a666113c7bb