From 401827c281928c00c8305b45e088fde3a6e27746 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 10 Oct 2018 18:13:10 +0100 Subject: [PATCH] talk: Add users page Signed-off-by: Michael Tremer --- Makefile.am | 5 +- src/backend/talk.py | 8 ++ src/templates/talk/base.html | 30 +++---- src/templates/talk/modules/accounts-list.html | 17 ++++ src/templates/talk/user.html | 79 +++++++++++++++++++ src/templates/talk/users.html | 9 +++ src/web/__init__.py | 19 +++++ src/web/talk.py | 24 ++++++ 8 files changed, 176 insertions(+), 15 deletions(-) create mode 100644 src/templates/talk/modules/accounts-list.html create mode 100644 src/templates/talk/user.html create mode 100644 src/templates/talk/users.html diff --git a/Makefile.am b/Makefile.am index aafa6324..01383c9b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -163,11 +163,14 @@ templates_staticdir = $(templatesdir)/static templates_talk_DATA = \ src/templates/talk/base.html \ src/templates/talk/index.html \ - src/templates/talk/registrations.html + src/templates/talk/registrations.html \ + src/templates/talk/user.html \ + src/templates/talk/users.html templates_talkdir = $(templatesdir)/talk templates_talk_modules_DATA = \ + src/templates/talk/modules/accounts-list.html \ src/templates/talk/modules/channels.html \ src/templates/talk/modules/registrations.html diff --git a/src/backend/talk.py b/src/backend/talk.py index 5103ab38..7f078a01 100644 --- a/src/backend/talk.py +++ b/src/backend/talk.py @@ -163,6 +163,14 @@ class Talk(Object): # Connect to FreeSWITCH self.freeswitch = Freeswitch(self.backend) + @property + def accounts(self): + for account in self.backend.accounts: + if not account.is_talk_enabled(): + continue + + yield account + def get_lines(self, account=None): accounts_cache = {} diff --git a/src/templates/talk/base.html b/src/templates/talk/base.html index cc1c44b5..46eecb25 100644 --- a/src/templates/talk/base.html +++ b/src/templates/talk/base.html @@ -21,20 +21,22 @@ {% block main %}{% end block %} -
- {{ current_user }} - -

{{ current_user.name }}

+ {% block right %} +
+ {{ current_user }} -

- {% if current_user.sip_registrations %} - - {{ _("Online") }} ({{ len(current_user.sip_registrations) }}) - - {% else %} - {{ _("Offline") }} - {% end %} -

-
+

{{ current_user.name }}

+ +

+ {% if current_user.sip_registrations %} + + {{ _("Online") }} ({{ len(current_user.sip_registrations) }}) + + {% else %} + {{ _("Offline") }} + {% end %} +

+
+ {% end block %} {% end block %} diff --git a/src/templates/talk/modules/accounts-list.html b/src/templates/talk/modules/accounts-list.html new file mode 100644 index 00000000..84c34f12 --- /dev/null +++ b/src/templates/talk/modules/accounts-list.html @@ -0,0 +1,17 @@ +{% for group in grouper(accounts, 2) %} +
+ {% for account in group %} +
+
+
+
+ {{ account }} + + {{ account }} +
+
+
+
+ {% end %} +
+{% end %} diff --git a/src/templates/talk/user.html b/src/templates/talk/user.html new file mode 100644 index 00000000..a7f3df26 --- /dev/null +++ b/src/templates/talk/user.html @@ -0,0 +1,79 @@ +{% extends "base.html" %} + +{% block title %}{{ account }}{% end block %} + +{% block main %} +
+
+ {{ account }} + +

{{ account }}

+ + {% if account.sip_id %} +
{{ account.sip_id }}
+ {% end %} +
+
+ +
+
+
+
+ + +
+ {% if account.address %} +
+
{{ _("Postal Address") }}
+ +
+ {{ account.name }} +
+ {% for line in account.address.splitlines() %} + {{ line }}
+ {% end %} +
+
+ {% end %} + + {% if account.telephone_numbers %} +
+
{{ _("Telephone Numbers") }}
+ +
    + {% for number in account.telephone_numbers %} +
  • + {% if number in account.mobile_telephone_numbers %} + + {% elif number in account.home_telephone_numbers %} + + {% else %} + + {% end %} + {{ number }} +
  • + {% end %} +
+
+ {% end %} +
+ + {% if (current_user == account or current_user.is_admin()) and account.uses_sip_forwarding() %} +

+ {{ _("All calls are forwarded to") }} + {{ account.sip_routing_url }} +

+ {% end %} +
+
+
+
+{% end block %} + +{% block right %}{% end block %} diff --git a/src/templates/talk/users.html b/src/templates/talk/users.html new file mode 100644 index 00000000..f0a168e3 --- /dev/null +++ b/src/templates/talk/users.html @@ -0,0 +1,9 @@ +{% extends "base.html" %} + +{% block title %}{{ _("Users") }}{% end block %} + +{% block main %} +

{{ _("Users") }}

+ + {% module TalkAccountsList() %} +{% end block %} diff --git a/src/web/__init__.py b/src/web/__init__.py index 1688715a..133edefd 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -1,6 +1,7 @@ #/usr/bin/python import logging +import itertools import os.path import tornado.locale import tornado.options @@ -39,6 +40,7 @@ class Application(tornado.web.Application): # UI Modules "ui_methods" : { "format_month_name" : self.format_month_name, + "grouper" : grouper, }, "ui_modules" : { "Menu" : ui_modules.MenuModule, @@ -53,6 +55,7 @@ class Application(tornado.web.Application): "Map" : ui_modules.MapModule, # Talk + "TalkAccountsList" : talk.AccountsListModule, "TalkChannels" : talk.ChannelsModule, "TalkRegistrations" : talk.RegistrationsModule, @@ -236,6 +239,8 @@ class Application(tornado.web.Application): # talk.ipfire.org self.add_handlers(r"talk(\.dev)?\.ipfire\.org", [ (r"/", talk.IndexHandler), + (r"/users", talk.UsersHandler), + (r"/users/(\w+)", talk.UserHandler), (r"/users/(\w+)/registrations", talk.RegistrationsHandler), (r"/conferences", TalkConferencesHandler), (r"/diagnosis", TalkDiagnosisHandler), @@ -314,3 +319,17 @@ class Application(tornado.web.Application): return _("December") return month + + +def grouper(handler, iterator, n): + """ + Returns groups of n from the iterator + """ + i = iter(iterator) + + while True: + ret = list(itertools.islice(i, 0, n)) + if not ret: + break + + yield ret diff --git a/src/web/talk.py b/src/web/talk.py index f0f52c14..7ab6f946 100644 --- a/src/web/talk.py +++ b/src/web/talk.py @@ -31,6 +31,30 @@ class RegistrationsHandler(base.BaseHandler): self.render("talk/registrations.html", account=account) +class UsersHandler(base.BaseHandler): + @tornado.web.authenticated + def get(self): + self.render("talk/users.html") + + +class UserHandler(base.BaseHandler): + @tornado.web.authenticated + def get(self, uid): + account = self.backend.accounts.get_by_uid(uid) + if not account: + raise tornado.web.HTTPError(404, "Could not find account %s" % uid) + + self.render("talk/user.html", account=account) + + +class AccountsListModule(ui_modules.UIModule): + def render(self, accounts=None): + if accounts is None: + accounts = self.backend.talk.accounts + + return self.render_string("talk/modules/accounts-list.html", accounts=accounts) + + class ChannelsModule(ui_modules.UIModule): def render(self, account): channels = self.backend.talk.freeswitch.get_sip_channels(account) -- 2.39.2