Ask Your Question
0

OpenStack Horizon - LinkAction is not passing data to the view

asked 2015-01-21 23:37:42 -0500

eugene.goldberg gravatar image

I'm having an issue in one of my data tables - when the table's LinkAction is clicked, it would not pass the data to the corresponding View. I need to have an experience identical to what you get when you choose to update an existing Network record. There, when you click on the "Edit" row action, the corresponding Form is populated with that Network data. In my case, I have a custom dashboard/panel/tab/table. So, when I click on the "Edit" link action within that table row, I do get my Form to show, but it is not passed any data from the row.. Here is my table and action (tables.py):

class UpdateWorkload(tables.LinkAction): name = "update" verbose_name = _("Edit Workload") url = "update" classes = ("ajax-modal",) icon = "pencil"

class WorkloadsTable(tables.DataTable): name = tables.Column("name", verbose_name=_("Name")) description = tables.Column("description", verbose_name=_("Description")) image = tables.Column("image", verbose_name=_("Image")) flavor = tables.Column("flavor", verbose_name=_("Flavor"))

class Meta:
    name = "workloads_table"
    verbose_name = _("Workloads Table")
    table_actions = (CreateNewWorkload,
                     UpdateWorkload,
                     DeleteWorkload)
    row_actions = (UpdateWorkload, DeleteWorkload)

Here is my update view (views.py):

class UpdateView(forms.ModalFormView): form_class = project_forms.UpdateWorkload template_name = 'update_workload.html' context_object_name = 'workload' success_url = reverse_lazy('index')

And here is my form (forms.py):

class UpdateWorkload(forms.SelfHandlingForm): name = forms.CharField(max_length="255", label=_("Workload Name")) description = forms.CharField(widget=forms.Textarea, label=_("Description"), required=False) image_choices = [] images = forms.ChoiceField(label=_("Images"), choices=image_choices) flavor_choices = [] flavors = forms.ChoiceField(label=_("Flavors"), choices=flavor_choices)

def handle(self, request, data):
    try:
        # here we will need to call update on http://127.0.0.1:8000/workloads/ and pass the id
        workload = 0
        msg = _('Workload was successfully updated.')
        messages.success(request, msg)
        # return workload
    except Exception:
        msg = _('Failed to update Workload %s')
        redirect = reverse(self.failure_url)
        exceptions.handle(request, msg, redirect=redirect)

What can I do to make this table and view pass the row data to the form?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-01-23 10:09:13 -0500

eugene.goldberg gravatar image

I had my url path set incorrectly in my view. What I should have had: url = "horizon:mydashboard:workloads_panel:update"

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2015-01-21 23:37:42 -0500

Seen: 419 times

Last updated: Jan 23 '15