Ejemplo n.º 1
0
Archivo: test.py Proyecto: zyrobin/lino
def run_test():
    tpl = os.path.join(os.path.abspath(os.path.dirname(__file__)),'test_template.odt')
    target = 'test_result.odt'
    if os.path.exists(target): 
        os.remove(target)
    init_demo()
    context = dict()
    renderer = Renderer(tpl,context,target,**APPY_PARAMS)
    renderer.run()
    print "Generated file", target
    os.startfile(target)    
Ejemplo n.º 2
0
 def write_odt_file(self,target):
     #~ from appy.pod.renderer import Renderer
     from lino.utils import iif
     #~ from lino.utils.appy_pod import setup_renderer
     from lino.utils.appy_pod import Renderer
     assert os.path.abspath(self.input_template) != os.path.abspath(target)
     if os.path.exists(target):
         os.remove(target)
     #~ tpl = os.path.join(os.path.dirname(__filename__),'cfr.odt')
     ses = settings.SITE.login("root") # not tested after 20130327
     context = dict(
         self=self,
         iif=iif,
         )
     appy_params = dict()
     logger.info(u"appy.pod render %s -> %s (params=%s)",self.input_template,target,appy_params)
     renderer = Renderer(ses,self.input_template, context, target,**appy_params)
     #~ setup_renderer(renderer)
     #~ renderer.context.update(restify=debug_restify)
     self.writing_format = 'odt'
     renderer.run()
Ejemplo n.º 3
0
Archivo: base.py Proyecto: DarioGT/lino
 def write_odt_file(self, target):
     #~ from appy.pod.renderer import Renderer
     from lino.utils import iif
     #~ from lino.utils.appy_pod import setup_renderer
     from lino.utils.appy_pod import Renderer
     assert os.path.abspath(self.input_template) != os.path.abspath(target)
     if os.path.exists(target):
         os.remove(target)
     #~ tpl = os.path.join(os.path.dirname(__filename__),'cfr.odt')
     ses = settings.SITE.login("root")  # not tested after 20130327
     context = dict(
         self=self,
         iif=iif,
     )
     appy_params = dict()
     logger.info(u"appy.pod render %s -> %s (params=%s)",
                 self.input_template, target, appy_params)
     renderer = Renderer(ses, self.input_template, context, target,
                         **appy_params)
     #~ setup_renderer(renderer)
     #~ renderer.context.update(restify=debug_restify)
     self.writing_format = 'odt'
     renderer.run()
