Skip to content

Commit

Permalink
Add a 'delete_tags' cfp task
Browse files Browse the repository at this point in the history
Because these will change and this way we can clean up
  • Loading branch information
SamLR committed Jan 15, 2024
1 parent 6e45022 commit 02d569b
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion apps/cfp/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def email_reserve():
)
@click.argument("tags_to_create", nargs=-1)
def create_tags(tags_to_create):
"""Upset tag list"""
"""Upsert tag list"""
if not tags_to_create:
tags_to_create = DEFAULT_TAGS

Expand All @@ -150,3 +150,31 @@ def create_tags(tags_to_create):

db.session.commit()
app.logger.info(f"Successfully created {tags_created} new tags.")


@cfp.cli.command(
"delete_tags",
help=f"Delete tags from the Database. Any tagged proposals will have the tags removed.",
)
@click.argument("tags_to_delete", required=True, nargs=-1)
def Delete_tags(tags_to_delete):
"""Delete tag list"""
tags_deleted = 0
for tag_name in tags_to_delete:
tag = Tag.query.filter_by(tag=tag_name).one_or_none()
if not tag:
app.logger.info(f"Couldn't find tag: '{tag_name}' exiting.")
return

if tag.proposals:
tagged_proposals = [p.id for p in tag.proposals]
app.logger.info(
f"'{tag_name}' is still applied to the following proposals: {tagged_proposals}"
)

db.session.delete(tag)
tags_deleted += 1
app.logger.info(f"'{tag_name}' added to session.")

db.session.commit()
app.logger.info(f"Successfully created {tags_deleted} new tags.")

0 comments on commit 02d569b

Please sign in to comment.