Upload files to "app_common"
This commit is contained in:
parent
6768acf648
commit
ac1b39badd
36
app_common/__init__.py
Normal file
36
app_common/__init__.py
Normal file
@ -0,0 +1,36 @@
|
||||
# import ldap
|
||||
# from flask import current_app
|
||||
# from flask_login import current_user, LoginManager
|
||||
#
|
||||
# login_manager = LoginManager()
|
||||
#
|
||||
#
|
||||
# def make_ldap_connection():
|
||||
# ldap_connection = ldap.initialize('ldap://ldap.quarter.int')
|
||||
# ldap_connection.protocol_version = 3
|
||||
# ldap_connection.set_option(ldap.OPT_REFERRALS, 0)
|
||||
# return ldap_connection
|
||||
#
|
||||
#
|
||||
# def close_ldap_connection(connection):
|
||||
# connection.unbind_s()
|
||||
#
|
||||
#
|
||||
# def search_users():
|
||||
# ldap_connection = make_ldap_connection()
|
||||
# try:
|
||||
# raw_users = ldap_connection.search_s(current_app.config['LDAP_BASE_DN'], ldap.SCOPE_SUBTREE, '(objectClass=posixAccount)')
|
||||
# return [current_user.from_raw_ldap(u) for u in raw_users]
|
||||
# except Exception as ex:
|
||||
# current_app.logger.error(str(ex))
|
||||
# finally:
|
||||
# close_ldap_connection(ldap_connection)
|
||||
#
|
||||
#
|
||||
# def parse_user_dn(user_dn):
|
||||
# group = user_dn.split(',')
|
||||
# result = {}
|
||||
# for g in group:
|
||||
# split = g.split('=')
|
||||
# result[split[0]] = split[1]
|
||||
# return result
|
||||
41
app_common/fields.py
Normal file
41
app_common/fields.py
Normal file
@ -0,0 +1,41 @@
|
||||
from wtforms.fields import DecimalField
|
||||
from wtforms.validators import Regexp
|
||||
|
||||
|
||||
class PercentageField(DecimalField):
|
||||
def __init__(self, label=None, validators=None, **kwargs):
|
||||
# if not validators:
|
||||
# validators = [Regexp('[0-9\.]+[0-9]*%')]
|
||||
|
||||
super(PercentageField, self).__init__(label, validators=validators, **kwargs)
|
||||
|
||||
def _value(self):
|
||||
super(PercentageField, self)._value()
|
||||
val = f'{self.data*100.0}%'
|
||||
# val = float(val)
|
||||
return val
|
||||
|
||||
def process_formdata(self, valuelist):
|
||||
if not valuelist:
|
||||
return self.default
|
||||
raw_data = valuelist[0]
|
||||
val = raw_data.replace('%', '')
|
||||
val = float(val)
|
||||
return val/100.0
|
||||
|
||||
|
||||
class DollarAmountField(DecimalField):
|
||||
def __init__(self, label=None, validators=None, **kwargs):
|
||||
super(DecimalField, self).__init__(label, validators=validators, **kwargs)
|
||||
|
||||
def _value(self):
|
||||
val = f'${self.data:.2f}'
|
||||
return val
|
||||
|
||||
def process_formdata(self, valuelist):
|
||||
if not valuelist:
|
||||
return self.default
|
||||
raw_data = valuelist[0]
|
||||
val = raw_data.replace('$', '')
|
||||
val = float(val)
|
||||
return val
|
||||
Loading…
Reference in New Issue
Block a user