def view_application(appid): """Handler for viewing a specific application.""" application = get_db().get_application(appid) # You can only see applications if you're a manager, or it's an # application you submitted. if (not (current_user.is_manager() or (application and application.user == current_user))): return render_template('manager-only.html') if not application: flash('Unknown application ID!') return redirect(url_for('mainpage')) # What you can edit depends on if it's a manager or the submitting member # who is viewing the application form. if current_user.is_manager(): mgrs = get_db().get_applications_by_type('mgr') form = MgrContribApplicationForm(formdata=request.form, obj=application) if (not application.manager or application.manager in [(mgr.user) for mgr in mgrs]): form.manager.choices = ([(0, 'None')] + [(mgr.user.memid, mgr.user.name) for mgr in mgrs]) else: # Current manager is no longer a manager, so make sure they're # still included in the list. form.manager.choices = ( [(0, 'None'), (application.manager.memid, application.manager.name)] + [(mgr.user.memid, mgr.user.name) for mgr in mgrs]) else: form = ContribApplicationForm(formdata=request.form, obj=application) if form.validate_on_submit(): if form.sub_private.data != application.user.sub_private(): get_db().update_member_field(application.user.email, 'sub_private', form.sub_private.data) if form.contrib.data != application.contrib: get_db().update_application_field(application.appid, 'contrib', form.contrib.data) # Deal with changes that are only possible from a manager if current_user.is_manager(): process_contrib_application(form, application) return render_template('application.html', application=application, form=form)
def view_application(appid): """Handler for viewing a specific application.""" application = get_db().get_application(appid) # You can only see applications if you're a manager, or it's an # application you submitted. if (not (current_user.is_manager() or (application and application.user == current_user))): return render_template('manager-only.html') if not application: flash('Unknown application ID!') return redirect(url_for('mainpage')) # What you can edit depends on if it's a manager or the submitting member # who is viewing the application form. if current_user.is_manager(): mgrs = get_db().get_applications_by_type('mgr') form = MgrContribApplicationForm(request.form, application) if (not application.manager or application.manager in [(mgr.user) for mgr in mgrs]): form.manager.choices = ([(0, 'None')] + [(mgr.user.memid, mgr.user.name) for mgr in mgrs]) else: # Current manager is no longer a manager, so make sure they're # still included in the list. form.manager.choices = ([(0, 'None'), (application.manager.memid, application.manager.name)] + [(mgr.user.memid, mgr.user.name) for mgr in mgrs]) else: form = ContribApplicationForm(request.form, application) if form.validate_on_submit(): if form.sub_private.data != application.user.sub_private(): get_db().update_member_field(application.user.email, 'sub_private', form.sub_private.data) if form.contrib.data != application.contrib: get_db().update_application_field(application.appid, 'contrib', form.contrib.data) # Deal with changes that are only possible from a manager if current_user.is_manager(): process_contrib_application(form, application) return render_template('application.html', application=application, form=form)
def delete(login): if current_user.is_authenticated and current_user.is_manager(): usuario = Usuario.query.filter_by(login_usuario=login).first() usuario.excluido_usuario = True db.session.add(usuario) db.session.commit() return redirect(url_for('list')) return redirect('pagina-inicial')
def privatesubs(): """Return the list of -private subscriber addressess""" if request.remote_addr not in app.config['LIST_HOSTS']: if not current_user.is_manager(): return render_template('manager-only.html') emails = sorted(get_db().get_private_emails()) emaillist = '\n'.join(emails) return Response(emaillist.lower(), mimetype='text/plain')
def list_applications(listtype): """Handler for listing applications; managers only.""" if not current_user.is_manager(): return render_template('manager-only.html') if listtype not in ['all', 'nca', 'ncm', 'ca', 'cm', 'mgr']: flash('Unknown application type!') return redirect(url_for('mainpage')) return render_template('applications.html', db=get_db(), listtype=listtype)
def view_member(memid): """Handler for viewing a member""" if not current_user.is_manager(): return render_template('manager-only.html') member = get_db().get_member_by_id(memid) if not member: flash('No such member.') return redirect(url_for('mainpage')) applications = get_db().get_applications_by_user(member) return render_template('member.html', applications=applications, db=get_db(), member=member)
def edit(login): if current_user.is_authenticated and current_user.is_manager(): form = UserForm() if form.is_submitted(): #Obtem usuário cadastrado no banco de dados usuario = Usuario.query.filter_by(login_usuario=login).first() #Informações do formulário nome = form.nome.data email = form.email.data.lower() senha = form.senha.data tipo = form.tipo.data.lower() situacao = form.situacao.data.lower() #Altera informações para alteração no banco de dados usuario.nome_usuario = nome usuario.email_usuario = email if senha: usuario.set_password(senha) usuario.tipo_usuario = tipo usuario.situacao_usuario = situacao #Grava no banco de dados db.session.add(usuario) db.session.commit() return redirect(url_for('list')) else: usuario = Usuario.query.filter_by(login_usuario=login).first() if usuario: #carrega campos de seleção funcionario = Funcionario.query.filter_by( id_funcionario=usuario.funcionario_id_funcionario).first() form.id_funcionario.choices = [(funcionario.id_funcionario, funcionario.nome_funcionario)] form.tipo.default = usuario.tipo_usuario.capitalize() form.situacao.default = usuario.situacao_usuario.capitalize() form.process() return render_template('user/user_edit.html', form=form, usuario=usuario) return redirect('pagina-inicial')
def register(): #Guarda de rota, apenas usuário autenticado e que for gerente pode registrar if current_user.is_authenticated and current_user.is_manager(): form = UserForm() if form.is_submitted(): #Obtem informações do formulário de registro nome = form.nome.data email = form.email.data.lower() login = form.login.data.lower() senha = form.senha.data tipo = form.tipo.data.lower() situacao = form.situacao.data.lower() id_funcionario = form.id_funcionario.data #Cria objeto Usuario usuario = Usuario(login=login, senha=senha, nome=nome, email=email, tipo=tipo, situacao=situacao, id_funcionario=id_funcionario) #Grava no banco de dados db.session.add(usuario) db.session.commit() #Redireciona para lista de usuários return redirect(url_for('list')) #carrega combo box com a lista de funcionários elif not form.id_funcionario.data: form.id_funcionario.choices = Funcionario.list_of_functionaries() form.process() return render_template('user/user_register.html', form=form) return redirect('pagina-inicial')
def decorated_function(*args, **kwargs): if not current_user.is_manager(): abort(403) return f(*args, **kwargs)
def list(): if current_user.is_authenticated and current_user.is_manager(): users = Usuario.query.filter_by(excluido_usuario=False) return render_template('user/user_list.html', users=users) return redirect('pagina-inicial')