def get_story(cls, self, ar): pv = ar.param_values cls.check_params(pv) # if not pv.start_period: # yield E.p(gettext("Select at least a start period")) # return bpv = dict(start_period=pv.start_period, end_period=pv.end_period) balances = [] if pv.with_general: balances.append(GeneralAccountBalances.request( param_values=bpv)) for tt in TradeTypes.get_list_items(): k = 'with_'+tt.name if pv[k]: balances.append( PartnerBalancesByTradeType.request( master_instance=tt, param_values=bpv)) # if pv.with_sales: # balances.append(CustomerAccountsBalance) # if pv.with_purchases: # balances.append(SupplierAccountsBalance) if pv.with_balances: for sar in balances: yield E.h1(str(sar.get_title())) yield sar
def get(self, request, app_label=None, actor=None): ar = action_request(app_label, actor, request, request.GET, True) ar.renderer = settings.SITE.kernel.extjs_renderer rh = ar.ah fmt = request.GET.get(constants.URL_PARAM_FORMAT, ar.bound_action.action.default_format) # print(20170921, fmt) if fmt == constants.URL_FORMAT_JSON: rows = [ rh.store.row2list(ar, row) for row in ar.sliced_data_iterator ] total_count = ar.get_total_count() # raise Exception("20171208 {}".format(ar.data_iterator.query)) for row in ar.create_phantom_rows(): if ar.limit is None or len( rows) + 1 < ar.limit or ar.limit == total_count + 1: d = rh.store.row2list(ar, row) rows.append(d) total_count += 1 kw = dict(count=total_count, rows=rows, success=True, no_data_text=ar.no_data_text) if True: kw.update(title=str(ar.get_title())) else: # 20190704 work in progress. # add open_in_own_window button after title of slave panel kw.update(title=str(ar.get_title()) + " " + tostring(ar.open_in_own_window_button())) if ar.actor.parameters: kw.update( param_values=ar.actor.params_layout.params_store.pv2dict( ar, ar.param_values)) kw.update(test_version_mismatch(request)) return json_response(kw) if fmt == constants.URL_FORMAT_HTML: after_show = ar.get_status() sp = request.GET.get(constants.URL_PARAM_SHOW_PARAMS_PANEL, None) if sp is not None: # ~ after_show.update(show_params_panel=sp) after_show.update( show_params_panel=constants.parse_boolean(sp)) # if isinstance(ar.bound_action.action, actions.ShowInsert): # elem = ar.create_instance() # rec = ar.elem2rec_insert(rh, elem) # after_show.update(data_record=rec) kw = dict(on_ready=ar.renderer.action_call( ar.request, ar.bound_action, after_show)) # ~ print '20110714 on_ready', params kw.update(title=ar.get_title()) return http.HttpResponse(ar.renderer.html_page(request, **kw)) if fmt == 'csv': # ~ response = HttpResponse(mimetype='text/csv') charset = settings.SITE.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.SITE.csv_params) w.writerow(ar.ah.store.column_names()) if True: # 20130418 : also column headers, not only internal names column_names = None fields, headers, cellwidths = ar.get_field_info(column_names) w.writerow(headers) for row in ar.data_iterator: w.writerow([str(v) for v in rh.store.row2list(ar, row)]) return response if fmt == constants.URL_FORMAT_PRINTER: if ar.get_total_count() > MAX_ROW_COUNT: raise Exception( _("List contains more than %d rows") % MAX_ROW_COUNT) response = http.HttpResponse( content_type='text/html;charset="utf-8"') doc = Document(force_text(ar.get_title())) doc.body.append(E.h1(doc.title)) t = doc.add_table() # ~ settings.SITE.kernel.ar2html(ar,t,ar.data_iterator) ar.dump2html(t, ar.data_iterator) doc.write(response, encoding='utf-8') return response return settings.SITE.kernel.run_action(ar)
def get(self, request, app_label=None, actor=None): ar = action_request(app_label, actor, request, request.GET, True) # Add this hack to support the 'sort' param which is different in Extjs6. if ar.order_by and ar.order_by[0]: _sort = ast.literal_eval(ar.order_by[0]) sort = _sort[0]['property'] if _sort[0]['direction'] and _sort[0]['direction'] == 'DESC': sort = '-' + sort ar.order_by = [str(sort)] ar.renderer = settings.SITE.kernel.default_renderer rh = ar.ah fmt = request.GET.get( constants.URL_PARAM_FORMAT, ar.bound_action.action.default_format) if fmt == constants.URL_FORMAT_JSON: rows = [rh.store.row2list(ar, row) for row in ar.sliced_data_iterator] total_count = ar.get_total_count() for row in ar.create_phantom_rows(): if ar.limit is None or len(rows) + 1 < ar.limit or ar.limit == total_count + 1: d = rh.store.row2list(ar, row) rows.append(d) total_count += 1 # assert len(rows) <= ar.limit kw = dict(count=total_count, rows=rows, success=True, no_data_text=ar.no_data_text, # title=str(ar.get_title()), title=ar.get_title()) if ar.actor.parameters: kw.update( param_values=ar.actor.params_layout.params_store.pv2dict( ar, ar.param_values)) return json_response(kw) if fmt == constants.URL_FORMAT_HTML: after_show = ar.get_status() sp = request.GET.get( constants.URL_PARAM_SHOW_PARAMS_PANEL, None) if sp is not None: # ~ after_show.update(show_params_panel=sp) after_show.update( show_params_panel=constants.parse_boolean(sp)) # if isinstance(ar.bound_action.action, actions.ShowInsert): # elem = ar.create_instance() # rec = ar.elem2rec_insert(rh, elem) # after_show.update(data_record=rec) kw = dict(on_ready= ar.renderer.action_call( ar.request, ar.bound_action, after_show)) # ~ print '20110714 on_ready', params kw.update(title=ar.get_title()) return http.HttpResponse(ar.renderer.html_page(request, **kw)) if fmt == 'csv': # ~ response = HttpResponse(mimetype='text/csv') charset = settings.SITE.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.SITE.csv_params) w.writerow(ar.ah.store.column_names()) if True: # 20130418 : also column headers, not only internal names column_names = None fields, headers, cellwidths = ar.get_field_info(column_names) w.writerow(headers) for row in ar.data_iterator: w.writerow([str(v) for v in rh.store.row2list(ar, row)]) return response if fmt == constants.URL_FORMAT_PRINTER: if ar.get_total_count() > MAX_ROW_COUNT: raise Exception(_("List contains more than %d rows") % MAX_ROW_COUNT) response = http.HttpResponse( content_type='text/html;charset="utf-8"') doc = xghtml.Document(force_text(ar.get_title())) doc.body.append(E.h1(doc.title)) t = doc.add_table() # ~ settings.SITE.kernel.ar2html(ar,t,ar.data_iterator) ar.dump2html(t, ar.data_iterator) doc.write(response, encoding='utf-8') return response return settings.SITE.kernel.run_action(ar)