Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a 'delete_tags' cfp task #1308

Merged
merged 2 commits into from
Jan 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. 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}' will be removed from the proposals with ids: {tagged_proposals}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicky: would it be helpful to mention each proposal title as well? (thinking: could provide a useful sense-check during tag removal)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not? This will hopefully be a pretty rare manual task (after I do what I need to do which is update the current list of tags to match those selected by the content team) and untagged proposals can be found via the UI.

In theory deleting a tag will only happen when it's not useful: i.e. has very few (probably no) members OR so many members it's pointless.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okie doke, just checking. Seems reasonable!

)

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

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