]>
git.ipfire.org Git - ipfire.org.git/blob - src/web/people.py
7 from . import handlers_base
as base
8 from . import ui_modules
10 class IndexHandler(base
.BaseHandler
):
11 @tornado.web
.authenticated
13 self
.render("people/index.html")
16 class AvatarHandler(base
.BaseHandler
):
18 # Get the desired size of the avatar file
19 size
= self
.get_argument("size", 0)
23 except (TypeError, ValueError):
26 logging
.debug("Querying for avatar of %s" % uid
)
29 account
= self
.backend
.accounts
.get_by_uid(uid
)
31 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
33 # Allow downstream to cache this for 60 minutes
34 self
.set_expires(3600)
37 avatar
= account
.get_avatar(size
)
39 # If there is no avatar, we serve a default image
41 logging
.debug("No avatar uploaded for %s" % account
)
43 return self
.redirect("https://static.ipfire.org%s" % self
.static_url("img/default-avatar.jpg"))
45 # Set headers about content
46 self
.set_header("Content-Disposition", "inline; filename=\"%s.jpg\"" % account
.uid
)
47 self
.set_header("Content-Type", "image/jpeg")
53 class CallsHandler(base
.BaseHandler
):
54 @tornado.web
.authenticated
55 def get(self
, uid
, date
=None):
56 account
= self
.backend
.accounts
.get_by_uid(uid
)
58 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
62 date
= datetime
.datetime
.strptime(date
, "%Y-%m-%d").date()
64 raise tornado
.web
.HTTPError(400, "Invalid date: %s" % date
)
66 date
= datetime
.date
.today()
68 self
.render("people/calls.html", account
=account
, date
=date
)
71 class RegistrationsHandler(base
.BaseHandler
):
72 @tornado.web
.authenticated
75 if self
.current_user
.uid
== uid
:
76 account
= self
.current_user
78 # Admins can access all other users, too
79 elif self
.current_user
.is_admin():
80 account
= self
.backend
.accounts
.get_by_uid(uid
)
82 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
84 # Otherwise, no access is permitted
86 raise tornado
.web
.HTTPError(403)
88 self
.render("people/registrations.html", account
=account
)
91 class SearchHandler(base
.BaseHandler
):
92 @tornado.web
.authenticated
94 q
= self
.get_argument("q")
97 accounts
= self
.backend
.accounts
.search(q
)
99 # Redirect when only one result was found
100 if len(accounts
) == 1:
101 self
.redirect("/users/%s" % accounts
[0].uid
)
104 self
.render("people/search.html", q
=q
, accounts
=accounts
)
107 class UsersHandler(base
.BaseHandler
):
108 @tornado.web
.authenticated
110 self
.render("people/users.html")
113 class UserHandler(base
.BaseHandler
):
114 @tornado.web
.authenticated
116 account
= self
.backend
.accounts
.get_by_uid(uid
)
118 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
120 self
.render("people/user.html", account
=account
)
123 class AccountsListModule(ui_modules
.UIModule
):
124 def render(self
, accounts
=None):
126 accounts
= self
.backend
.accounts
128 return self
.render_string("people/modules/accounts-list.html", accounts
=accounts
)
131 class CDRModule(ui_modules
.UIModule
):
132 def render(self
, account
, date
=None, limit
=None):
133 cdr
= account
.get_cdr(date
=date
, limit
=limit
)
135 return self
.render_string("people/modules/cdr.html", account
=account
, cdr
=cdr
)
138 class ChannelsModule(ui_modules
.UIModule
):
139 def render(self
, account
):
140 channels
= self
.backend
.talk
.freeswitch
.get_sip_channels(account
)
142 return self
.render_string("people/modules/channels.html", account
=account
, channels
=channels
)
145 class RegistrationsModule(ui_modules
.UIModule
):
146 def render(self
, account
):
147 return self
.render_string("people/modules/registrations.html", account
=account
)