def copy(self, evt, format="json"): x = self.GetTable().copy() if x: if wx.TheClipboard.Open(): if format == "csv": data = [] first_rec = True for obj in x: row = obj["fields"] if first_rec: rec = [] for key, value in row.items(): rec.append(key) data.append(rec) first_rec = False rec = [] for pos in data[0]: if pos in row: rec.append(row[pos]) else: rec.append(None) data.append(rec) writer = io.StringIO() csvwriter = csv.writer(writer) for row in data: csvwriter.writerow(row) writer.seek(0) x = writer.read() wx.TheClipboard.SetData(wx.TextDataObject(x)) if format == "json": wx.TheClipboard.SetData( wx.TextDataObject(json_dumps(x, indent=4))) wx.TheClipboard.Close() else: wx.MessageBox(_("Unable to open the clipboard"), _("Error"))
def put(request): fun = request.POST.get("func", "") title = request.POST.get("title", "") username = request.POST.get("username", "guest") param = json_loads(request.POST.get("param", "{}")) ret = get_process_manager().put(username, title, fun, **param) return HttpResponse(json_dumps(ret), content_type="application/json")
def thread_info(request): id = request.POST.get("id", 0) pos = get_process_manager().thread_info(int(id)) elem = {} elem['id'] = pos.id elem['title'] = pos.title elem['status'] = pos.status elem['username'] = pos.username elem['time_from'] = pos.time_from elem['time_to'] = pos.time_to return HttpResponse(json_dumps(elem), content_type="application/json")
def list_threads(request): id = request.POST.get("id", 0) ret = get_process_manager().list_threads(int(id)) ret2 = [] for pos in ret: elem = {} elem['id'] = pos.id elem['title'] = pos.title elem['status'] = pos.status elem['username'] = pos.username elem['time_from'] = pos.time_from elem['time_to'] = pos.time_to ret2.append(elem) return HttpResponse(json_dumps(ret2), content_type="application/json")
def inner(request, *args, **kwargs): v = func(request, *args, **kwargs) return HttpResponse(schjson.json_dumps(v), content_type="application/json")
def render(self): if self.context_data['view'].doc_type()=='odf': self['Content-Type'] = 'application/vnd.oasis.opendocument.spreadsheet' file_out, file_in = render_odf(self.template_name, Context(self.resolve_context(self.context_data))) if file_out: f = open(file_out,"rb") self.content = f.read() f.close() os.remove(file_out) file_in_name = os.path.basename(file_in) self['Content-Disposition'] = 'attachment; filename=%s' % file_in_name return self elif self.context_data['view'].doc_type()=='xlsx': self['Content-Type'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' context = self.resolve_context(self.context_data) if 'object_list' in context: transform_list = list(context['object_list']) else: transform_list = context['object'] stream_out = render_xlsx(self.template_name, transform_list) self.content = stream_out.getvalue() file_in_name = os.path.basename(self.template_name[0]) self['Content-Disposition'] = 'attachment; filename=%s' % file_in_name return self else: ret = TemplateResponse.render(self) if self.context_data['view'].doc_type()=='pdf': if self._request.META['HTTP_USER_AGENT'].startswith('Py'): self['Content-Type'] = 'application/zip' self['Content-Disposition'] = 'attachment; filename="somefilename.zip"' zip_stream = stream_from_html(self.content, stream_type='zip', base_url="file://") self.content = zip_stream.getvalue() else: self['Content-Type'] = 'application/pdf' pdf_stream = stream_from_html(self.content, stream_type='pdf', base_url="file://") self.content = pdf_stream.getvalue() elif self.context_data['view'].doc_type()=='json': self['Content-Type'] = 'application/json' mp = SimpleTabParserBase() mp.feed(self.content.decode('utf-8')) mp.close() row_title = mp.tables[-1][0] tab = mp.tables[-1][1:] if ':' in row_title[0]: x = row_title[0].split(':') title=x[0] per_page, c = x[1].split('/') row_title[0] = title else: per_page = 1 c = len(tab)-1 for i in range(len(row_title)): row_title[i] = "%d" % i row_title[0] = 'cid' row_title[-1] = 'caction' tab2 = [] for row in tab: tab2.append(dict(zip(row_title, row))) d = {} d['total'] = c d['rows'] = tab2 self.content = schjson.json_dumps(d) return ret
def send_message(self, msg): super().sendMessage(json_dumps(msg).encode("utf-8"))
async def send_message(self, msg): await self.input_queue.put(json_dumps(msg))
def wait_for_result(request): ret = get_process_manager().wait_for_result() return HttpResponse(json_dumps(ret), content_type="application/json")
def kill_all(request): id = request.POST.get("id", 0) ret = get_process_manager().kill_all(int(id)) return HttpResponse(json_dumps(ret), content_type="application/json")
def get_messages(request): id = request.POST.get("id", 0) id_start = request.POST.get("id_start", 0) ret = get_process_manager().get_messages(int(id), int(id_start)) return HttpResponse(json_dumps(ret), content_type="application/json")
def put_message(request): id = request.POST.get("id", 0) message = request.POST.get("message", "") ret = get_process_manager().put_message(int(id), message) return HttpResponse(json_dumps(ret), content_type="application/json")
def render(self): if self.context_data["view"].doc_type() == "odf": self[ "Content-Type"] = "application/vnd.oasis.opendocument.spreadsheet" file_out, file_in = render_odf( self.template_name, Context(self.resolve_context(self.context_data))) if file_out: f = open(file_out, "rb") self.content = f.read() f.close() os.remove(file_out) file_in_name = os.path.basename(file_in) self[ "Content-Disposition"] = "attachment; filename=%s" % file_in_name return self elif self.context_data["view"].doc_type() == "xlsx": self[ "Content-Type"] = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" context = self.resolve_context(self.context_data) if "object_list" in context: transform_list = list(context["object_list"]) elif "object" in context: transform_list = context["object"] else: transform_list = Context(context) stream_out = render_ooxml(self.template_name, transform_list) if type(stream_out) == tuple: with open(stream_out[0], "rb") as f: self.content = f.read() file_in_name = os.path.basename(stream_out[1]) else: self.content = stream_out.getvalue() file_in_name = os.path.basename(self.template_name[0]) self[ "Content-Disposition"] = "attachment; filename=%s" % file_in_name return self else: ret = TemplateResponse.render(self) if self.context_data["view"].doc_type() == "pdf": if self._request.META["HTTP_USER_AGENT"].startswith("Py"): self["Content-Type"] = "application/zip" self[ "Content-Disposition"] = 'attachment; filename="somefilename.zip"' zip_stream = stream_from_html(self.content, stream_type="zip", base_url="file://") self.content = zip_stream.getvalue() else: self["Content-Type"] = "application/pdf" pdf_stream = stream_from_html( self.content, stream_type="pdf", base_url="file://", info={"template_name": self.template_name}, ) self.content = pdf_stream.getvalue() elif self.context_data["view"].doc_type() == "json": self["Content-Type"] = "application/json" mp = SimpleTabParserBase() mp.feed(self.content.decode("utf-8")) mp.close() row_title = mp.tables[-1][0] tab = mp.tables[-1][1:] if ":" in row_title[0]: x = row_title[0].split(":") title = x[0] per_page, c = x[1].split("/") row_title[0] = title else: per_page = 1 c = len(tab) - 1 for i in range(len(row_title)): row_title[i] = "%d" % (i + 1) row_title[0] = "cid" row_title[-1] = "caction" row_title.append("id") tab2 = [] for row in tab: d = dict(zip(row_title, row)) if hasattr(row, "row_id"): d["id"] = row.row_id if hasattr(row, "class_attr"): d["class"] = row.class_attr tab2.append(d) d = {} d["total"] = c d["rows"] = tab2 self.content = schjson.json_dumps(d) return ret