summaryrefslogtreecommitdiffstats
path: root/idp/extra/modules/identities_ui.ptl
diff options
context:
space:
mode:
authorFrederic Peters <fpeters@0d.be>2008-08-21 08:16:23 (GMT)
committerFrederic Peters <fpeters@0d.be>2008-08-21 08:16:23 (GMT)
commit82fe03b8dbc7de2c952f2f25e4d084371985f709 (patch)
tree01383cb5d28100e5fcb8839e175dbe40f4a942b8 /idp/extra/modules/identities_ui.ptl
parentdf998a0f1a8c547f42ffaeaa10dec1dcbad7b518 (diff)
downloadpratic-82fe03b8dbc7de2c952f2f25e4d084371985f709.zip
pratic-82fe03b8dbc7de2c952f2f25e4d084371985f709.tar.gz
pratic-82fe03b8dbc7de2c952f2f25e4d084371985f709.tar.bz2
import of csv files
Diffstat (limited to 'idp/extra/modules/identities_ui.ptl')
-rw-r--r--idp/extra/modules/identities_ui.ptl90
1 files changed, 71 insertions, 19 deletions
diff --git a/idp/extra/modules/identities_ui.ptl b/idp/extra/modules/identities_ui.ptl
index c21b06e..5cc00e7 100644
--- a/idp/extra/modules/identities_ui.ptl
+++ b/idp/extra/modules/identities_ui.ptl
@@ -12,11 +12,26 @@ from qommon.form import *
import string
import directory
+def generate_password():
+ passwords_cfg = get_cfg('passwords', {})
+ min_len = passwords_cfg.get('min_length', 0)
+ max_len = passwords_cfg.get('max_length', 0)
+ if min_len == 0 and max_len == 0:
+ password_len = 6
+ elif min_len == 0:
+ password_len = min(6, max_len)
+ elif max_len == 0:
+ password_len = max(6, min_len)
+ else:
+ password_len = (max_len + min_len) / 2
+ return ''.join([random.choice(string.letters) for x in range(password_len)])
+
+
class AgentDirectory(Directory):
_q_exports = ['', 'edit', 'delete', 'disable', 'enable', 'password']
attrs = [
- ('cdg59agentSirhCode', _('SIRH Code'), {'required': True, 'size': 30}),
+ ('cdg59agentSirhCode', N_('SIRH Code'), {'required': True, 'size': 30}),
('sn', N_('Last Name'), {'required': True, 'size': 30}),
('givenName', N_('First Name'), {'required': True, 'size': 30}),
('cdg59direction', N_('Direction'), {'size': 30}),
@@ -27,7 +42,7 @@ class AgentDirectory(Directory):
('telephoneNumber', N_('Telephone Number'), {'size': 30}),
('facsimileTelephoneNumber', N_('Fax Number'), {'size': 30}),
('mobile', N_('Professional Mobile Number'), {'size': 30}),
- ('cdg59isAdmin', _('Collectivity Admin'), {'widget_class': CheckboxWidget}),
+ ('cdg59isAdmin', N_('Collectivity Admin'), {'widget_class': CheckboxWidget}),
]
def __init__(self, agent):
@@ -164,7 +179,7 @@ class AgentDirectory(Directory):
class IdentitiesDirectory(Directory):
- _q_exports = ['', 'new', 'lookup_sirh', 'authorizations']
+ _q_exports = ['', 'new', 'lookup_sirh', 'authorizations', 'csv']
collectivity = None
@@ -216,9 +231,11 @@ class IdentitiesDirectory(Directory):
self.collectivity.ou, _('Services Management'))
else:
'<a href="../services/">%s</a> - ' % _('Services Management')
- '<a href="new">%s</a>' % _('Add a new Agent')
+ if user.is_admin() or user.is_local_admin():
+ '<a href="new">%s</a> - ' % _('Add a new Agent')
+ '<a href="csv">%s</a> - ' % _('Import CSV File')
if (user.is_admin() or user.is_local_admin()) and (self.collectivity.ou != 'admin'):
- '- <a href="authorizations">%s</a>' % _('Manage Authorizations')
+ '<a href="authorizations">%s</a>' % _('Manage Authorizations')
'</p>'
@@ -444,21 +461,9 @@ class IdentitiesDirectory(Directory):
form.add(StringWidget, 'sn', title = _('Last Name'), required = True, size = 30)
form.add(StringWidget, 'givenName', title = _('First Name'), required = True, size = 30)
form.add(StringWidget, 'mail', title = _('Mail'), size = 30, required = True)
-
- passwords_cfg = get_cfg('passwords', {})
- min_len = passwords_cfg.get('min_length', 0)
- max_len = passwords_cfg.get('max_length', 0)
- if min_len == 0 and max_len == 0:
- password_len = 6
- elif min_len == 0:
- password_len = min(6, max_len)
- elif max_len == 0:
- password_len = max(6, min_len)
- else:
- password_len = (max_len + min_len) / 2
-
+
form.add(StringWidget, 'password', title = _('Password'), size = 30, required = True,
- value = ''.join([random.choice(string.letters) for x in range(password_len)]))
+ value = generate_password())
form.add_submit('submit', _('Submit'))
form.add_submit('cancel', _('Cancel'))
@@ -518,6 +523,53 @@ class IdentitiesDirectory(Directory):
return directory.get_agent(self.collectivity, form.get_widget('uid').parse())
+ def csv [html] (self):
+ form = Form(enctype='multipart/form-data')
+ form.add(FileWidget, 'csv', title = _('CSV File'), required = True)
+ form.add_submit('submit', _('Submit'))
+ form.add_submit('cancel', _('Cancel'))
+
+ if form.get_submit() == 'cancel':
+ return redirect('.')
+
+ if not form.is_submitted() or form.has_errors():
+ get_response().breadcrumb.append(('csv', _('CSV Import')))
+ html_top('identities', title = _('CSV Import'))
+ '<h2>%s</h2>' % _('CSV Import')
+ '<p>'
+ _('Fields must be separated by ; and in the following order.')
+ '</p>'
+ '<p>'
+ _('You will get a CSV file with generated identifies and passwords appended.')
+ '</p>'
+ '<ul>'
+ for i, attr in enumerate(AgentDirectory.attrs):
+ '<li>%s</li>' % _(attr[1])
+ '</ul>'
+ form.render()
+ else:
+ return self.csv_submit(form)
+
+ def csv_submit(self, form):
+ output = []
+ for line in form.get_widget('csv').parse().fp.readlines():
+ fields = line.strip().split(';')
+ data = {}
+ for i, attr in enumerate(AgentDirectory.attrs):
+ if fields[i]:
+ data[attr[0]] = fields[i]
+ data['uid'] = ('%s.%s' % (data['givenName'], data['sn'])).lower()
+ data['password'] = generate_password()
+ output.append(line.strip() + ';%s;%s' % (data['uid'], data['password']))
+ try:
+ directory.add_agent(self.collectivity, data)
+ except:
+ output[-1] = output[-1] + ';ERROR'
+
+ response = get_response()
+ response.set_content_type('text/csv')
+ response.set_header('content-disposition', 'attachment; filename=result.csv')
+ return '\n'.join(output)
def _q_lookup(self, component):
if not self.collectivity: