# Path: polls/utils.py
# def dump_polls_as_json(filename='polls/static/polls/data.json'):
#     """Dumps all the polls in JSON format.
# 
#     This function retrieves all the polls from the database
#     and dumps them in JSON format in a file. This function
#     is intended to be run periodically to provide a snapshot
#     of the database.
# 
#     Keyword arguments:
#     filename -- the file name in which it should be dumped (default: 'polls/data.json')"""
#     polls = VotingPoll.objects.all()
#     polls_dict = []
#     for poll in polls:
#         polls_dict.append(dict(poll.__iter__(anonymize=True)))
# 
#     with open(filename, 'w') as outfile:
#         json.dump(polls_dict, outfile, indent=4, sort_keys=True)


from django.core.management.base import BaseCommand, CommandError
from polls.utils import dump_polls_as_json

class Command(BaseCommand):
    """Dumps all the polls of the database"""
    help = 'Dumps all the polls of the database'

    def add_arguments(self, parser):
        pass

    def handle(self, *args, **options):

# Path: polls/utils.py
# def dump_polls_as_json(filename='polls/static/polls/data.json'):
#     """Dumps all the polls in JSON format.
# 
#     This function retrieves all the polls from the database
#     and dumps them in JSON format in a file. This function
#     is intended to be run periodically to provide a snapshot
#     of the database.
# 
#     Keyword arguments:
#     filename -- the file name in which it should be dumped (default: 'polls/data.json')"""
#     polls = VotingPoll.objects.all()
#     polls_dict = []
#     for poll in polls:
#         polls_dict.append(dict(poll.__iter__(anonymize=True)))
# 
#     with open(filename, 'w') as outfile:
#         json.dump(polls_dict, outfile, indent=4, sort_keys=True)


# Path: polls/management/commands/dump_polls.py
from django.core.management.base import BaseCommand, CommandError
from polls.utils import dump_polls_as_json


class Command(BaseCommand):
    """Dumps all the polls of the database"""
    help = 'Dumps all the polls of the database'

    def add_arguments(self, parser):
        pass

    def handle(self, *args, **options):

        dump_polls_as_json()