2016-06-02 23:01:28 +02:00
|
|
|
from django.http import HttpRequest, HttpResponse
|
2016-02-12 21:08:56 +01:00
|
|
|
from django.core.exceptions import ValidationError
|
|
|
|
|
2016-06-02 23:01:28 +02:00
|
|
|
from zerver.models import UserProfile
|
|
|
|
|
2016-02-12 21:08:56 +01:00
|
|
|
from zerver.lib.response import json_success, json_error
|
|
|
|
from zerver.lib.actions import check_add_realm_emoji, do_remove_realm_emoji
|
|
|
|
|
2016-06-02 23:01:28 +02:00
|
|
|
from six import text_type
|
2016-02-12 21:08:56 +01:00
|
|
|
|
|
|
|
def list_emoji(request, user_profile):
|
2016-06-02 23:01:28 +02:00
|
|
|
# type: (HttpRequest, UserProfile) -> HttpResponse
|
2016-02-12 21:08:56 +01:00
|
|
|
return json_success({'emoji': user_profile.realm.get_emoji()})
|
|
|
|
|
|
|
|
def upload_emoji(request, user_profile):
|
2016-06-02 23:01:28 +02:00
|
|
|
# type: (HttpRequest, UserProfile) -> HttpResponse
|
2016-02-12 21:08:56 +01:00
|
|
|
emoji_name = request.POST.get('name', None)
|
|
|
|
emoji_url = request.POST.get('url', None)
|
|
|
|
try:
|
|
|
|
check_add_realm_emoji(user_profile.realm, emoji_name, emoji_url)
|
|
|
|
except ValidationError as e:
|
2016-06-04 08:02:40 +02:00
|
|
|
return json_error(e.messages[0])
|
2016-02-12 21:08:56 +01:00
|
|
|
return json_success()
|
|
|
|
|
|
|
|
def delete_emoji(request, user_profile, emoji_name):
|
2016-06-02 23:01:28 +02:00
|
|
|
# type: (HttpRequest, UserProfile, text_type) -> HttpResponse
|
2016-02-12 21:08:56 +01:00
|
|
|
do_remove_realm_emoji(user_profile.realm, emoji_name)
|
2016-10-21 07:34:04 +02:00
|
|
|
return json_success()
|