gva/gnuviechadmin/hostingpackages/views.py
Jan Dittberner 680f091cba 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
2015-01-20 00:51:05 +01:00

47 lines
1.3 KiB
Python

"""
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)