Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

create button and open scooby in new window #401

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

grantgeorge
Copy link
Contributor

Proposed fix for #272

I don't know of a way to open a new window within the django admin.py. This hack opens Scooby in a new window while the save functionality is fired.

My concern is that there's potential for a race condition where the new window fetches the location data before it can be saved.

Perhaps I can test this in a stage environment but I'll have to spend some time getting acquainted with stage. @simonw is it possible for me to get setup in stage?

@grantgeorge grantgeorge added help wanted Extra attention is needed django-admin and tools Anything involving the /admin/ tools labels Apr 23, 2021
@grantgeorge grantgeorge requested a review from simonw April 23, 2021 03:58
@grantgeorge
Copy link
Contributor Author

image

@codecov
Copy link

codecov bot commented Apr 23, 2021

The author of this PR, grantgeorge, is not an activated member of this organization on Codecov.
Please activate this user on Codecov to display this PR comment.
Coverage data is still being uploaded to Codecov.io for purposes of overall coverage calculations.
Please don't hesitate to email us at [email protected] with any questions.

@simonw
Copy link
Collaborator

simonw commented Apr 27, 2021

Sorry for not reviewing this sooner!

The way you have this working at the moment affects all of the admin pages - for example here's what I'm seeing on http://0.0.0.0:3000/admin/auth/group/11/change/

Banners_and_Alerts_and_Change_group___VIAL_admin

To avoid this, one way could be to create a brand new template called admin/change_form_location.html that looks something like this:

{% extends "admin/change_form.html" %}
{% block admin_change_form_document_ready %}
{{ block.super }}
<script>
function onClickSaveOpenScooby(element, locationId) {
    window.open('https://help.vaccinateca.com/call/?location_id=' + locationId, '_blank');
}
</script>
{% endblock %}

{% block submit_buttons_bottom %}
{% load admin_modify %}
    <input 
        onclick="onClickSaveOpenScooby(this, ({{ location_id }}))"
        type="submit"
        value="Save and open Scooby"
        style="margin-bottom: 15px;"
    >
{% submit_row %}
{% endblock %}

Then add the following to the LocationAdmin class:

    change_form_template = "admin/change_form_location.html"

@grantgeorge
Copy link
Contributor Author

@simonw circling back to this now, thanks for the feedback! I'll take a look at that and test on other admin pages :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
django-admin and tools Anything involving the /admin/ tools help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants