By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,767 Members | 1,987 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,767 IT Pros & Developers. It's quick & easy.

how to access module level variable in class

P: 5
Expand|Select|Wrap|Line Numbers
  1. import smtplib
  2. import mimetypes;
  3. from optparse import OptionParser;
  4. from email import Encoders;
  5. from email.Message import Message;
  6. from email.MIMEBase import MIMEBase;
  7. from email.MIMEMultipart import MIMEMultipart;
  8. from email.MIMEText import MIMEText;
  9.  
  10. from StringIO  import StringIO
  11.  
  12. mail_server_not_specify_form='''<?xml version="1.0"?>
  13. <form string="SMTP Mail Server Error!">
  14.     <separator string="Required Mail-Server!!!" colspan="4"/>
  15.     <label string="Mail-Server Configuration Required" colspan="4"/>
  16. </form>''';
  17.  
  18. error_form = '''<?xml version="1.0"?>
  19. <form string="SMTP Mail Server Error!">
  20.     <separator string="Required Mail-Server!!!" colspan="4"/>
  21.     <label string="%s" colspan="4"/>
  22. </form>'''
  23.  
  24. class wiz_latepayment(wizard.interface):
  25.     def __init__(self,name):
  26.         self.error_message = '';
  27.         super(wiz_latepayment,self).__init__(name)
  28.  
  29.     def _send_reminder(self, cr, uid, data, context):
  30. #        print "In send reminder ::",
  31.         this_obj = pooler.get_pool(cr.dbname).get('position.reminder').read(cr,uid,data['ids'])[0];
  32.         send_currier_ids = pooler.get_pool(cr.dbname).get('position.reminder.line').search(cr,uid,[('reminder_id','=',this_obj['id']),('states','=','gen')])
  33.         reminder_lines = pooler.get_pool(cr.dbname).get('position.reminder.line').browse(cr,uid,send_currier_ids);
  34.  
  35.         canal = False
  36. #        print "Reminder Linses ::",reminder_lines
  37.         for reminder_line in reminder_lines:
  38.             try:
  39.                 if reminder_line.send_by_email == 'yes' and not this_obj['smtp_id']:
  40.                     return 'mailservernotgivan';
  41.                 #end if reminder_line.send_by_email == 'yes' and not this_obj['smtp_id']:
  42.  
  43.                 ret_create_report = self._create_report(cr, uid, reminder_line)
  44. #                print "After create report ::",ret_create_report
  45.                 if not ret_create_report[0]:
  46.                     raise ret_create_report[1]
  47.                 #end if not ret_create_report[0]:
  48.  
  49.                 if reminder_line.send_by_email == 'yes':
  50.                     ret_get_email = self._get_email(cr, uid, reminder_line)
  51. #                    print "After get email ::",ret_get_email
  52.                     if ret_get_email[0]:
  53.                         body_message = self._get_body_message(reminder_line)
  54.                         ret_send_mail = self._send_mail(cr, uid, this_obj['smtp_id'][0], ret_get_email[1], ret_create_report[1], body_message)
  55.                         if not ret_send_mail[0]:
  56.                             raise ret_send_mail[1]
  57.                         else:
  58.                             canal = 'E-mail'
  59.                         #end if not ret_send_mail[0]:
  60.                     #end if ret_get_email[0]:
  61.                 #end if reminder_line.send_by_email == 'yes':
  62.                 if reminder_line.send_by_currier == 'yes':
  63.                     if canal:
  64.                         canal = 'Currier&E-mail'
  65.                     else:
  66.                         canal = 'Currier'
  67.                 #end if reminder_line.send_by_currier == 'yes':
  68.  
  69.                 if canal:
  70.                     self._create_crm_case(cr, uid, canal, 'Normal Reminder', reminder_line,ret_create_report[1])
  71.                     reminder_line.write(cr,uid,[reminder_line.id],{'states':'sent'})
  72.                 #end if canal:
  73.                 #DELETE FILE AFTER USE
  74.                 if os.path.exists(ret_create_report[1]):
  75.                     os.remove(ret_create_report[1]);
  76.                 #End if os.path.exists(file_name):
  77.             except Exception,e:
  78.                 print "Exception e :",e
  79.                 if not self.error_message:
  80.                     self.error_message = e.__str__() + '\n'
  81.                 else:
  82.                     self.error_message = self.error_message + e.__str__() + '\n'
  83.                 pass
  84.         if self.error_message:
  85.             error_form = error_form % self.error_message
  86.             return 'errorform'
  87.  
  88.         return 'printflag';
  89.     #end def _send_reminder(self, cr, uid, data, context):
  90.  

and i want to set the value of the %s by value of error_message and show it in the last as
Expand|Select|Wrap|Line Numbers
  1.  states = {
  2.  
  3.             'init': {
  4.                          'actions': [],
  5.                         'result': {'type':'choice', 'next_state': _send_reminder},
  6.                      },
  7.              'printflag':{
  8.                            'actions': [],
  9.                         'result': {'type':'print', 'report':'position.reminder.report', 'state':'end'}
  10.                           },
  11.              'errorform':{
  12.                            'actions': [],
  13.                             'result': {'type':'form', 'arch': str(error_form.buf), 'fields':{},'state':[('printflag','OK')]}
  14.                           },
  15.               'mailservernotgivan': {
  16.                             'actions': [],
  17.                             'result': {'type':'form', 'arch':mail_server_not_specify_form, 'fields':{}, 'state':[('end','OK')]}
  18.                             },
  19.              }
  20.  
  21.  
and states is class level variable so how can i set the value
May 1 '07 #1
Share this Question
Share on Google+
1 Reply


bartonc
Expert 5K+
P: 6,596
I wish that I got credit for every time I add [code] tags.
May 2 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.