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

1# Imports 

2 

3from django.conf import settings 

4from django.utils.timezone import now 

5from django.urls import reverse, NoReverseMatch 

6import os 

7from superdjango.utils import append_file, write_file 

8from uuid import uuid4 

9from .base import ErrorHandler 

10 

11# Exports 

12 

13__all__ = ( 

14 "CSV", 

15) 

16 

17# Classes 

18 

19 

20class CSV(ErrorHandler): 

21 """Write errors to a CSV file.""" 

22 

23 required_settings = [ 

24 "SUPERDJANGO_ERROR_CAPTURE_OUTPUT_PATH", 

25 ] 

26 

27 # def handle(self, request, exception, traceback): 

28 def handle(self, report): 

29 """Write meta data to a CSV file and traceback to text file.""" 

30 base_path = settings.SUPERDJANGO_ERROR_CAPTURE_OUTPUT_PATH 

31 file_path = os.path.join(base_path, "current.csv") 

32 

33 if not os.path.exists(file_path): 

34 write_file(file_path, "id,date,error,path,line\n") 

35 

36 current_dt = now() 

37 error_id = uuid4() 

38 

39 line = None 

40 path = None 

41 if 'lastframe' in self.context: 

42 line = self.context['lastframe']['lineno'] 

43 path = self.context['lastframe']['filename'] 

44 

45 content = [ 

46 str(error_id), 

47 str(current_dt), 

48 report.exc_type.__name__, 

49 path, 

50 str(line), 

51 ] 

52 append_file(file_path, ",".join(content) + "\n") 

53 

54 detail_path = os.path.join(base_path, "tracebacks", "%s.txt" % error_id) 

55 write_file(detail_path, report.get_traceback_text(), make_directories=True) 

56 

57 try: 

58 url = reverse("captured_error_detail", kwargs={'uuid': error_id}) 

59 return {'issue_url': url} 

60 except NoReverseMatch: 

61 pass 

62 

63 return { 

64 'identifier': error_id, 

65 }