Skip to content

Instantly share code, notes, and snippets.

@eugene-goldberg
Created January 22, 2015 18:44
Show Gist options
  • Save eugene-goldberg/54317c59986b9e6be097 to your computer and use it in GitHub Desktop.
Save eugene-goldberg/54317c59986b9e6be097 to your computer and use it in GitHub Desktop.
Edit action
tables.py:
class UpdateWorkload(tables.LinkAction):
name = "update"
verbose_name = _("Edit Workload")
url = "horizon:mydashboard:workload_panel:update"
classes = ("ajax-modal",)
icon = "pencil"
urls.py:
WORKLOADS = r'(?P<id>[^/]+)/%s$'
urlpatterns = patterns('',
url(r'^create/$', views.CreateView.as_view(), name='create'),
url(WORKLOADS % 'update', views.UpdateView.as_view(), name='update'),
url(r'^$', views.IndexView.as_view(), name='index'),
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')
def get_context_data(self, **kwargs):
context = super(UpdateView, self).get_context_data(**kwargs)
context["id"] = self.kwargs['id']
return context
@memoized.memoized_method
def _get_object(self, *args, **kwargs):
workload_id = self.kwargs['id']
try:
print workload_id
except Exception:
redirect = self.success_url
msg = _('Unable to retrieve Workload.')
exceptions.handle(self.request, msg, redirect=redirect)
def get_initial(self):
workload = self._get_object()
return {'id': workload['id'],
'name': workload['name'],
'description': workload['description'],
'image': workload['image']}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment