implement CustomerHostingPackageDetails view
This commit is contained in:
parent
0baee51d19
commit
0d08d9876b
3 changed files with 54 additions and 6 deletions
|
@ -22,3 +22,17 @@
|
||||||
|
|
||||||
.. automodule:: hostingpackages.models
|
.. automodule:: hostingpackages.models
|
||||||
:members:
|
:members:
|
||||||
|
|
||||||
|
|
||||||
|
:py:mod:`views <hostingpackages.views>`
|
||||||
|
---------------------------------------
|
||||||
|
|
||||||
|
.. automodule:: hostingpackages.views
|
||||||
|
:members:
|
||||||
|
|
||||||
|
|
||||||
|
:py:mod:`urls <hostingpackages.urls>`
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
.. automodule:: hostingpackages.urls
|
||||||
|
:members:
|
||||||
|
|
|
@ -1,12 +1,22 @@
|
||||||
|
"""
|
||||||
|
This module defines the URL patterns for hosting package related views.
|
||||||
|
|
||||||
|
"""
|
||||||
from __future__ import absolute_import, unicode_literals
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
from django.conf.urls import patterns, url
|
from django.conf.urls import patterns, url
|
||||||
|
|
||||||
from .views import CreateHostingPackage
|
from .views import (
|
||||||
|
CreateHostingPackage,
|
||||||
|
CustomerHostingPackageDetails,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = patterns(
|
urlpatterns = patterns(
|
||||||
'',
|
'',
|
||||||
url(r'^(?P<user>[\w0-9@.+-_]+)/create$', CreateHostingPackage.as_view(),
|
url(r'^(?P<user>[\w0-9@.+-_]+)/create$', CreateHostingPackage.as_view(),
|
||||||
name='create_hosting_package'),
|
name='create_hosting_package'),
|
||||||
|
url(r'^(?P<user>[\w0-9@.+-_]+)/hostingpackage/(?P<pk>\d+)/$',
|
||||||
|
CustomerHostingPackageDetails.as_view(),
|
||||||
|
name='hosting_package_details'),
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,18 +4,22 @@ This module defines views related to hosting packages.
|
||||||
"""
|
"""
|
||||||
from __future__ import absolute_import, unicode_literals
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
from django.views.generic import DetailView
|
||||||
from django.views.generic.edit import CreateView
|
from django.views.generic.edit import CreateView
|
||||||
from django.contrib.auth import get_user_model
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
from braces.views import (
|
from braces.views import (
|
||||||
LoginRequiredMixin,
|
LoginRequiredMixin,
|
||||||
StaffuserRequiredMixin,
|
StaffuserRequiredMixin,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from gvacommon.viewmixins import StaffOrSelfLoginRequiredMixin
|
||||||
|
|
||||||
from .forms import CreateHostingPackageForm
|
from .forms import CreateHostingPackageForm
|
||||||
from .models import CustomerHostingPackage
|
from .models import CustomerHostingPackage
|
||||||
|
|
||||||
|
@ -37,13 +41,12 @@ class CreateHostingPackage(
|
||||||
kwargs.update(self.kwargs)
|
kwargs.update(self.kwargs)
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
def _get_customer(self):
|
def get_customer_object(self):
|
||||||
return get_user_model().objects.get(username=self.kwargs['user'])
|
return get_user_model().objects.get(username=self.kwargs['user'])
|
||||||
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(CreateHostingPackage, self).get_context_data(**kwargs)
|
context = super(CreateHostingPackage, self).get_context_data(**kwargs)
|
||||||
context['customer'] = self._get_customer()
|
context['customer'] = self.get_customer_object()
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
|
@ -52,7 +55,7 @@ class CreateHostingPackage(
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
hostingpackage = form.save(commit=False)
|
hostingpackage = form.save(commit=False)
|
||||||
hostingpackage.customer = self._get_customer()
|
hostingpackage.customer = self.get_customer_object()
|
||||||
hostingpackage.save()
|
hostingpackage.save()
|
||||||
messages.success(
|
messages.success(
|
||||||
self.request,
|
self.request,
|
||||||
|
@ -60,3 +63,24 @@ class CreateHostingPackage(
|
||||||
name=hostingpackage.name)
|
name=hostingpackage.name)
|
||||||
)
|
)
|
||||||
return redirect(self.get_success_url())
|
return redirect(self.get_success_url())
|
||||||
|
|
||||||
|
|
||||||
|
class CustomerHostingPackageDetails(StaffOrSelfLoginRequiredMixin, DetailView):
|
||||||
|
"""
|
||||||
|
This view is for showing details of a customer hosting package.
|
||||||
|
|
||||||
|
"""
|
||||||
|
model = CustomerHostingPackage
|
||||||
|
context_object_name = 'hostingpackage'
|
||||||
|
|
||||||
|
def get_customer_object(self):
|
||||||
|
return get_user_model().objects.get(username=self.kwargs['user'])
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super(CustomerHostingPackageDetails, self).get_context_data(
|
||||||
|
**kwargs)
|
||||||
|
context.update({
|
||||||
|
'customer': self.get_customer_object(),
|
||||||
|
'uploadserver': settings.OSUSER_UPLOAD_SERVER,
|
||||||
|
})
|
||||||
|
return context
|
||||||
|
|
Loading…
Reference in a new issue