Initial commit.
[django-ssify.git] / ssify / exceptions.py
1 class SsifyError(BaseException):
2     pass
3
4
5 class SsifyWarning(Warning):
6     pass
7
8
9 class UndeclaredSsiVarsError(SsifyError):
10     def __init__(self, request, ssi_vars):
11         super(UndeclaredSsiVarsError, self).__init__(request, ssi_vars)
12
13     def __str__(self):
14         request = self.args[0]
15         view = request.resolver_match.func
16         return "The view '%s.%s' at '%s' is marked as `ssi_included`, "\
17             "but it uses ssi variables not declared in `get_ssi_vars` "\
18             "argument: %s. " % (
19                 view.__module__, view.__name__, request.path,
20                 repr(self.args[1]))
21
22
23 class UnusedSsiVarsWarning(SsifyWarning):
24     def __init__(self, request, ssi_vars):
25         super(UnusedSsiVarsWarning, self).__init__(request, ssi_vars)
26
27     def __str__(self):
28         request = self.args[0]
29         view = request.resolver_match.func
30         return "The `ssi_included` view '%s.%s' at '%s' declares "\
31             "using SSI variables %s but it looks like they're not "\
32             "really used. " % (
33                 view.__module__, view.__name__, request.path, self.args[1])
34
35
36 class UndeclaredSsiRefError(SsifyError):
37     def __init__(self, request, var, ref_name):
38         super(UndeclaredSsiRefError, self).__init__(request, var, ref_name)
39
40     def __str__(self):
41         request = self.args[0]
42         view = request.resolver_match.func
43         return "Error while rendering ssi_included view '%s.%s' at '%s': "\
44             "SSI variable %s references variable %s, which doesn't match "\
45             "any variable declared in `get_ssi_vars`. " % (
46                 view.__module__, view.__name__, request.path,
47                 repr(self.args[1]), self.args[2])
48
49
50 class NoLangFieldError(SsifyError):
51     def __init__(self, request):
52         super(NoLangFieldError, self).__init__(request)
53
54     def __str__(self):
55         request = self.args[0]
56         view = request.resolver_match.func
57         return "The view '%s.%s' at '%s' is marked as `ssi_included` "\
58             "with use_lang=True, but its URL match doesn't provide "\
59             "a 'lang' keyword argument for language. " % (
60             view.__module__, view.__name__, request.path)
61
62
63 class SsiVarsDependencyCycleError(SsifyError):
64     def __init__(self, ssi_vars):
65         super(SsiVarsDependencyCycleError, self).__init__(ssi_vars)
66
67     def __str__(self):
68         return "Dependency cycle in SSI variables: %s." % self.args[0]