'Return a string of the file contents.'

def as_string(self):

    items = {'replaces_str': '', 'initial_str': ''}
    imports = set()
    operations = []
    for operation in self.migration.operations:
        (operation_string, operation_imports) = OperationWriter(operation).serialize()
        imports.update(operation_imports)
        operations.append(operation_string)
    items['operations'] = (('\n'.join(operations) + '\n') if operations else '')
    dependencies = []
    for dependency in self.migration.dependencies:
        if (dependency[0] == '__setting__'):
            dependencies.append(('                                migrations.swappable_dependency(settings.%s),' % dependency[1]))
            imports.add('from    django.conf    import    settings')
        else:
            dependencies.append(('                                %s,' % self.serialize(dependency)[0]))
    items['dependencies'] = (('\n'.join(dependencies) + '\n') if dependencies else '')
    migration_imports = set()
    for line in list(imports):
        if re.match('^import    (.*)\\.\\d+[^\\s]*$', line):
            migration_imports.add(line.split('import')[1].strip())
            imports.remove(line)
            self.needs_manual_porting = True
    if ('from    django.db    import    models' in imports):
        imports.discard('from    django.db    import    models')
        imports.add('from    django.db    import    migrations,    models')
    else:
        imports.add('from    django.db    import    migrations')
    sorted_imports = sorted(imports, key=(lambda i: i.split()[1]))
    items['imports'] = (('\n'.join(sorted_imports) + '\n') if imports else '')
    if migration_imports:
        items['imports'] += ('\n\n#    Functions    from    the    following    migrations    need    manual    copying.\n#    Move    them    and    any    dependencies    into    this    file,    then    update    the\n#    RunPython    operations    to    refer    to    the    local    versions:\n#    %s' % '\n#    '.join(sorted(migration_imports)))
    if self.migration.replaces:
        items['replaces_str'] = ('\n                replaces    =    %s\n' % self.serialize(self.migration.replaces)[0])
    items.update(version=get_version(), timestamp=now().strftime('%Y-%m-%d    %H:%M'))
    if self.migration.initial:
        items['initial_str'] = '\n                initial    =    True\n'
    return (MIGRATION_TEMPLATE % items)
