Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

87 deactivate the current branch when creating a new one #185

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions netbox_branching/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
from core.choices import ObjectChangeActionChoices
from core.filtersets import ObjectChangeFilterSet
from core.models import ObjectChange
from netbox_branching.contextvars import active_branch
from netbox.views import generic
from utilities.views import ViewTab, register_model_view
from . import filtersets, forms, tables
from .choices import BranchStatusChoices
from .jobs import MergeBranchJob, RevertBranchJob, SyncBranchJob
from .models import Branch, ChangeDiff
from .utilities import activate_branch


#
Expand Down Expand Up @@ -74,6 +76,15 @@ def alter_object(self, obj, request, url_args, url_kwargs):
obj.owner = request.user
return obj

def post(self, request, **kwargs):
# if creating and there is an active branch - switch to main
obj = self.get_object(**kwargs)
if not obj.pk and active_branch.get():
with activate_branch(None):
return super().post(request, **kwargs)

return super().post(request, **kwargs)


@register_model_view(Branch, 'delete')
class BranchDeleteView(generic.ObjectDeleteView):
Expand Down
Loading