Last active
August 29, 2015 14:16
-
-
Save rvause/5ce3653e0dbc81d781c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ConsoleOutputDammit(object): | |
| class Colors: | |
| HEADER = '\033[95m' | |
| OKBLUE = '\033[94m' | |
| OKPINK = '\033[95m' | |
| OKGREEN = '\033[92m' | |
| OKCYAN = '\033[96m' | |
| WARNING = '\033[93m' | |
| FAIL = '\033[91m' | |
| NATIVE = '\033[m' | |
| def process_response(self, request, response): | |
| if settings.TESTING: | |
| return response | |
| posts = ['PUT', 'POST', 'DELETE'] | |
| if response.status_code == 200 and request.method == 'GET': | |
| color = self.Colors.OKGREEN | |
| elif response.status_code == 200: | |
| color = self.Colors.OKBLUE | |
| elif response.status_code == 302 and request.method in posts: | |
| color = self.Colors.OKPINK | |
| elif response.status_code in [301, 302]: | |
| color = self.Colors.OKCYAN | |
| elif response.status_code == 404: | |
| color = self.Colors.WARNING | |
| elif response.status_code == 500: | |
| color = self.Colors.FAIL | |
| elif response.status_code == 403: | |
| color = self.Colors.FAIL | |
| else: | |
| color = self.Colors.NATIVE | |
| if request.is_ajax(): | |
| color = color.replace('9', '3') | |
| sys.stderr.write( | |
| '{color}{is_ajax} {method} {status_code} {path}{reset}\n'.format( | |
| color=color, | |
| is_ajax='@' if request.is_ajax() else '#', | |
| method=request.method.ljust(4), | |
| status_code=response.status_code, | |
| path=request.get_full_path(), | |
| reset=self.Colors.NATIVE | |
| ) | |
| ) | |
| return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment