Created
May 23, 2013 20:25
-
-
Save ghing/5639148 to your computer and use it in GitHub Desktop.
Create a fixture of all HtmlAsset models that include 'script' in the body
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Create a fixture of all HtmlAsset models that include 'script' in the | |
# body | |
# Usage: dump_script_assets.py | python -mjson.tool > script_assets.json | |
from django.core.management import setup_environ | |
# Edit this to use a particular settings module | |
import settings.dev | |
setup_environ(settings.dev) | |
from django.core import serializers | |
from storybase_asset.models import Asset, HtmlAsset | |
to_serialize = [] | |
for ha in HtmlAsset.objects.all(): | |
if 'script' in ha.body or 'SCRIPT' in ha.body: | |
to_serialize.append(ha) | |
# Since we're using multi-table inheritance, we need to get the | |
# parent model as well | |
a = Asset.objects.get(pk=ha.pk) | |
# Clobber the owner attribute so there's not a dependency when | |
# importing the | |
a.owner = None | |
to_serialize.append(a) | |
# Also get the translations | |
for atrans in ha._get_translated_manager().all(): | |
to_serialize.append(atrans) | |
print serializers.serialize("json", to_serialize) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment