Welcome    Usage    Browse    Find CID    Search     Log in

cM API Documentation

module.py

Go to the documentation of this file.
00001 #
00002 # Collective Mind
00003 #
00004 # See cM LICENSE.txt for licensing details.
00005 # See cM Copyright.txt for copyright details.
00006 #
00007 # Developer(s): (C) Grigori Fursin, started on 2011.09
00008 #
00009 
00010 # Should always be here
00011 ini={}
00012 cm_kernel=None
00013 
00014 # Local settings
00015 
00016 # ============================================================================
00017 def init(i):
00018     return {'cm_return':0}
00019 
00020 # ============================================================================
00021 def welcome(i):
00022 
00023     """
00024     Custom welcome page
00025 
00026     Input:  {
00027             }
00028 
00029     Output: {
00030               cm_return  - return code >0 if error
00031             }
00032     """
00033 
00034     # Check styles, etc
00035     if 'cfg' in cm_kernel.ini['web_style']: web=cm_kernel.ini['web_style']['cfg']
00036     else:
00037        return {'cm_return':1, 'cm_error':'web style is not defined'}
00038 
00039     # Check welcome page
00040     cm_kernel.print_for_con('<table border="0" cellpadding="20"><tr><td align="center" valign="middle">')
00041 
00042     cm_kernel.print_for_con('<center><small><b>Customized view</b></small></center>')
00043     cm_kernel.print_for_web(web['table_init']+'<tr><td>')
00044 
00045     cm_kernel.print_for_con('<img src="'+web['http_prefix']+'cm_web_action=show&cm_module_uoa=web&cm_data_uoa=default&cm_web_filename=cm-logo.png"><br><br>')
00046 
00047     cm_kernel.print_for_con('</td></tr></table>')
00048 
00049     cm_kernel.print_for_con('</td></tr></table>')
00050 
00051     return {'cm_return':0}
00052 
00053 # ============================================================================
00054 def scenarios(i):
00055 
00056     """
00057     Show cM web scenarios
00058 
00059     Input:  {
00060               cm_submenu - scenario sub menu
00061             }
00062 
00063     Output: {
00064               cm_return  - return code >0 if error
00065             }
00066     """
00067 
00068     rr={'cm_return':0}
00069 
00070     # Check styles, etc
00071     if 'cfg' in cm_kernel.ini['web_style']: web=cm_kernel.ini['web_style']['cfg']
00072     else:
00073        return {'cm_return':1, 'cm_error':'web style is not defined'}
00074 
00075     # Select scenario
00076     if 'cm_submenu' not in i or i['cm_submenu']=='':
00077        # Show all scenarios
00078 
00079        ht={};fht={}
00080        ht["0"]=web['table_init']+'<TR><TD><ul>'
00081        ht["1"]=web['table_init']+'<TR><TD><ul>'
00082        fht["0"]=True
00083        fht["1"]=True
00084 
00085        for x in web['cm_menu_scenarios']:
00086            text="Go"
00087            if 'menu_text' in x: text=x['menu_text']
00088 
00089            form="0"
00090            if 'menu_form' in x: form=x['menu_form']
00091 
00092            nw=''
00093            if x.get('open_in_new_window','')=='yes': nw=' target="_blank" '
00094 
00095            if 'menu_title_before' in x and x['menu_title_before']!='':
00096               if fht[form]: fht[form]=False
00097               else: ht[form]+='<BR><BR>'
00098               ht[form]+='<span class="cm-title">'+x['menu_title_before']+'</span><BR><BR>'
00099 #              ht[form]+='<HR class="cm-hr">'
00100 
00101            show=True
00102            if x.get('only_for_admin','')=='yes':
00103               show=False
00104               if cm_kernel.ini['web_auth'].get('cm_admin','')=='yes':
00105                  show=True
00106            elif x.get('only_for_registered','')=='yes':
00107               show=False
00108               if cm_kernel.ini['web_auth'].get('cm_user_status','')=='logged_in' or \
00109                  cm_kernel.ini['web_auth'].get('cm_admin','')=='yes':
00110                  show=True
00111 
00112            if show:
00113               if x.get('menu_space_before','')=='yes':
00114                  ht[form]+='<BR><BR>'
00115 
00116               dc=''
00117               if 'direct_call_params' in x and len(x['direct_call_params'])>0:
00118                 for y in x['direct_call_params']:
00119                     if dc!='': dc+='&'
00120                     dc+=y+'='+str(x['direct_call_params'][y])
00121 
00122               if 'submenu' in x and x['submenu']!='': 
00123                  if dc!='': dc='&'+dc
00124                  ht[form]+='<li><a href="'+web['http_prefix']+'cm_menu=scenarios&cm_submenu='+x['submenu']+dc+'"'+nw+'>'+text+'</a>'
00125               else:
00126                 ht[form]+='<li><a href="'+web['http_prefix']+dc+'"'+nw+'>'+text+'</a>'
00127            else:
00128               if x.get('only_for_admin','')=='yes':
00129                  ht[form]+='<li><i><s>Only for admins</s></i>'
00130               else:
00131                  ht[form]+='<li><i><s>Only for registered users</s></i>'
00132 
00133        ht["0"]+='</ul></TD></TR></table>'
00134        ht["1"]+='</ul></TD></TR></table>'
00135 
00136        cm_kernel.print_for_web('<table border="0"><TR><TD valign="top" align="left">')
00137        cm_kernel.print_for_web(ht["0"])
00138        cm_kernel.print_for_web('</TD><TD valign="top" align="left">')
00139        cm_kernel.print_for_web(ht["1"])
00140        cm_kernel.print_for_web('</table>')
00141 
00142     else:
00143        found=False
00144        for x in web['cm_menu_scenarios']:
00145            if 'submenu' in x and x['submenu']==i['cm_submenu']:
00146               found=True
00147 
00148               if 'menu_module' in x and 'menu_action' in x:
00149                  ii={}; 
00150 #                 if 'direct_call_params' in x and len(x['direct_call_params'])>0:
00151 #                    ii=x['direct_call_params']
00152 #                    ii.update(i)
00153 #                 else:
00154                  ii.update(i)
00155                  ii['cm_run_module_uoa']=x['menu_module']
00156                  ii['cm_action']=x['menu_action']
00157                  ii['cm_console']='web'
00158                  rr=cm_kernel.access(ii)
00159 #                 if rr['cm_return']>0: 
00160 #                    cm_kernel.print_for_web('<B>cM error:</B> '+rr['cm_error']+'<BR><BR>')
00161 
00162               else:
00163                  cm_kernel.print_for_con('<B>cM error:</B> wrong scenario description!<BR><BR>')
00164 
00165        if not found:
00166           cm_kernel.print_for_con('<B>cM error:</B> Submenu not found!<BR><BR>')
00167 
00168     if rr['cm_return']==0:
00169        cm_kernel.print_for_con('<FORM><INPUT TYPE="button" CLASS="cm-button" VALUE="Back" onClick="history.go(-1);return true;"></FORM>')
00170 
00171     return rr

Generated on Wed May 28 02:49:02 2014 for Collective Mind Framework by DoxyGen 1.6.1
Concept, design and coordination: Grigori Fursin (C) 1993-2013