35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
from .models import *
|
|
|
|
def get_options_by_opt_types(opt_types, only_vals=False, w_prefix=False):
|
|
if type(opt_types) == str:
|
|
kwargs = {'opt_type': opt_types}
|
|
elif type(opt_types) == dict:
|
|
kwargs = opt_types
|
|
else:
|
|
kwargs = {'opt_type__in': opt_types}
|
|
|
|
opts = Option.objects.filter(**kwargs)
|
|
if opts and only_vals:
|
|
opts = opts.values('opt_type', 'value', 'prefix')
|
|
res_Dict = {}
|
|
for item in opts:
|
|
val = item['value']
|
|
if w_prefix and item['prefix']:
|
|
val = item['prefix'] + val
|
|
res_Dict.update({item['opt_type']: val})
|
|
return res_Dict
|
|
|
|
return opts
|
|
|
|
def get_first_option_value_by_opt_type(opt_type):
|
|
opts = get_options_by_opt_types(opt_type)
|
|
if opts:
|
|
return opts[0].value
|
|
else:
|
|
return None
|
|
|
|
def get_mail_send_options():
|
|
opt_types = ['mail_server_url', 'mail_server_smtp_port', 'sender_mail_login', 'sender_mail_password', 'sender_email']
|
|
|
|
return get_options_by_opt_types(opt_types, only_vals=True)
|