def get(self, request, pk, *args, **kwargs): try: mdn = models.MDN.objects.get(message_id=pk) if request.GET['action'] == 'downl': response = HttpResponse(content_type='multipart/report') disposition_type = 'attachment' response[ 'Content-Disposition'] = disposition_type + '; filename=' + pk + '.mdn' response.write(as2utils.readdata(mdn.file)) return response elif request.GET['action'] == 'this': file_obj = dict() file_obj['name'] = pk + '.mdn' file_obj['id'] = pk file_obj['content'] = as2utils.readdata(mdn.file, charset='utf-8', errors='ignore') file_obj['direction'] = mdn.get_status_display() file_obj['type'] = 'AS2 MDN' file_obj['headers'] = dict(HeaderParser().parsestr( mdn.headers or '').items()) return render(request, self.template_name, {'file_obj': file_obj}) except Exception: return render(request, self.template_name, {'error_content': _(u'No such file.')})
def get(self, request, pk, *args, **kwargs): try: message = models.Message.objects.get(message_id=pk) payload = message.payload if request.GET['action'] == 'downl': response = HttpResponse(content_type=payload.content_type) dispositiontype = 'attachment' response['Content-Disposition'] = dispositiontype + '; filename=' + payload.name response.write(as2utils.readdata(payload.file)) return response elif request.GET['action'] == 'this': file_obj = dict() file_obj['name'] = payload.name file_obj['id'] = pk file_obj['content'] = as2utils.readdata(payload.file,charset='utf-8',errors='ignore') if payload.content_type == 'application/EDI-X12': file_obj['content'] = viewlib.indent_x12(file_obj['content']) elif payload.content_type == 'application/EDIFACT': file_obj['content'] = viewlib.indent_edifact(file_obj['content']) elif payload.content_type == 'application/XML': file_obj['content'] = viewlib.indent_xml(file_obj['content']) file_obj['direction'] = message.get_direction_display() file_obj['type'] = 'AS2 MESSAGE' file_obj['headers'] = dict(HeaderParser().parsestr(message.headers or '').items()) return render(request,self.template_name,{'file_obj': file_obj}) except Exception,e: return render(request,self.template_name,{'error_content': _(u'No such file.')})
def get(self, request, pk, *args, **kwargs): try: message = models.Message.objects.get(message_id=pk) payload = message.payload if request.GET['action'] == 'downl': # Returns the payload contents as an attachment, thus enabling users to download the data response = HttpResponse(content_type=payload.content_type) disposition_type = 'attachment' response['Content-Disposition'] = disposition_type + '; filename=' + payload.name response.write(as2utils.readdata(payload.file)) return response elif request.GET['action'] == 'this': # Displays the payload contents, Formatting is applied based on the content type of the message. file_obj = dict() file_obj['name'] = payload.name file_obj['id'] = pk file_obj['content'] = as2utils.readdata(payload.file, charset='utf-8', errors='ignore') if payload.content_type == 'application/EDI-X12': file_obj['content'] = viewlib.indent_x12(file_obj['content']) elif payload.content_type == 'application/EDIFACT': file_obj['content'] = viewlib.indent_edifact(file_obj['content']) elif payload.content_type == 'application/XML': file_obj['content'] = viewlib.indent_xml(file_obj['content']) file_obj['direction'] = message.get_direction_display() file_obj['type'] = 'AS2 MESSAGE' file_obj['headers'] = dict(HeaderParser().parsestr(message.headers or '').items()) return render(request, self.template_name, {'file_obj': file_obj}) except Exception: return render(request, self.template_name, {'error_content': _(u'No such file.')})
def get(self, request, pk, *args, **kwargs): try: mdn = models.MDN.objects.get(message_id=pk) message = mdn.omessage mdnDirection = { 'IN' : 'Sent', 'OUT' : 'Received' } if request.GET['action'] == 'downl': response = HttpResponse(content_type='multipart/report') dispositiontype = 'attachment' response['Content-Disposition'] = dispositiontype + '; filename=' + pk + '.mdn' response.write(as2utils.readdata(mdn.file)) return response elif request.GET['action'] == 'this': file_obj = dict() file_obj['name'] = pk + '.mdn' file_obj['id'] = pk file_obj['content'] = as2utils.readdata(mdn.file,charset='utf-8',errors='ignore') file_obj['direction'] = mdn.get_status_display() file_obj['type'] = 'AS2 MDN' file_obj['headers'] = dict(HeaderParser().parsestr(mdn.headers or '').items()) return render(request,self.template_name,{'file_obj': file_obj}) except Exception,e: return render(request,self.template_name,{'error_content': _(u'No such file.')})