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

Refactor ValidatedSoftwareLCM and the software helper logic. #32

Merged
merged 3 commits into from
Nov 18, 2021

Conversation

progala
Copy link
Contributor

@progala progala commented Nov 9, 2021

Note This PR introduces schema changes.

Refactored the ValidatedSoftwareLCM model and filters, forms etc. that reference it.

Moved helper functions for working with SoftwareLCM and ValidatedSoftwareLCM objects to software module.

List of changes:

  • ValidatedSoftwareLCM now allows assignment to multiple objects.
  • ValidatedSoftwareLCM can now be assigned to:
    • devices
    • device types
    • device roles (new)
    • inventory items
    • tags applied to any of the above (new)
  • Re-worked CSV import/export for ValidatedSoftwareLCM
  • Refactored out helper logic computing SoftwareLCM and ValidatedSoftwareLCM related objects.
  • Updates to view templates.
  • Added valid filter to ValidatedSoftwareLCMFilterSet
  • Change ordering of the SoftwareLCM objects.
  • Removed ValidatedSoftwareLCM content template for the DeviceType.
  • ValidatedSoftwareLCM can now return queryset tailored to a given object with get_for_object.

Copy link
Contributor

@dgarros dgarros left a comment

Choose a reason for hiding this comment

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

Great work @progala

from .tables import ValidatedSoftwareLCMTable


class ItemSoftware:
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to convert get_validated_software_qs into a queryset class for ValidatedSoftwareLCM
This would allow us to have something like that

device = Device.objects.get(XXX)
validated_software = ValidatedSoftwareLCM.objects.get_for_model(device)

it's easier than it look to implement
We just need to create a new class

class ValidatedSoftwareLCMQuerySet(RestrictedQuerySet):
    """Queryset for `ValidatedSoftwareLCM` objects."""

    def get_for_object(self, obj):
        """
        Return all `ValidatedSoftwareLCM` assigned to the given object.
        """
       if obj is of type Device:
             do this
       else:
             do that

       [..]

class ValidatedSoftwareLCM([..]):
      objects = ValidatedSoftwareLCMQuerySet.as_manager()

Here is an example https://github.com/nautobot/nautobot/pull/1047/files#diff-01ee6b16cefc4c5378473d290760c32b2507d31249d3df90972f4dca6a93d33aR16

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made an attempt at implementing that and moved a few things around. Seems to work well.

@dgarros @josh5276 @jvanderaa Could you please review and we could hopefully merge it soon.

Copy link
Contributor

@dgarros dgarros left a comment

Choose a reason for hiding this comment

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

LGTM, great work @progala

@progala progala merged commit baf5fde into develop Nov 18, 2021
@progala progala deleted the pr-valsoft-m2m branch February 11, 2022 11:12
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.

None yet

4 participants