res = self.attributes.get(attr, [])
if res:
- return res[0].decode()
+ return res[0]
def get(self, key):
try:
@property
def uid(self):
- return self._get_first_attribute("uid")
+ return self._get_first_attribute("uid").decode()
@property
def name(self):
- return self._get_first_attribute("cn")
+ return self._get_first_attribute("cn").decode()
@property
def first_name(self):
- return self._get_first_attribute("givenName")
+ return self._get_first_attribute("givenName").decode(9)
@lazy_property
def groups(self):
@property
def address(self):
- address = self._get_first_attribute("homePostalAddress", "")
+ address = self._get_first_attribute("homePostalAddress", "").decode()
address = address.replace(", ", "\n")
return address
@property
def sip_id(self):
if "sipUser" in self.classes:
- return self._get_first_attribute("sipAuthenticationUser")
+ return self._get_first_attribute("sipAuthenticationUser").decode()
if "sipRoutingObject" in self.classes:
- return self._get_first_attribute("sipLocalAddress")
+ return self._get_first_attribute("sipLocalAddress").decode()
@property
def sip_password(self):
- return self._get_first_attribute("sipPassword")
+ return self._get_first_attribute("sipPassword").decode()
@property
def sip_url(self):
@property
def sip_routing_url(self):
if "sipRoutingObject" in self.classes:
- return self._get_first_attribute("sipRoutingAddress")
+ return self._get_first_attribute("sipRoutingAddress").decode()
@lazy_property
def sip_registrations(self):
return self._resize_avatar(avatar, size)
def _resize_avatar(self, image, size):
- image = io.StringIO(image)
+ image = io.BytesIO(image)
image = PIL.Image.open(image)
# Resize the image to the desired resolution
image.thumbnail((size, size), PIL.Image.ANTIALIAS)
- f = io.StringIO()
+ f = io.BytesIO()
# If writing out the image does not work with optimization,
# we try to write it out without any optimization.
{% elif chan.application == "voicemail" %}
{{ _("Voicemail") }}
- {% else %}
+ {% elif chan.callee %}
{% if chan.callee %}
<a href="/users/{{ chan.callee.uid }}">{{ chan.callee }}</a>
{% else %}
{% end %}
<span class="text-muted">({{ chan.callee_number }})</span>
+
+ {% else %}
+ {{ chan.called_number }}
{% end %}
{% elif chan.direction == "outbound" %}
{% if chan.caller %}
import logging
import tornado.web
-from .handlers_base import *
+from . import handlers_base as base
-class AccountsAvatarHandler(BaseHandler):
+class AccountsAvatarHandler(base.BaseHandler):
def get(self, who):
# Get the desired size of the avatar file
size = self.get_argument("size", 0)
except (TypeError, ValueError):
size = None
- # Cache handle
- cache_handle = "accounts-avatar-%s-%s" % (who, size or 0)
- avatar = self.memcached.get(cache_handle)
+ logging.debug("Querying for avatar of %s" % who)
- if not avatar:
- logging.debug("Querying for avatar of %s" % who)
-
- account = self.backend.accounts.get_by_uid(who)
- if not account:
- raise tornado.web.HTTPError(404)
+ # Fetch user account
+ account = self.backend.accounts.get_by_uid(who)
+ if not account:
+ raise tornado.web.HTTPError(404)
- avatar = account.get_avatar(size)
+ # Allow downstream to cache this for 60 minutes
+ self.set_expires(3600)
- # Save the avatar to cache for 6 hours
- if avatar:
- self.memcached.set(cache_handle, avatar, 6 * 3600)
+ # Resize avatar
+ avatar = account.get_avatar(size)
- # Otherwise raise 404 (XXX should send a default image)
- else:
- raise tornado.web.HTTPError(404, "No avatar set for %s" % account)
+ # If there is no avatar, we serve a default image
+ if not avatar:
+ raise tornado.web.HTTPError(404, "No avatar set for %s" % account)
- self.set_header("Cache-Control", "public,max-age=300")
+ # Set headers about content
self.set_header("Content-Disposition", "inline; filename=\"%s.jpg\"" % who)
self.set_header("Content-Type", "image/jpeg")
+ # Deliver payload
self.finish(avatar)
from .. import util
class BaseHandler(tornado.web.RequestHandler):
+ def set_expires(self, seconds):
+ # For HTTP/1.1
+ self.set_header("Cache-Control", "max-age=%s, must-revalidate" % seconds)
+
+ # For HTTP/1.0
+ expires = datetime.datetime.utcnow() + datetime.timedelta(seconds=seconds)
+ self.set_header("Expires", expires)
+
def write_error(self, status_code, **kwargs):
# Translate code into message
try: