def post(self, request, uuid, **kw): # uuid = request.POST.get('uuid') card_data = request.POST.get('card_data') # card_data = json.loads(card_data) # msg = "20180412 raw data {}".format(request.body) # dd.logger.info(msg) # if not card_data: # raise Exception("No card_data found in {}".format( # request.POST)) fn = dd.plugins.beid.data_cache_dir.child(uuid) # pth = dd.plugins.beid.data_cache_dir # pth = join(pth, uuid) try: fp = open(fn, 'w') fp.write(card_data) # json.dump(card_data, fp) fp.close() # msg = "20181002 wrote {} : {}".format(fn, card_data) # dd.logger.info(msg) return json_response(dict(success=True, message="OK")) except IOError as e: dd.logger.warning( "Failed to store data to file %s : %s", fn, e) return json_response( dict(success=False, message=str(e)), status=502)
def post(self, request, uuid, **kw): # uuid = request.POST.get('uuid') card_data = request.POST.get('card_data') # card_data = json.loads(card_data) # msg = "20180412 raw data {}".format(request.body) # dd.logger.info(msg) # if not card_data: # raise Exception("No card_data found in {}".format( # request.POST)) fn = dd.plugins.beid.data_cache_dir.child(uuid) # pth = dd.plugins.beid.data_cache_dir # pth = join(pth, uuid) try: fp = open(fn, 'w') fp.write(card_data) # json.dump(card_data, fp) fp.close() # msg = "20181002 wrote {} : {}".format(fn, card_data) # dd.logger.info(msg) return json_response(dict(success=True, message="OK")) except IOError as e: dd.logger.warning("Failed to store data to file %s : %s", fn, e) return json_response(dict(success=False, message=str(e)), status=502)
def getit(): # print(20200419, settings.SITE.build_media_url(*settings.SITE.plugins.react.renderer.lino_js_parts())) if not settings.SITE.build_js_cache_on_startup: settings.SITE.plugins.react.renderer.build_js_cache(False) user_settings = dict( user_type=u.user_type, dashboard_items=len(u.get_preferences().dashboard_items), # [d.serialize() for d in u.get_preferences().dashboard_items], lv=str(settings.SITE.kernel.code_mtime), lang=get_language(), site_data=settings.SITE.build_media_url( *settings.SITE.plugins.react.renderer.lino_js_parts()), logged_in=not_anon, username=u.get_full_name() if not_anon else _("Anonymous"), su_name= su_name, # subst_user # must be passed as param in get_user_settings request, act_as_subtext=_( "You are authorised to act as the following users."), act_as_title_text=_("Act as another user"), act_as_button_text=_("Act as another user"), act_as_self_text=_("Stop acting as another user"), # #3070: Add id and the text of "My setting" menu my_setting_text=_("My settings"), user_id=u.pk, ) if su_name: user_settings["user_id"] = user_settings["su_id"] = su.id user_settings["su_user_type"] = su.user_type if not_anon: user_settings["authorities"] = u.get_authorities() return json_response(user_settings)
def get(self, request): data = { str(cl): [{ "key": py2js(c[0]).strip('"'), "text": py2js(c[1]).strip('"') } for c in cl.get_choices()] for cl in kernel.CHOICELISTS.values() } return json_response(data)
def get(self, request, app_label=None, actor=None, pk=None): """ Works, but is ugly to get list and detail """ rpt = requested_actor(app_label, actor) action_name = request.GET.get(constants.URL_PARAM_ACTION_NAME, rpt.default_elem_action_name) fmt = request.GET.get(constants.URL_PARAM_FORMAT, constants.URL_FORMAT_JSON) sr = request.GET.getlist(constants.URL_PARAM_SELECTED) if not sr: sr = [pk] ar = rpt.request(request=request, selected_pks=sr) if pk is None: rh = ar.ah rows = [ rh.store.row2dict(ar, row, rh.store.all_fields) for row in ar.sliced_data_iterator ] kw = dict(count=ar.get_total_count(), rows=rows) kw.update(title=str(ar.get_title())) return json_response(kw) else: # action_name=="detail": #ba.action.opens_a_window: ba = rpt.get_url_action(action_name) ah = ar.ah ar = ba.request(request=request, selected_pks=sr) elem = ar.selected_rows[0] if fmt == constants.URL_FORMAT_JSON: if pk == '-99999': elem = ar.create_instance() datarec = ar.elem2rec_insert(ah, elem) elif pk == '-99998': elem = ar.create_instance() datarec = elem2rec_empty(ar, ah, elem) elif elem is None: datarec = dict(success=False, message=NOT_FOUND % (rpt, pk)) else: datarec = ar.elem2rec_detailed(elem) return json_response(datarec)
def get(self, request, app_label=None, actor=None, pk=None): rpt = requested_actor(app_label, actor) assert pk is None, 20120814 ar = rpt.request(request=request) rh = ar.ah rows = [ rh.store.row2dict(ar, row, rh.store.list_fields) for row in ar.sliced_data_iterator] kw = dict(count=ar.get_total_count(), rows=rows) kw.update(title=unicode(ar.get_title())) return json_response(kw)
def get(self, request, app_label=None, actor=None, pk=None): rpt = requested_actor(app_label, actor) assert pk is None, 20120814 ar = rpt.request(request=request) rh = ar.ah rows = [ rh.store.row2dict(ar, row, rh.store.list_fields) for row in ar.sliced_data_iterator] kw = dict(count=ar.get_total_count(), rows=rows) kw.update(title=str(ar.get_title())) return json_response(kw)
def get(self, request, *args, **kw): """Returns a json struct for the main user dashboard.""" # ~ logger.info("20130719 MainHtml") settings.SITE.startup() # ~ raise Exception("20131023") ar = BaseRequest(request) html = settings.SITE.get_main_html( request, extjs=settings.SITE.plugins.openui5) html = settings.SITE.plugins.openui5.renderer.html_text(html) ar.success(html=html) return json_response(ar.response, ar.content_type)
def get(self, request, index, *args, **kw): """Returns a rendered HTML version the requested user dashboard.""" ar = BaseRequest(request) ar.renderer = settings.SITE.plugins.react.renderer ar.requesting_panel = f"dashboard-{index}" dash = ar.get_user().get_preferences().dashboard_items if len(dash) > index: html = ar.show_story([dash[index]]) else: html = "" ar.success(html=html) return json_response(ar.response, ar.content_type)
def get(self, request, *args, **kw): """Returns a json struct for the main user dashboard.""" # ~ logger.info("20130719 MainHtml") settings.SITE.startup() # ~ raise Exception("20131023") ar = BaseRequest(request) # Add to reqeust not ar, as there's error if passing ar to get_main_html request.requesting_panel = "dashboard-main" html = settings.SITE.get_main_html(request, extjs=settings.SITE.plugins.react) html = settings.SITE.plugins.react.renderer.html_text(html) ar.success(html=html) return json_response(ar.response, ar.content_type)
def put(self, request, app_label=None, actor=None, pk=None): rpt = requested_actor(app_label, actor) ar = rpt.request(request=request) ar.set_selected_pks(pk) elem = ar.selected_rows[0] rh = ar.ah data = http.QueryDict(request.body).get('rows') data = json.loads(data) a = rpt.get_url_action(rpt.default_list_action_name) ar = rpt.request(request=request, action=a) ar.renderer = settings.SITE.kernel.extjs_renderer ar.form2obj_and_save(data, elem, False) # Ext.ensible needs list_fields, not detail_fields ar.set_response( rows=[rh.store.row2dict(ar, elem, rh.store.list_fields)]) return json_response(ar.response)
def post(self, request, app_label=None, actor=None, pk=None): rpt = requested_actor(app_label, actor) ar = rpt.request(request=request) instance = ar.create_instance() # store uploaded files. # html forms cannot send files with PUT or GET, only with POST if ar.actor.handle_uploaded_files is not None: ar.actor.handle_uploaded_files(instance, request) data = request.POST.get('rows') data = json.loads(data) ar.form2obj_and_save(data, instance, True) # Ext.ensible needs list_fields, not detail_fields ar.set_response( rows=[ar.ah.store.row2dict(ar, instance, ar.ah.store.list_fields)]) return json_response(ar.response)
def post(self, request, app_label=None, actor=None, pk=None): rpt = requested_actor(app_label, actor) ar = rpt.request(request=request) instance = ar.create_instance() # store uploaded files. # html forms cannot send files with PUT or GET, only with POST if ar.actor.handle_uploaded_files is not None: ar.actor.handle_uploaded_files(instance, request) data = request.POST.get('rows') data = json.loads(data) ar.form2obj_and_save(data, instance, True) # Ext.ensible needs list_fields, not detail_fields ar.set_response( rows=[ar.ah.store.row2dict( ar, instance, ar.ah.store.list_fields)]) return json_response(ar.response)
def get(self, request, app_label=None, actor=None, pk=None): ui = settings.SITE.kernel rpt = requested_actor(app_label, actor) action_name = request.GET.get(constants.URL_PARAM_ACTION_NAME, rpt.default_elem_action_name) ba = rpt.get_url_action(action_name) if ba is None: raise http.Http404("%s has no action %r" % (rpt, action_name)) if pk and pk != '-99999' and pk != '-99998': #~ ar = ba.request(request=request,selected_pks=[pk]) #~ print 20131004, ba.actor ar = ba.request(request=request) ar.set_selected_pks(pk) elem = ar.selected_rows[0] else: ar = ba.request(request=request) elem = None ar.renderer = ui.extjs_renderer ah = ar.ah fmt = request.GET.get( constants.URL_PARAM_FORMAT, ba.action.default_format) if ba.action.opens_a_window: if fmt == constants.URL_FORMAT_JSON: if pk == '-99999': elem = ar.create_instance() datarec = ar.elem2rec_insert(ah, elem) elif pk == '-99998': elem = ar.create_instance() datarec = elem2rec_empty(ar, ah, elem) elif elem is None: datarec = dict( success=False, message=NOT_FOUND % (rpt, pk)) else: datarec = ar.elem2rec_detailed(elem) return json_response(datarec) after_show = ar.get_status(record_id=pk) tab = request.GET.get(constants.URL_PARAM_TAB, None) if tab is not None: tab = int(tab) after_show.update(active_tab=tab) return http.HttpResponse( ui.extjs_renderer.html_page( request, ba.action.label, on_ready=ui.extjs_renderer.action_call( request, ba, after_show))) if isinstance(ba.action, actions.RedirectAction): target = ba.action.get_target_url(elem) if target is None: raise http.Http404("%s failed for %r" % (ba, elem)) return http.HttpResponseRedirect(target) if pk == '-99998': assert elem is None elem = ar.create_instance() ar.selected_rows = [elem] elif elem is None: raise http.Http404(NOT_FOUND % (rpt, pk)) return settings.SITE.kernel.run_action(ar)
def render_action_response(self, ar): """Builds a JSON response from response information stored in given ActionRequest. """ return views.json_response(ar.response, ar.content_type)
def get(self, request, app_label=None, actor=None, pk=None, field=None): suggesters = settings.SITE.plugins.memo.parser.suggesters trigger = request.GET.get("trigger") query = request.GET.get("query") return json_response( {"suggestions": list(suggesters[trigger].get_suggestions(query))})
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) 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(): 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, title=unicode(ar.get_title())) if ar.actor.parameters: kw.update( param_values=ar.actor.params_layout.params_store.pv2dict( 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.InsertRow): # 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([unicode(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_unicode(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)] if not ar.get_permission(): msg = "No permission to run {}".format(ar) # raise Exception(msg) raise PermissionDenied(msg) ar.renderer = settings.SITE.kernel.default_renderer rh = ar.ah fmt = request.GET.get(constants.URL_PARAM_FORMAT, ar.bound_action.action.default_format) action_name = request.GET.get(constants.URL_PARAM_ACTION_NAME) if action_name: return settings.SITE.kernel.run_action(ar) if fmt == constants.URL_FORMAT_JSON: window_type = request.GET.get(constants.URL_PARAM_WINDOW_TYPE, "g") def serialize(ar, row): """Use window_type to determin which serizlisation store metod and fields to use""" if window_type == "g": return rh.store.row2list(ar, row) else: return rh.store.row2dict( ar, row, fields=rh.store.card_fields if window_type == "c" else rh.store.detail_fields, card_title=ar.get_card_title(row)) rows = [serialize(ar, row) for row in ar.sliced_data_iterator] total_count = ar.get_total_count() if window_type == "g": 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 = serialize(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=ar.get_title()) if window_type != "g": mc = ar.get_main_card() if mc is not None: rows.insert(0, mc) if ar.actor.parameters: kw.update( param_values=ar.actor.params_layout.params_store.pv2dict( ar, ar.param_values)) return json_response(kw) return settings.SITE.kernel.run_action(ar)
def get(self, request, app_label=None, actor=None, pk=None): ui = settings.SITE.kernel rpt = requested_actor(app_label, actor) action_name = request.GET.get(constants.URL_PARAM_ACTION_NAME, rpt.default_elem_action_name) ba = rpt.get_url_action(action_name) if ba is None: raise http.Http404("%s has no action %r" % (rpt, action_name)) if pk and pk != '-99999' and pk != '-99998': #~ ar = ba.request(request=request,selected_pks=[pk]) #~ print 20131004, ba.actor ar = ba.request(request=request, selected_pks=[pk]) # print( # "20170116 views.ApiElement.get", ba, # ar.action_param_values) elem = ar.selected_rows[0] else: ar = ba.request(request=request) elem = None ar.renderer = ui.extjs_renderer ah = ar.ah fmt = request.GET.get(constants.URL_PARAM_FORMAT, ba.action.default_format) if ba.action.opens_a_window: if fmt == constants.URL_FORMAT_JSON: if pk == '-99999': elem = ar.create_instance() datarec = ar.elem2rec_insert(ah, elem) elif pk == '-99998': elem = ar.create_instance() datarec = elem2rec_empty(ar, ah, elem) elif elem is None: datarec = dict(success=False, message=NOT_FOUND % (rpt, pk)) else: datarec = ar.elem2rec_detailed(elem) return json_response(datarec) after_show = ar.get_status(record_id=pk) tab = request.GET.get(constants.URL_PARAM_TAB, None) if tab is not None: tab = int(tab) after_show.update(active_tab=tab) return http.HttpResponse( ui.extjs_renderer.html_page( request, ba.action.label, on_ready=ui.extjs_renderer.action_call( request, ba, after_show))) if isinstance(ba.action, actions.RedirectAction): target = ba.action.get_target_url(elem) if target is None: raise http.Http404("%s failed for %r" % (ba, elem)) return http.HttpResponseRedirect(target) if pk == '-99998': assert elem is None elem = ar.create_instance() ar.selected_rows = [elem] elif elem is None: raise http.Http404(NOT_FOUND % (rpt, pk)) return settings.SITE.kernel.run_action(ar)
def get(self, request, app_label=None, actor=None, pk=None): # this is also used by the react front end ui = settings.SITE.kernel rpt = requested_actor(app_label, actor) # if not rpt.get_view_permission(request.user.user_type): # raise PermissionDenied("{} has permission to view {}".format( # request.user.user_type, rpt)) # print(rpt, request.user.user_type) action_name = request.GET.get(constants.URL_PARAM_ACTION_NAME, rpt.default_elem_action_name) ba = rpt.get_url_action(action_name) if ba is None: raise http.Http404("%s has no action %r" % (rpt, action_name)) if pk and pk != '-99999' and pk != '-99998': # ~ ar = ba.request(request=request,selected_pks=[pk]) # ~ print 20131004, ba.actor # Use url selected rows as selected PKs if defined, otherwise use the PK defined in the url path sr = request.GET.getlist(constants.URL_PARAM_SELECTED) if not sr: sr = [pk] ar = ba.request(request=request, selected_pks=sr) # print( # "20170116 views.ApiElement.get", ba, # ar.action_param_values) if len(ar.selected_rows): elem = ar.selected_rows[0] else: raise http.Http404("No permission to see {} {}.".format(rpt, action_name)) else: ar = ba.request(request=request) elem = None # ar.renderer = ui.extjs_renderer ar.renderer = ui.default_renderer ah = ar.ah if not ar.get_permission(): msg = "No permission to run {}".format(ar) # raise Exception(msg) raise PermissionDenied(msg) fmt = request.GET.get( constants.URL_PARAM_FORMAT, ba.action.default_format) if ba.action.opens_a_window: if fmt == constants.URL_FORMAT_JSON: if pk == '-99999': elem = ar.create_instance() datarec = ar.elem2rec_insert(ah, elem) elif pk == '-99998': elem = ar.create_instance() datarec = elem2rec_empty(ar, ah, elem) elif elem is None: datarec = dict( success=False, message=NOT_FOUND % (rpt, pk)) else: datarec = ar.elem2rec_detailed(elem) datarec.update(test_version_mismatch(request)) return json_response(datarec) after_show = ar.get_status(record_id=pk) tab = request.GET.get(constants.URL_PARAM_TAB, None) if tab is not None: tab = int(tab) after_show.update(active_tab=tab) return http.HttpResponse( ar.renderer.html_page( request, ba.action.label, on_ready=ar.renderer.action_call( request, ba, after_show))) # if isinstance(ba.action, actions.RedirectAction): # target = ba.action.get_target_url(elem) # if target is None: # raise http.Http404("%s failed for %r" % (ba, elem)) # return http.HttpResponseRedirect(target) if pk == '-99998': assert elem is None elem = ar.create_instance() ar.selected_rows = [elem] elif elem is None: raise http.Http404(NOT_FOUND % (rpt, pk)) return settings.SITE.kernel.run_action(ar)
def get(self, request, app_label=None, actor=None, pk=None): ui = settings.SITE.kernel rpt = requested_actor(app_label, actor) # if not rpt.get_view_permission(request.user.user_type): # raise PermissionDenied("{} has permission to view {}".format( # request.user.user_type, rpt)) # print(rpt, request.user.user_type) action_name = request.GET.get(constants.URL_PARAM_ACTION_NAME, rpt.default_elem_action_name) ba = rpt.get_url_action(action_name) if ba is None: raise http.Http404("%s has no action %r" % (rpt, action_name)) if pk and pk != '-99999' and pk != '-99998': # ~ ar = ba.request(request=request,selected_pks=[pk]) # ~ print 20131004, ba.actor # Use url selected rows as selected PKs if defined, otherwise use the PK defined in the url path sr = request.GET.getlist(constants.URL_PARAM_SELECTED) if not sr: sr = [pk] ar = ba.request(request=request, selected_pks=sr) # print( # "20170116 views.ApiElement.get", ba, # ar.action_param_values) elem = ar.selected_rows[0] else: ar = ba.request(request=request) elem = None ar.renderer = ui.extjs_renderer ah = ar.ah fmt = request.GET.get( constants.URL_PARAM_FORMAT, ba.action.default_format) if ba.action.opens_a_window: if fmt == constants.URL_FORMAT_JSON: if pk == '-99999': elem = ar.create_instance() datarec = ar.elem2rec_insert(ah, elem) elif pk == '-99998': elem = ar.create_instance() datarec = elem2rec_empty(ar, ah, elem) elif elem is None: datarec = dict( success=False, message=NOT_FOUND % (rpt, pk)) else: datarec = ar.elem2rec_detailed(elem) datarec.update(test_version_mismatch(request)) return json_response(datarec) after_show = ar.get_status(record_id=pk) tab = request.GET.get(constants.URL_PARAM_TAB, None) if tab is not None: tab = int(tab) after_show.update(active_tab=tab) return http.HttpResponse( ui.extjs_renderer.html_page( request, ba.action.label, on_ready=ui.extjs_renderer.action_call( request, ba, after_show))) # if isinstance(ba.action, actions.RedirectAction): # target = ba.action.get_target_url(elem) # if target is None: # raise http.Http404("%s failed for %r" % (ba, elem)) # return http.HttpResponseRedirect(target) if pk == '-99998': assert elem is None elem = ar.create_instance() ar.selected_rows = [elem] elif elem is None: raise http.Http404(NOT_FOUND % (rpt, pk)) 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) ar.renderer = settings.SITE.kernel.extjs_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(): 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, title=str(ar.get_title())) if ar.actor.parameters: kw.update(param_values=ar.actor.params_layout.params_store. pv2dict(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)
def result(): if not settings.SITE.build_js_cache_on_startup: settings.SITE.plugins.react.renderer.build_js_cache(False) # http.HttpResponseRedirect(target) # Seems that fetch has some issues with this... return json_response({"success": True})