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

Add Support for Custom JS/CSS on Job Schedule Form #1866

Conversation

tbotnz
Copy link
Contributor

@tbotnz tbotnz commented Jun 9, 2022

Closes: #1865

What's Changed

Just an idea to get the ball rolling on this, can tidy up if required

  • Job definitions can now set a template_name prop the to use custom Job templates with custom JS & CSS ( same as object edit view etc )

@tbotnz tbotnz changed the title Update views.py #1865 add support for custom JS/CSS on Job schedule form Jun 9, 2022
@bryanculver
Copy link
Member

Solid start @tbotnz!

Mind updating the example_plugin to demonstrate how one would use this?

@tbotnz
Copy link
Contributor Author

tbotnz commented Jun 9, 2022

@bryanculver done

@bryanculver bryanculver changed the base branch from develop to next June 10, 2022 19:11
@bryanculver bryanculver changed the title #1865 add support for custom JS/CSS on Job schedule form Add Support for Custom JS/CSS on Job Schedule Form Jun 14, 2022
@tbotnz tbotnz requested a review from jathanism June 19, 2022 00:25
@bryanculver bryanculver added the type: feature Introduction of new or enhanced functionality to the application label Jun 23, 2022
Copy link
Member

@bryanculver bryanculver left a comment

Choose a reason for hiding this comment

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

Looking pretty good @tbotnz. Some nitpicks as well as please run black.

nautobot/extras/views.py Outdated Show resolved Hide resolved
nautobot/extras/views.py Outdated Show resolved Hide resolved
nautobot/extras/views.py Outdated Show resolved Hide resolved
nautobot/extras/views.py Outdated Show resolved Hide resolved
job_form = job_class.as_form(request.POST, request.FILES) if job_model.job_class is not None else None
if hasattr(job_class, "template_name"):
template_name = job_class.template_name
except RuntimeError as err:
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the case in which this RuntimeError was encountered?

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'm not exactly sure, i did not look into it. This was the in-place exception handling that was used in the codebase for the existing get method when trying to access the job class. I can remove it if its not required

Copy link
Contributor

Choose a reason for hiding this comment

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

I missed that this was patterned after the existing code above 🤦 . Fine to leave as-is!

Copy link
Member

Choose a reason for hiding this comment

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

I removed this because the error condition this was handling is already being handled below and in fact changes the existing behavior:

https://github.com/nautobot/nautobot/blob/next/nautobot/extras/views.py#L999-L1000

When jobs were no longer installed it redirected to the list view and failed the tests previously for that. Instead of changing that behavior we have slightly duplicate check for the class existing.

The get and post could probably be made more succinct with their checks, error messaging, and return paths but I believe they are fine as-is at the moment.

examples/example_plugin/example_plugin/jobs.py Outdated Show resolved Hide resolved
nautobot/extras/views.py Outdated Show resolved Hide resolved
examples/example_plugin/example_plugin/jobs.py Outdated Show resolved Hide resolved
nautobot/extras/views.py Outdated Show resolved Hide resolved
Copy link
Contributor

@glennmatthews glennmatthews left a comment

Choose a reason for hiding this comment

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

Great stuff!

@bryanculver bryanculver merged commit 31c0405 into nautobot:next Jul 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature Introduction of new or enhanced functionality to the application
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Add support for Custom JS / CSS in jobs run form
4 participants