Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1from builtins import object 

2import io 

3import csv 

4import re 

5from decimal import Decimal 

6from datetime import datetime 

7 

8 

9class renderer_plain_text(object): 

10 """ 

11 *The plain_text renderer - can return content to browser or a file to download* 

12 """ 

13 

14 def __init__(self, info): 

15 pass 

16 

17 def __call__(self, content, system): 

18 

19 request = system.get('request') 

20 if request is not None: 

21 response = request.response 

22 ct = response.content_type 

23 if ct == response.default_content_type: 

24 response.content_type = 'text/plain' 

25 

26 # setup the file if "download" is true 

27 if "filename" in request.params: 

28 now = datetime.now() 

29 now = now.strftime("%Y%m%dt%H%M%S") 

30 filename = request.params["filename"].replace(" ", "_") 

31 filename = """%(filename)s_%(now)s""" % locals() 

32 response.content_type = 'text/plain' 

33 response.content_disposition = "attachment; filename=%(filename)s" % locals( 

34 ) 

35 

36 # create a virutal file to write the content to 

37 output = io.StringIO(content) 

38 output = output.getvalue() 

39 output = output.strip() 

40 returnOutput = output 

41 

42 return returnOutput