pylint 1.4.3 version fixes
[cascardo/ipsilon.git] / ipsilon / admin / loginstack.py
1 # Copyright (C) 2014  Ipsilon Contributors see COPYING for license
2
3 from ipsilon.admin.common import AdminPlugins
4
5
6 FACILITY = 'login stack'
7
8
9 class LoginStackPlugins(AdminPlugins):
10
11     def __init__(self, name, site, parent, facility, **kwargs):
12         super(LoginStackPlugins, self).__init__(name, site, parent,
13                                                 facility,  **kwargs)
14         self.parent = parent
15
16     def root_with_msg(self, message=None, message_type=None, changed=None):
17         return self.parent.root_with_msg(message, message_type, changed)
18
19
20 class LoginStack(AdminPlugins):
21     def __init__(self, site, parent):
22         self.children = []
23         site[FACILITY] = None
24         super(LoginStack, self).__init__('loginstack', site, parent, FACILITY)
25         self.title = 'Login Stack'
26         self.template = 'admin/loginstack.html'
27
28     def add_subtree(self, name, page):
29         self.__dict__[name] = page
30         self.children.append(page)
31
32     def del_subtree(self, name):
33         self.children.remove(self.__dict__[name])
34         del self.__dict__[name]
35
36     def root_with_msg(self, message=None, message_type=None, changed=None):
37         # Force the url to be that of the Login Stack
38         kwargs = {'title': self.title,
39                   'menu': self._master.menu,
40                   'message': message,
41                   'message_type': message_type,
42                   'newurl': self.url,
43                   'sections': list()}
44         for child in self.children:
45             # pylint: disable=protected-access
46             plugins = child._site[child.facility]
47
48             if changed is None:
49                 changed = dict()
50
51             targs = {'title': child.title,
52                      'available': plugins.available,
53                      'enabled': plugins.enabled,
54                      'changed': changed,
55                      'baseurl': child.url}
56             if child.order:
57                 targs['order_name'] = '%s_order_form' % child.name
58                 targs['order_action'] = child.order.url
59
60             kwargs['sections'].append(targs)
61
62         return self._template(self.template, **kwargs)