Changeset 1599 for WAeUP_SRP/trunk
- Timestamp:
- 19 Mar 2007, 22:03:20 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/trunk/Students.py
r1594 r1599 22 22 i_home = Globals.INSTANCE_HOME 23 23 MAX_TRANS = 1000 24 from urllib import urlencode 25 24 26 import DateTime 25 27 # import PIL.Image … … 36 38 37 39 ###) 40 41 def response_write(response,s): 42 response.setHeader('Content-type','text/html; charset=ISO-8859-15') 43 while s.find('<') > -1: 44 s = s.replace('<','<') 45 while s.find('>') > -1: 46 #from pdb import set_trace;set_trace() 47 s = s.replace('>','>') 48 response.write("%s<br>\n" % s) 38 49 39 50 def getInt(s): ###( … … 534 545 wftool = self.portal_workflow 535 546 current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") 536 students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() 547 #students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() 548 students_folder = self.portal_url().getPortalObject().campus.students 537 549 tr_count = 1 538 550 total = 0 … … 699 711 logger.info(em) 700 712 return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) 713 ###) 714 715 security.declareProtected(ModifyPortalContent,"fixAllNames")###( 716 def fixAllNames(self): 717 "fix all students names" 718 import transaction 719 response = self.REQUEST.RESPONSE 720 logger = logging.getLogger('fixAllNames') 721 logger.info('Start') 722 students = self.portal_catalog(portal_type='Student') 723 count = 0 724 total = 0 725 for student in students: 726 scat_res = self.students_catalog(id = student.getId) 727 if not scat_res: 728 self.students_catalog.addRecord(id = student.getId) 729 scat_res = self.students_catalog(id = student.getId) 730 student_entry = scat_res[0] 731 old_new = self.fixName(student,student_entry) 732 count += 1 733 response_write(response,"%d) %s: %s" % (count + total,student_entry.id,old_new)) 734 if count > 2000: 735 transaction.commit() 736 logger.info("%d transactions commited" % count) 737 total += count 738 count = 0 739 ###) 740 741 security.declareProtected(ModifyPortalContent,"fixName")###( 742 def fixName(self,student_brain, student_entry): 743 "fix the name of a student" 744 fix = "first" 745 if student_entry.get('name_fixed',None) == fix: 746 return "Name already fixed" 747 student_id = student_entry.id 748 new_student = student_entry.jamb_reg_no.startswith('6') 749 student_obj = student_brain.getObject() 750 personal = getattr(student_obj,'personal',None) 751 invalid = '' 752 if personal is None: 753 return '"%s", "Returning: %s","%s"' % (invalid,student_entry.name,"not logged in") 754 per_doc = personal.getContent() 755 old_first = per_doc.firstname 756 old_middle = per_doc.middlename 757 old_last = per_doc.lastname 758 new_first = '' 759 new_middle = '' 760 new_last = '' 761 if new_student: 762 if not old_first and not old_middle and old_last: 763 new_names = [n.capitalize() for n in old_last.split()] 764 if len(new_names) > 3: 765 old_first = new_names[0] 766 old_last = new_names[1] 767 old_middle = ' '.join(new_names[2:]) 768 elif len(new_names) == 3: 769 old_first = new_names[0] 770 old_last = new_names[1] 771 old_middle = new_names[2] 772 elif len(new_names) == 2: 773 old_first = new_names[0] 774 old_last = new_names[1] 775 old_middle = '' 776 elif len(new_names) == 1: 777 old_last = new_names[0] 778 old_first = '' 779 old_middle = '' 780 if old_last: 781 new_first = old_last 782 if old_middle: 783 new_middle = old_middle 784 if old_first: 785 new_last = old_first 786 787 if old_first.find('<') != -1 or\ 788 old_first.find('>') != -1 or\ 789 old_middle.find('<') != -1 or\ 790 old_middle.find('>') != -1 or\ 791 old_last.find('<') != -1 or\ 792 old_last.find('>') != -1: 793 invalid = "invalid characters" 794 else: 795 if old_first and old_middle and old_last: 796 new_first = old_first.capitalize() 797 new_middle = old_middle.capitalize() 798 new_last = old_last.capitalize() 799 elif old_first and not old_middle and old_last: 800 new_names = [n.capitalize() for n in old_first.split()] 801 if len(new_names) > 1: 802 new_first = new_names[0] 803 new_middle = ' '.join(new_names[1:]) 804 else: 805 new_first = old_first.capitalize() 806 new_middle = '' 807 new_last = old_last.capitalize() 808 elif not old_first and not old_middle and old_last: 809 new_first = '' 810 new_middle = '' 811 new_last = old_last.capitalize() 812 else: 813 new_first = '' 814 new_middle = '' 815 new_last = '' 816 name = "%(new_last)s %(new_first)s %(new_middle)s" % vars() 817 if new_student: 818 text = "New" 819 else: 820 text = "Returning" 821 old_new = '"%s", "%s: %s","%s"' % (invalid,text, 822 student_entry.name, 823 name) 824 if not invalid: 825 self.students_catalog.modifyRecord(id = student_id, 826 name_fixed = fix, 827 name = name) 828 per_doc.edit(mapping = {'firstname' : new_first, 829 'middlename' : new_middle, 830 'lastname' : new_last, 831 }) 832 return old_new 701 833 ###) 702 834
Note: See TracChangeset for help on using the changeset viewer.