def alterar_tarefas(db): aaa.require(fail_redirect='/login') id = request.forms.get('id') descricao = request.forms.get('descricao') if (id and descricao): try: db.query(Tarefas).filter_by(id_tarefa=id).update( {"descricao": descricao}) db.commit() tarefas = db.query(Tarefas).all() status = getStatus('SUCESS') user_logged = not aaa.user_is_anonymous return template('layout_tipo_tarefa', tarefas=tarefas, status=status, user_logged=user_logged) except BaseException as e: error = e.args else: status = getStatus('WARNING', 'Preencha todos os campos') tarefas = db.query(Tarefas).all() user_logged = not aaa.user_is_anonymous return template('layout_tipo_tarefa', tarefas=tarefas, status=status, user_logged=user_logged)
def deletar_erros(db, id): aaa.require(fail_redirect='/login') if (id): try: erro = db.query(Erros).filter(Erros.id_erro == id)[0] db.delete(erro) db.commit() erros = db.query(Erros).all() tarefas = db.query(Tarefas).all() status = getStatus('SUCESS') user_logged = not aaa.user_is_anonymous return template('layout_erros', err=erros, tarefas=tarefas, status=status, user_logged=user_logged) except BaseException as e: erros = db.query(Erros).all() tarefas = db.query(Tarefas).all() status = getStatus('ERROR', 'Código nao existe ' + e.args[0]) user_logged = not aaa.user_is_anonymous return template('layout_erros', err=erros, tarefas=tarefas, status=status, user_logged=user_logged) redirect('/exibir_erros')
def cadastrar_erros(db): aaa.require(fail_redirect='/login') descricao = request.forms.get('descricao') tarefa = request.forms.get('tipo-tarefa') if descricao and tarefa: erro = Erros(descricao, tarefa) db.add(erro) db.commit() erros = db.query(Erros).all() tarefas = db.query(Tarefas).all() status = getStatus('SUCESS') user_logged = not aaa.user_is_anonymous return template('layout_erros', err=erros, tarefas=tarefas, status=status, user_logged=user_logged) else: status = getStatus('WARNING', 'Preencha todos os campos') erros = db.query(Erros).all() tarefas = db.query(Tarefas).all() user_logged = not aaa.user_is_anonymous return template('layout_erros', err=erros, tarefas=tarefas, status=status, user_logged=user_logged)
def admin(): """Only admin users can see this""" aaa.require(role='admin', fail_redirect='/sorry_page') user_logged = not aaa.user_is_anonymous return dict(current_user=aaa.current_user, users=aaa.list_users(), roles=aaa.list_roles(), user_logged=user_logged)
def exibir_tarefas(db, status=False): aaa.require(fail_redirect='/login') tarefas = db.query(Tarefas).all() user_logged = not aaa.user_is_anonymous return template('layout_tipo_tarefa', tarefas=tarefas, status=status, user_logged=user_logged)
def buscar_erros_registrados(db): aaa.require(fail_redirect='/login') from json import dumps from bottle import response limit = request.query.get('limit') offset = request.query.get('offset') search = request.query.get('search') sort = request.query.get('sort') order = request.query.get('order') r_json = {'total': 0, 'rows': []} if (limit and offset): registros = db.query(RegistroDeErros) if search: registros = registros.filter( RegistroDeErros.cliente.like("%{}%".format(search))) if sort: if order == 'desc': registros = registros.order_by( desc(getattr(RegistroDeErros, sort))) else: registros = registros.order_by(getattr(RegistroDeErros, sort)) registros = registros.limit(limit) registros = registros.offset(offset) r_json['total'] = db.query(func.count( RegistroDeErros.id_registro)).first() for r in registros: r_json['rows'].append({ 'id_registro': r.id_registro, 'id_onda': r.id_onda, 'cliente': r.cliente.capitalize(), 'id_produto': r.id_produto, 'id_tarefa': r.erro.tarefa.descricao, 'id_erro': r.erro.descricao, 'descricao_produto': r.descricao_produto.capitalize(), 'colaborador': r.colaborador, 'data_cadastro': str(r.data_cadastro), }) response.content_type = 'application/json' return dumps(r_json)
def chrats(db, search=False, option=False): aaa.require(fail_redirect='/login') if option: from json import dumps from bottle import response erros = None if option == 'por_colaborador': erros = db.query(RegistroDeErros.colaborador.label('label'), func.count(RegistroDeErros.id_onda).label('count'))\ .group_by(RegistroDeErros.colaborador).all() if option == 'por_erro': erros = db.query(RegistroDeErros.id_erro.label('label'), func.count(RegistroDeErros.id_onda).label('count'))\ .group_by(RegistroDeErros.id_erro).all() if option == 'por_tarefa': erros = db.query(RegistroDeErros.erro.tarefa.descricao.label('label'), func.count(RegistroDeErros.id_onda).label('count'))\ .group_by(RegistroDeErros.erro.tarefa.descricao).all() e_json = { 'chart': { "caption": "Grafico de erros", "xaxisname": "Colaboradores", "yaxisname": "Erros", "showvalues": "1", "animation": "1" }, 'data': [], "trendlines": [{ "line": [{ "startvalue": "0", "istrendzone": "1", "valueonright": "1", "tooltext": "AYAN", "endvalue": "30", "color": "009933", "displayvalue": "Target", "showontop": "1", "thickness": "5" }] }] } for e in erros: e_json['data'].append({'label': str(e.label), 'value': e.count}) response.content_type = 'application/json' return dumps(e_json) else: user_logged = not aaa.user_is_anonymous return template('layout_charts', user_logged=user_logged, search=search)
def cadastrar_tarefas(db): aaa.require(fail_redirect='/login') descricao = request.forms.get('descricao') if descricao: tarefa = Tarefas(descricao) db.add(tarefa) db.commit() tarefas = db.query(Tarefas).all() status = getStatus('SUCESS') user_logged = not aaa.user_is_anonymous return template('layout_tipo_tarefa', tarefas=tarefas, status=status, user_logged=user_logged) else: status = getStatus('WARNING', 'Preencha o campo descrição') tarefas = db.query(Tarefas).all() user_logged = not aaa.user_is_anonymous return template('layout_tipo_tarefa', tarefas=tarefas, status=status, user_logged=user_logged)
def erros_registrados(db): aaa.require(fail_redirect='/login') user_logged = not aaa.user_is_anonymous return template('layout_erros_registrados', user_logged=user_logged)