Created
January 21, 2015 17:04
-
-
Save eugene-goldberg/03d272fb41f56931b24e to your computer and use it in GitHub Desktop.
horizon - forms - issue with form_action:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The issue is: when the form_action in my _create.html is specified this way: {% block form_action %}{% url 'workloads_panel:create' %}{% endblock %} - I get NoReverseMatch: u'workloads_panel' is not a registered namespace; "GET /mydashboard/workloads_panel/create/ HTTP/1.1" 500 35672 | |
Here is my directory structure under openstack_dashboard/dashboards/mydashboard: | |
. | |
├── blueprints_panel | |
│ ├── __init__.py | |
│ ├── __init__.pyc | |
│ ├── models.py | |
│ ├── models.pyc | |
│ ├── panel.py | |
│ ├── panel.pyc | |
│ ├── tables.py | |
│ ├── tables.pyc | |
│ ├── tabs.py | |
│ ├── tabs.pyc | |
│ ├── templates | |
│ │ └── blueprints_panel | |
│ │ └── index.html | |
│ ├── tests.py | |
│ ├── tests.pyc | |
│ ├── urls.py | |
│ ├── urls.pyc | |
│ ├── views.py | |
│ └── views.pyc | |
├── dashboard.py | |
├── dashboard.pyc | |
├── __init__.py | |
├── __init__.pyc | |
├── models.py | |
├── models.pyc | |
├── software_packages_panel | |
│ ├── __init__.py | |
│ ├── __init__.pyc | |
│ ├── models.py | |
│ ├── panel.py | |
│ ├── panel.pyc | |
│ ├── tables.py | |
│ ├── tables.pyc | |
│ ├── tabs.py | |
│ ├── tabs.pyc | |
│ ├── templates | |
│ │ └── software_packages_panel | |
│ │ └── index.html | |
│ ├── urls.py | |
│ ├── urls.pyc | |
│ ├── views.py | |
│ └── views.pyc | |
├── static | |
│ └── mydashboard | |
│ ├── css | |
│ │ └── mydashboard.css | |
│ └── js | |
│ └── mydashboard.js | |
├── templates | |
│ └── mydashboard | |
│ ├── base.html | |
│ └── workload_detail.html | |
└── workloads_panel | |
├── forms.py | |
├── forms.pyc | |
├── __init__.py | |
├── __init__.pyc | |
├── models.py | |
├── panel.py | |
├── panel.pyc | |
├── tables.py | |
├── tables.pyc | |
├── tabs.py | |
├── tabs.pyc | |
├── templates | |
│ └── workloads_panel | |
│ ├── _create.html | |
│ ├── create.html | |
│ └── index.html | |
├── urls.py | |
├── urls.pyc | |
├── views.py | |
├── views.pyc | |
├── workflows.py | |
└── workflows.pyc | |
Here is the workloads_panel/urls.py: | |
from django.conf.urls import patterns | |
from django.conf.urls import url | |
from openstack_dashboard.dashboards.mydashboard.workloads_panel import views | |
from openstack_dashboard.dashboards.mydashboard.workloads_panel.views import UpdateView | |
RESOURCE_CLASS = r'^(?P<resource_class_id>[^/]+)/%s$' | |
urlpatterns = patterns('', | |
url(r'^create/$', views.CreateView.as_view(), name='create'), | |
url(r'^$', views.IndexView.as_view(), name='index'), | |
url(r'^\?tab=workloads_tabs_tab$', | |
views.IndexView.as_view(), name='workloads_tabs'), | |
url(r'^(?P<instance_id>[^/]+)/$', | |
views.UpdateView.as_view(), name='update'), | |
url(RESOURCE_CLASS % 'update', UpdateView.as_view(), name='update'), | |
) | |
Here is the workloads_panel/templates/workloads_panel/create.html | |
{% extends 'base.html' %} | |
{% load i18n %} | |
{% block title %}{% trans "Create Workload" %}{% endblock %} | |
{% block page_header %} | |
{% include "horizon/common/_page_header.html" with title=_("Create Workload") %} | |
{% endblock page_header %} | |
{% block main %} | |
{% include "_create.html" %} | |
{% endblock %} | |
Here is Here is the workloads_panel/templates/workloads_panel/_create.html | |
{% extends "horizon/common/_modal_form.html" %} | |
{% load i18n %} | |
{% load url from future %} | |
{% block form_id %}create_workload_form{% endblock %} | |
{% block form_action %}{% url 'workloads_panel:create' %}{% endblock %} | |
{% block modal_id %}create_workload_modal{% endblock %} | |
{% block modal-header %}{% trans "Create Workload" %}{% endblock %} | |
{% block modal-body %} | |
<div class="left"> | |
<fieldset> | |
{% include "horizon/common/_form_fields.html" %} | |
</fieldset> | |
</div> | |
<div class="right"> | |
<h3>{% trans "Description:" %}</h3> | |
<p>{% trans "Create a new Workload."%}</p> | |
<p>{% trans "A Workload includes OS type from Images and Size from Flavors"%}</p> | |
</div> | |
{% endblock %} | |
{% block modal-footer %} | |
<input class="btn btn-primary pull-right" type="submit" value="{% trans "Create Workload" %}" /> | |
<a href="{% url 'horizon:admin:networks:index' %}" class="btn btn-default secondary cancel close">{% trans "Cancel" %}</a> | |
{% endblock %} | |
Here is workloads_panel/views.py (partial) | |
class CreateView(forms.ModalFormView): | |
form_class = project_forms.CreateWorkloadForm | |
template_name = 'create.html' | |
Here is workloads_panel/forms.py | |
class CreateWorkloadForm(forms.SelfHandlingForm): | |
name = forms.CharField(max_length="255", label=_("Workload Name")) | |
description = forms.CharField(widget=forms.Textarea, | |
label=_("Description"), required=False) | |
def __init__(self, request, *args, **kwargs): | |
super(CreateWorkloadForm, self).__init__(request, *args, **kwargs) | |
# populate volume_id | |
volume_id = kwargs.get('initial', {}).get('volume_id', []) | |
self.fields['volume_id'] = forms.CharField(widget=forms.HiddenInput(), | |
initial=volume_id) | |
def handle(self, request, data): | |
try: | |
message = _('Creating Workload') | |
messages.info(request, message) | |
return True | |
except Exception: | |
redirect = reverse("horizon:project:volumes:index") | |
exceptions.handle(request, | |
_('Unable to create Workload.'), | |
redirect=redirect) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm no Django expert, but @ line 93 where you have
urlpatterns = patterns('',
I think you want something like
urlpatterns = patterns('openstack_dashboard.dashboards.workloads_panel.views',
to describe where your views are found
relevant doc:
https://docs.djangoproject.com/en/1.7/ref/urls/