Пример #1
0
 def clean_timezone(self):
     timezone = self.cleaned_data['timezone']
     try:
         with override_timezone(timezone):
             return timezone
     except:
         raise forms.ValidationError(INVALID_TIMEZONE_ERROR)
Пример #2
0
def export_event(event, destination):
    with override_settings(
        COMPRESS_ENABLED=True, COMPRESS_OFFLINE=True
    ), override_timezone(event.timezone):
        with fake_admin(event) as get:
            logging.info("Collecting URLs for export")
            urls = [*event_urls(event)]
            assets = set()

            logging.info(f"Exporting {len(urls)} pages")
            for url in map(get_path, urls):
                content = dump_content(destination, url, get)
                assets |= set(map(get_path, find_assets(content)))

            css_assets = set()

            logging.info(f"Exporting {len(assets)} static files from HTML links")
            for url in assets:
                content = dump_content(destination, url, get)

                if url.endswith(".css"):
                    css_assets |= set(find_urls(content))

            logging.info(f"Exporting {len(css_assets)} files from CSS links")
            for url in (get_path(urllib.parse.unquote(url)) for url in css_assets):
                dump_content(destination, url, get)
Пример #3
0
    def handle(self, *args, **options):
        event_slug = options.get('event')
        try:
            event = Event.objects.get(slug__iexact=event_slug)
        except Event.DoesNotExist:
            raise CommandError(
                f'Could not find event with slug "{event_slug}".')

        self._exporting_event = event
        translation.activate(event.locale)

        output_dir = self.get_output_dir(event)
        with override_settings(
                COMPRESS_ENABLED=True,
                COMPRESS_OFFLINE=True,
                BUILD_DIR=output_dir,
                MEDIA_URL=os.path.join(settings.MEDIA_URL, event_slug),
                MEDIA_ROOT=os.path.join(settings.MEDIA_ROOT, event_slug),
        ):
            with override_timezone(event.timezone):
                super().handle(*args, **options)
                if options.get('zip', False):
                    make_archive(
                        base_name=output_dir,
                        format='zip',
                        root_dir=settings.HTMLEXPORT_ROOT,
                        base_dir=event.slug,
                    )
                    output_dir += '.zip'
        self.stdout.write(output_dir)