incomplete create_hosting_package view
- add staff user view create_hosting_package - add hostingpackages.forms.CreateHostingPackageForm - add hostingpackages.views.CreateHostingPackage - add link for staff users on user_dashboard page - add url pattern - TODO: implement saving the hosting package, update docs
This commit is contained in:
parent
9890248e80
commit
680f091cba
7 changed files with 117 additions and 4 deletions
|
@ -3,15 +3,14 @@ from __future__ import absolute_import
|
||||||
from django.conf.urls import patterns, include, url
|
from django.conf.urls import patterns, include, url
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
import dashboard.urls
|
|
||||||
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
admin.autodiscover()
|
admin.autodiscover()
|
||||||
|
|
||||||
urlpatterns = patterns(
|
urlpatterns = patterns(
|
||||||
'',
|
'',
|
||||||
url(r'', include(dashboard.urls)),
|
url(r'', include('dashboard.urls')),
|
||||||
url(r'^accounts/', include('allauth.urls')),
|
url(r'^accounts/', include('allauth.urls')),
|
||||||
|
url(r'^hosting/', include('hostingpackages.urls')),
|
||||||
url(r'^admin/', include(admin.site.urls)),
|
url(r'^admin/', include(admin.site.urls)),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
44
gnuviechadmin/hostingpackages/forms.py
Normal file
44
gnuviechadmin/hostingpackages/forms.py
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
"""
|
||||||
|
This module contains the form classes related to hosting packages.
|
||||||
|
|
||||||
|
"""
|
||||||
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
|
from django import forms
|
||||||
|
from django.core.urlresolvers import reverse
|
||||||
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
|
from crispy_forms.helper import FormHelper
|
||||||
|
from crispy_forms.layout import (
|
||||||
|
Layout,
|
||||||
|
Submit,
|
||||||
|
)
|
||||||
|
|
||||||
|
from .models import CustomerHostingPackage
|
||||||
|
|
||||||
|
|
||||||
|
class CreateHostingPackageForm(forms.ModelForm):
|
||||||
|
"""
|
||||||
|
This form class is used for creating new customer hosting packages.
|
||||||
|
|
||||||
|
"""
|
||||||
|
class Meta:
|
||||||
|
model = CustomerHostingPackage
|
||||||
|
fields = ['template', 'name', 'description']
|
||||||
|
|
||||||
|
def __init__(self, instance, *args, **kwargs):
|
||||||
|
username = kwargs.pop('user')
|
||||||
|
super(CreateHostingPackageForm, self).__init__(
|
||||||
|
*args, **kwargs
|
||||||
|
)
|
||||||
|
self.fields['description'].widget.attrs['rows'] = 2
|
||||||
|
self.helper = FormHelper()
|
||||||
|
self.helper.form_action = reverse(
|
||||||
|
'create_hosting_package', kwargs={'user': username}
|
||||||
|
)
|
||||||
|
self.helper.layout = Layout(
|
||||||
|
'template',
|
||||||
|
'name',
|
||||||
|
'description',
|
||||||
|
Submit('submit', _('Add Hosting Package')),
|
||||||
|
)
|
12
gnuviechadmin/hostingpackages/urls.py
Normal file
12
gnuviechadmin/hostingpackages/urls.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
|
from django.conf.urls import patterns, url
|
||||||
|
|
||||||
|
from .views import CreateHostingPackage
|
||||||
|
|
||||||
|
|
||||||
|
urlpatterns = patterns(
|
||||||
|
'',
|
||||||
|
url(r'^(?P<user>[\w0-9@.+-_]+)/create$', CreateHostingPackage.as_view(),
|
||||||
|
name='create_hosting_package'),
|
||||||
|
)
|
47
gnuviechadmin/hostingpackages/views.py
Normal file
47
gnuviechadmin/hostingpackages/views.py
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
"""
|
||||||
|
This module defines views related to hosting packages.
|
||||||
|
|
||||||
|
"""
|
||||||
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
|
from django.core.urlresolvers import reverse
|
||||||
|
from django.views.generic.edit import CreateView
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
|
from braces.views import (
|
||||||
|
LoginRequiredMixin,
|
||||||
|
StaffuserRequiredMixin,
|
||||||
|
)
|
||||||
|
|
||||||
|
from .forms import CreateHostingPackageForm
|
||||||
|
from .models import CustomerHostingPackage
|
||||||
|
|
||||||
|
|
||||||
|
class CreateHostingPackage(
|
||||||
|
LoginRequiredMixin, StaffuserRequiredMixin, CreateView
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Create a hosting package.
|
||||||
|
|
||||||
|
"""
|
||||||
|
model = CustomerHostingPackage
|
||||||
|
raise_exception = True
|
||||||
|
template_name_suffix = '_create'
|
||||||
|
form_class = CreateHostingPackageForm
|
||||||
|
|
||||||
|
def get_form_kwargs(self):
|
||||||
|
kwargs = super(CreateHostingPackage, self).get_form_kwargs()
|
||||||
|
kwargs.update(self.kwargs)
|
||||||
|
return kwargs
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super(CreateHostingPackage, self).get_context_data(**kwargs)
|
||||||
|
customer = get_user_model().objects.get(username=self.kwargs['user'])
|
||||||
|
context['customer'] = customer
|
||||||
|
return context
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
return reverse('customer_dashboard', slug=self.kwargs['user'])
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
return super(CreateHostingPackage, self).form_valid(form)
|
|
@ -39,7 +39,10 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p class="text-info">{% trans "You have no hosting packages yet." %}</p>
|
<p class="text-info">{% if user == object %}{% trans "You have no hosting packages yet." %}{% else %}{% trans "This user has no hosting packages assigned yet." %}{% endif %}</p>
|
||||||
|
{% endif %}
|
||||||
|
{% if user.is_staff %}
|
||||||
|
<a href="{% url "create_hosting_package" user=object.username %}" class="btn btn-primary">{% trans "Add hosting package" %}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
1
gnuviechadmin/templates/hostingpackages/base.html
Normal file
1
gnuviechadmin/templates/hostingpackages/base.html
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{% extends "base.html" %}
|
|
@ -0,0 +1,7 @@
|
||||||
|
{% extends "hostingpackages/base.html" %}
|
||||||
|
{% load i18n crispy_forms_tags %}
|
||||||
|
{% block title %}{{ block.super }} - {% blocktrans with full_name=customer.get_full_name %}Add hosting package for Customer {{ full_name }}{% endblocktrans %}{% endblock title %}
|
||||||
|
{% block page_title %}{% blocktrans with full_name=customer.get_full_name %}Add Hosting Package for Customer {{ full_name }}{% endblocktrans %}{% endblock page_title %}
|
||||||
|
{% block content %}
|
||||||
|
{% crispy form %}
|
||||||
|
{% endblock content %}
|
Loading…
Reference in a new issue