def get_form_kwargs(self): kwargs = { 'initial': self.get_initial(), 'prefix': self.get_prefix(), } submit = ExtensionSubmit() submit.ParseFromString(self.request.body) type_callable_map = copy(TYPE_CALLABLE_MAP) type_callable_map[FieldDescriptor.TYPE_BYTES] = lambda x: '[binary content]' pb_dict = protobuf_to_dict(submit, type_callable_map=type_callable_map, use_enum_labels=True) data = dict( description=submit.common_data.description, email=submit.common_data.user_email, page_url=submit.web_data.url, feedback_data=pb_dict, ip=get_client_ip(self.request) ) files = dict() if submit.screenshot.binary_content: files['screenshot'] = SimpleUploadedFile('screenshot.png', submit.screenshot.binary_content) if submit.blackbox.data: files['blackbox'] = SimpleUploadedFile('blackbox.tar', submit.blackbox.data) for attach in submit.product_specific_binary_data: key = 'attached_file' logs_key = 'system_logs' if attach.name == u'system_logs.zip' and logs_key not in files: key = logs_key files[key] = SimpleUploadedFile(attach.name, attach.data) kwargs.update(dict(data=data, files=files)) return kwargs
def form_valid(self, form): meta = self.request.POST.dict() meta.pop("appid", None) meta.pop("userid", None) obj = form.save(commit=False) if meta: obj.meta = meta obj.ip = get_client_ip(self.request) obj.save() return HttpResponse(obj.pk, status=200)
def post(self, request): try: response = build_response(request.body, ip=get_client_ip(request)) except XMLSyntaxError: logger.error('UpdateView', exc_info=True, extra=dict(request=request)) msg = b"""<?xml version="1.0" encoding="utf-8"?> <data> <message> Bad Request </message> </data>""" return HttpResponse(msg, status=400, content_type="text/html; charset=utf-8") return HttpResponse(response, content_type="text/xml; charset=utf-8")
def get_form_kwargs(self): kwargs = { 'initial': self.get_initial(), 'prefix': self.get_prefix(), } submit = ExtensionSubmit() submit.ParseFromString(self.request.body) type_callable_map = copy(TYPE_CALLABLE_MAP) type_callable_map[ FieldDescriptor.TYPE_BYTES] = lambda x: '[binary content]' pb_dict = protobuf_to_dict(submit, type_callable_map=type_callable_map, use_enum_labels=True) data = dict(description=submit.common_data.description, email=submit.common_data.user_email, page_url=submit.web_data.url, feedback_data=pb_dict, ip=get_client_ip(self.request)) files = dict() if submit.screenshot.binary_content: files['screenshot'] = SimpleUploadedFile( 'screenshot.png', submit.screenshot.binary_content) if submit.blackbox.data: blackbox_name = self.handle_file_extension( StringIO.StringIO(submit.blackbox.data).read(1024)) files['blackbox'] = SimpleUploadedFile(blackbox_name, submit.blackbox.data) for attach in submit.product_specific_binary_data: key = 'attached_file' logs_key = 'system_logs' if attach.name == u'system_logs.zip' and logs_key not in files: key = logs_key files[key] = SimpleUploadedFile(attach.name, attach.data) kwargs.update(dict(data=data, files=files)) return kwargs