0

I have a page "A" with some CharField to fill programmatically. The value to fill come from another page "B", opened by javascript code executed only when the page is showed (after the init). This is the situation:

  1. page A __init__
  2. during the init, start a thread listening on the port 8080
  3. page A initialized and showed --> javascript in the template is executed
  4. the javascript tag opens a new webpage, that sends data to the 8080
  5. the thread reads data sent by page B, and try to fill CharFields

Is there a way to do this? I don't know...a refresh method..

If it is not possible...

  • I need a way to call the javascript function before the init of the form OR
  • A way to modify the HTML code of the page created
DeLac
  • 1,068
  • 13
  • 43
  • You should be able to achieve this by using dynamic HTML, in other words, identify the field which you want to modify, e.g. by its name, in the HTML DOM of page A and set its value in JavaScript, no? – class stacker Jan 15 '13 at 09:42
  • do you mean...instead of listening at 8080 from python, listen from javascript? – DeLac Jan 15 '13 at 10:10
  • Basically, yes. Because DJango has excellent support for relational data models, where you can have forms for selection/input of related data automatically, I was silently assuming that this must be some convenience feature. I'd limit that to AJAX, then, and leave Django alone. If that's not the case, then there may even be a totally different Django way to achieve what you want. Maybe you set up another, more conceptual question for that. – class stacker Jan 15 '13 at 11:20
  • the problem is that I already have the software built. I have to modify it, but the less possible. And i can't use javascript to listen for the answer, because then the answer will be handled by python libraries. I can't believe that I can not modify CharField's value.. – DeLac Jan 15 '13 at 12:26
  • I currently don't understand where your problem is. WHat is supposed to happen after you receive the value in JavaScript and fill it in? Why not submit the form from within JavaScript after that? – class stacker Jan 15 '13 at 12:35
  • when I receive data from page B, python libraries handle them. Then, some attributes contained in data are filled in CharFields. The problem is that if the page A receives data from B after the init, charFields can not be updated with values. `self.fields['name'].widget=form.TextInput(attrs={'value':response})` doesn't work after '__init__' – DeLac Jan 15 '13 at 13:10
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/22749/discussion-between-delac-and-class-stacker) – DeLac Jan 15 '13 at 13:16
  • 1
    As discussed, wait for the result from page B in the constructor of page A (there should be a timeout, though), and you should be fine. – class stacker Jan 15 '13 at 14:14

1 Answers1

0

This seems overly complicated. Apart from anything else, tying up an entire process waiting for someone to fill in a form is a bad idea.

Although I can't really understand exactly what you want to do, it seems likely that there are better solutions. Here's a few possibilities:

  • Page A redirects to Page B before initializing the form, and B redirects back to A on submit;
  • Page A loads the popup then loads the form via Ajax;
  • Page B dynamically fills in the form fields in A on submit via client-side Javascript;

and so on.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • it's for authentication. Page B is the IdP (so I can't change it), that sends back user attributes. I want these attributes back to be written in CharFields – DeLac Jan 15 '13 at 10:09