Пример #1
0
    def handle(self, *args, **options):
        self.options = options
        self.base_url = options['baseurl'] or absolutify('')

        if options['all']:
            logging.info(u"Querying ALL %s documents..." %
                         Document.objects.count())
            docs = Document.objects.order_by('-modified').iterator()
            for doc in docs:
                self.do_render(doc)

        else:
            if not len(args) == 1:
                raise CommandError("Need at least one document path to render")
            for path in args:
                # Accept a single page path from command line, but be liberal in
                # what we accept, eg: /en-US/docs/CSS (full path); /en-US/CSS (no
                # /docs); or even en-US/CSS (no leading slash)
                if path.startswith('/'):
                    path = path[1:]
                locale, sep, slug = path.partition('/')
                head, sep, tail = slug.partition('/')
                if head == 'docs':
                    slug = tail
                self.do_render(Document.objects.get(locale=locale, slug=slug))
Пример #2
0
    def test_absolutify(self, get_current):
        get_current.return_value.domain = 'testserver'

        eq_(absolutify(''), 'https://testserver/')
        eq_(absolutify('/'), 'https://testserver/')
        eq_(absolutify('//'), 'https://testserver/')
        eq_(absolutify('/foo/bar'), 'https://testserver/foo/bar')
        eq_(absolutify('http://domain.com'), 'http://domain.com')

        site = Site(domain='otherserver')
        eq_(absolutify('/woo', site), 'https://otherserver/woo')

        eq_(absolutify('/woo?var=value'), 'https://testserver/woo?var=value')
        eq_(absolutify('/woo?var=value#fragment'),
            'https://testserver/woo?var=value#fragment')
Пример #3
0
    def test_absolutify(self, get_current):
        get_current.return_value.domain = 'testserver'

        eq_(absolutify(''), 'https://testserver/')
        eq_(absolutify('/'), 'https://testserver/')
        eq_(absolutify('//'), 'https://testserver/')
        eq_(absolutify('/foo/bar'), 'https://testserver/foo/bar')
        eq_(absolutify('http://domain.com'), 'http://domain.com')

        site = Site(domain='otherserver')
        eq_(absolutify('/woo', site), 'https://otherserver/woo')

        eq_(absolutify('/woo?var=value'), 'https://testserver/woo?var=value')
        eq_(absolutify('/woo?var=value#fragment'),
            'https://testserver/woo?var=value#fragment')
Пример #4
0
    def handle(self, *args, **options):
        self.options = options
        self.base_url = options['baseurl'] or absolutify('')
        if self.options['nocache']:
            self.cache_control = 'no-cache'
        else:
            self.cache_control = 'max-age=0'

        if options['all']:
            # Query all documents, excluding those whose `last_rendered_at` is
            # within `min_render_age` or NULL.
            min_render_age = (
                datetime.datetime.now() -
                datetime.timedelta(seconds=self.options['min_age']))
            docs = Document.objects.filter(
                Q(last_rendered_at__isnull=True)
                | Q(last_rendered_at__lt=min_render_age))
            docs = docs.order_by('-modified')
            docs = docs.values_list('id', flat=True)

            self.chain_render_docs(docs)

        else:
            if not len(args) == 1:
                raise CommandError('Need at least one document path to render')
            for path in args:
                # Accept a single page path from command line, but be liberal
                # in what we accept, eg: /en-US/docs/CSS (full path);
                # /en-US/CSS (no /docs); or even en-US/CSS (no leading slash)
                if path.startswith('/'):
                    path = path[1:]
                locale, sep, slug = path.partition('/')
                head, sep, tail = slug.partition('/')
                if head == 'docs':
                    slug = tail
                doc = Document.objects.get(locale=locale, slug=slug)
                log.info(u'Rendering %s (%s)' % (doc, doc.get_absolute_url()))
                try:
                    render_document(doc.pk, self.cache_control, self.base_url,
                                    self.options['force'])
                    log.debug(u'DONE.')
                except DocumentRenderingInProgress:
                    log.error(
                        u'Rendering is already in progress for this document.')
Пример #5
0
    def handle(self, *args, **options):
        self.options = options
        self.base_url = options['baseurl'] or absolutify('')
        if self.options['nocache']:
            self.cache_control = 'no-cache'
        else:
            self.cache_control = 'max-age=0'

        if options['all']:
            # Query all documents, excluding those whose `last_rendered_at` is
            # within `min_render_age` or NULL.
            min_render_age = (
                datetime.datetime.now() -
                datetime.timedelta(seconds=self.options['min_age']))
            docs = Document.objects.filter(
                Q(last_rendered_at__isnull=True) |
                Q(last_rendered_at__lt=min_render_age))
            docs = docs.order_by('-modified')
            docs = docs.values_list('id', flat=True)

            self.chain_render_docs(docs)

        else:
            if not len(args) == 1:
                raise CommandError('Need at least one document path to render')
            for path in args:
                # Accept a single page path from command line, but be liberal
                # in what we accept, eg: /en-US/docs/CSS (full path);
                # /en-US/CSS (no /docs); or even en-US/CSS (no leading slash)
                if path.startswith('/'):
                    path = path[1:]
                locale, sep, slug = path.partition('/')
                head, sep, tail = slug.partition('/')
                if head == 'docs':
                    slug = tail
                doc = Document.objects.get(locale=locale, slug=slug)
                log.info(u'Rendering %s (%s)' % (doc, doc.get_absolute_url()))
                try:
                    render_document(doc.pk, self.cache_control, self.base_url,
                                    self.options['force'])
                    log.debug(u'DONE.')
                except DocumentRenderingInProgress:
                    log.error(
                        u'Rendering is already in progress for this document.')