From: Michael Tremer Date: Mon, 15 Oct 2018 12:12:14 +0000 (+0100) Subject: people: Add page with recent calls X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bdaf6b463ea9161b7ef77cbaaf059a714fb62555;p=ipfire.org.git people: Add page with recent calls Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index a0e3b52d..2937ac28 100644 --- a/Makefile.am +++ b/Makefile.am @@ -148,6 +148,7 @@ templates_modulesdir = $(templatesdir)/modules templates_people_DATA = \ src/templates/people/base.html \ + src/templates/people/calls.html \ src/templates/people/index.html \ src/templates/people/registrations.html \ src/templates/people/search.html \ diff --git a/src/backend/accounts.py b/src/backend/accounts.py index 22881086..0872db95 100644 --- a/src/backend/accounts.py +++ b/src/backend/accounts.py @@ -313,8 +313,8 @@ class Account(Object): return sip_registrations - def get_cdr(self, limit=None): - return self.backend.talk.freeswitch.get_cdr_by_account(self, limit=limit) + def get_cdr(self, date=None, limit=None): + return self.backend.talk.freeswitch.get_cdr_by_account(self, date=date, limit=limit) @property def telephone_numbers(self): diff --git a/src/backend/talk.py b/src/backend/talk.py index ed0b1210..30f11213 100644 --- a/src/backend/talk.py +++ b/src/backend/talk.py @@ -48,11 +48,13 @@ class Freeswitch(Object): return channels - def get_cdr_by_account(self, account, limit=None): + def get_cdr_by_account(self, account, date=None, limit=None): res = self.db.query("SELECT * FROM cdr \ - WHERE (caller_id_number = %s AND bleg_uuid IS NOT NULL) \ - OR (destination_number = %s AND bleg_uuid IS NULL) \ - ORDER BY end_stamp DESC LIMIT %s", account.sip_id, account.sip_id, limit) + WHERE ((caller_id_number = %s AND bleg_uuid IS NOT NULL) \ + OR (destination_number = %s AND bleg_uuid IS NULL)) \ + AND (%s IS NULL OR start_stamp::date = %s) \ + ORDER BY end_stamp DESC LIMIT %s", account.sip_id, + account.sip_id, date, date, limit) for row in res: yield CDR(self, data=row) diff --git a/src/templates/people/base.html b/src/templates/people/base.html index d92db680..4628bc0d 100644 --- a/src/templates/people/base.html +++ b/src/templates/people/base.html @@ -6,10 +6,16 @@ {% if current_user %}
diff --git a/src/templates/people/calls.html b/src/templates/people/calls.html new file mode 100644 index 00000000..f95e15f7 --- /dev/null +++ b/src/templates/people/calls.html @@ -0,0 +1,13 @@ +{% extends "base.html" %} + +{% block title %}{{ _("Calls") }}{% end block %} + +{% block main %} +
+
+

{{ _("Calls on %s") % locale.format_day(date) }}

+ + {% module TalkCDR(account, date=date) %} +
+
+{% end block %} diff --git a/src/web/__init__.py b/src/web/__init__.py index 88fcd270..90653f65 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -249,6 +249,7 @@ class Application(tornado.web.Application): (r"/users", people.UsersHandler), (r"/users/(\w+)", people.UserHandler), (r"/users/(\w+)\.jpg", people.AvatarHandler), + (r"/users/(\w+)/calls(?:/(\d{4}-\d{2}-\d{2}))?", people.CallsHandler), (r"/users/(\w+)/registrations", people.RegistrationsHandler), ] + authentication_handlers) diff --git a/src/web/people.py b/src/web/people.py index 23339daa..fb8b3659 100644 --- a/src/web/people.py +++ b/src/web/people.py @@ -1,5 +1,6 @@ #!/usr/bin/python +import datetime import logging import tornado.web @@ -49,6 +50,21 @@ class AvatarHandler(base.BaseHandler): self.finish(avatar) +class CallsHandler(base.BaseHandler): + @tornado.web.authenticated + def get(self, uid, date=None): + account = self.backend.accounts.get_by_uid(uid) + if not account: + raise tornado.web.HTTPError(404, "Could not find account %s" % uid) + + if date: + date = datetime.datetime.strptime(date, "%Y-%m-%d").date() + else: + date = datetime.date.today() + + self.render("people/calls.html", account=account, date=date) + + class RegistrationsHandler(base.BaseHandler): @tornado.web.authenticated def get(self, uid): @@ -110,8 +126,8 @@ class AccountsListModule(ui_modules.UIModule): class CDRModule(ui_modules.UIModule): - def render(self, account, limit=None): - cdr = account.get_cdr(limit=limit) + def render(self, account, date=None, limit=None): + cdr = account.get_cdr(date=date, limit=limit) return self.render_string("people/modules/cdr.html", account=account, cdr=cdr)