Skip to content
New issue

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

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

Already on GitHub? # to your account

Passing values to Detailview of Popup #5

Closed
ImanoWilliams opened this issue Aug 3, 2018 · 11 comments
Closed

Passing values to Detailview of Popup #5

ImanoWilliams opened this issue Aug 3, 2018 · 11 comments

Comments

@ImanoWilliams
Copy link

@djk2 I want to make a detailview popupview like so. When the user clicks on the selectionReason where the popupfield is placed, I want to pass a primary key from the AttackPatternForm to detail view of the popupview. I will then call the attackpattern values in the template file.

I basically want to get a value from the template file where the AttackPatternForm is and pass it to the
popupview that inherits from Detail view. See code below. It is quite similar to your CountryPopupView, but the user would not search since the query filter will be passed in from the template that renders AttackPatternForm.
My issue is how to pass the value from the form and then use it to query in the detailview of the popupfield view.

forms.py

class AttackPatternForm(ModelForm):
    class Meta:
        model=AttackPattern
        fields='__all__'
    selectionReason=PopupViewField(
        view_class=SelectionReasonPopUpView,
        popup_dialog_title="Please select a reason for",
        required=True
        )
    def __init__(self, *args, **kwargs):
        super(AttackPatternForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()

popups.py

class SelectionReasonPopUpViews(DetailView):
    template_name = 'popups/selectionReason.html'
    model = AttackPattern
    #How to get a value from the parent form in the detailview?

template: 'popups/selectionReason.html

<ul>
    <li data-popup-view-value="Description"> {{attackpattern.description}} </li>
	<li data-popup-view-value="Flow" > {{attackpattern.flow}} </li>
</ul>
@djk2
Copy link
Owner

djk2 commented Sep 20, 2018

I will try find solution, please be patient.

@djk2
Copy link
Owner

djk2 commented Sep 21, 2018

Can you prepare full not working example.
I do not quite understand how you would like to pass a PK from an object to DetailView. Currently, it is not possible to forward PK in the url, because the views are regitraed in a simple way

url (r '^ (? P <view_class_name> \ w +) / $', GetPopupView.as_view (), name = "get_popup_view"),

I can add a new functionality but I would like to have a good example.

@ImanoWilliams
Copy link
Author

ImanoWilliams commented Sep 21, 2018 via email

djk2 pushed a commit that referenced this issue Sep 26, 2018
@djk2
Copy link
Owner

djk2 commented Sep 26, 2018

Hi.
Thanks for code.
I prepared some solution.
This should solve problem.
Can you see my new branch issue_5 : https://github.com/djk2/django-popup-view-field/tree/issue_5
I added your code to demo application and modifed PopupViewField.
I added new attribute callback_data.
Now you can pass additional data as dictionary to PopupView.
This additional data will be add to url and pass in request.GET.
Please see example in demo in my new branche.
If this solution will be satisfi, then I add this mechanism to master branch and I will prepare new release.

You can test your code if you run demo and hit to url : http://127.0.0.1:8000/ap/

Example:

class APReviewForm(forms.ModelForm):
    class Meta:
        model=APReview
        fields=['rating', 'selectionReason', ]

    def __init__(self, *args, **kwargs):
        super(APReviewForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.fields['selectionReason']=PopupViewField(
            view_class=SelectionReasonPopUpViews,
            popup_dialog_title="Please select a reason for",
            callback_data={'my_id':'APid_1', 'other_param': 'xxx'},
            required=True,

        )

@djk2
Copy link
Owner

djk2 commented Oct 1, 2018

@ImanoWilliams Can you see my new branch issuse_5

@ImanoWilliams
Copy link
Author

ImanoWilliams commented Oct 1, 2018 via email

@djk2
Copy link
Owner

djk2 commented Oct 1, 2018

Thanks for info.
I will wait for response.

K2, I apologize for not reply to you sooner. Yes, I can see issue 5 branch. I will copy the modified code base to my existing source code. Best regards, IWill

On Mon, Oct 1, 2018 at 4:31 AM K2 @.***> wrote: @ImanoWilliams https://github.com/ImanoWilliams Can you see my new branch issuse_5 — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#5 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/ALC_jBAJeoGNI0dkX7yctwPV7BsCpNDMks5ugdL9gaJpZM4VuHWC .

@ImanoWilliams
Copy link
Author

ImanoWilliams commented Oct 2, 2018 via email

@djk2
Copy link
Owner

djk2 commented Oct 2, 2018

Its Great.
I will add this functionality to master branch.
During few days I will prepare new release.
I must write new unit tests.

djk2 pushed a commit that referenced this issue Oct 4, 2018
@djk2 djk2 closed this as completed Oct 4, 2018
@djk2
Copy link
Owner

djk2 commented Oct 4, 2018

Release 0.4.0

@ImanoWilliams
Copy link
Author

ImanoWilliams commented Oct 8, 2018 via email

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

No branches or pull requests

2 participants