# # Collective Knowledge (CK web front-end) # # See CK LICENSE.txt for licensing details # See CK COPYRIGHT.txt for copyright details # # Developer: cTuning foundation # cfg={} # Will be updated by CK (meta description of this module) work={} # Will be updated by CK (temporal data) ck=None # Will be updated by CK (initialized CK kernel) # Local settings import os fdata_name='ck_top_data' fmodule_name='ck_top_module' frepo_name='ck_top_repo' form_name='ck_top_form' onchange='document.'+form_name+'.submit();' ############################################################################## # Initialize module def init(i): """ Input: {} Output: { return - return code = 0, if successful > 0, if error (error) - error text if return > 0 } """ return {'return':0} ############################################################################## # index def index(i): """ Input: { (template) - use different template uoa (cid) - direct CID (search) - search string (search_by_tags) - search by tags (separated by comma or | for OR operator) (native_action) - if !='', use this instead of action and just show output (with menu but without query) (aview) - if 'yes', alternative view (module+data UOA) in title instead of data_name (since not all may have it and there is currently no standard) (skip_links) - if 'yes', do not show links (view meta, etc) (skip_desc) - if 'yes', do not show desc (ignore_without_alias) - if 'yes', skip entries without alias (i.e. ignoring ENV when showing CK AI market entries) (limit) - limit number of CK entries to show (force_limit) - force limit number of CK entries to show (no_limit) - show all entries } Output: { return - return code = 0, if successful > 0, if error (error) - error text if return > 0 html - unicoded html page } """ nat=i.get('native_action','') nmuoa=i.get('native_module_uoa','') native=False if nat!='' and nmuoa!='': native=True page=i.get('page','') if page!='': return view_page(i) fsearch_name='ck_top_search' fsearch_tag_name='ck_top_search_tag' fdate_after_name='ck_top_date_after' fdate_before_name='ck_top_date_before' fsubmit_name='ck_top_prune' fadd_name='ck_top_add' xskip_links=i.get('skip_links','') xskip_desc=i.get('skip_desc','') aview=(i.get('aview','')=='yes') flimit_name='ck_limit' fmore_button_name='ck_top_more' fview_raw='view_raw' # Check filters cid=i.get('wcid','') # That was not a good thing but I was using _ in some refs if cid.find('_')>0 and cid.find(':')<0: cid=cid.replace('_',':') # Remove HTML characters to avoid hacking cid=cid.replace('<','').replace('%22','').replace('%3E','').replace('%3C','') cduoa='' cmuoa='' cruoa='' clruoa=[] x=i.get('repo_list','').strip() if x!='': clruoa=x.split(',') cs=i.get('search', '').strip() if fsearch_name in i: cs=i[fsearch_name] cst=i.get('search_by_tags','') if fsearch_tag_name in i: cst=i[fsearch_tag_name] find_cid=False if cs!='' and cs.lower().startswith('cid='): find_cid=True cid=cs[4:].strip() if cid!='': r=ck.parse_cid({'cid':cid}) if r['return']>0: return r cduoa=r['data_uoa'] cmuoa=r['module_uoa'] cruoa=r.get('repo_uoa','') if i.get('wrepo_uoa','')!='': cruoa=i['wrepo_uoa'] if not find_cid and fdata_name in i: cduoa=i[fdata_name] if not find_cid and fmodule_name in i: cmuoa=i[fmodule_name] if not find_cid and frepo_name in i: cruoa=i[frepo_name] cid='' cidx='' if cruoa!='' or cmuoa!='' or cduoa!='': if cduoa!='': cid=cduoa cid=':'+cid if cmuoa!='': cid=cmuoa+cid cid=':'+cid cidx=cid if cruoa!='': cid=cruoa+cid # Check host/port and default module/action. rx=form_url_prefix(i) if rx['return']>0: return rx url0=rx['url'] url0w=rx['url_without_template'] template=rx['template'] d=rx['meta'] p=rx['path'] h=rx['html'] url_template_pull=rx['url_template_pull'] url00=url0w # wfe_url_prefix_subst is used to make "good" looking URL for referencing # when CK server is behind some redirecting services such as no-ip. if ck.cfg.get('wfe_url_prefix_subst','')!='': url00=ck.cfg['wfe_url_prefix_subst'] url=url0 action=i.get('action','').replace('<','').replace('%22','').replace('%3E','').replace('%3C','') muoa=i.get('module_uoa','').replace('<','').replace('%22','').replace('%3E','').replace('%3C','') hstyle='' top_menu=cfg['top_menu'] if len(d.get('top_menu',{})): top_menu=d['top_menu'] # Prepare URL url+='action='+action+'&'+'module_uoa='+muoa url1=url url_add=url0+'action=webadd&module_uoa='+muoa if cid!='': url_add+='&wcid='+cid # PRUNE ************************************************************* view_entry=False lst=[] no_limit=i.get('no_limit','').replace('<','').replace('%22','').replace('%3E','').replace('%3C','') if no_limit=='yes': ln='-1' else: # Check limits if i.get('force_limit','')!='': ln=i['force_limit'] else: ln=i.get(flimit_name,'') lnstep=15 if ln=='': ln=i.get('limit','').replace('<','').replace('%22','').replace('%3E','').replace('%3C','') if ln=='': ln=str(lnstep) if ln=='': ln=str(lnstep) if fmore_button_name in i: ln=str(int(ln)+lnstep) vr=i.get(fview_raw,'') if i.get('nolimit','')=='yes': ln='' if ln!='': url+='&limit='+ln # Check dates datea=i.get('search_by_date_after','') dateb=i.get('search_by_date_before','') if fdate_after_name in i: datea=i[fdate_after_name] if fdate_before_name in i: dateb=i[fdate_before_name] datea=datea.replace(' ','T') # To make ISO standard dateb=dateb.replace(' ','T') # To make ISO standard # If viewing a given entry # if cmuoa!='' and cduoa!='' and \ # cmuoa.find('*')<0 and cmuoa.find('?')<0 and \ # cduoa.find('*')<0 and cduoa.find('?')<0: # view_entry=True if not native: # Check if has | in string, then multiple searches qcst=cst.split('|') lst=[] for q in qcst: # Create pruned list ii={'action':'search', 'repo_uoa':cruoa, 'module_uoa':cmuoa, 'data_uoa':cduoa, 'add_info':'yes', 'add_meta':'yes', 'ignore_case':'yes'} if ln!='' and int(ln)>0: ii['limit_size']=int(ln) if cs!='' and not find_cid: ii['search_string']=cs if cst!='' and not find_cid: ii['tags']=q if len(clruoa)>0: ii['repo_uoa_list']=clruoa if datea!='' or dateb!='': if datea==dateb: ii['add_if_date']=datea else: if datea!='': ii['add_if_date_after']=datea if dateb!='': ii['add_if_date_before']=dateb r=ck.access(ii) if r['return']>0: # On some machines, some modules are not available - so do not process error to avoid crashing ... r['lst']=[] lst+=r['lst'] if len(lst)==1: view_entry=True # Top html ************************************************************ ht='' ht+='
\n' xcmuoa=cmuoa if view_entry and len(lst)==1: xcmuoa=lst[0]['module_uoa'] skip_div_box='' for q in top_menu: name=q['name'] x=q.get('url','') y=q.get('url_extra','') z=q.get('url_extra_browse','') muoas=q.get('module_uoas',[]) xmuoa=q.get('module_uoa','') style='ck_menu_text_0' qnmuoa=q.get('native_module_uoa','') if (q.get('default','')!='yes' or (i.get('wcid','')=='' and cmuoa=='')) and \ ((native and i.get('native_module_uoa','')==q.get('native_module_uoa','-')) or \ (not native and (q.get('any_module','')=='yes' or (xcmuoa in muoas)))): style='ck_menu_text_0_selected' if qnmuoa!='' : if nmuoa=='': nmuoa=qnmuoa if nat=='' and q.get('native_action','')!='': nat=q['native_action'] skip_div_box=q.get('skip_div_box','') native=True if x=='' and y=='': x=url0+'wcid='+xmuoa+':' if z!='': x+='&'+z elif y!='': x=url0+y xtb='' if q.get('new_window','')=='yes': xtb=' target="_blank"' line=''+name+'' if q.get('bold','')=='yes': line=''+line+'' ht+=line+'\n' ht+='
\n' # Check if show after menu text, such as number of shared artifacts if d.get('extra_html_after_menu','')!='': ht+=d['extra_html_after_menu'].replace('$#ck_root_url#$', url0) ad=ck.cfg.get('extra_browser_text','') if ad!='': ht+=ad show_more=False # Check if html only ************************************************************** if i.get('html_only','')=='yes': q=lst[0] ruoa=q['repo_uoa'] muoa=q['module_uoa'] muid=q['module_uid'] ruid=q['repo_uid'] duoa=q['data_uoa'] duid=q['data_uid'] xcid=muid+':'+duid utp=url0+'action=pull&common_func=yes&cid='+xcid+'&filename=' utp_data_uoa='wfe' x='tmp:'+utp_data_uoa if ck.cfg.get('graph_tmp_repo_uoa','')!='': x=ck.cfg['graph_tmp_repo_uoa']+':'+x utp_tmp=url0+'action=pull&common_func=yes&cid='+x+'&filename=' hp='' ii={'action':'html_viewer', 'module_uoa':muid, 'data_uoa':duid, 'url_base':url0, 'url_cid':x, 'url_pull':utp, 'url_pull_tmp':utp_tmp, 'tmp_data_uoa':utp_data_uoa, 'form_name':form_name, 'all_params':i} rx=ck.access(ii) if rx['return']==0: hspec=rx.get('html','') hstyle+=rx.get('style','')+'\n' # Process special vars rx=process_ck_page({'html':hspec}) if rx['return']>0: return rx hspec=rx['html'] if rx.get('style','')!='': hstyle+='\n\n'+rx['style']+'\n\n' # Replace Root URL hspec=hspec.replace('$#ck_root_url#$', url0) else: x=rx['error'] if 'not found in module' not in x: hspec='CK warning: '+rx['error'] h='\n' h+='\n' h+='\n' h+=hspec+'\n' h+='\n' h+='\n' hp='' # Check if native action ************************************************************** elif native: hp='' if skip_div_box!='yes': hp+='
\n' import copy ii=copy.deepcopy(i) ii['action']=nat if 'native_action' in i: del(i['native_action']) ii['module_uoa']=nmuoa if 'native_module_uoa' in i: del(i['native_module_uoa']) rx=ck.access(ii) if rx['return']>0: hp+='Error: '+rx['error'] else: hp+=rx.get('html','')+'\n' hstyle+=rx.get('style','')+'\n' if skip_div_box!='yes': hp+='
\n' else: # Prepare query div *************************************************************** # Start form + URL (even when viewing entry) ii={'url':url1, 'name':form_name} r=start_form(ii) if r['return']>0: return r hf=r['html'] # Some params for k in ['no_limit','aview','skip_links','skip_desc']: rx=create_input({'type':'hidden', 'name': k, 'value':i.get(k,'')}) if rx['return']>0: return rx hf+=rx['html']+'\n' if view_entry: ht+='\n' ht+='\n' # ht+='
\n' # ht+=' \n' # ht+='
\n' else: ht+='
\n' # Get list of repos r=ck.access({'action':'list', 'module_uoa':ck.cfg["repo_name"], 'add_info':'yes', 'add_meta':'yes'}) if r['return']>0: return r lm=r['lst'] r=convert_ck_list_to_select_data({'lst':lm, 'add_empty':'yes', 'sort':'yes', 'value_uoa':cruoa, 'ignore_remote':'yes'}) if r['return']>0: return r dlm=r['data'] if r.get('value_uid','')!='': cruoa=r['value_uid'] ii={'data':dlm, 'name':frepo_name, 'onchange':onchange, 'style':'width:300px;'} if cruoa!='': ii['selected_value']=cruoa r=create_selector(ii) if r['return']>0: return r hlr=r['html'] # Get list of modules r=ck.access({'action':'list', 'module_uoa':ck.cfg["module_name"], 'add_info':'yes'}) if r['return']>0: return r lm=r['lst'] r=convert_ck_list_to_select_data({'lst':lm, 'add_empty':'yes', 'sort':'yes', 'value_uoa':cmuoa}) if r['return']>0: return r dlm=r['data'] if r.get('value_uid','')!='': cmuoa=r['value_uid'] ii={'data':dlm, 'name':fmodule_name, 'onchange':onchange, 'style':'width:300px;'} if cmuoa!='': ii['selected_value']=cmuoa r=create_selector(ii) if r['return']>0: return r hlm=r['html'] # Prepare general search r=create_input({'size':'25', 'name': fsearch_name, 'value':cs}) if r['return']>0: return r hs1=r['html'] # Prepare search by tags r=create_input({'size':'25', 'name': fsearch_tag_name, 'value':cst}) if r['return']>0: return r hs2=r['html'] # Prepare date after r=create_input({'size':'25', 'name': fdate_after_name, 'value':datea}) if r['return']>0: return r hda=r['html'] # Prepare date after r=create_input({'size':'25', 'name': fdate_before_name, 'value':dateb}) if r['return']>0: return r hdb=r['html'] # Prepare reset hreset='[Reset form]' # Prepare submit r=create_button({'name': fsubmit_name, 'value':'Search / Prune'}) if r['return']>0: return r hsubmit=r['html'] # Prepare add hadd='[Add new entry]' # Prepare top ht+=hf ht+='
\n' ht+='Prune entries by:
\n' ht+='
\n' ht+='\n' ht+=' \n' ht+=' \n' ht+=' \n' ht+=' \n' ht+=' \n' ht+=' \n' ht+=' \n' ht+=' \n' ht+=' \n' ht+=' \n' ht+=' \n' ht+=' \n' ht+=' \n' ht+=' \n' ht+=' \n' ht+=' \n' ht+='
Module/class:'+hlm+'String:'+hs1+'After date (ISO):'+hda+'
Repository:'+hlr+'Tags:'+hs2+'Before date (ISO):'+hdb+'
\n' ht+='
\n' ht+=hreset+'  '+hsubmit+'            '+hadd+'\n' if ck.cfg.get('use_indexing','')=='no': ht+='

