from __future__ import absolute_import, unicode_literals


class AuthorshipFormMixin(object):
    """Set the ``created_by`` and ``updated_by`` fields on a model.

    This form requires that a property, ``self.user`` be set to an instance of
    :py:class`~django.contrib.auth.models.User` before the ``save()`` method is
    called.

    """

    def save(self, *args, **kwargs):
        self.instance.updated_by = self.user
        if not self.instance.pk:
            self.instance.created_by = self.user

        return super(AuthorshipFormMixin, self).save(*args, **kwargs)

from __future__ import absolute_import, unicode_literals


class AuthorshipFormMixin(object):
    """Set the ``created_by`` and ``updated_by`` fields on a model.

    Requires that a ``User`` instance be passed in to the constructor. Views
    that inherit from ``AuthorshipViewMixin`` automatically pass this in.

    """

    def __init__(self, user, *args, **kwargs):
        self.user = user
        super(AuthorshipFormMixin, self).__init__(*args, **kwargs)

    def save(self, *args, **kwargs):
        self.instance.updated_by = self.user
        if not self.instance.pk:
            self.instance.created_by = self.user

        return super(AuthorshipFormMixin, self).save(*args, **kwargs)

Set the `self.user` property on the `AuthorshipFormMixin`.
Set the `self.user` property on the `AuthorshipFormMixin`.

  from __future__ import absolute_import, unicode_literals
  
  
  class AuthorshipFormMixin(object):
      """Set the ``created_by`` and ``updated_by`` fields on a model.
  
+     Requires that a ``User`` instance be passed in to the constructor. Views
+     that inherit from ``AuthorshipViewMixin`` automatically pass this in.
-     This form requires that a property, ``self.user`` be set to an instance of
-     :py:class`~django.contrib.auth.models.User` before the ``save()`` method is
-     called.
  
      """
+ 
+     def __init__(self, user, *args, **kwargs):
+         self.user = user
+         super(AuthorshipFormMixin, self).__init__(*args, **kwargs)
  
      def save(self, *args, **kwargs):
          self.instance.updated_by = self.user
          if not self.instance.pk:
              self.instance.created_by = self.user
  
          return super(AuthorshipFormMixin, self).save(*args, **kwargs)
  
Set the `self.user` property on the `AuthorshipFormMixin`.
## Code Before:
from __future__ import absolute_import, unicode_literals


class AuthorshipFormMixin(object):
    """Set the ``created_by`` and ``updated_by`` fields on a model.

    This form requires that a property, ``self.user`` be set to an instance of
    :py:class`~django.contrib.auth.models.User` before the ``save()`` method is
    called.

    """

    def save(self, *args, **kwargs):
        self.instance.updated_by = self.user
        if not self.instance.pk:
            self.instance.created_by = self.user

        return super(AuthorshipFormMixin, self).save(*args, **kwargs)

## Instruction:
Set the `self.user` property on the `AuthorshipFormMixin`.
## Code After:
from __future__ import absolute_import, unicode_literals


class AuthorshipFormMixin(object):
    """Set the ``created_by`` and ``updated_by`` fields on a model.

    Requires that a ``User`` instance be passed in to the constructor. Views
    that inherit from ``AuthorshipViewMixin`` automatically pass this in.

    """

    def __init__(self, user, *args, **kwargs):
        self.user = user
        super(AuthorshipFormMixin, self).__init__(*args, **kwargs)

    def save(self, *args, **kwargs):
        self.instance.updated_by = self.user
        if not self.instance.pk:
            self.instance.created_by = self.user

        return super(AuthorshipFormMixin, self).save(*args, **kwargs)
