[GH-ISSUE #95] Unable to access dictionay in /storage/views.py from storage.html #79

Closed
opened 2026-02-27 16:00:59 +03:00 by kerem · 4 comments
Owner

Originally created by @swatcat on GitHub (Aug 2, 2013).
Original GitHub issue: https://github.com/retspen/webvirtmgr/issues/95

I am a newbie to Django and struggling with it. So this is what I am trying to do:
I do a POST.get to get value of "directorypath" from the UI.

file_info=volumes_by_path(path)

This will return a dictionary with key as filename and values as (filesize, fileformat).
Now I need to use file_info and print all the values in the table. I tried doin this the way u had done for "Add Image". Same html code, same way u loop through the dictionary. But the storage.html file is not able to access "file_info" in views.py.

This is what I have in views.py:

if 'addimg' in request.POST:
........
........

if 'cloneaddimg' in request.POST:
name = request.POST.get('name','')
path = request.POST.get('path','')

                f3 = open("/x/webvirtmgr/templates/path.txt", "w+")
                f3.write(str(path))
                f3.close()

                name_have_symbol = re.search('[^a-zA-Z0-9\_\-\.]+', name)
                path_have_symbol = re.search('[^a-zA-Z0-9\/]+', path)

                if not name:
                    msg = _("No name has been entered")
                    errors.append(msg)
                if not path:
                    msg = _("No path has been entered")
                    errors.append(msg)
                if len(name) > 20:
                    msg = _("The host name must not exceed 20")
                    errors.append(msg)
                else:
                    if name_have_symbol:
                        msg = _("The host name must not contain any special characters")
                        errors.append(msg)
                    if path_have_symbol:
                        msg = _("The path must not contain any special characters other than "/"")
                        errors.append(msg)
                if not errors:
                             file_info = volumes_by_path(path)
                             return HttpResponseRedirect('/storage/%s/%s' % (host_id, pool))

I would really appreciate if you could help me with this asap. I want to use this file_info and simply print it in the table they way u doing it.

Thank you in advance.

Originally created by @swatcat on GitHub (Aug 2, 2013). Original GitHub issue: https://github.com/retspen/webvirtmgr/issues/95 I am a newbie to Django and struggling with it. So this is what I am trying to do: I do a POST.get to get value of "directorypath" from the UI. file_info=volumes_by_path(path) This will return a dictionary with key as filename and values as (filesize, fileformat). Now I need to use file_info and print all the values in the table. I tried doin this the way u had done for "Add Image". Same html code, same way u loop through the dictionary. But the storage.html file is not able to access "file_info" in views.py. This is what I have in views.py: if 'addimg' in request.POST: ........ ........ if 'cloneaddimg' in request.POST: name = request.POST.get('name','') path = request.POST.get('path','') ``` f3 = open("/x/webvirtmgr/templates/path.txt", "w+") f3.write(str(path)) f3.close() name_have_symbol = re.search('[^a-zA-Z0-9\_\-\.]+', name) path_have_symbol = re.search('[^a-zA-Z0-9\/]+', path) if not name: msg = _("No name has been entered") errors.append(msg) if not path: msg = _("No path has been entered") errors.append(msg) if len(name) > 20: msg = _("The host name must not exceed 20") errors.append(msg) else: if name_have_symbol: msg = _("The host name must not contain any special characters") errors.append(msg) if path_have_symbol: msg = _("The path must not contain any special characters other than "/"") errors.append(msg) if not errors: file_info = volumes_by_path(path) return HttpResponseRedirect('/storage/%s/%s' % (host_id, pool)) ``` I would really appreciate if you could help me with this asap. I want to use this file_info and simply print it in the table they way u doing it. Thank you in advance.
kerem closed this issue 2026-02-27 16:00:59 +03:00
Author
Owner

@swatcat commented on GitHub (Aug 2, 2013):

Figured out the problem. WHen I click on the submit button after entering value for a path in the form, the views.py for some reason gets refreshed twice and hence the data wipes out and nothing gets displayed on the screen.

Any idea why this is happening and how it can be fixed?
Thank you

<!-- gh-comment-id:22043566 --> @swatcat commented on GitHub (Aug 2, 2013): Figured out the problem. WHen I click on the submit button after entering value for a path in the form, the views.py for some reason gets refreshed twice and hence the data wipes out and nothing gets displayed on the screen. Any idea why this is happening and how it can be fixed? Thank you
Author
Owner

@retspen commented on GitHub (Aug 5, 2013):

Commet all lines where 'return HttpResponseRedirect' for test. What happen?

<!-- gh-comment-id:22129058 --> @retspen commented on GitHub (Aug 5, 2013): Commet all lines where 'return HttpResponseRedirect' for test. What happen?
Author
Owner

@swatcat commented on GitHub (Aug 6, 2013):

I tried that but nothing changed. I did a work around. wrote requesr.session["vol"] = dictionaryname
and then inputing all the values to db and doing a select. Its a patch.

Now I intend to copy a disk from the machine where I have webvirtmgr running to a hypervisor. Basically I am providing the user option of selecting an existing image from their machine (where webvirtmgr is deployed) and then copy that image to the hypervisor for launchin a VM.

Can you suggest as to how to achieve this. I dont find any command online neither there is a libvirt function which can do this.

I would appreciate if you could reply back ASAP.

Thank you for all your help.

<!-- gh-comment-id:22202890 --> @swatcat commented on GitHub (Aug 6, 2013): I tried that but nothing changed. I did a work around. wrote requesr.session["vol"] = dictionaryname and then inputing all the values to db and doing a select. Its a patch. Now I intend to copy a disk from the machine where I have webvirtmgr running to a hypervisor. Basically I am providing the user option of selecting an existing image from their machine (where webvirtmgr is deployed) and then copy that image to the hypervisor for launchin a VM. Can you suggest as to how to achieve this. I dont find any command online neither there is a libvirt function which can do this. I would appreciate if you could reply back ASAP. Thank you for all your help.
Author
Owner

@retspen commented on GitHub (Aug 7, 2013):

I understand you modify the panel to fit your needs or webvirtmgr does not work?

<!-- gh-comment-id:22240995 --> @retspen commented on GitHub (Aug 7, 2013): I understand you modify the panel to fit your needs or webvirtmgr does not work?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/webvirtmgr#79
No description provided.