Exemple #1
0
    def process_response(self, request, response):
        if self.is_resource(request):
            return response

        from django.core.context_processors import debug
        import settings
        self.localOut = hasattr(settings,
                                'CONSOLE_SQL_LOG') and settings.CONSOLE_SQL_LOG
        if settings.DEBUG and request.META.get(
                'REMOTE_ADDR') in settings.INTERNAL_IPS:
            try:
                queries = debug(request)['sql_queries']
            except:
                queries = None
            if queries:
                if not hasattr(self, 'f'):
                    try:
                        self.f = codecs.open(
                            os.path.join(settings.PROJECT_ROOT, 'sql.log'),
                            'wt', 'utf-8')
                    except:
                        pass
#                if len(queries)>0:
#self.out('-----------------------------------------------\n')
                i = 1
                for query in queries:
                    sql = force_unicode(query['sql'])
                    #                    sql = sql[:1024]
                    self.out(u'%03d:    %s: %s\n\n' %
                             (i, force_unicode(query['time']), sql))
                    i = i + 1

#                if len(queries)>0 and self.localOut:
#                    print '-----------------------------------------------\n'
        return response
Exemple #2
0
def debug(request):
    # override the core processor to avoid depending on the request
    try:
        context_extras = context_processors.debug(request)
    except AttributeError:
        context_extras = {}
    return context_extras
Exemple #3
0
    def process_response(self, request, response):
        if self.is_resource(request):
            return response

        from django.core.context_processors import debug
        import settings
        self.localOut=hasattr(settings,'CONSOLE_SQL_LOG') and settings.CONSOLE_SQL_LOG
        if settings.DEBUG and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
            try:
                queries=debug(request)['sql_queries']
            except:
                queries=None
            if queries:
                if not hasattr(self,'f') :
                    try:
                        self.f = codecs.open(os.path.join(settings.PROJECT_ROOT, 'sql.log'), 'wt', 'utf-8')
                    except:
                        pass
#                if len(queries)>0:
                    #self.out('-----------------------------------------------\n')
                i=1
                for query in queries:
                    sql = force_unicode(query['sql'])
#                    sql = sql[:1024]
                    self.out(u'%03d:    %s: %s\n\n' % (i, force_unicode(query['time']), sql))
                    i=i+1               

#                if len(queries)>0 and self.localOut:
#                    print '-----------------------------------------------\n'
        return response
def debug(request):
    '''Return context variables that may be helpful for debugging.
    Extends :meth:`django.core.context_processors.debug` to include
    output from a secondary (esd) database.

    Runs the :meth:`django.core.context_processors.debug`; if the
    returned context indicates that debugging should be enabled and
    the ``esd`` database is configured, adds any queries made against
    the esd database to the ``sql_queries`` added to the context.
    '''
    context_extras = context_processors.debug(request)
    context_extras['ENABLE_BETA_WARNING'] = getattr(settings, 'ENABLE_BETA_WARNING', False)
    if 'debug' in context_extras and context_extras['debug'] \
           and 'esd' in settings.DATABASES:
        from django.db import connections
        esd_queries = connections['esd'].queries
        for q in esd_queries:
            q['db'] = 'esd'
        context_extras['sql_queries'].extend(esd_queries)
    return context_extras
def debug(request):
    '''Return context variables that may be helpful for debugging.
    Extends :meth:`django.core.context_processors.debug` to include
    output from a secondary (esd) database.

    Runs the :meth:`django.core.context_processors.debug`; if the
    returned context indicates that debugging should be enabled and
    the ``esd`` database is configured, adds any queries made against
    the esd database to the ``sql_queries`` added to the context.
    '''
    context_extras = context_processors.debug(request)
    context_extras['ENABLE_BETA_WARNING'] = getattr(settings,
                                                    'ENABLE_BETA_WARNING',
                                                    False)
    if 'debug' in context_extras and context_extras['debug'] \
           and 'esd' in settings.DATABASES:
        from django.db import connections
        esd_queries = connections['esd'].queries
        for q in esd_queries:
            q['db'] = 'esd'
        context_extras['sql_queries'].extend(esd_queries)
    return context_extras
def print_queries(context):
    return context_processors.debug(context['request'])
Exemple #7
0
def print_queries(context):
    return context_processors.debug(context['request'])