]> git.ipfire.org Git - ipfire.org.git/commitdiff
people: Add page with recent calls
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 15 Oct 2018 12:12:14 +0000 (13:12 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 15 Oct 2018 12:12:14 +0000 (13:12 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/backend/accounts.py
src/backend/talk.py
src/templates/people/base.html
src/templates/people/calls.html [new file with mode: 0644]
src/web/__init__.py
src/web/people.py

index a0e3b52df64b516562c3d8e8b9e1d8c612ddb8d8..2937ac28e0b8ebb3ef63745321c7c21d2c0820b6 100644 (file)
@@ -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 \
index 228810860bcb37b148cf44799aafa624ab53f7a1..0872db953ff07d7acae4214a0df1f7a116a3d30d 100644 (file)
@@ -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):
index ed0b1210bd50e773a43d1cd1c8fdc9eb494495e6..30f112133523b3c99ea4c0a1a67c08858b4a9beb 100644 (file)
@@ -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)
index d92db680f915913da2b06efec0302b2c81596742..4628bc0d87e4b0c136008ff805d6673b36f322c5 100644 (file)
@@ -6,10 +6,16 @@
        {% if current_user %}
                <ul class="navbar-nav ml-auto mr-3">
                        <li class="nav-item">
-                               <a class="nav-link {% if request.path.startswith("/users") %}active{% end %}" href="/users">
+                               <a class="nav-link {% if request.path == "/users" %}active{% end %}" href="/users">
                                        {{ _("Users") }}
                                </a>
                        </li>
+
+                       <li class="nav-item">
+                               <a class="nav-link {% if request.path.startswith("/users/%s/calls" % current_user.uid) %}active{% end %}" href="/users/{{ current_user.uid }}/calls">
+                                       {{ _("Calls") }}
+                               </a>
+                       </li>
                </ul>
 
                <form class="form-inline my-2 my-lg-0" action="/search" method="GET">
diff --git a/src/templates/people/calls.html b/src/templates/people/calls.html
new file mode 100644 (file)
index 0000000..f95e15f
--- /dev/null
@@ -0,0 +1,13 @@
+{% extends "base.html" %}
+
+{% block title %}{{ _("Calls") }}{% end block %}
+
+{% block main %}
+       <div class="card">
+               <div class="card-body">
+                       <h4>{{ _("Calls on %s") % locale.format_day(date) }}</h4>
+
+                       {% module TalkCDR(account, date=date) %}
+               </div>
+       </div>
+{% end block %}
index 88fcd270b038920ff5b42172ed424a1767a5f191..90653f656f3930aa0eac75c451ea8bfbd76a8e05 100644 (file)
@@ -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)
 
index 23339daa4c480fb7a9a30b1476caff5b3db0da47..fb8b3659e7f0016dd12288f3ea43e5fbbba1dd24 100644 (file)
@@ -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)