Ejemplo n.º 4
0
    def get(self,request,app_label=None,actor=None):
        #~ ar = action_request(app_label,actor,request,request.GET,limit=PLAIN_PAGE_LENGTH)
        ar = action_request(app_label,actor,request,request.GET,True)
        ar.renderer = settings.LINO.ui.ext_renderer
        rh = ar.ah
        
        #~ print 20120630, 'api_list_view'
        fmt = request.GET.get(
            ext_requests.URL_PARAM_FORMAT,
            ar.bound_action.action.default_format)
            
        #~ logger.info("20121203 views.ApiList.get() %s",ar.bound_action.full_name())
      
        if fmt == ext_requests.URL_FORMAT_JSON:
            #~ ar.renderer = ui.ext_renderer
            rows = [ rh.store.row2list(ar,row) for row in ar.sliced_data_iterator]
            #~ return json_response_kw(msg="20120124")
            #~ total_count = len(ar.data_iterator)
            total_count = ar.get_total_count()
            #~ if ar.create_rows:
            for row in ar.create_phantom_rows():
                d = rh.store.row2list(ar,row)
                rows.append(d)
                total_count += 1
            #~ 20120918
            kw = dict(count=total_count,
              rows=rows,
              success=True,
              no_data_text=ar.no_data_text, 
              #~ status=ar.get_status(ar.ui),
              title=unicode(ar.get_title()))
              #~ disabled_actions=rpt.disabled_actions(ar,None),
              #~ gc_choices=[gc.data for gc in ar.actor.grid_configs])
            if ar.actor.parameters:
                #~ kw.update(param_values=ar.ah.store.pv2dict(ar.ui,ar.param_values))
                kw.update(param_values=ar.actor.params_layout.params_store.pv2dict(ar.ui,ar.param_values))
            return json_response(kw) 
                
        if fmt == ext_requests.URL_FORMAT_HTML:
            #~ ar.renderer = ui.ext_renderer
            after_show = ar.get_status(ar.ui)
            if isinstance(ar.bound_action.action,actions.InsertRow):
                elem = ar.create_instance()
                #~ print 20120630
                #~ print elem.national_id
                rec = elem2rec_insert(ar,rh,elem)
                after_show.update(data_record=rec)

            kw = dict(on_ready=
                ar.renderer.action_call(ar.request,ar.bound_action,after_show))
                #~ ui.ext_renderer.action_call(ar.request,ar.action,after_show))
            #~ print '20110714 on_ready', params
            kw.update(title=ar.get_title())
            return http.HttpResponse(ar.ui.html_page(request,**kw))
        
        if fmt == 'csv':
            #~ response = HttpResponse(mimetype='text/csv')
            charset = settings.LINO.csv_params.get('encoding','utf-8')
            response = http.HttpResponse(
              content_type='text/csv;charset="%s"' % charset)
            if False:
                response['Content-Disposition'] = \
                    'attachment; filename="%s.csv"' % ar.actor
            else:
                #~ response = HttpResponse(content_type='application/csv')
                response['Content-Disposition'] = \
                    'inline; filename="%s.csv"' % ar.actor
              
            #~ response['Content-Disposition'] = 'attachment; filename=%s.csv' % ar.get_base_filename()
            w = ucsv.UnicodeWriter(response,**settings.LINO.csv_params)
            w.writerow(ar.ah.store.column_names())
            for row in ar.data_iterator:
                w.writerow([unicode(v) for v in rh.store.row2list(ar,row)])
            return response
            
        if fmt in (ext_requests.URL_FORMAT_PDF,ext_requests.URL_FORMAT_ODT):
            if ar.get_total_count() > MAX_ROW_COUNT:
                raise Exception(_("List contains more than %d rows") % MAX_ROW_COUNT)
        
            from lino.utils.appy_pod import Renderer
            
            tpl_leaf = "Table.odt" 
            tplgroup = None
            tplfile = find_config_file(tpl_leaf,tplgroup)
            if not tplfile:
                raise Exception("No file %s / %s" % (tplgroup,tpl_leaf))
                
            ip = ar.request.META.get('REMOTE_ADDR','unknown_ip')
            target_parts = ['cache', 'appypdf', ip, str(ar.actor) + '.' + fmt]
            target_file = os.path.join(settings.MEDIA_ROOT,*target_parts)
            makedirs_if_missing(os.path.dirname(target_file))
            target_url = settings.LINO.build_media_url(*target_parts)
            ar.renderer = ar.ui.ext_renderer # 20120624
            """
            [NOTE] `/blog/2012/0211`
            
            """
            context = dict(
                ar=ar,
                title=unicode(ar.get_title()),
                dtos=babel.dtos,
                dtosl=babel.dtosl,
                dtomy=babel.dtomy,
                babelattr=babel.babelattr,
                babelitem=babel.babelitem,
                tr=babel.babelitem,
                settings=settings,
                _ = _,
                #~ knowledge_text=fields.knowledge_text,
                )
            if os.path.exists(target_file):
                os.remove(target_file)
            logger.info(u"appy.pod render %s -> %s (params=%s",
                tplfile,target_file,settings.LINO.appy_params)
            renderer = Renderer(tplfile, context, target_file,**settings.LINO.appy_params)
            renderer.run()
            return http.HttpResponseRedirect(target_url)
            
        if fmt == ext_requests.URL_FORMAT_PRINTER:
            if ar.get_total_count() > MAX_ROW_COUNT:
                raise Exception(_("List contains more than %d rows") % MAX_ROW_COUNT)
            #~ ar.renderer = ui.ext_renderer
            response = http.HttpResponse(content_type='text/html;charset="utf-8"')
            doc = xghtml.Document(force_unicode(ar.get_title()))
            doc.body.append(xghtml.E.h1(doc.title))
            t = doc.add_table()
            ar.ui.ar2html(ar,t,ar.data_iterator)
            doc.write(response,encoding='utf-8')
            return response
            
        raise http.Http404("Format %r not supported for GET on %s" % (fmt,ar.actor))