david / django-roa (http://welldev.org/)

Turn your models into remote resources that you can access through Django's ORM. ROA stands for Resource Oriented Architecture.

Clone this repository (size: 560.7 KB): HTTPS / SSH
$ hg clone http://code.welldev.org/django-roa

Changed (Δ518 bytes):

raw changeset »

django_roa/db/exceptions.py (14 lines added, 5 lines removed)

Up to file-list django_roa/db/exceptions.py:

@@ -7,11 +7,13 @@ ROA_DJANGO_ERRORS = getattr(settings, 'R
7
7
8
8
class ROAException(Exception):
9
9
    def __init__(self, exception):
10
        if ROA_DJANGO_ERRORS:
11
            self.msg = exception.message
10
        if ROA_DJANGO_ERRORS and 'message' in exception \
11
                             and 'status_code' in exception:
12
            self.msg = force_unicode(exception.message)
12
13
            self.status_code = exception.status_code
13
14
        else:
14
15
            self.msg = force_unicode(exception)
16
            self.status_code = 'XXX'
15
17
16
18
    def __str__(self):
17
19
        if ROA_DJANGO_ERRORS and '<body>' in self.msg:
@@ -20,8 +22,10 @@ class ROAException(Exception):
20
22
    
21
23
    def parse_django_error(self):
22
24
        """Extract the summary part of a Django HTML error."""
23
        summary = self.msg.split('<body>\n<div id="summary">\n  ', 1)[1]\
24
                          .split('<th>Python Executable:</th>', 1)[0]
25
        summary = self.msg.split(u'<body>\n<div id="summary">\n  ', 1)[1]\
26
                          .split(u'<th>Python Executable:</th>', 1)[0]
27
        traceback = self.msg.split(u'\n\nTraceback:', 1)[1]\
28
                            .split(u'</textarea>', 1)[0]
25
29
        result = []
26
30
        title = None
27
31
        for line in strip_tags(summary).split('\n'):
@@ -34,7 +38,12 @@ class ROAException(Exception):
34
38
                else:
35
39
                    result.append("%s %s\n" % (title, line_content))
36
40
        result.append("Status code: %s" % self.status_code)
37
        return u" ".join([force_unicode(line) for line in result])
41
        indent, indent2 = u'  ', u'    '
42
        return u"%(summary)s %(traceback)s".strip() % {
43
            'summary': indent.join(force_unicode(line) for line in result),
44
            'traceback': indent2.join(force_unicode(line+"\n") \
45
                                        for line in traceback.split('\n')),
46
        }
38
47
39
48
40
49
class ROANotImplementedYetException(Exception):