Skip to content

Commit

Permalink
Merge pull request #22 from dennybiasiolli/fixing-deprecation-notice
Browse files Browse the repository at this point in the history
mixins: displaying deprecation notice only when needed
  • Loading branch information
dennybiasiolli authored Sep 8, 2022
2 parents dc26831 + c6e6d4d commit 14ed131
Showing 1 changed file with 46 additions and 36 deletions.
82 changes: 46 additions & 36 deletions src/reversion_rest_framework/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ class BaseHistoryMixin:
class BaseHistoryModelMixin(BaseHistoryMixin):
"""Deprecated! Use BaseHistoryMixin instead"""

warnings.warn(
'Deprecation notice: the "BaseHistoryModelMixin" has been renamed to '
'"BaseHistoryMixin" and will be removed in the next version of '
"django-reversion-rest-framework",
category=FutureWarning,
stacklevel=2,
)
def __init_subclass__(cls):
warnings.warn(
'Deprecation notice: the "BaseHistoryModelMixin" has been renamed to '
'"BaseHistoryMixin" and will be removed in the next version of '
"django-reversion-rest-framework",
category=FutureWarning,
stacklevel=2,
)
return super().__init_subclass__()


class HistoryMixin(BaseHistoryMixin):
Expand Down Expand Up @@ -96,13 +98,15 @@ def version(self, request, pk=None, version_pk=None):
class HistoryOnlyMixin(HistoryMixin):
"""Deprecated! Use HistoryMixin instead"""

warnings.warn(
'Deprecation notice: the "HistoryOnlyMixin" has been renamed to '
'"HistoryMixin" and will be removed in the next version of '
"django-reversion-rest-framework",
category=FutureWarning,
stacklevel=2,
)
def __init_subclass__(cls):
warnings.warn(
'Deprecation notice: the "HistoryOnlyMixin" has been renamed to '
'"HistoryMixin" and will be removed in the next version of '
"django-reversion-rest-framework",
category=FutureWarning,
stacklevel=2,
)
return super().__init_subclass__()


class DeletedMixin(BaseHistoryMixin):
Expand Down Expand Up @@ -131,26 +135,30 @@ def deleted(self, request):
class DeletedOnlyMixin(DeletedMixin):
"""Deprecated! Use DeletedMixin instead"""

warnings.warn(
'Deprecation notice: the "DeletedOnlyMixin" has been renamed to '
'"DeletedMixin" and will be removed in the next version of '
"django-reversion-rest-framework",
category=FutureWarning,
stacklevel=2,
)
def __init_subclass__(cls):
warnings.warn(
'Deprecation notice: the "DeletedOnlyMixin" has been renamed to '
'"DeletedMixin" and will be removed in the next version of '
"django-reversion-rest-framework",
category=FutureWarning,
stacklevel=2,
)
return super().__init_subclass__()


class ReadOnlyHistoryModel(HistoryMixin, DeletedMixin):
"""Deprecated! Use (HistoryMixin, DeletedMixin)instead"""

warnings.warn(
'Deprecation notice: the "ReadOnlyHistoryModel" '
"will be removed in the next version of "
"django-reversion-rest-framework. "
" Please use `HistoryMixin` and `DeletedMixin` for the same behaviour",
category=FutureWarning,
stacklevel=2,
)
def __init_subclass__(cls):
warnings.warn(
'Deprecation notice: the "ReadOnlyHistoryModel" '
"will be removed in the next version of "
"django-reversion-rest-framework. "
" Please use `HistoryMixin` and `DeletedMixin` for the same behaviour",
category=FutureWarning,
stacklevel=2,
)
return super().__init_subclass__()


class RevertMixin(HistoryMixin):
Expand Down Expand Up @@ -193,10 +201,12 @@ def revert(self, request, pk=None, version_pk=None, *args, **kwargs):
class HistoryModelMixin(DeletedMixin, RevertMixin):
"""Deprecated! Use `(RevertMixin, DeletedMixin)` instead"""

warnings.warn(
'Deprecation notice: the "ReadOnlyHistoryModel" '
"will be removed in the next version of "
"django-reversion-rest-framework",
category=FutureWarning,
stacklevel=2,
)
def __init_subclass__(cls):
warnings.warn(
'Deprecation notice: the "ReadOnlyHistoryModel" '
"will be removed in the next version of "
"django-reversion-rest-framework",
category=FutureWarning,
stacklevel=2,
)
return super().__init_subclass__()

0 comments on commit 14ed131

Please sign in to comment.