
import click

from byceps.database import db

from bootstrap.helpers import promote_orga
from bootstrap.util import app_context, get_config_name_from_env
from bootstrap.validators import validate_brand, validate_user_screen_name


@click.command()
@click.argument('brand', callback=validate_brand)
@click.argument('user', callback=validate_user_screen_name)
def execute(brand, user):
    click.echo('Promoting user "{}" to orga for brand "{}" ... '
               .format(user.screen_name, brand.title), nl=False)

    promote_orga(brand, user)
    db.session.commit()

    click.secho('done.', fg='green')


if __name__ == '__main__':
    config_name = get_config_name_from_env()
    with app_context(config_name):
        execute()


import click

from byceps.services.orga import service as orga_service

from bootstrap.util import app_context, get_config_name_from_env
from bootstrap.validators import validate_brand, validate_user_screen_name


@click.command()
@click.argument('brand', callback=validate_brand)
@click.argument('user', callback=validate_user_screen_name)
def execute(brand, user):
    click.echo('Promoting user "{}" to orga for brand "{}" ... '
               .format(user.screen_name, brand.title), nl=False)

    orga_service.create_orga_flag(brand.id, user.id)

    click.secho('done.', fg='green')


if __name__ == '__main__':
    config_name = get_config_name_from_env()
    with app_context(config_name):
        execute()

Use service in script to promote a user to organizer
Use service in script to promote a user to organizer

  
  import click
  
- from byceps.database import db
+ from byceps.services.orga import service as orga_service
  
- from bootstrap.helpers import promote_orga
  from bootstrap.util import app_context, get_config_name_from_env
  from bootstrap.validators import validate_brand, validate_user_screen_name
  
  
  @click.command()
  @click.argument('brand', callback=validate_brand)
  @click.argument('user', callback=validate_user_screen_name)
  def execute(brand, user):
      click.echo('Promoting user "{}" to orga for brand "{}" ... '
                 .format(user.screen_name, brand.title), nl=False)
  
+     orga_service.create_orga_flag(brand.id, user.id)
-     promote_orga(brand, user)
-     db.session.commit()
  
      click.secho('done.', fg='green')
  
  
  if __name__ == '__main__':
      config_name = get_config_name_from_env()
      with app_context(config_name):
          execute()
  
Use service in script to promote a user to organizer
## Code Before:

import click

from byceps.database import db

from bootstrap.helpers import promote_orga
from bootstrap.util import app_context, get_config_name_from_env
from bootstrap.validators import validate_brand, validate_user_screen_name


@click.command()
@click.argument('brand', callback=validate_brand)
@click.argument('user', callback=validate_user_screen_name)
def execute(brand, user):
    click.echo('Promoting user "{}" to orga for brand "{}" ... '
               .format(user.screen_name, brand.title), nl=False)

    promote_orga(brand, user)
    db.session.commit()

    click.secho('done.', fg='green')


if __name__ == '__main__':
    config_name = get_config_name_from_env()
    with app_context(config_name):
        execute()

## Instruction:
Use service in script to promote a user to organizer
## Code After:

import click

from byceps.services.orga import service as orga_service

from bootstrap.util import app_context, get_config_name_from_env
from bootstrap.validators import validate_brand, validate_user_screen_name


@click.command()
@click.argument('brand', callback=validate_brand)
@click.argument('user', callback=validate_user_screen_name)
def execute(brand, user):
    click.echo('Promoting user "{}" to orga for brand "{}" ... '
               .format(user.screen_name, brand.title), nl=False)

    orga_service.create_orga_flag(brand.id, user.id)

    click.secho('done.', fg='green')


if __name__ == '__main__':
    config_name = get_config_name_from_env()
    with app_context(config_name):
        execute()
