diff --git a/app/blueprints/packages/packages.py b/app/blueprints/packages/packages.py index 6344abb1..d3e29c79 100644 --- a/app/blueprints/packages/packages.py +++ b/app/blueprints/packages/packages.py @@ -281,7 +281,7 @@ class PackageForm(FlaskForm): def handle_create_edit(package: typing.Optional[Package], form: PackageForm, author: User): wasNew = False if package is None: - package = Package.query.filter_by(name=form["name"].data, author_id=author.id).first() + package = Package.query.filter_by(name=form.name.data, author_id=author.id).first() if package is not None: if package.state == PackageState.DELETED: flash( @@ -293,6 +293,12 @@ def handle_create_edit(package: typing.Optional[Package], form: PackageForm, aut gettext("Package already exists")), "danger") return None + if Collection.query \ + .filter(Collection.name == form.name.data, Collection.author == author) \ + .count() > 0: + flash(gettext("A collection with a similar name already exists"), "danger") + return + package = Package() db.session.add(package) package.author = author