I got to work! I needed a good nights sleep to see it. the url was '/DHM_run/' NOT '/run_DHM/'.
Thanks Alec On Thu, Sep 9, 2010 at 4:20 PM, Bradley Hintze <bradle...@aggiemail.usu.edu> wrote: > Ok, cant quite get it. Here is what I have: > > please_wait.html > ... > <script type="text/javascript" > src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> > <script type="text/javascript"> > $.get({{ calculation_url }}, function(data) { > if (data == 'OK') { > window.location.href = {{ view_url }}; > } > else { > alert(data); > } > }); > </script> > ... > > url.py > url(r'^DHM_run_start/$', please_wait, kwargs={'calculation_url': > '/run_DHM/', 'view_url':'/DHM_display/'}, name='run_DHM_start'), > url(r'^analyze_start/$', please_wait, kwargs={'calculation_url': > '/analyze_compare/', 'view_url':'/results_display/'}, > name='analyze_start'), > > view.py > ... > def please_wait(request, calculation_url, view_url): > c = {'calculation_url': calculation_url, 'view_url': view_url} > return render_to_response('please_wait.html', c, > context_instance=RequestContext(request)) > > def run_DHM(request): > #run calculations > return HttpResponse('OK') > > > def analyze_compare(request): > #run calculations > return HttpResponse('OK') > ... > > I could have run_DHM and analyze_compare return views rather than the > HTTPResponse "OK" as you indicated but was unsure how to change the > javascript to make it work. This seems like it should work but I just > get the "please_wait" page indefinitely. Seems as if its not calling > {{ calculation_url }}. > > Any ideas or elaborations (hold my hand) on JSON would be great. > > Thanks, > Bradley > > On Thu, Sep 9, 2010 at 12:44 PM, Alec Shaner <asha...@chumpland.org> wrote: >> A lot of ways to do this. Yes you could do it as above, but that can get >> ugly as you start adding more views. You can indeed access the context >> dictionary in please_wait.html. It's hard to say without knowing more >> details about your application. How does the user pass arguments (if any) >> used in these calculations? If you're looking for a simple way to abstract >> this process, consider using URL confs: >> >> # Create a url specific to the DHM calulcation >> url(r'^DHM_run_start/$', please_wait, kwargs={'calculation_url': 'run_DHM'}, >> name='run_DHM_start'), >> >> and you'd call it like /DHM_run_start/ >> >> or >> >> # Create a URL with a regex pattern to capture a calculation_url >> url(r'^please_wait/(?P<calculation_url>[\d\w]+)/$', please_wait), >> >> and you'd call it like /please_wait/run_DHM/ >> >> The second option is more generic, but you'll need to validate the url >> argument. The first option means adding more url entries. In either case >> your please_wait view would be defined like: >> >> def please_wait(request, calculation_url): >> return render_to_response('please_wait.html', {'calculation_url': >> calculation_url}, ...) >> >> please_wait.html could then substitute the {{ calculation_url }} context >> variable as the argument to the {% url %} tag. >> >> Your run_DHM view could now return the url to redirect to instead of just >> 'OK'. You'll have to return the full URL, e.g., '/display_DHM/', from your >> run_DHM view. This is probably where you'd start thinking about a JSON >> response as you might return a dictionary with an result code ('OK' or >> 'error') along with a url to redirect the user to. >> >> window.location.href = data; >> >> Or if you've switched to a JSON response it might be data.display_url after >> checking that data.result = 'OK'. >> >> Hope that all makes sense. >> >> On Thu, Sep 9, 2010 at 12:00 PM, Bradley Hintze >> <bradle...@aggiemail.usu.edu> wrote: >>> >>> OK, >>> >>> Got it working. Sorry one more question. I have a couple of places >>> where I'd like to display the 'Please Wait' page. I'd imagine I'd do >>> something similar to the following:: >>> >>> # please_wait.html >>> ... >>> <script type="text/javascript" >>> >>> src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> >>> <script type="text/javascript"> >>> if (If_come_from_pageA) { >>> $.get('{% url run_DHM %}', function(data) { >>> if (data == 'OK') { >>> window.location.href = '{% url display_DHM %}'; >>> } else { >>> alert(data); >>> } >>> } >>> else if (If_come_from_pageB) { >>> $.get('{% url run_analysis %}', function(data) { >>> if (data == 'OK') { >>> window.location.href = '{% url display_analysis %}'; >>> } else { >>> alert(data); >>> } >>> } >>> }); >>> </script> >>> >>> an of course configure url.py and view.py as explained previously. Is >>> there an easy way to do this? In other words, what are the >>> If_come_from_pageA and If_come_from_pageB conditions? Can I access the >>> context dictionary that I passed to please_wait.html? >>> >>> On Thu, Sep 9, 2010 at 11:23 AM, Bradley Hintze >>> <bradle...@aggiemail.usu.edu> wrote: >>> > Yeah, I just tried out what I wrote in my last and it worked! >>> > >>> > Thanks for all your help!!! >>> > >>> > Bradley >>> > >>> > On Thu, Sep 9, 2010 at 11:17 AM, Alec Shaner <asha...@chumpland.org> >>> > wrote: >>> >> That's really a design issue up to you, i.e., how you get data from >>> >> your >>> >> view to your template. Since I don't know the format or how much data >>> >> you're >>> >> storing in the session it's hard to say. I was just assuming you'd use >>> >> context variable(s) to pass the data to the template. I'm not >>> >> intimately >>> >> familiar with the Session API, but isn't it just a dictionary? >>> >> >>> >> On Thu, Sep 9, 2010 at 11:05 AM, Bradley Hintze >>> >> <bradle...@aggiemail.usu.edu> wrote: >>> >>> >>> >>> Thanks Alec, >>> >>> >>> >>> That finally makes sense. However, I do have a question here: >>> >>> >>> >>> def display_DHM(request): >>> >>> # Get results from session >>> >>> return render_to_response('ran_DHM.html', ...) >>> >>> >>> >>> '# Get results from session'???? Would I not just do this: >>> >>> >>> >>> def display_DHM(request): >>> >>> return render_to_response('DHM_ran.html', request.session, ...) >>> >>> >>> >>> Or do I have to explicitly get the session data? If so, how? >>> >>> >>> >>> >>> >>> On Thu, Sep 9, 2010 at 10:37 AM, Alec Shaner <asha...@chumpland.org> >>> >>> wrote: >>> >>> > I feel your pain - javascript has always been a pain for me, but >>> >>> > libraries >>> >>> > like jQuery make it more bearable! >>> >>> > >>> >>> > AJAX calls are made in the background (usually asynchronously), so >>> >>> > they >>> >>> > don't directly change the page you're currently viewing in your >>> >>> > browser. >>> >>> > The >>> >>> > browser is responsible for dispatching the response returned from >>> >>> > your >>> >>> > AJAX >>> >>> > call, typically by invoking a callback function you specified when >>> >>> > the >>> >>> > AJAX >>> >>> > request was initiated. So you don't do a redirect from the server, >>> >>> > rather >>> >>> > you can do it using client side javascript in your callback >>> >>> > function. >>> >>> > >>> >>> > Here is how it basically works: >>> >>> > 1. Please Wait page makes AJAX request to run_DHM, specifies >>> >>> > callback >>> >>> > function when request completes. >>> >>> > 2. run_DHM performs calculations, stores results in session, returns >>> >>> > an >>> >>> > "OK" >>> >>> > response. >>> >>> > 3. Browser invokes the callback function specified in step 1, which >>> >>> > should >>> >>> > change the page to display_DHM view. >>> >>> > 4. display_DHM retrieves calculation results from session and >>> >>> > renders >>> >>> > HTML >>> >>> > page. >>> >>> > >>> >>> > Your first problem is with the url template tag. You might try this: >>> >>> > >>> >>> > {% url MolProbity_Compare_test.views.run_DHM %} >>> >>> > >>> >>> > You can also use a named urls, e.g., >>> >>> > ... >>> >>> > url(r'^DHM_run/$', run_DHM, name="run_DHM"), >>> >>> > ... >>> >>> > in which case {% url run_DHM %} should also work >>> >>> > >>> >>> > Or you can just call the url directly instead of using the url >>> >>> > template >>> >>> > tag, >>> >>> > e.g., '/run_DHM/'. >>> >>> > >>> >>> > The request argument is always passed to your views, you don't have >>> >>> > to >>> >>> > do it >>> >>> > explicitly. So your run_DHM and display_DHM views will always have >>> >>> > that >>> >>> > available. Just get the session out of the request object in each >>> >>> > view >>> >>> > you >>> >>> > need it. >>> >>> > >>> >>> > Basic skeleton: >>> >>> > >>> >>> > # please_wait.html >>> >>> > ... >>> >>> > <script type="text/javascript" >>> >>> > >>> >>> > >>> >>> > src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> >>> >>> > <script type="text/javascript"> >>> >>> > $.get('{% url run_DHM %}', function(data) { >>> >>> > if (data == 'OK') { >>> >>> > window.location.href = '{% url display_DHM %}'; >>> >>> > } else { >>> >>> > alert(data); >>> >>> > } >>> >>> > }); >>> >>> > </script> >>> >>> > >>> >>> > Note I've used the shorthand urls above, you could just use >>> >>> > '/run_DHM/' >>> >>> > and >>> >>> > '/display_DHM/' instead of the url template tags. You could also use >>> >>> > the >>> >>> > full package path. Also note that the callback function I refer to >>> >>> > is >>> >>> > defined inline - the function(data) ... part. >>> >>> > >>> >>> > # views.py >>> >>> > from django.http import HttpResponse >>> >>> > >>> >>> > def please_wait(request): >>> >>> > return render_to_response('please_wait.html', ...) >>> >>> > >>> >>> > def run_DHM(request): >>> >>> > # Do calculations, store results in request.session >>> >>> > ... >>> >>> > # If everything ok, return OK (otherwise return some error) >>> >>> > return HttpResponse('OK') >>> >>> > >>> >>> > def display_DHM(request): >>> >>> > # Get results from session >>> >>> > return render_to_response('ran_DHM.html', ...) >>> >>> > >>> >>> > This is over simplified, but should serve to get started if you want >>> >>> > to >>> >>> > use >>> >>> > this redirect approach. >>> >>> > >>> >>> > On Thu, Sep 9, 2010 at 9:59 AM, Bradley Hintze >>> >>> > <bradle...@aggiemail.usu.edu> >>> >>> > wrote: >>> >>> >> >>> >>> >> Alec, >>> >>> >> >>> >>> >> Thanks for your patience. The jquery tutorials have been >>> >>> >> frustrating. >>> >>> >> Anyway, I do not have three 'views' as you suggested. I will try >>> >>> >> that. >>> >>> >> But I need to understand a few things before I try that. How to >>> >>> >> call >>> >>> >> run_DHM from my please_wait.html page. (I assume AJAX but I've >>> >>> >> tried >>> >>> >> and tries what have been suggested with no success, most likely due >>> >>> >> to >>> >>> >> my failed attempts at understanding AJAX) I assume after I run the >>> >>> >> run_DHM view function I will somehow have run_DHM redirect it to >>> >>> >> the >>> >>> >> display_DHM. My question is, how do I redirect AND pass the >>> >>> >> request.session arguments, which is where the data from run_DHM >>> >>> >> will >>> >>> >> be stored? >>> >>> >> >>> >>> >> As requested, here is my full url.py: >>> >>> >> >>> >>> >> from django.conf.urls.defaults import * >>> >>> >> from MolProbity_Compare_test.views import * >>> >>> >> >>> >>> >> # Uncomment the next two lines to enable the admin: >>> >>> >> # from django.contrib import admin >>> >>> >> # admin.autodiscover() >>> >>> >> >>> >>> >> urlpatterns = patterns('', >>> >>> >> (r'^home/$', home_view),#the 'index' or home or top page view >>> >>> >> (r'^about/$', about_view), >>> >>> >> (r'^log_out_confirm/$', log_out_confirm), >>> >>> >> (r'^log_out/$', log_out), >>> >>> >> (r'^upload/$', uploaded_PDBs), >>> >>> >> (r'^rotamer_diff/$', rotamer_dif_frame), >>> >>> >> (r'^side-by-side/$', side_by_side), >>> >>> >> (r'^side-by-side-key/$', side_by_side_key), >>> >>> >> (r'^side-by-side-frame/$', side_by_side_frame), >>> >>> >> (r'^DHM_run/$', run_DHM), >>> >>> >> (r'^please_wait/', please_wait), >>> >>> >> (r'^analyze/$', analyze_compare), >>> >>> >> ) >>> >>> >> >>> >>> >> >>> >>> >> On Thu, Sep 9, 2010 at 9:22 AM, Alec Shaner <asha...@chumpland.org> >>> >>> >> wrote: >>> >>> >> > Could you post the full url.py file? >>> >>> >> > >>> >>> > >>> >>> > ... >>> >>> > >>> >>> > -- >>> >>> > You received this message because you are subscribed to the Google >>> >>> > Groups >>> >>> > "Django users" group. >>> >>> > To post to this group, send email to django-us...@googlegroups.com. >>> >>> > To unsubscribe from this group, send email to >>> >>> > django-users+unsubscr...@googlegroups.com. >>> >>> > For more options, visit this group at >>> >>> > http://groups.google.com/group/django-users?hl=en. >>> >>> > >>> >>> >>> >>> >>> >>> >>> >>> -- >>> >>> Bradley J. Hintze >>> >>> Graduate Student >>> >>> Duke University >>> >>> School of Medicine >>> >>> 801-712-8799 >>> >>> >>> >>> -- >>> >>> You received this message because you are subscribed to the Google >>> >>> Groups >>> >>> "Django users" group. >>> >>> To post to this group, send email to django-us...@googlegroups.com. >>> >>> To unsubscribe from this group, send email to >>> >>> django-users+unsubscr...@googlegroups.com. >>> >>> For more options, visit this group at >>> >>> http://groups.google.com/group/django-users?hl=en. >>> >>> >>> >> >>> >> -- >>> >> You received this message because you are subscribed to the Google >>> >> Groups >>> >> "Django users" group. >>> >> To post to this group, send email to django-us...@googlegroups.com. >>> >> To unsubscribe from this group, send email to >>> >> django-users+unsubscr...@googlegroups.com. >>> >> For more options, visit this group at >>> >> http://groups.google.com/group/django-users?hl=en. >>> >> >>> > >>> > >>> > >>> > -- >>> > Bradley J. Hintze >>> > Graduate Student >>> > Duke University >>> > School of Medicine >>> > 801-712-8799 >>> > >>> >>> >>> >>> -- >>> Bradley J. Hintze >>> Graduate Student >>> Duke University >>> School of Medicine >>> 801-712-8799 >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Django users" group. >>> To post to this group, send email to django-us...@googlegroups.com. >>> To unsubscribe from this group, send email to >>> django-users+unsubscr...@googlegroups.com. >>> For more options, visit this group at >>> http://groups.google.com/group/django-users?hl=en. >>> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To post to this group, send email to django-us...@googlegroups.com. >> To unsubscribe from this group, send email to >> django-users+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/django-users?hl=en. >> > > > > -- > Bradley J. Hintze > Graduate Student > Duke University > School of Medicine > 801-712-8799 > -- Bradley J. Hintze Graduate Student Duke University School of Medicine 801-712-8799 -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.