Warning: Elastic Search indexing is off - search by string/tags/date can be slow ...
' ht+='
\n' # Continue showing entries if len(lst)==0: ########################################### No entries ############# hp='
\n' hp+='No entries found!' hp+='
\n' elif len(lst)==1: ########################################### Entry viewer ############# import json q=lst[0] ruoa=q['repo_uoa'] muoa=q['module_uoa'] muid=q['module_uid'] ruid=q['repo_uid'] duoa=q['data_uoa'] duid=q['data_uid'] hp=hf # init html + form # Preset current entry params rx=create_input({'type':'hidden', 'name': frepo_name, 'value':ruid}) if rx['return']>0: return rx hp+=rx['html']+'\n' rx=create_input({'type':'hidden', 'name': fmodule_name, 'value':muid}) if rx['return']>0: return rx hp+=rx['html']+'\n' rx=create_input({'type':'hidden', 'name': fdata_name, 'value':duid}) if rx['return']>0: return rx hp+=rx['html']+'\n' # hp='
\n' # hp+='View entry:
\n' # hp+='[ Back to CK browser ]\n' # hp+='
\n' # hp+='\n' # Load for full info rx=ck.access({'action':'load', 'repo_uoa':ruid, 'module_uoa':muid, 'data_uoa':duid}) if rx['return']>0: return rx dd=rx['dict'] dx=rx.get('desc',{}) pp=rx['path'] skip_links=dd.get('skip_links','') info=q.get('info',{}) control=info.get('control',{}) author=control.get('author','') author_wp=control.get('author_webpage','') iso_datetime=control.get('iso_datetime','') license=control.get('license','') tags=dd.get('tags', []) stags='' if type(tags)!=list: stags=tags elif len(tags)>0: stags='' for q in tags: if stags!='': stags+=',' stags+=str(q) desc=info.get('description','') au='' if author!='': au=author if author_wp!='': au=''+au+'' if iso_datetime!='': iso_datetime=iso_datetime.replace('T',' ') # ix=iso_datetime.find('.') # if ix>0: iso_datetime=iso_datetime[:ix] dn=info.get('data_name','') if dn=='': dn=duoa xcid=muid+':'+duid url2=url1+'&wcid='+xcid url3=url0+'&action=pull&common_func=yes&archive=yes&skip_tmp=yes&all=yes&cid='+xcid url3x=url0+'&action=pull&common_func=yes&archive=yes&skip_tmp=yes&cid='+xcid url4=url0+'&action=load&out=json&cid='+xcid url7=url0+'&action=webadd&update=yes&module_uoa=wfe&wcid='+xcid url5=ck.cfg.get('wiki_data_web','') if url5!='': url5+=muid+'_'+duid urlself1=url00+'wcid='+xcid # urlself=url0+'action=index%26module_uoa=wfe%26wcid='+xcid urlself=url00+'wcid='+xcid url6=url0+'action=generate&module_uoa=qr-code&qr_level=6&image_size=170&string='+urlself hp+='
\n' # Check if share ps=os.path.join(p, 'share.html') hshare='' ishare=False if os.path.isfile(ps): r=ck.load_text_file({'text_file':ps}) if r['return']>0: return r hshare=r['string'].replace('$#url#$',url2) # Check if specialized rendering function exists for the given module raw=True show_top=True hspec='' utp=url0+'action=pull&common_func=yes&cid='+xcid+'&filename=' utp_data_uoa='wfe' x='tmp:'+utp_data_uoa if ck.cfg.get('graph_tmp_repo_uoa','')!='': x=ck.cfg['graph_tmp_repo_uoa']+':'+x utp_tmp=url0+'action=pull&common_func=yes&cid='+x+'&filename=' ii={'action':'html_viewer', 'module_uoa':muid, 'data_uoa':duid, 'url_base':url0, 'url_cid':x, 'url_pull':utp, 'url_pull_tmp':utp_tmp, 'url_wiki':url5, 'html_share':hshare, 'tmp_data_uoa':utp_data_uoa, 'form_name':form_name, 'all_params':i} # for q in i: # if q.startswith('cur_form'): # ii[q]=i[q] rx=ck.access(ii) if rx['return']==0: if rx.get('raw','')!='yes': raw=False if rx.get('show_top','')!='yes': show_top=False if vr=='on': raw=True show_top=True hspec=rx.get('html','') hstyle=rx.get('style','') # Process special vars rx=process_ck_page({'html':hspec}) if rx['return']>0: return rx hspec=rx['html'] if rx.get('style','')!='': hstyle+='\n\n'+rx['style']+'\n\n' # Replace Root URL hspec=hspec.replace('$#ck_root_url#$', url0) else: x=rx['error'] if 'not found in module' not in x: hspec='CK warning: '+rx['error'] # Show top info if show_top: hp+=' \n' hp+=' \n' hp+=' \n' hp+=' \n' hp+=' \n' hp+='
\n' hp+=' \n' # Check if share if hshare!='': ishare=True hp+=hshare+'\n' hp+=' \n' hp+=''+dn+'
\n' hp+='
\n' hp+='
\n' if au!='': hp+='Added by: '+au+'
\n' hp+='Date: '+iso_datetime+'
\n' hp+='License: '+license+'
\n' hp+='
\n' hp+='Module: '+muoa+'
\n' hp+='Repo: '+ruoa+'
\n' hp+='
\n' hp+='CID (DOI-like distributed ID): '+xcid+'
\n' if desc!='': hp+='
\n' hp+=''+desc+'
\n' hp+='
\n' hp+='
\n' # Show tags if stags!='': hp+='
Tags: '+stags+'
\n' if skip_links!='yes': hp+='
\n' if url5!='': hp+='[Discuss (wiki)] \n' hp+='[Update] \n' hp+='[Download entry as archive]\n' hp+='
\n' # Check if has specialized html if hspec!='' and vr!='on': hp+='
\n' hp+=' '+hspec+'\n' hp+='
\n' if raw: # Check files rx=ck.list_all_files({'path':pp, 'limit':10000}) if rx['return']==0: files=rx['list'] ll=sorted(files) if len(ll)>0: hp+='
\n' hp+='Files:\n' hp+='
\n' hp+='
\n' for q in ll: if not q.startswith('tmp'): v=files[q] hp+=''+q+'    ('+str(int((v.get('size',0)+999)/1000))+'KB)
\n' hp+='
\n' hp+='
\n' if i.get('archive_all','')=='yes': x=url3 else: x=url3x hp+='[Download archive]\n' hp+='
\n' ################################################################################################## # Show dependencies hp+='
\n' hp+=' Cross-linking (dependencies):\n' hp+='
\n' hp+='
\n' hp+='
\n' # Show meta hp+='
\n' hp+=' Meta:\n' hp+='
\n' hp+='
\n' hp+='
\n'
             rx=ck.dumps_json({'dict':dd, 'sort_keys':'yes'})
             if rx['return']>0: return rx

             mt=rx['string']

             # Try to detect links
             i0=0
             while i0'+x+''
                   mt=mt[:i1+1]+y+mt[i2:]
                   i0=i1+len(y)
                elif x.startswith('http://') or x.startswith('https://'):
                   y=''+x+''
                   mt=mt[:i1+1]+y+mt[i2:]
                   i0=i1+len(y)
                elif x.startswith('cm:'):
                   # For compatibility with cM
                   x1=x[3:].split(':')
                   y=''+x+''
                   mt=mt[:i1+1]+y+mt[i2:]
                   i0=i1+len(y)

                else:   
                   i0=i1+1

             # Next is for compatibility with cM
             i0=0
             while True:
                i1=mt.find('$#cm_',i0)
                if i1<0: break

                i2=mt.find('#$',i1+1)
                if i2<0: break

                x=mt[i1:i2+2]
                x1=x[5:-2].split('_')
                if len(x1)>1:
                   y=''+x+''
                else:
                   y=x
                mt=mt[:i1]+y+mt[i2+2:]
                i0=i1+len(y)

             hp+=mt

             hp+='
