示例#1
0
def chrono(label):
    '''
        Used to measure how much time is spent rendering parts of any template

        Usage:
            {% chrono:"before listing" %}
        In debug mode it will print this on the std output:
            before listing: CURRENT DATE TIME
    '''
    from digipal.utils import get_mem

    if getattr(settings, 'DEBUG_PERFORMANCE', False):
        t = datetime.now()
        d = t - chrono.last_time
        chrono.last_time = t

        if label.endswith(':'):
            chrono.last_times[label[:-1]] = t
        slice_duration = t - t
        if label.startswith(':'):
            k = label[1:]
            if k in chrono.last_times:
                slice_duration = t - chrono.last_times[k]

        message = '%5dMB %8.4f %8.4f %s' % (get_mem(), d.total_seconds(), slice_duration.total_seconds(), label)
        dplog(message)

    return''
示例#2
0
class HttpsAdminMiddleware(object):
    def process_request(self, request):
        from datetime import datetime
        request.start_time = datetime.now()

        if are_perf_info_enabled():
            dplog('START REQUEST' + '-' * 60)

        return None

    def process_response(self, request, response):
        '''Redirect a request to a non admin paths to http'''
        if getattr(settings, 'ADMIN_FORCE_HTTPS', False):
            path = request.get_full_path()
            if request.is_secure() and not re.search(ur'(?i)^/admin(/|$)',
                                                     path):
                new_url = 'http://%s%s' % (request.get_host(), path)
                response = http.HttpResponseRedirect(new_url)

        if are_perf_info_enabled():
            from datetime import datetime
            request.stop_time = datetime.now()
            dplog('%s (%s)' %
                  (request.path, request.stop_time - request.start_time))
            dplog('END RESPONSE' + '-' * 60)

        return response
示例#3
0
def chrono(label):
    '''
        Used to measure how much time is spent rendering parts of any template

        Usage:
            {% chrono:"before listing" %}
        In debug mode it will print this on the std output:
            before listing: CURRENT DATE TIME
    '''
    from digipal.utils import get_mem

    if getattr(settings, 'DEBUG_PERFORMANCE', False):
        t = datetime.now()
        d = t - chrono.last_time
        chrono.last_time = t

        if label.endswith(':'):
            chrono.last_times[label[:-1]] = t
        slice_duration = t - t
        if label.startswith(':'):
            k = label[1:]
            if k in chrono.last_times:
                slice_duration = t - chrono.last_times[k]

        message = '%5dMB %8.4f %8.4f %s' % (get_mem(), d.total_seconds(),
                                            slice_duration.total_seconds(),
                                            label)
        dplog(message)

    return ''
示例#4
0
    def process_request(self, request):
        from datetime import datetime
        request.start_time = datetime.now()

        if are_perf_info_enabled():
            dplog('START REQUEST' + '-' * 60)

        return None
示例#5
0
    def process_request(self, request):
        from datetime import datetime
        request.start_time = datetime.now()

        if are_perf_info_enabled():
            dplog('START REQUEST' + '-' * 60)

        return None
示例#6
0
    def __iter__(self):
        # NOT RECOMMENDED!
        if self.get_bulk_ids() is None:
            dplog('TextUnit.__iter__() called for ALL UNITS. Use .iterator() instead.', 'WARNING')
        else:
            dplog('TextUnit.__iter__() called', 'INFO')

        ret = []

        if self.recs is None:
            ret = self.recs = list(self.iterator())

        return ret.__iter__()
示例#7
0
    def __iter__(self):
        # NOT RECOMMENDED!
        if self.get_bulk_ids() is None:
            dplog(
                'TextUnit.__iter__() called for ALL UNITS. Use .iterator() instead.',
                'WARNING')
        else:
            dplog('TextUnit.__iter__() called', 'INFO')

        ret = []

        if self.recs is None:
            ret = self.recs = list(self.iterator())

        return ret.__iter__()