Пример #1
0
 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.')})
Пример #2
0
 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.')})