def handle(self, *args, **options):
        from django.conf import settings
        style = color_style()
        template_dirs = set(settings.TEMPLATE_DIRS)
        template_dirs |= set(options.get('includes', []))
        template_dirs |= set(
            getattr(
                settings,
                'VALIDATE_TEMPLATES_EXTRA_TEMPLATE_DIRS',
                []))
        settings.TEMPLATE_DIRS = list(template_dirs)
        settings.TEMPLATE_DEBUG = True
        verbosity = int(options.get('verbosity', 1))
        errors = 0

        template_loader = Loader()

        # Replace built in template tags with our own validating versions
        if options.get('check_urls', False):
            add_to_builtins('django_extensions.utils.validatingtemplatetags')

        for template_dir in template_dirs:
            for root, dirs, filenames in os.walk(template_dir):
                for filename in filenames:
                    if filename.endswith(".swp"):
                        continue
                    if filename.endswith("~"):
                        continue
                    filepath = os.path.join(root, filename)
                    if verbosity > 1:
                        print(filepath)
                    validatingtemplatetags.before_new_template(
                        options.get('force_new_urls', False))
                    try:
                        template_loader.load_template(filename, [root])
                    except Exception as e:
                        errors += 1
                        print(
                            "%s: %s" %
                            (filepath, style.ERROR(
                                "%s %s" %
                                (e.__class__.__name__, str(e)))))
                    template_errors = validatingtemplatetags.get_template_errors()
                    for origin, line, message in template_errors:
                        errors += 1
                        print(
                            "%s(%s): %s" %
                            (origin, line, style.ERROR(message)))
                    if errors and options.get('break', False):
                        raise CommandError("Errors found")

        if errors:
            raise CommandError("%s errors found" % errors)
        print("%s errors found" % errors)
    def handle(self, *args, **options):
        from django.conf import settings
        style = color_style()
        template_dirs = set(settings.TEMPLATE_DIRS)
        template_dirs |= set(options.get('includes', []))
        template_dirs |= set(
            getattr(settings, 'VALIDATE_TEMPLATES_EXTRA_TEMPLATE_DIRS', []))
        settings.TEMPLATE_DIRS = list(template_dirs)
        settings.TEMPLATE_DEBUG = True
        verbosity = int(options.get('verbosity', 1))
        errors = 0

        template_loader = Loader()

        # Replace built in template tags with our own validating versions
        if options.get('check_urls', False):
            add_to_builtins('django_extensions.utils.validatingtemplatetags')

        for template_dir in template_dirs:
            for root, dirs, filenames in os.walk(template_dir):
                for filename in filenames:
                    if filename.endswith(".swp"):
                        continue
                    if filename.endswith("~"):
                        continue
                    filepath = os.path.join(root, filename)
                    if verbosity > 1:
                        print(filepath)
                    validatingtemplatetags.before_new_template(
                        options.get('force_new_urls', False))
                    try:
                        template_loader.load_template(filename, [root])
                    except Exception as e:
                        errors += 1
                        print("%s: %s" %
                              (filepath,
                               style.ERROR("%s %s" %
                                           (e.__class__.__name__, str(e)))))
                    template_errors = validatingtemplatetags.get_template_errors(
                    )
                    for origin, line, message in template_errors:
                        errors += 1
                        print("%s(%s): %s" %
                              (origin, line, style.ERROR(message)))
                    if errors and options.get('break', False):
                        raise CommandError("Errors found")

        if errors:
            raise CommandError("%s errors found" % errors)
        print("%s errors found" % errors)
Exemple #3
0
    def handle(self, *args, **options):
        context = Context({
            'object_list': Registration.objects.all(),
        })
        loader = Loader()
        template, _ = loader.load_template(
            'willard/registration_list_table.html')
        filedata = template.render(context)

        bucket_name = 'assets.sunlightfoundation.com'
        connection = S3Connection(settings.MEDIASYNC.get('AWS_KEY'),
                                  settings.MEDIASYNC.get('AWS_SECRET'))

        headers = {
            "x-amz-acl": "public-read",
            "Content-Type": 'text/csv',
        }

        # calculate md5 digest of filedata
        checksum = hashlib.md5(filedata)
        hexdigest = checksum.hexdigest()
        b64digest = base64.b64encode(checksum.digest())

        bucket = connection.get_bucket(bucket_name)
        key = Key(bucket)
        key.key = '/reporting/uploads/%s' % 'lobbyist_registrations.html'
        key.set_contents_from_string(filedata,
                                     headers=headers,
                                     md5=(hexdigest, b64digest))

        print key.generate_url(60 * 60 * 24 * 8).split('?')[0].replace(
            'https', 'http').replace('//', '/')