Esempio n. 1
0
def normalize_text(value, change_to=''):
    """
When value is None or an empty string replace it for rpcl.
    :param value:
    :param change_to:
    :return:
    """
    if isinstance(value, int) or isinstance(value, float):
        value = str(value)
    return replace_when_none(nwe(value), change_to)
Esempio n. 2
0
def build_query(report):
    """
Build a query to be displayed in Bifrost Format.
    :param report:
    :return:
    """
    if isinstance(report.script, bytes):
        try:
            text = replace_when_none(report.script.decode())
        except UnicodeDecodeError:
            text = replace_when_none(report.script.decode('cp1252'))
    else:
        text = replace_when_none(report.script)
    for parameter in report.parameters:
        text += ';\n{}={}'.format(parameter.type, parameter.name)
        if parameter.default_value:
            text += '={}'.format(parameter.default_value)
        if parameter.legend:
            text += '={}'.format(parameter.legend)
    return text
Esempio n. 3
0
 def get(self, result_type=T_CLASS, **where_clauses):
     """
 Get objects from specifieds clauses.
 :param result_type: type to store in resultset:
                     'class' for a model.
                     'dict' for a dictionary
                     'list' for a list.
 :param where_clauses: clauses according with model fields.
 :return:
     """
     connection = self._obj.create_connection()
     query = replace_when_none(nwe(self._custom_qry_init_part), self._qry_init_part)
     where_clauses = normalize_db_values(where_clauses, self._obj)
     self._resultset = ()
     result_type = T_DICT if self._custom_qry_init_part else result_type
     if len(where_clauses) == 0:
         query += ' 1=1'
     else:
         for key in where_clauses.keys():
             sep = '__'
             if sep in key:
                 opt = key.split(sep)[-1]
                 if opt in self._where_opt:
                     if where_clauses[key] is None and opt == 'not':
                         query += ' {} is not %({})s ' \
                                  'AND'.format(self._obj.normalize_column(
                             key.split(sep + opt)[0]), key)
                     else:
                         query += ' {} {} %({})s AND'.format(
                             self._obj.normalize_column(
                                 key.split(sep + opt)[0]),
                             self._where_opt[opt], key)
                     continue
             if where_clauses[key] is None:
                 query += ' {} is %({})s AND'.format(
                     self._obj.normalize_column(key), key)
             else:
                 query += ' {} = %({})s AND'.format(
                     self._obj.normalize_column(key), key)
     query = query.strip('AND') + self._order_by
     if result_type == T_CLASS:
         self._populate_dict(connection.query_with_columns(query,
                                                           where_clauses))
     elif result_type == T_DICT:
         self._populate_dict(
             connection.query_with_columns(query, where_clauses),
             result_type)
     else:
         self._populate(connection.query(query, where_clauses))
     connection.close()
     self._order_by = ''
     self._custom_qry_init_part = ''
     return self
Esempio n. 4
0
 def load_from_web(self, form):
     try:
         self.date = load_date(form['date'])
         self.type = nwe(form['type'])
         self.conclusion = form['conclusion'] == 'Y'
         self.observations = nwe(form['observations'])
         self.document_ext = replace_when_none(
             nwe(form['document_filename'].split('.')[-1]),
             self.document_ext)
         if len(form['document']) > 0:
             self.document = b64decode(
                 form['document'].split(';base64,')[1].encode())
     except BadRequestKeyError as ke:
         abort(403)
Esempio n. 5
0
 def load_from_web(self, form):
     try:
         self.date = load_date(form['date'])
         self.type = nwe(form['type'])
         self.conclusion = form['conclusion'] == 'Y'
         self.observations = nwe(form['observations'])
         self.document_ext = replace_when_none(
             nwe(form['document_filename'].split('.')[-1]),
             self.document_ext)
         if len(form['document']) > 0:
             self.document = b64decode(
                 form['document'].split(';base64,')[1].encode())
     except BadRequestKeyError as ke:
         abort(403)
Esempio n. 6
0
 def update_data(self, rid=None):
     report = Report()
     report.load(replace_when_none(rid, self.widget))
     connection = report.report_connection()
     rset = connection.query_with_columns(report.script)
     Query(self).get(widget=report.id).delete_all()
     if rset[1]:
         data = []
         for row in rset[1]:
             data.append(dict(zip(rset[0], all_as_str(row))))
         self.widget = report.id
         self.data = json.dumps(data)
         self.rows_count = len(data)
         self.last_update = datetime.now()
         self.save()
