def export_detail(request, o_id): """ 导出住院结算详情表 :param request: :param o_id: :return: """ a = Workbook() sheet = a.active # sheet = a.add_sheet(u'住院办理表') # sheet.title = u'结算详情表' list_obj = PatientOne.objects.get(id=o_id) b = [ list_obj.id, list_obj.patient_name, list_obj.patient_medicine, list_obj.patient_live_day, list_obj.patient_one_enter_time ] c = ['病历号', '姓名', '收费项目', '收费金额', '收费日期', []] c[1] = b for i in range(len(c)): for j in range(len(c[i])): sheet.cell(i + 1, j + 1, c[i][j]) exits_file = os.path.exists('结算详情表.xlsx') if exits_file: os.remove(r'结算详情表.xlsx') a.save('d:\\结算详情表.xlsx') # a.close() a = open('d:\\住院详情表.xlsx', 'rb') response = HttpResponse() response.content = a response['content-Type'] = 'application/octet-stream' response['Content-Disposition'] = 'attachment;filename=住院详情表.xls' return response
def export_excel_patient(request): """ 导出住院结算Excel表格 :param request: :return: """ a = Workbook() sheet = a.active # sheet = a.add_sheet(u'住院办理表') sheet.title = u'住院结算表' list_obj = Money.objects.all() e = [[], ] for obj in list_obj: b = [obj.fk_patientone.id, obj.fk_patientone.patient_name, obj.collect_money, obj.is_hospital] e.append(b) c = ['病历号', '姓名', '押金', '状态'] e[0] = c print(e) for i in range(len(e)): for j in range(len(e[i])): sheet.cell(i + 1, j + 1, e[i][j]) exits_file = os.path.exists('住院结算表.xlsx') if exits_file: os.remove(r'住院结算表.xlsx') a.save('d:\\住院结算表.xlsx') response = HttpResponse() a = open('d:\\住院结算表.xlsx', 'rb') response.content = a response['content-Type'] = 'application/octet-stream' response['Content-Disposition'] = 'attachment;filename=住院结算表.xls' return response
def export_excel(request): """ 导出住院办理Excel表格 :param request: :return: """ a = Workbook() sheet = a.active sheet.title = u'住院办理表' list_obj = PatientOne.objects.all() e = [ [], ] for obj in list_obj: b = [ obj.id, obj.patient_name, obj.patient_main_doctor, obj.patient_one_enter_time, obj.fk_patient_department_id, obj.patient_status ] e.append(b) c = ['病历号', '姓名', '主治医生', '入院时间', '科室', '状态'] e[0] = c for i in range(len(e)): for j in range(len(e[i])): sheet.cell(i + 1, j + 1, e[i][j]) exits_file = os.path.exists('住院办理表.xlsx') if exits_file: os.remove(r'住院办理表.xlsx') a.save('d:\\住院办理表.xlsx') a = open('d:\\住院办理表.xlsx', 'rb') response = HttpResponse() response.content = a response['content-Type'] = 'application/octet-stream' response['Content-Disposition'] = 'attachment;filename=住院办理表.xls' return response
def response_index(req): response = HttpResponse() response.content = "content" response.write("write") response.flush() response.status_code = 404 return response
def insert(request): response = HttpResponse() response.status_code = 200 if request.method == 'POST': lat = request.POST.get('latitude') lng = request.POST.get('longitude') test_key = b'\x75\x37\x34\x72\x53\x76\x41\x6e\x4b\x46\x68\x55\x4e\x52\x55\x62' \ b'\x4c\x6f\x48\x69\x72\x31\x35\x71\x4d\x63\x45\x7a\x59\x7a\x6e\x51' # test_iv = b'\x9E\x7B\x98\x04\x41\x6D\xF6\xC7\x0E\x1C\xF3\x4E\x9F\x75\x2D\x08' iv = bytes.fromhex(request.POST.get('data')[:32]) cyph = AES.new(test_key, AES.MODE_CBC, iv) decrypted = cyph.decrypt(bytes.fromhex( request.POST.get('data')[32:])).decode("ascii") data = json.loads(decrypted.replace(chr(0), '')) timestamp = datetime.now() item = DataItem(latitude=lat, longitude=lng, data=data['val'], timestamp=timestamp, sensor_id=data['id']) item.save() elif request.method == 'GET': response.content = 'You must send POST queries!' return response
def index(request): rep = HttpResponse() if not request.COOKIES.get('p1', None): rep.set_cookie('p1', 1) else: print request.COOKIES['p1'] rep.content = 'ok' return rep # 响应
def make_response(status=200, content_type='text/plain', content=None): """ Construct a response to a request. Also, content-type is text/plain by default since IE9 and below chokes on application/json. """ response = HttpResponse() response.status_code = status response['Content-Type'] = content_type response.content = content return response
def get(self, request, doc_id): document = Document.objects.get(id=doc_id) product = Product.objects.get(id=doc_id) if product.users.filter(id=request.user.id).exists(): response = HttpResponse() response.content = document.file.read() response[ "Content-Disposition"] = "attachment; filename={0}".format( document.pretty_name) return response return HttpResponse("No haz comprado este articulo")
def login(request): if request.method == 'POST': # print(request.META['HTTP_ACCESSTOKEN']) # print(request.POST) user = request.POST.get("user", None) pwd = request.POST.get("pwd", None) check_code = request.POST.get("auth_code", None) check_code = check_code.lower() server_check_code = request.session['check_code'] server_check_code = server_check_code.lower() res = {} Hres = HttpResponse() if check_code == server_check_code: user_info = UserInfo.objects.filter(user=user) if user_info[0].user == user and user_info[0].pwd == pwd: # 颁发签证 nonce = ''.join( random.sample(string.ascii_letters + string.digits, 16)) key = user_info[0].key t = int(time.time()) sign_array = [str(t), nonce, key] sign_str = "".join(sorted(sign_array)) server_signature = hashlib.sha1(sign_str.encode()).hexdigest() # 保存签名并设置过期时间 request.session['sign'] = server_signature request.session['sign_timeout'] = time.time( ) + 3600 * 24 # 默认过期时间一天 res = { "errNum": 0, "errMsg": "ok", "access_token": server_signature, } request.session['user'] = user Hres.set_cookie(key="accessToken", value=server_signature, expires=time.time() + 36000) else: res = { "errNum": 100, "errMsg": "用户名或密码错误", } else: res = { "errNum": 102, "errMsg": "验证码错误", } time.sleep(1) Hres.content = json.dumps(res) Hres.content_type = 'application/json' return Hres else: auth_code(request) return render(request, 'host_manage/login.html')
def get(self, request, path, include_body=True): session_dir = getsettings( 'session_dir', os.path.join(getsettings('BASE_DIR'), 'sessions')) #default session dir user = self.request.session.get('gateone_user') if user and 'session' in self.request.session.get('gateone_user'): session = user['session'] else: return HttpResponse('User session is not valid') filepath = os.path.join(session_dir, session, 'downloads', path) abspath = os.path.abspath(filepath) if not os.path.exists(abspath): return HttpResponse(self.get_error_html(404), status=404) if not os.path.isfile(abspath): return HttpResponse("%s is not a file" % (path), status=403) import stat, mimetypes stat_result = os.stat(abspath) modified = datetime.datetime.fromtimestamp(stat_result[stat.ST_MTIME]) response = HttpResponse() response["Last-Modified"] = modified mime_type, encoding = mimetypes.guess_type(abspath) if mime_type: response["Content-Type"] = mime_type # Set the Cache-Control header to private since this file is not meant # to be public. response["Cache-Control"] = "private" # Add some additional headers response['Access-Control-Allow-Origin'] = '*' # Check the If-Modified-Since, and don't send the result if the # content has not been modified ims_value = self.request.META.get('If-Modified-Since', None) if ims_value is not None: import email.utils date_tuple = email.utils.parsedate(ims_value) if_since = datetime.datetime.fromtimestamp(time.mktime(date_tuple)) if if_since >= modified: response.status = 304 return response # Finally, deliver the file with io.open(abspath, "rb") as file: data = file.read() hasher = hashlib.sha1() hasher.update(data) response["Etag"] = '"%s"' % hasher.hexdigest() if include_body: response.content = data response.status = 200 return response else: assert self.request.method in ("HEAD", "head") response["Content-Length"] = len(data)
def to_excel(request): patients = PatientOne.objects.all() content = [["病人编号", "病人姓名", "病人性别", "挂号科室", "主治医生", "挂号时间"]] for patient in patients: content.append([patient.id, patient.patient_name, patient.patient_sex, patient.fk_patient_depart.depart_name, patient.fk_patient_doctor.fk_doctor_user.user_name, patient.patient_registed_time]) print(content) f = openpyxl.Workbook() d = f.active d.title = '挂号情况' for i in range(0, len(content)): for j in range(0, len(content[i])): d.cell(i + 1, j + 1, str(content[i][j])) f.save(r'a.xlsx') f = open(r'a.xlsx', 'rb') h = HttpResponse() h.content = f h['Content-TYpe'] = "application/octet-stream" h['Content-Disposition'] = 'attachment;filename="a.xlsx"' return h
def resize(request, image_pk, width_str, height_str): db_image = Image.objects.get(pk=image_pk) response = HttpResponse(mimetype=db_image.content_type or 'image') width, height = int(width_str), int(height_str) if settings.ALLOW_CACHE_RESIZED_IMAGES: resized_path = list(os.path.splitext(db_image.file.path)) resized_path.insert(1, '_%dx%d' % (width, height)) resized_path = ''.join(resized_path) if os.path.exists(resized_path): response.content = file(resized_path) return response image_type = db_image.content_type.replace('image/', '').upper() image = PIL.Image.open(db_image.file).convert('RGBA') resized = image.resize((int(width), int(height)), PIL.Image.ANTIALIAS) if settings.ALLOW_CACHE_RESIZED_IMAGES: resized.save(resized_path, image_type) resized.save(response, image_type) return response
def aaa_a_b(request): response = HttpResponse() response.set_cookie('name', 'abc', path='/aaa/a/b/') response.content = '测试' return response
def wazi(request): response = HttpResponse() response.set_cookie('abc', '123', domain='.dongyang.com') response.content = '测试袜子站种的cookie是否在鞋站中找到' return response
def __call__(self, request): q=request.META['QUERY_STRING'] q=('?'+q) if q else '' url=request.path+q try: # if not U.DEBUG:raise Exception(request._stream.stream) ip='' try: if U.isLinux():ip,port=request._stream.stream.stream.raw._sock.getpeername() else :ip,port=request._stream.stream.raw._sock.getpeername() except: ip=request.META[ 'REMOTE_ADDR'] port=py.No("can't access stream.raw._sock.getpeername() ") ip=N.ip_location(ip,reverse_ip=True) log_obj={ 'url': url, 'ua': request.environ['HTTP_USER_AGENT'], 'data':request.body, 'ip':ip, 'port':port, } self.s=log_obj F.write('log/8000/'+U.stime(),U.pformat(log_obj)) except Exception as e: self.e=e F.write('log/8000/e'+U.stime(),U.pformat(e)) if url.startswith('/#rpc\n'): self.g['self']=self #test? request.url=url self.g['q']=request response = HttpResponse() response['content-type'] = 'text/plain; charset=utf-8' response['X-XSS-Protection']='0' response['Access-Control-Allow-Origin'] = '*' self.g['p']=response r=U.execStrResult(url[1:],globals=self.g) if not response.content: response.content=r return response # Code to be executed for each request before # the view (and later middleware) are called. response = self.get_response(request) # Code to be executed for each request/response after # the view is called. return response # from django import template # register = template.Library() # @register.tag(name='eval') # def do_eval(parser, token): # "Usage: {% eval %}1 + 1{% endeval %}" # nodelist = parser.parse(('endeval',)) # class EvalNode(template.Node): # def render(self, context): # return eval(nodelist.render(context)) # parser.delete_first_token() # return EvalNode()