\n' hp+='
\n' ################################################################################################## # Show meta hp+='
\n' hp+=' API desc:\n' hp+='
\n' hp+='
\n' hp+='
\n'
             rx=ck.dumps_json({'dict':dx, 'sort_keys':'yes'})
             if rx['return']>0: return rx

             hp+=rx['string']

             hp+='
\n' hp+='
\n' ################################################################################################## hp+='
\n' hp+='[Download meta] \n' hp+='
\n' # Check if report ps=os.path.join(p, 'report.html') if os.path.isfile(ps): r=ck.load_text_file({'text_file':ps}) if r['return']>0: return r hp+='
\n' htx=r['string'].replace('$#cid#$',xcid) hp+=htx+'\n' # Raw selector if hspec!='': checked='' if vr=='on': checked=' checked ' hp+='
View entry in raw format
\n' hp+='
\n' hp+='\n' else: ######################################## View multiple entries ############### show_more=True if aview: lst1=sorted(lst, key=lambda k: (k['module_uoa']+':'+k['data_uoa']).lower()) else: lst1=sorted(lst, key=lambda k: k.get('info',{}).get('data_name','').lower()) hp='' iq=0 for q in lst1: iq+=1 siq=str(iq) ruoa=q['repo_uoa'] muoa=q['module_uoa'] muid=q['module_uid'] ruid=q['repo_uid'] duoa=q['data_uoa'] duid=q['data_uid'] meta=q.get('meta',{}) info=q.get('info',{}) control=info.get('control',{}) author=control.get('author','') author_wp=control.get('author_webpage','') iso_datetime=control.get('iso_datetime','') tags=meta.get('tags', []) stags='' if type(tags)!=list: stags=tags elif len(tags)>0: stags='' for q in tags: if stags!='': stags+=',' stags+=str(q) desc=info.get('description','') au='' if author!='': au=author if author_wp!='': au=''+au+'' au='Added by '+au if iso_datetime!='': if au!='': au+=', ' x=iso_datetime.replace('T',' ') ix=x.find('.') if ix>0: x=x[:ix] au+=x if au!='': au+=', ' au+='Repo: '+ruoa if stags!='': if au!='': au+=', ' au+='Tags: '+stags if aview: dn=muoa+':'+duoa else: dn=info.get('data_name','') if dn=='': dn=duoa if i.get('ignore_without_alias','')=='yes' and ck.is_uid(duoa): iq-=1 continue # xcid=muid+':'+duid xcid=ruid+':'+muid+':'+duid url2=url0+'wcid='+xcid url3=url0+'&action=pull&common_func=yes&archive=yes&skip_tmp=yes&all=yes&cid='+xcid url3x=url0+'&action=pull&common_func=yes&archive=yes&skip_tmp=yes&cid='+xcid url4=url0+'&action=load&out=json&cid='+xcid url7=url0+'&action=webadd&update=yes&module_uoa=wfe&wcid='+xcid url5=ck.cfg.get('wiki_data_web','') if url5!='': url5+=muid+'_'+duid hp+='
\n' hp+=''+str(iq)+') '+dn+' ('+muoa+')
\n' if au!='' and xskip_desc!='yes': hp+='
\n' hp+=''+au+'
\n' if desc!='' and xskip_desc!='yes': hp+='
\n' hp+=''+desc+'
\n' if xskip_links!='yes': hp+='
\n' hp+='
\n' hp+='[View meta] \n' if url5!='': hp+='[Discuss (wiki)] \n' hp+='[Update] \n' hp+='[Download entry]\n' hp+='
\n' hp+='
\n' # Replace styles if hstyle!='': hstyle='\n\n' h=h.replace('$#ck_styles#$',hstyle) # Replace top if needed h=h.replace('$#template_top#$',ht) # Prepare middle if view_entry: hp+='
\n' hp+=' \n' hp+='
\n' h=h.replace('$#template_middle#$',hp) hm='' if not native and not no_limit=='yes': # Show more r=create_input({'type':'hidden', 'name': flimit_name, 'value':ln}) if r['return']>0: return r hm=r['html']+'\n' # Prepare submit if show_more: r=create_button({'name': fmore_button_name, 'value':'Show more entries'}) if r['return']>0: return r hm+=r['html']+'
\n' hm+='\n' h=h.replace('$#template_middle_finish#$', hm) # Check if visits px=os.path.join(p, 'visits.html') htx='' if os.path.isfile(px): r=ck.load_text_file({'text_file':px}) if r['return']>0: return r htx=r['string'] h=h.replace('$#template_end#$',htx) # Substitute specials h=h.replace('$#title#$', 'CK Browser') h=h.replace('$#ck_url_template_pull#$', url_template_pull) return {'return':0, 'html':h} ############################################################################## # create HTML selector def create_selector(i): """ Input: { (class) - if !='', add this class (name) - if !='', add this name (onchange) - if !='', add this onchange function (style) - if !='', use this style (data) - [{'name':name, 'value': uid}, ...] (selected_value) - if !='', select this item (skip_sort) - if 'yes', do not sort } Output: { return - return code = 0, if successful > 0, if error (error) - error text if return > 0 html - returned generated HTML } """ # Prepare header h='\n' if first: first=False # Finish h+='\n' return {'return':0, 'html':h, 'selected_value':sv} ############################################################################## # def convert_ck_list_to_select_data(i): """ Input: { lst - CK list object (add_empty) - if 'yes', add empty line (sort) - if 'yes', sort by name (value_uoa) - if !='', find uoa and return uid (ignore_remote) - if 'yes', ignore if meta has 'remote':'yes' (to avoid remote repositories) } Output: { return - return code = 0, if successful > 0, if error (error) - error text if return > 0 data - data list in selector format (value_uid) - if value_uoa is set, find UID of the entry } """ dat=[] if i.get('add_empty','')=='yes': dat.append({'name':'', 'value':''}) lst=i['lst'] vuoa=i.get('value_uoa','') vuid='' ir=i.get('ignore_remote','') for q in lst: duoa=q['data_uoa'] duid=q['data_uid'] skip=False if ir=='yes': meta=q.get('meta',{}) if meta.get('remote','')=='yes': skip=True if not skip: dn=q.get('info',{}).get('data_name','') if dn=='': dn=duoa if vuoa!='' and vuoa==duoa: vuid=duid dat.append({'name':dn, 'value':duid}) if i.get('sort','')=='yes': dat=sorted(dat, key=lambda k: k['name'].lower()) return {'return':0, 'data':dat, 'value_uid':vuid} ############################################################################## # start form def start_form(i): """ Input: { (url) - url (name) - name (method) - 'POST' by default (enctype) - 'multipart/form-data' by default (charset) - 'utf-8' by default } Output: { return - return code = 0, if successful > 0, if error (error) - error text if return > 0 html - html for the form } """ h='
0, if error (error) - error text if return > 0 html - html for the form } """ tp=i.get('type','') if tp=='': tp='text' h=' 0, if error (error) - error text if return > 0 html - html for the form } """ cols=i.get('cols','') if cols=='': cols='50' rows=i.get('rows','') if rows=='': rows='10' h='