Esempio n. 7
0
 def update_data(self, rid=None):
     report = Report()
     report.load(replace_when_none(rid, self.widget))
     connection = report.report_connection()
     rset = connection.query_with_columns(report.script)
     Query(self).get(widget=report.id).delete_all()
     if rset[1]:
         data = []
         for row in rset[1]:
             data.append(dict(zip(rset[0], all_as_str(row))))
         self.widget = report.id
         self.data = json.dumps(data)
         self.rows_count = len(data)
         self.last_update = datetime.now()
         self.save()
Esempio n. 8
0
 def load_from_web(self, form):
     try:
         self.relative_start = load_date(form['relative_start'])
         self.relative_end = load_date(form['relative_end'])
         self.use_start = load_date(form['use_start'])
         self.use_end = load_date(form['use_end'])
         self.allowance_start = load_date(form['allowance_start'])
         self.allowance_end = load_date(form['allowance_end'])
         self.observations = nwe(form['observations'])
         self.document_ext = replace_when_none(
             nwe(form['document_filename'].split('.')[-1]),
             self.document_ext)
         if len(form['document']) > 0:
             self.document = b64decode(
                 form['document'].split(';base64,')[1].encode())
     except BadRequestKeyError:
         abort(403)
Esempio n. 9
0
 def load_from_web(self, form):
     try:
         self.type = int(form['type'])
         self.date = load_date(form['date'])
         self.reason = int(form['reason'])
         self.requester = form['requester']
         self.witness1 = nwe(form['witness1'])
         self.witness2 = nwe(form['witness2'])
         self.observations = nwe(form['observations'])
         self.document_ext = replace_when_none(
             nwe(form['document_filename'].split('.')[-1]),
             self.document_ext)
         if len(form['document']) > 0:
             self.document = b64decode(
                 form['document'].split(';base64,')[1].encode())
     except BadRequestKeyError:
         abort(403)
Esempio n. 10
0
 def load_from_web(self, form):
     try:
         self.relative_start = load_date(form['relative_start'])
         self.relative_end = load_date(form['relative_end'])
         self.use_start = load_date(form['use_start'])
         self.use_end = load_date(form['use_end'])
         self.allowance_start = load_date(form['allowance_start'])
         self.allowance_end = load_date(form['allowance_end'])
         self.observations = nwe(form['observations'])
         self.document_ext = replace_when_none(
             nwe(form['document_filename'].split('.')[-1]),
             self.document_ext)
         if len(form['document']) > 0:
             self.document = b64decode(
                 form['document'].split(';base64,')[1].encode())
     except BadRequestKeyError:
         abort(403)
Esempio n. 11
0
 def load_from_web(self, form):
     try:
         self.type = int(form['type'])
         self.date = load_date(form['date'])
         self.reason = int(form['reason'])
         self.requester = form['requester']
         self.witness1 = nwe(form['witness1'])
         self.witness2 = nwe(form['witness2'])
         self.observations = nwe(form['observations'])
         self.document_ext = replace_when_none(
             nwe(form['document_filename'].split('.')[-1]),
             self.document_ext)
         if len(form['document']) > 0:
             self.document = b64decode(
                 form['document'].split(';base64,')[1].encode())
     except BadRequestKeyError:
         abort(403)
Esempio n. 12
0
    def command(self, command, params=None, encoding='cp1252'):
        """
Execute a command into database.
    :param command: command string to be executed.
    :param params: binding variables.
        """
        try:
            new_params = {}
            for p in replace_when_none(params, {}):
                if not p.startswith(':'):
                    new_params[':{}'.format(p)] = params[p]
                else:
                    new_params[p] = params[p]
            return self._command(command.encode(encoding), new_params)
        except cx_Oracle.DatabaseError as e:
            print(e)
            raise e
        except Exception as ee:
            print(ee)
            raise ee
