Skip to content

Commit

Permalink
Add 'create_tags' cfp task
Browse files Browse the repository at this point in the history
We want the cfp tags to be relatively limited so it (should) be fine to
manage them via CLI. If need-be a management page can be added but I'd
like to avoid that for the time being as hopefully they'll be a
one-and-done set up. It's a separate command but I've also hooked it
into the `dev data` command just to make sure there's something there.
  • Loading branch information
SamLR authored and marksteward committed Jan 4, 2024
1 parent 6c806c8 commit 13ded78
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions apps/base/dev/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from models.volunteer.shift import Shift
from models.volunteer.role import Role

from apps.cfp.tasks import create_tags

from . import dev_cli
from .fake import FakeDataGenerator

Expand All @@ -20,6 +22,7 @@ def dev_data(ctx):
ctx.invoke(fake_data)
ctx.invoke(volunteer_data)
ctx.invoke(volunteer_shifts)
ctx.invoke(create_tags)


@dev_cli.command("cfp_data")
Expand Down
25 changes: 25 additions & 0 deletions apps/cfp/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from main import db
from models.cfp import Proposal, TalkProposal, WorkshopProposal, InstallationProposal
from models.cfp_tag import Tag, DEFAULT_TAGS
from models.user import User
from apps.cfp_review.base import send_email_for_proposal
from ..common.email import from_email
Expand Down Expand Up @@ -125,3 +126,27 @@ def email_reserve():
send_email_for_proposal(
proposal, reason="reserve-list", from_address=from_email("SPEAKERS_EMAIL")
)


@cfp.cli.command(
"create_tags",
help=f"Add tags to the database. Defaults are {DEFAULT_TAGS}.",
)
@click.argument("tags_to_create", nargs=-1)
def create_tags(tags_to_create):
"""Upset tag list"""
if not tags_to_create:
tags_to_create = DEFAULT_TAGS

tags_created = 0
for tag in tags_to_create:
if Tag.query.filter_by(tag=tag).all():
app.logger.info(f"'{tag}' already exists, skipping.")
continue

db.session.add(Tag(tag))
tags_created += 1
app.logger.info(f"'{tag}' added to session.")

db.session.commit()
app.logger.info(f"Successfully created {tags_created} new tags.")
15 changes: 15 additions & 0 deletions models/cfp_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
from . import BaseModel


DEFAULT_TAGS = [
"computing",
"film",
"health",
"misc",
"music",
"radio",
"robotics",
"science",
"security",
"trains",
"show & tell",
]


class Tag(BaseModel):
__versioned__: dict = {}
__tablename__ = "tag"
Expand Down

0 comments on commit 13ded78

Please sign in to comment.