Skip to content

Fixes: #7 - Allow devices in Child Locations #9

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DanSheps
Copy link
Member

@DanSheps DanSheps commented Mar 7, 2024

Fixes: #7 - Allow devices in Child Locations

  • Alter queryset to allow devices in child locations to be added

@DanSheps
Copy link
Member Author

DanSheps commented Mar 7, 2024

@natm Can't assign reviewers for some reason. If you could give this a look see that would be great.

@dionrowney
Copy link

dionrowney commented Mar 14, 2024

Can someone review and approve this so I can start testing this in my dev environment? Is this something I can do?

Copy link

@dionrowney dionrowney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I Tested this and it works as expected.

Copy link

@dionrowney dionrowney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I see all devices and racks rather than just racks in the current location and sub locations. It solves the problem but I was not expecting to see ALL objects.

Copy link

@dionrowney dionrowney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upon closer investigation it seems to be a UI error that causes the list to display everything. I would say the initial list displayed is correct and I will submit a bug for this new error once this change is in the main branch

@earendilfr
Copy link

earendilfr commented Mar 24, 2025

The patch working well with rack.
Concerning devices, I think the best way is the following :

class FloorplanDeviceListView(generic.ObjectListView):
    queryset = Device.objects.all()
    table = tables.FloorplanDeviceTable

    def get(self, request):
        fp_id = request.GET["floorplan_id"]
        fp_instance = models.Floorplan.objects.get(pk=fp_id)
        if fp_instance.record_type == "site":
            self.queryset = Device.objects.all().filter(~Q(id__in=fp_instance.mapped_devices)).filter(
                site=fp_instance.site.id).order_by("name")
        else:
            fp_locations = Location.objects.get(pk=fp_instance.location.id).get_descendants(include_self=True)
            fp_racks = Rack.objects.all().filter(location__in=fp_locations)
            self.queryset = Device.objects.all().filter(~Q(id__in=fp_instance.mapped_devices)).filter(
                location__in=fp_locations).exclude(rack__in=fp_racks).order_by("name")
        return super().get(request)

The idea is to exclude the devices that are already racked in a rack inside this location

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow devices from child locations to be included in drawing
3 participants