Esempio n. 13
0
    def query(self, query, params=None, encoding='cp1252'):
        """
Execute a query into database.
    :param query: query string to be executed.
    :param params: binding variables.
    :return: array of tuples with query data.
        """
        try:
            new_params = {}
            for p in replace_when_none(params, {}):
                if not p.startswith(':'):
                    new_params[':{}'.format(p)] = params[p]
                else:
                    new_params[p] = params[p]
            return self._query(query.encode(encoding), new_params)
        except cx_Oracle.DatabaseError as e:
            print(e)
            raise e
        except Exception as ee:
            print(ee)
            raise ee
Esempio n. 14
0
def img_for_web(data):
    """
    Transform data into a image to use into HTML pages
    """
    anybody = (
        b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01'
        b'\x00\x00\xff\xdb\x00\x84\x00\t\x06\x07\x14\x07\x06\x14\x08'
        b'\x07\x13\x13\x15\x14\x14\x17\x1e\x15\x19\x14\x17\x18\x17\x1b'
        b'\x17\x1c\x1a\x1a\x18"\x19\x1d\x19\x19\x17\x1a\x1d+,\x1c\x1a( '
        b'\x1a\x17$5!%)....\x17\x1f883,7,'
        b'-.+\x01\n\n\n\x05\x05\x05\x0e\x05\x05\x0e+\x19\x13\x19'
        b'++++++++++++++++++++++++++++++++++++++++++++++++++\xff\xc0'
        b'\x00\x11\x08\x00\xe0\x00\xe0\x03\x01"\x00\x02\x11\x01\x03'
        b'\x11\x01\xff\xc4\x00\x1b\x00\x01\x01\x01\x00\x03\x01\x01\x00'
        b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x05\x01\x03\x04\x07'
        b'\x02\xff\xc4\x00:\x10\x01\x00\x01\x03\x01\x04\x07\x04\t\x02'
        b'\x07\x00\x00\x00\x00\x00\x00\x01\x02\x03\x11\x04\x05!1A\x06'
        b'\x12\x13Qaq\x915\x81\xa1\xc1\x14"4BRr\xb1\xc2\xd1\x92\xf0'
        b'\x162C\x82\xa2\xb2\xf1\xff\xc4\x00\x14\x01\x01\x00\x00\x00'
        b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xc4'
        b'\x00\x14\x11\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
        b'\x00\x00\x00\x00\x00\xff\xda\x00\x0c\x03\x01\x00\x02\x11\x03'
        b'\x11\x00?\x00\xfa\xd0\x00\x00\x00\x00\x00\x00\x00\x03\xae'
        b'\xe5\xfamN.\xd5M3\xe31\x1f\xa8;\x06F\xa3\xa4\x16\xac\xd7\xd5'
        b'\xa3\xad_\x8d8\xc7\xc6a\xd7\xfe%\xb7\xf8.\x7f\xc7\xf9\x06'
        b'\xd8\xc2\xaf\xa4\xd4E?R\x8a\xe6{'
        b'\xa7\x11\x1e\xb9\x9f\xd1\xfb\xb5\xd2KuN.S]>\x93\x1f\x0f\xe0'
        b'\x1bC\xae\xcd\xfao\xc6l\xd5M^S\x13\xc7\xbf\xb9\xd8\x00\x00'
        b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x17'
        b']\xd2\x08\xd2\xeaf\xcd\xba:\xf8\xe7\xd6\xc6\xfeq\x8e\xaf '
        b'um\x8d\xb7Oa\xd4\xd9\xf5\xfdl\xc6f#\x97\x84\xcf\xb99]sr\xae'
        b'\xb5\xc9\x99\x9e\xf9\x99\x99\xf5\x977k\xed.\xcdt\xc6"fg\x1d'
        b'\xd9\x9e\x0f\xc0\x00\x00\x009\xa6\xa9\xa2\xae\xbd\x1311'
        b'\xc2ct\xfa\xbd\x9am\xabwOTM5\xd51\x9c\xe2\xa9\xccO\xab\xc4'
        b'\x02\xc3e\xed\x9au\xd3\x16\xeb\x8e\xad}\xdc\xa7\xca~MG\xcf'
        b'"q9\x85.\xc6\xdb\x9d\xb5}\x86\xb6c3\x88\xa6\xacq\x9e\x18\x9f'
        b'\x1e\x1f\x10o\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
        b'<\xbbKU\x1aM\x1dW*\x9cN&#\xbf\xad1\xb8\x12\x9b_iN\xbe\xfc'
        b'\xf5f{>T\xf2\xf3\x98\xefx\x00\x00\x00\x00\x00\x00\x00\x00'
        b'\x01]\xd1\xdd|\xeb4\xd3n\xf6f\xaa1\xf5\xa7\x9cNq\xef\xdd-d'
        b'\x87F\xefv[N)\x9f\xbd\x13O\xcf\xe4\xaf\x00\x00\x00\x00\x00'
        b'\x00\x00\x00\x00\x01\x87\xd2\xcf\xb1Q\xdd\xd7\xfd\xb3\xcf'
        b'\xd5\xb8\x90\xe9\x0e\xbb\xe9z\xbe\xce\x88\xddo4\xf9\xcew\xfb'
        b'\xb7G\xa02\x80\x00\x00\x00\x00\x00\x00\x00\x00sMSEQ];\xa67'
        b'\xc4\xf8\xc2\xfe\xc5sr\xccWv:\xb5Lo\xa7\xbay\xbe~\xb3\xd8Z'
        b'\xb9\xd6h"\xab\x9b\xea\xa6z\xb3>\\=\xf8\xc04@\x00\x00\x00'
        b'\x00\x00\x00\x00\x00qT\xccS3DfyG\x0c\xcfvy>{'
        b'Usr\xae\xbdS\x99\x9d\xf3>2\xfa\x1a3n\xe9>\x89\xaf\x9d\xf9'
        b'\x8a\xf3\\{\xe6x\xfb\xf2\x0c\xe0\x00\x00\x00\x00\x00\x00\x00'
        b'\x00\x05OD\xfe\xc3_\xe7\xfd\xb0\x96V\xf4b\xdfSfu\xe3\xefU3'
        b'\xe9\xbb\xe4\rp\x00\x00\x00\x00\x00\x00\x00\x00\x06\x0fK'
        b'-\xc7\xd1\xe8\xbb\xce*\xea\xe7\xc2c?/\xd5\xbc\xcf\xdb\xf6'
        b'\xfbM\x93^yb}$\x11`\x00\x00\x00\x00\x00\x00\x00\x00\x13\xc1y'
        b'\xa0\xd3F\x93IM\x98\x8cb7\xf9\xf3\xf8\xa3\xb6V\x9f\xe9;B\x8b'
        b'|\xb3\x99\xdd\x9d\xd1\xbew\x7f|W '
        b'\x00\x00\x00\x00\x00\x00\x00\x00\x00%\xfaK\xaa\xae\x9d\\\xe9'
        b'\xf31D\xd3\x1b\xb9O\xf2\xa8Kt\xb3\xed\xd4~O\xdd '
        b'\xc4\x00\x00\x00\x00\x00\x00\x00\x00\x01\xa5\xd1\xeb\x9d\x9e'
        b'\xd6\xa7<\xf3\x1e\xb0\xb2JtV\x88\xabhMS\xc6('
        b'\x99\x8fX\x8f\x9a\xac\x00\x00\x00\x00\x00\x00\x00\x00\x00'
        b'\x04\xf7K\xa8\xddn\xe4G\xe2\x89\x9fI\x88\xf8U\xf1P\xbc\x9bOG'
        b'\xf4\xed\x1dVy\xf1\xa6|c\x87\xf1\xef\x040\xe6c\x13\x89\xf4p'
        b'\x00\x00\x00\x00\x00\x00\x00\x00\xa2\xe8\x8f\xfa\xbf\xec\xfd'
        b'\xca&OF\xb4\xfd\x8e\xce\xed\'\x8ds\x9fw\x08\xfe\xfce\xac\x00'
        b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xcd\xda\xfb>\x8dF'
        b'\x96\xbb\xb3LEqL\xcf['
        b'\x1b\xf7o\xf7\xa3_C\x98\xccb\xad\xf1\xdc\x81\xd5\xd9\xfa6'
        b'\xa6\xab3\x9f\xab3\x1b\xf8\xe3\x97\xc3\x00\xea\x00\x00\x00'
        b'\x00\x00\x00z4::\xb5\xda\x8e\xc6\xce3\xc73\xc2#\xc5\xe7StWM'
        b'\xd5\xb1V\xaa\xaf\xbd\xf5c\xca8\xfa\xce?\xa4\x1b\x1a=?\xd1t'
        b'\xb4\xd8\xa6s\xd5\x8ce\xdc\x00\x00\x00\x00\x00\x00\x00\x00'
        b'\x00\x00\x00\x023\xa4\x16\xfb=\xad^\xfe8\x9fXY\xa4:K\xedY'
        b'\xfc\xb1\xfa\x03('
        b'\x00\x00\x00\x00\x00\x07\xee\xd5\xbe\xd6\xec['
        b'\xa7\x8dS\x11\xeb8^\xe9\xec\xc6\x9e\xc4Y\xb7\xc2\x98\xc4'
        b'!\xb4?n\xb7\xf9\xe9\xff\x00\xb4/@\x00\x00\x00\x00\x00\x00'
        b'\x00\x00\x00\x00\x00\x00Ht\x97\xda\xb3\xf9c\xf4T\xea\xf5T'
        b'\xe9,\xf6\xb7\xe7\x11\xc3\xff\x00!\x1d\xb65q\xad\xd7M\xebY'
        b'\xc6"7\xf8\x03\xc4\x00\x00\x00\x00\x00\x03\xd1\xa0\x8e\xb6'
        b'\xba\xdcG\xe3\xa7\xf5^!6m\xf8\xd3k\xa8\xbds8\xa6w\xe3\xd1k'
        b'\xa5\xd5Q\xab\xb7\xd7\xd3\xd5\x13\x1f\x18\xf3\x8e@\xee\x00'
        b'\x00\x00\x00\x00\x00\x00\x00\x00\x1cL\xe23,'
        b'\xddf\xdc\xb5\xa6\xcd4\xcf^\xae\xeax\x7fP4\xd9\xfb['
        b'jS\xb3\xa9\x8aq\x9a\xe63\x11\xcb\xceg\xb9\x89\xa8\xe9\x1d'
        b'\xcb\x91\x8b1M\x1f\x19\xf5\x9f\xe1\x93v\xec\xde\xb97.\xcc'
        b'\xcc\xcf9\x07n\xb3WV\xb6\xf7i~s\xdd\x1c\xa3\xc2#\xd1\xe7\x00'
        b'\x00\x00\x00\x00\x00\x00\x1f\xbb7j\xb1r.Y\x99\x89\x8ep\xfc'
        b'\x00\xad\xd8\xdbf5\xb3\xd8\xea1\x15\xf2\xee\xab\xcb\xc7\xc1'
        b'\xae\xf9\xfd\x8b\xb3b\xf4]\xb58\x98\x9c\xc4\xa8t\xdd&\x89'
        b'\x8cjh\x98\xf1\xa6s\x1e\x93\xc3\xe2\r\xf1\xd1\xa5\xd6Q\xab'
        b'\x8c\xe9\xea\x89\xf0\xe7\x1e\xe7x\x00\x00\x00\x00\x00\xce'
        b'\xda;b\x8d\x0eh\xff\x005\x7f\x86>s\xc9\xa2\x89\xdb~\xd6\xb9'
        b'\xe7\xf2\x80s\xb4v\xb5\xcdt\xe2\xa9\xea\xd3\xf8c\x87\xbf\xbd'
        b'\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00s'
        b'\x13\x89\xccq\x8d\xf9kh\xbaAsOOV\xf4v\x91\xe38\x9f\xea\xc7'
        b'\xc9\x90\x02\xd3E\xb6-k*\x8a('
        b'\x99\x8a\xa7\xee\xcco\xfe\xf74\x11;\x13\xda\xd6\xfc\xfeR\xb6'
        b'\x00\x00\x00\x01\x13\xb6\xfd\xads\xcf\xe5\x0bdN\xdb\xf6\xb5'
        b'\xcf?\x94\x03\xc2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
        b'\x00\x00\x00\x00\x03\xdd\xb1=\xado\xcf\xe5+dN\xc4\xf6\xb5'
        b'\xbf?\x94\xad\x80\x00\x1f\xff\xd9')
    return 'data:image/jpeg;base64,{}'.format(
        b64encode(replace_when_none(data, anybody)).decode())