2013-08-22 19:15:54 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
from django.core.management.base import BaseCommand
|
2013-11-04 17:22:58 +01:00
|
|
|
from zerver.models import Realm
|
2013-08-22 19:15:54 +02:00
|
|
|
from zerver.lib.actions import do_add_realm_emoji, do_remove_realm_emoji
|
|
|
|
import sys
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
help = """Manage emoji for the specified realm
|
|
|
|
|
|
|
|
Example: python manage.py realm_emoji --realm=zulip.com --op=add robotheart https://humbug-user-avatars.s3.amazonaws.com/95ffa70fe0e7aea3c052ba91b38a28d8779f5705
|
|
|
|
Example: python manage.py realm_emoji --realm=zulip.com --op=remove robotheart
|
|
|
|
Example: python manage.py realm_emoji --realm=zulip.com --op=show
|
|
|
|
"""
|
|
|
|
|
2015-08-21 02:10:41 +02:00
|
|
|
def add_arguments(self, parser):
|
|
|
|
parser.add_argument('-r', '--realm',
|
|
|
|
dest='domain',
|
|
|
|
type=str,
|
|
|
|
required=True,
|
|
|
|
help='The name of the realm.')
|
|
|
|
parser.add_argument('--op',
|
|
|
|
dest='op',
|
|
|
|
type=str,
|
|
|
|
default="show",
|
|
|
|
help='What operation to do (add, show, remove).')
|
|
|
|
parser.add_argument('name', metavar='<name>', type=str, nargs='?', default=None,
|
|
|
|
help="name of the emoji")
|
|
|
|
parser.add_argument('img_url', metavar='<image url>', type=str, nargs='?',
|
|
|
|
help="URL of image to display for the emoji")
|
2013-08-22 19:15:54 +02:00
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
realm = Realm.objects.get(domain=options["domain"])
|
|
|
|
if options["op"] == "show":
|
|
|
|
for name, url in realm.get_emoji().iteritems():
|
|
|
|
print name, url
|
|
|
|
sys.exit(0)
|
|
|
|
|
2015-08-21 02:10:41 +02:00
|
|
|
name = options['name']
|
|
|
|
if name is None:
|
2013-08-22 19:15:54 +02:00
|
|
|
self.print_help("python manage.py", "realm_emoji")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if options["op"] == "add":
|
2015-08-21 02:10:41 +02:00
|
|
|
img_url = options['img_url']
|
|
|
|
if img_url is None:
|
|
|
|
self.print_help("python manage.py", "realm_emoji")
|
|
|
|
sys.exit(1)
|
2013-08-22 19:15:54 +02:00
|
|
|
do_add_realm_emoji(realm, name, img_url)
|
|
|
|
sys.exit(0)
|
|
|
|
elif options["op"] == "remove":
|
|
|
|
do_remove_realm_emoji(realm, name)
|
|
|
|
sys.exit(0)
|
|
|
|
else:
|
|
|
|
self.print_help("python manage.py", "realm_emoji")
|
|
|
|
sys.exit(1)
|