Sort record list alphabetically if python version < 3.6

This commit is contained in:
Khanh Ngo 2018-09-04 08:57:41 +07:00
parent 26c2b5e169
commit 0081adff36
No known key found for this signature in database
GPG Key ID: B9AE3BAF6D5A7B22
3 changed files with 14 additions and 5 deletions

View File

@ -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):

View File

@ -41,7 +41,7 @@
</div>
<div class="form-group has-feedback">
<label class="control-label" for="pdns_api_key">PDNS API KEY</label>
<input type="text" class="form-control" placeholder="PowerDNS API key" name="pdns_api_key" data-error="Please input a valid PowerDNS API key" required value="{{ pdns_api_key }}">
<input type="password" class="form-control" placeholder="PowerDNS API key" name="pdns_api_key" data-error="Please input a valid PowerDNS API key" required value="{{ pdns_api_key }}">
<span class="help-block with-errors"></span>
</div>
<div class="form-group has-feedback">

View File

@ -1,4 +1,4 @@
"""Change setting.value data type
"""Remove all setting in the DB
Revision ID: 31a4ed468b18
Revises: 4a666113c7bb