def create_group(project_id): """Adds a new group to a project""" ps = ProjectService() project = ps.get(project_id) form = GroupService().get_form(project) if form.validate_on_submit() and project.id is int(form.project_id.data): group = GroupService().new(number=form.number.data, name=form.name.data) ps.add_group(project, group) flash("Successfully added a new group '%s'" % group, "success") return redirect(url_for("view_project", project_id=project.id)) if request.method == "POST": flash("Unable to add a new group", "danger") return CreateGroup(project).render(form)
def create_animal(project_id): """Adds a new animal to a project""" project = ProjectService().get(project_id) form = AnimalService().get_form(project) if form.validate_on_submit(): gs = GroupService() group = gs.get(form.group.data) animal = AnimalService().new(number=form.number.data, age=form.age.data, gender=form.gender.data) gs.add_animal(group, animal) flash("Successfully added a new animal '%s'" % animal, "success") return redirect(url_for("view_project", project_id=project.id)) if request.method == "POST": flash("Unable to add a new animal", "danger") return CreateAnimal(Project).render(form)