def edit_dep(id): form = DepartmentForm() if request.method == "GET": session = db.create_session() dep = session.query(models.departments.Dep).filter( models.departments.Department.id == id, ((models.departments.Department.user == current_user) | (current_user.id == 1))).first() if dep: form.title.data = dep.title form.members.data = dep.members form.chief.data = dep.chief form.email.data = dep.email else: abort(404) if form.validate_on_submit(): session = db.create_session() job = session.query(models.jobs.Jobs).filter( models.jobs.Jobs.id == id, ((models.jobs.Jobs.user == current_user) | (models.jobs.Jobs.team_leader == 1))).first() if job: title = form.title.data members = form.members.data chief = form.chief.data emai = form.email.data session.commit() return redirect('/departments') else: abort(404) return render_template('new_dep.html', title='Редактирование новости', form=form)
def edit_department(id): """ Editar um departamento """ check_admin() add_department = False department = Department.query.get_or_404(id) form = DepartmentForm(obj=department) if form.validate_on_submit(): department.name = form.name.data department.description = form.description.data db.session.commit() flash('Voce editou com sucesso o departamento.') return redirect(url_for('admin.list_departments')) form.description.data = department.description form.name.data = department.name return render_template('admin/departments/department.html', action="Editar", add_department=add_department, form=form, department=department, title="Editar Departamento")
def add_department(): """ Add a department to the database """ check_admin() add_department = True form = DepartmentForm() if form.validate_on_submit(): department = Department(name=form.name.data, description=form.description.data) try: # add department to the database db.session.add(department) db.session.commit() flash('Novo departamento adicionado com sucesso.') except: # in case department name already exists flash('Erro: nome do departamento ja existe.') # redirect to departments page return redirect(url_for('admin.list_departments')) # load department template return render_template('admin/departments/department.html', action="Add", add_department=add_department, form=form, title="Adicionar Departamento")
def edit_department(id): """ edit a department """ check_admin() add_department = False # this department object stores and carries over the information # querried from the database department = Department.query.get_or_404(id) # simplifies the creation of object form without using the constructor that takes in the database columns # as parametres e.g in the add_department view form = DepartmentForm(obj=department) if form.validate_on_submit(): # replacing existing information in database with the new changes department.name = form.name.data department.description = form.description.data db.session.commit() flash('you have successfully edited the department.') # redirect to the departments page to view the new changes return redirect(url_for('admin.list_departments')) # this seems like a repetition of form = DepartmentForm(obj=department) # taking te information from database to be displayed in the editing form form.description.data = department.description form.name.data = department.name return render_template('admin/departments/department.html', action="Edit", add_department=add_department, form=form, department=department, title="Edit Department")
def add_department(): """ Adicionar um departamento ao DB """ check_admin() add_department = True form = DepartmentForm() if form.validate_on_submit(): department = Department(name=form.name.data, description=form.description.data) try: db.session.add(department) db.session.commit() flash('Voce adicionou com sucesso um novo departamento.') except: flash('Erro: nome do departamento ja existe.') return redirect(url_for('admin.list_departments')) return render_template('admin/departments/department.html', action="Add", add_department=add_department, form=form, title="Adicionar Departamento")
def edit_department(id): """ Edit a department """ add_department = False department = Department.query.get_or_404(id) form = DepartmentForm( obj=department ) # pass obj to the form (To edit the form, load data from database to fill the form) if form.validate_on_submit( ): # method is POST ( only if the form is submitted) department.name = form.name.data department.description = form.description.data db.session.commit() flash('You have successfully edited the department.') # redirect to the departments page return redirect(url_for('admin.list_departments')) form.description.data = department.description form.name.data = department.name return render_template('admin/departments/department.html', action="Edit", add_department=add_department, form=form, department=department, title="Edit Department")
def edit_department(id): check_admin() add_department = False department = Department.query.get_or_404(id) form = DepartmentForm(obj=department) if form.validate_on_submit(): department.name = form.name.data department.description = form.description.data try: db.session.commit() logger.info('department edited succesflly') flash('You have successfully edited the department.') return redirect(url_for('admin.list_departments')) except Exception as e: logger.error('department couldnt be edited') flash("cannot edit department try again") form.description.data = department.description form.name.data = department.name return render_template('admin/departments/department.html', action="Edit", add_department=add_department, form=form, department=department, title="Edit Department")
def add_department(): check_admin() add_department = True form = DepartmentForm() if form.validate_on_submit(): department = Department(name=form.name.data, description=form.description.data) try: db.session.add(department) db.session.commit() logger.info('department added successfully') flash('You have successfully added a new department.') except: logger.error('department couldnt be added') flash('Error: department name already exists.') return redirect(url_for('admin.list_departments')) return render_template('admin/departments/department.html', action="Add", add_department=add_department, form=form, title="Add Department")
def edit_department(id): """ Edit a department """ check_admin() add_department = False department = Department.query.get_or_404(id) form = DepartmentForm(obj=department) if form.validate_on_submit(): department.name = form.name.data department.description = form.description.data db.session.commit() flash('You have successfully edited the department.') # redirect to the departments page return redirect(url_for('admin.list_departments')) form.description.data = department.description form.name.data = department.name return render_template('admin/departments/department.html', action="Edit", add_department=add_department, form=form, department=department, title="Edit Department")
def add_department(): """ Add a department to the database """ check_admin() add_department = True form = DepartmentForm() if form.validate_on_submit(): department = Department(name=form.name.data, description=form.description.data) try: # add department to the database db.session.add(department) db.session.commit() flash('You have successfully added a new department.') except: # in case department name already exists flash('Error: department name already exists.') # redirect to departments page return redirect(url_for('admin.list_departments')) # load department template return render_template('admin/departments/department.html', action="Add", add_department=add_department, form=form, title="Add Department")
def add(): form = DepartmentForm() if form.validate_on_submit(): department = Department(name=form.name.data, user_id=form.dept_admin.data) db.session.add(department) db.session.commit() flash('You have successfully added a new department.') return redirect(url_for('admin.view')) return render_template('admin/add.html', form = form, title = "Add Department")
def add(): form = DepartmentForm() if form.validate_on_submit(): department = Department(name=form.name.data, user_id=form.dept_admin.data) db.session.add(department) db.session.commit() flash('You have successfully added a new department.') return redirect(url_for('admin.view')) return render_template('admin/add.html', form=form, title="Add Department")
def add_department(): """ Add a department to the database """ check_admin() add_department = True form = DepartmentForm() if form.validate_on_submit(): department = Department(name=form.name.data, description=form.description.data) try: # add department to the database db.session.add(department) db.session.commit() try: ak1 = Attacker(name='Cyberkrieg(Staaten)', wert=4) ak2 = Attacker(name='Cyber-Terroristen', wert=4) ak3 = Attacker(name='Organisierte Cyberkriminelle', wert=3) ak4 = Attacker(name='Cyberkriminelle Einzeltater', wert=2) ak5 = Attacker(name='Hacker-Gruppen', wert=2) ak6 = Attacker(name='Cyber-Aktivist', wert=2) ak7 = Attacker(name='Skriptkiddies', wert=1) ak8 = Attacker(name='Unzufriedener Mitarbeiter', wert=1) db.session.add(ak1) db.session.add(ak2) db.session.add(ak3) db.session.add(ak4) db.session.add(ak5) db.session.add(ak6) db.session.add(ak7) db.session.add(ak8) db.session.commit() except: db.session.rollback() flash('You have successfully added a new department.') except: # in case department name already exists flash('Error: department name already exists.') # redirect to departments page return redirect(url_for('admin.list_departments')) # load department template return render_template('admin/departments/department.html', action="Add", add_department=add_department, form=form, title="Add Department")
def edit_department(id): """ Edit an entry """ check_admin() add_department = False department = Department.query.get_or_404(id) form = DepartmentForm(obj=department) if form.validate_on_submit(): department.accNum = form.accNum.data department.name = form.name.data #department.description = form.description.data #department.Normalside = form.Normalside.data department.AccCategory = form.AccCategory.data #department.SaccCategory = form.SaccCategory.data #department.iBalance = form.iBalance.data #department.debit = form.debit.data #department.credit = form.credit.data department.balance = form.balance.data department.Dtime = form.Dtime.data #department.statement =form.statement.data department.Comment = form.Comment.data db.session.commit() flash('You have successfully edited the account.') # redirect to the departments page return redirect(url_for('admin.list_departments')) form.accNum.data = department.accNum form.name.data = department.name #form.description.data = department.description #form.Normalside.data = department.Normalside form.AccCategory.data = department.AccCategory #form.SaccCategory.data = department.SaccCategory #form.iBalance.data = department.iBalance #form.debit.data = department.debit #form.credit.data = department.credit form.balance.data = department.balance form.Dtime.data = department.Dtime #form.statement.data = department.statement form.Comment.data = department.Comment return render_template('admin/departments/department.html', action="Edit", add_department=add_department, form=form, department=department, title="Edit account")
def edit(id): department = Department.query.get_or_404(id) # if current_user.id != issue.user_id: # abort(403) form = DepartmentForm(obj=department) if form.validate_on_submit(): department.name = form.name.data department.user_id = form.dept_admin.data db.session.add(department) db.session.commit() return redirect(url_for('admin.view')) form.name.data = department.name form.dept_admin.data = department.user_id return render_template('admin/edit.html', form=form, title="Edit Department")
def new_dep(): form = DepartmentForm() if form.validate_on_submit(): session = db.create_session() dep = models.departments.Department(title=form.title.data, members=form.members.data, chief=form.chief.data, email=form.email.data) session.add(dep) session.commit() return redirect('/departments') return render_template('new_dep.html', title='New departments', form=form, current_user=current_user)
def departments(): form = DepartmentForm() if form.validate_on_submit(): department_to_add = form.name.data.title() dept_check = Department.query.filter_by(name=department_to_add).first() if dept_check: flash('This department already exists.') return redirect(url_for('departments')) else: new_department = Department(name=department_to_add, user_id=current_user.id) db.session.add(new_department) db.session.commit() flash('New department added to the list.') return redirect(url_for('departments')) department_list = Department.query.filter_by(user_id=current_user.id).order_by(Department.name).all() return render_template('departments.html', department_list=department_list, form=form)
def add_department(): """ Add a department to the database """ check_admin() add_department = True form = DepartmentForm() if form.validate_on_submit(): department = Department( accNum=form.accNum.data, name=form.name.data, #description = form.description.data, #Normalside = form.Normalside.data, AccCategory=form.AccCategory.data, #SaccCategory = form.SaccCategory.data, #iBalance = form.iBalance.data, #debit = form.debit.data, #credit = form.credit.data, balance=form.balance.data, Dtime=form.Dtime.data, #statement = form.statement.data, Comment=form.Comment.data) try: # add department to the database db.session.add(department) db.session.commit() flash('You have successfully added a new entry.') except: # in case department name already exists flash('Error: entry name already exists.') # redirect to departments page return redirect(url_for('admin.list_departments')) # load department template return render_template('admin/departments/department.html', action="Add", add_department=add_department, form=form, title="Add Account")
def edit_department(id): # Edit a department check_admin() add_department = False #The view queries the database for a department with id,if dep. doesn't exist,throw a 404 not found department = Department.query.get_or_404( id) #If it does, updated with the form data form = DepartmentForm(obj=department) if form.validate_on_submit(): department.name = form.name.data department.description = form.description.data db.session.commit() flash('You have successfully edited the department.') # redirect to the departments page return redirect(url_for('admin.list_departments')) form.description.data = department.description form.name.data = department.name return render_template('admin/departments/department.html', action='Edit', add_department=add_department, form=form, department=department, title='Edit Department')