
from byceps.blueprints.snippet.models.snippet import \
    CurrentVersionAssociation, Snippet, SnippetVersion


def create_snippet(party, name):
    return Snippet(
        party=party,
        name=name)


def create_snippet_version(snippet, creator, *, created_at=None,
                           title='', head='', body='', image_url_path=None):
    return SnippetVersion(
        snippet=snippet,
        created_at=created_at,
        creator=creator,
        title=title,
        head=head,
        body=body,
        image_url_path=image_url_path)


def create_current_version_association(snippet, version):
    return CurrentVersionAssociation(
        snippet=snippet,
        version=version)


from byceps.blueprints.snippet.models.snippet import \
    CurrentVersionAssociation, Snippet, SnippetVersion


def create_snippet(party, name):
    return Snippet(
        party=party,
        name=name)


def create_snippet_version(snippet, creator, *, created_at=None,
                           title='', head='', body='', image_url_path=None):
    version = SnippetVersion(
        snippet=snippet,
        creator=creator,
        title=title,
        head=head,
        body=body,
        image_url_path=image_url_path)

    if created_at is not None:
        version.created_at = created_at

    return version

def create_current_version_association(snippet, version):
    return CurrentVersionAssociation(
        snippet=snippet,
        version=version)

Set creation date via field, not via constructor
Set creation date via field, not via constructor

  
  from byceps.blueprints.snippet.models.snippet import \
      CurrentVersionAssociation, Snippet, SnippetVersion
  
  
  def create_snippet(party, name):
      return Snippet(
          party=party,
          name=name)
  
  
  def create_snippet_version(snippet, creator, *, created_at=None,
                             title='', head='', body='', image_url_path=None):
-     return SnippetVersion(
+     version = SnippetVersion(
          snippet=snippet,
-         created_at=created_at,
          creator=creator,
          title=title,
          head=head,
          body=body,
          image_url_path=image_url_path)
  
+     if created_at is not None:
+         version.created_at = created_at
+ 
+     return version
  
  def create_current_version_association(snippet, version):
      return CurrentVersionAssociation(
          snippet=snippet,
          version=version)
  
Set creation date via field, not via constructor
## Code Before:

from byceps.blueprints.snippet.models.snippet import \
    CurrentVersionAssociation, Snippet, SnippetVersion


def create_snippet(party, name):
    return Snippet(
        party=party,
        name=name)


def create_snippet_version(snippet, creator, *, created_at=None,
                           title='', head='', body='', image_url_path=None):
    return SnippetVersion(
        snippet=snippet,
        created_at=created_at,
        creator=creator,
        title=title,
        head=head,
        body=body,
        image_url_path=image_url_path)


def create_current_version_association(snippet, version):
    return CurrentVersionAssociation(
        snippet=snippet,
        version=version)

## Instruction:
Set creation date via field, not via constructor
## Code After:

from byceps.blueprints.snippet.models.snippet import \
    CurrentVersionAssociation, Snippet, SnippetVersion


def create_snippet(party, name):
    return Snippet(
        party=party,
        name=name)


def create_snippet_version(snippet, creator, *, created_at=None,
                           title='', head='', body='', image_url_path=None):
    version = SnippetVersion(
        snippet=snippet,
        creator=creator,
        title=title,
        head=head,
        body=body,
        image_url_path=image_url_path)

    if created_at is not None:
        version.created_at = created_at

    return version

def create_current_version_association(snippet, version):
    return CurrentVersionAssociation(
        snippet=snippet,
        version=version)
