comparison roundup/cgi/actions.py @ 2531:f8c6a09ef485

translate web ui messages in _EditAction, PassResetAction
author Alexander Smishlajev <a1s@users.sourceforge.net>
date Sat, 03 Jul 2004 17:17:47 +0000
parents 3a0a248289dd
children 82f53c270e7c
comparison
equal deleted inserted replaced
2530:a182c536b72d 2531:f8c6a09ef485
1 #$Id: actions.py,v 1.31 2004-06-06 12:40:30 a1s Exp $ 1 #$Id: actions.py,v 1.32 2004-07-03 17:17:47 a1s Exp $
2 2
3 import re, cgi, StringIO, urllib, Cookie, time, random 3 import re, cgi, StringIO, urllib, Cookie, time, random
4 4
5 from roundup import hyperdb, token, date, password, rcsv, exceptions 5 from roundup import hyperdb, token, date, password, rcsv, exceptions
6 from roundup.i18n import _ 6 from roundup.i18n import _
407 props = self._changenode(cn, nodeid, props) 407 props = self._changenode(cn, nodeid, props)
408 408
409 # and some nice feedback for the user 409 # and some nice feedback for the user
410 if props: 410 if props:
411 info = ', '.join(props.keys()) 411 info = ', '.join(props.keys())
412 m.append('%s %s %s edited ok'%(cn, nodeid, info)) 412 m.append(
413 self._('%(class)s %(id)s %(properties)s edited ok')
414 % {'class':cn, 'id':nodeid, 'properties':info})
413 else: 415 else:
414 m.append('%s %s - nothing changed'%(cn, nodeid)) 416 m.append(self._('%(class)s %(id)s - nothing changed')
417 % {'class':cn, 'id':nodeid})
415 else: 418 else:
416 assert props 419 assert props
417 420
418 # make a new node 421 # make a new node
419 newid = self._createnode(cn, props) 422 newid = self._createnode(cn, props)
420 if nodeid is None: 423 if nodeid is None:
421 self.nodeid = newid 424 self.nodeid = newid
422 nodeid = newid 425 nodeid = newid
423 426
424 # and some nice feedback for the user 427 # and some nice feedback for the user
425 m.append('%s %s created'%(cn, newid)) 428 m.append(self._('%(class)s %(id)s created')
429 % {'class':cn, 'id':newid})
426 430
427 # fill in new ids in links 431 # fill in new ids in links
428 if links.has_key(needed): 432 if links.has_key(needed):
429 for linkcn, linkid, linkprop in links[needed]: 433 for linkcn, linkid, linkprop in links[needed]:
430 props = all_props[(linkcn, linkid)] 434 props = all_props[(linkcn, linkid)]
450 454
451 def _changenode(self, cn, nodeid, props): 455 def _changenode(self, cn, nodeid, props):
452 """Change the node based on the contents of the form.""" 456 """Change the node based on the contents of the form."""
453 # check for permission 457 # check for permission
454 if not self.editItemPermission(props): 458 if not self.editItemPermission(props):
455 raise Unauthorised, 'You do not have permission to edit %s'%cn 459 raise Unauthorised, self._(
460 'You do not have permission to edit %(class)s'
461 ) % {'class': cn}
456 462
457 # make the changes 463 # make the changes
458 cl = self.db.classes[cn] 464 cl = self.db.classes[cn]
459 return cl.set(nodeid, **props) 465 return cl.set(nodeid, **props)
460 466
461 def _createnode(self, cn, props): 467 def _createnode(self, cn, props):
462 """Create a node based on the contents of the form.""" 468 """Create a node based on the contents of the form."""
463 # check for permission 469 # check for permission
464 if not self.newItemPermission(props): 470 if not self.newItemPermission(props):
465 raise Unauthorised, 'You do not have permission to create %s'%cn 471 raise Unauthorised, self._(
472 'You do not have permission to create %(class)s'
473 ) % {'class': cn}
466 474
467 # create the node and return its id 475 # create the node and return its id
468 cl = self.db.classes[cn] 476 cl = self.db.classes[cn]
469 return cl.create(**props) 477 return cl.create(**props)
470 478
576 if self.form.has_key('otk'): 584 if self.form.has_key('otk'):
577 # pull the rego information out of the otk database 585 # pull the rego information out of the otk database
578 otk = self.form['otk'].value 586 otk = self.form['otk'].value
579 uid = otks.get(otk, 'uid') 587 uid = otks.get(otk, 'uid')
580 if uid is None: 588 if uid is None:
581 self.client.error_message.append("""Invalid One Time Key! 589 self.client.error_message.append(
582 (a Mozilla bug may cause this message to show up erroneously, 590 self._("Invalid One Time Key!\n"
583 please check your email)""") 591 "(a Mozilla bug may cause this message "
592 "to show up erroneously, please check your email)"))
584 return 593 return
585 594
586 # re-open the database as "admin" 595 # re-open the database as "admin"
587 if self.user != 'admin': 596 if self.user != 'admin':
588 self.client.opendb('admin') 597 self.client.opendb('admin')
618 '''%{'name': name, 'password': newpw} 627 '''%{'name': name, 'password': newpw}
619 if not self.client.standard_message([address], subject, body): 628 if not self.client.standard_message([address], subject, body):
620 return 629 return
621 630
622 self.client.ok_message.append( 631 self.client.ok_message.append(
623 'Password reset and email sent to %s'%address) 632 self._('Password reset and email sent to %s') % address)
624 return 633 return
625 634
626 # no OTK, so now figure the user 635 # no OTK, so now figure the user
627 if self.form.has_key('username'): 636 if self.form.has_key('username'):
628 name = self.form['username'].value 637 name = self.form['username'].value
629 try: 638 try:
630 uid = self.db.user.lookup(name) 639 uid = self.db.user.lookup(name)
631 except KeyError: 640 except KeyError:
632 self.client.error_message.append('Unknown username') 641 self.client.error_message.append(self._('Unknown username'))
633 return 642 return
634 address = self.db.user.get(uid, 'address') 643 address = self.db.user.get(uid, 'address')
635 elif self.form.has_key('address'): 644 elif self.form.has_key('address'):
636 address = self.form['address'].value 645 address = self.form['address'].value
637 uid = uidFromAddress(self.db, ('', address), create=0) 646 uid = uidFromAddress(self.db, ('', address), create=0)
638 if not uid: 647 if not uid:
639 self.client.error_message.append('Unknown email address') 648 self.client.error_message.append(
649 self._('Unknown email address'))
640 return 650 return
641 name = self.db.user.get(uid, 'username') 651 name = self.db.user.get(uid, 'username')
642 else: 652 else:
643 self.client.error_message.append('You need to specify a username ' 653 self.client.error_message.append(
644 'or address') 654 self._('You need to specify a username or address'))
645 return 655 return
646 656
647 # generate the one-time-key and store the props for later 657 # generate the one-time-key and store the props for later
648 otk = ''.join([random.choice(chars) for x in range(32)]) 658 otk = ''.join([random.choice(chars) for x in range(32)])
649 while otks.exists(otk): 659 while otks.exists(otk):
664 You should then receive another email with the new password. 674 You should then receive another email with the new password.
665 '''%{'name': name, 'tracker': tracker_name, 'url': self.base, 'otk': otk} 675 '''%{'name': name, 'tracker': tracker_name, 'url': self.base, 'otk': otk}
666 if not self.client.standard_message([address], subject, body): 676 if not self.client.standard_message([address], subject, body):
667 return 677 return
668 678
669 self.client.ok_message.append('Email sent to %s'%address) 679 self.client.ok_message.append(self._('Email sent to %s') % address)
670 680
671 class ConfRegoAction(Action): 681 class ConfRegoAction(Action):
672 def handle(self): 682 def handle(self):
673 """Grab the OTK, use it to load up the new user details.""" 683 """Grab the OTK, use it to load up the new user details."""
674 try: 684 try:

Roundup Issue Tracker: http://roundup-tracker.org/