def create_quote(POST={}, GET={}, ENVIRO={}, CLIENT_STATE={}, COOKIES={}, CONTEXT={}, TEMPLATE='', TEMPLATE_ENGINE=None, CSB='', TEMPLATE_STACK={}): _key = int(GET.get('incdt_id', ['-1'])[0]) if _key < 0: return m.client_redirect(ENVIRO, '/list_services', '303', CLIENT_STATE, COOKIES, CSB) q_str = """select xmag.create_quote_from_incident(%(key)s) as quhead_id """ _r = m.run_sql_command(ENVIRO.get('CONN'), q_str, {'key': _key}) if _r[0]['quhead_id'] > 1: return m.client_redirect(ENVIRO, '/edit_quote?quhead_id=' + _r[0]['quhead_id'], '303', CLIENT_STATE, COOKIES, CSB) return m.client_redirect(ENVIRO, '/list_services?message=', +qp('Failed to Create Quote Template'), '303', CLIENT_STATE, COOKIES, CSB)
def add_line_to_quote(POST={}, GET={}, ENVIRO={}, CLIENT_STATE={}, COOKIES={}, CONTEXT={}, TEMPLATE='', TEMPLATE_ENGINE=None, CSB='', TEMPLATE_STACK={}): _quhead = int(POST.get('quhead', ['-1'])[0]) _qunumber = int(POST.get('qunumber', ['-1'])[0]) _itemsite_id = int(POST.get('itemsite_id', ['-1'])[0]) _qty = int(POST.get('qty', ['0'])[0]) _warehouse = int(POST.get('warehouse', ['0'])[0]) _message = 'Failed to Add Item the Quote' q_str = """select xmag.additem_to_quote( %(quhead)s, %(itemsite_id)s, %(qty)s ) as idkey; """ _r = m.run_sql_command(ENVIRO.get('CONN'), q_str, { 'itemsite_id': _itemsite_id, 'quhead': _quhead, 'qty': _qty }) if _r[0]['idkey'] > 0: _message = 'Added the Item to the Quote' _redirect = """ /list_van_inventory?message=%s;warehouse=%s;qunumber=%s;quhead=%s""" % ( _message, _warehouse, _qunumber, _quhead) return m.client_redirect(ENVIRO, _redirect, '303', CLIENT_STATE, COOKIES, CSB)
def save_blog(POST, GET, ENVIRO, CLIENT_STATE, COOKIES, CONTEXT, TEMPLATE, TEMPLATE_ENGINE, CSB='', TEMPLATE_STACK={}): if 'blog_id' in GET: _key = int(''.join(GET.get('blog_id')), '-1') _search_tags = ''.join(GET.get('search_tags', '')).split(',') _text = ''.join(GET.get('content', '')) _title = ''.join(GET.get('title', '')) elif 'blog_id' in POST: _key = int(''.join(POST.get('blog_id', '-1'))) _search_tags = ''.join(POST.get('search_tags', '')).split(',') _text = ''.join(POST.get('content', '')) _title = ''.join(POST.get('title', '')) else: return False, '', ENVIRO, CLIENT_STATE, COOKIES, CSB CONTEXT.update({'PAGE_NAME': "New Blog Was Saved"}) _sql = """ insert into blog values ( %(blog_id)s , %(blog_user_id)s , now(), %(blog_htmltext)s , %(search_tags)s , to_tsvector(%(tvs)s), %(blog_title)s ) on Conflict ( blog_id ) do Update set blog_htmltext = %(blog_htmltext)s , search_tags = %(search_tags)s, tvs = to_tsvector(%(tvs)s), blog_title =%(blog_title)s ;""" _topadd = { 'blog_id': _key, 'blog_user_id': int(ENVIRO.get('SEC', {}).get('USER_ID', -1)), 'blog_htmltext': _text, 'search_tags': _search_tags, 'tvs': _title + extext(_text), 'blog_title': _title } m.run_sql_command(ENVIRO.get('CONN'), _sql, _topadd) #GET = {'blogkey':_key} #_is_in_cache, TEMPLATE, _template_name = m.build_template('view', TEMPLATE_STACK['view'], ENVIRO=ENVIRO) #return view({}, GET, ENVIRO, CLIENT_STATE, COOKIES, CONTEXT,TEMPLATE, TEMPLATE_ENGINE, '', TEMPLATE_STACK ) _r, url_path = m.furl_get_to_app('view', ENVIRO, {'blog_id': _key}) if _r: ENVIRO = m.client_redirect(url_path, ENVIRO) return True, '', ENVIRO, CLIENT_STATE, COOKIES, CSB
def get_file_from_xdb(POST={}, GET={}, ENVIRO={}, CLIENT_STATE={}, COOKIES={}, CONTEXT={}, TEMPLATE='', TEMPLATE_ENGINE=None, CSB='', TEMPLATE_STACK={}): if 'file_id' in GET: _key = int(''.join(GET.get('file_id', ['-1']))) _redirect = ''.join(GET.get('redirect', ['/'])) elif 'file_id' in POST: _key = int(''.join(POST.get('file_id', ['-1']))) _redirect = ''.join(GET.get('redirect', ['/'])) CONTEXT.update({'PAGE_NAME': "DownloadFile"}) q_str = """select file_title, file_stream, lower('.'||file_type) as file_type from file where file_id = %(key)s """ _r = m.run_sql_command(ENVIRO.get('CONN'), q_str, {'key': _key}) mt.init() ct = mt.types_map[_r[0]['file_type']] _d = _r[0]['file_stream'] if len(_r) > 0: _output = bytes(_d[0:]) ENVIRO.get('HEADERS', {}).update({ 'Content-Type': ct, 'Content-Description': _r[0]['file_title'], 'Content-Disposition': 'attachment; filename="%s"' % (_r[0]['file_title']) }) return True, _output, ENVIRO, CLIENT_STATE, COOKIES, CSB else: return m.client_redirect(ENVIRO, _redirect, '303', CLIENT_STATE, COOKIES, CSB)
def email_cert(POST={}, GET={}, ENVIRO={}, CLIENT_STATE={}, COOKIES={}, CONTEXT={}, TEMPLATE='', TEMPLATE_ENGINE=None, CSB='', TEMPLATE_STACK={}): if 'calhead_id' in GET: _key = int(''.join(GET.get('calhead_id', '-1'))) elif 'calhead_id' in POST: _key = int(''.join(POST.get('calhead_id', '-1'))) _sql = "select email_certificate(%(calhead_id)s) as message;" _r = m.run_sql_command(ENVIRO.get('CONN'), _sql, {'calhead_id': _key}) return m.client_redirect(ENVIRO, '/list_cal?message=' + qp(_r[0]['message']), '303', CLIENT_STATE, COOKIES, CSB)
def save_incident(POST={}, GET={}, ENVIRO={}, CLIENT_STATE={}, COOKIES={}, CONTEXT={}, TEMPLATE='', TEMPLATE_ENGINE=None, CSB='', TEMPLATE_STACK={}): q_str = """Update incident set incdt_descrip = %()s where incdt_id = %()s""" _incdt = m.run_sql_command(ENVIRO.get('CONN'), q_str, {'key': p_key}) q_str = """update cntct set cntct_first_name = %()s, cntct_last_name = %()s , cntct_phone = %()s, cntct_email = %()s where cntct_id = %()s""" _cntct = m.run_sql_command(ENVIRO.get('CONN'), q_str, {'key': p_key}) q_str = """update addr set addr_line1 = %()s, addr_line2 =%()s , addr_line3 = %()s, addr_city = %()s, addr_state = %()s where addr_id = %()s""" _addr = m.run_sql_command(ENVIRO.get('CONN'), q_str, {'key': p_key}) return m.client_redirect(ENVIRO, '/edit_incdt?message=', +qp('Failed to Create Quote Template'))