add new view CustomerHostingPackageList
- create view hostingpackages.views.CustomerHostingPackageList to display a specific customer's hosting packages - add docstring to view AllCustomerHostingPackageList - add URL pattern 'hosting_packages' to hostingpackages.urls - restructure hostingpackages URL patterns to remove useless parts - add template hostingpackages/customerhostingpackage_list.html - change links in template base.html to link to 'hosting_packages'
This commit is contained in:
parent
3f07ddb062
commit
2d4282194f
4 changed files with 92 additions and 7 deletions
|
@ -12,6 +12,7 @@ from .views import (
|
|||
CreateCustomerHostingPackage,
|
||||
CreateHostingPackage,
|
||||
CustomerHostingPackageDetails,
|
||||
CustomerHostingPackageList,
|
||||
HostingOptionChoices,
|
||||
)
|
||||
|
||||
|
@ -20,10 +21,12 @@ urlpatterns = patterns(
|
|||
'',
|
||||
url(r'^create$', CreateHostingPackage.as_view(),
|
||||
name='create_hosting_package'),
|
||||
url(r'^(?P<user>[\w0-9@.+-_]+)/create$',
|
||||
url(r'^(?P<user>[\w0-9@.+-]+)/$',
|
||||
CustomerHostingPackageList.as_view(), name='hosting_packages'),
|
||||
url(r'^(?P<user>[\w0-9@.+-]+)/create$',
|
||||
CreateCustomerHostingPackage.as_view(),
|
||||
name='create_customer_hosting_package'),
|
||||
url(r'^(?P<user>[\w0-9@.+-_]+)/hostingpackage/(?P<pk>\d+)/$',
|
||||
url(r'^(?P<user>[\w0-9@.+-]+)/(?P<pk>\d+)/$',
|
||||
CustomerHostingPackageDetails.as_view(),
|
||||
name='hosting_package_details'),
|
||||
url(r'^allpackages/',
|
||||
|
|
|
@ -103,10 +103,13 @@ class CustomerHostingPackageDetails(StaffOrSelfLoginRequiredMixin, DetailView):
|
|||
"""
|
||||
model = CustomerHostingPackage
|
||||
context_object_name = 'hostingpackage'
|
||||
customer = None
|
||||
|
||||
def get_customer_object(self):
|
||||
return get_object_or_404(
|
||||
get_user_model(), username=self.kwargs['user'])
|
||||
if self.customer is None:
|
||||
self.customer = get_object_or_404(
|
||||
get_user_model(), username=self.kwargs['user'])
|
||||
return self.customer
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(CustomerHostingPackageDetails, self).get_context_data(
|
||||
|
@ -128,10 +131,39 @@ class CustomerHostingPackageDetails(StaffOrSelfLoginRequiredMixin, DetailView):
|
|||
class AllCustomerHostingPackageList(
|
||||
LoginRequiredMixin, StaffuserRequiredMixin, ListView
|
||||
):
|
||||
"""
|
||||
This view is used for showing a list of all hosting packages.
|
||||
|
||||
"""
|
||||
model = CustomerHostingPackage
|
||||
template_name_suffix = '_admin_list'
|
||||
|
||||
|
||||
class CustomerHostingPackageList(StaffOrSelfLoginRequiredMixin, ListView):
|
||||
"""
|
||||
This view is used for showing a list of a customer's hosting packages.
|
||||
|
||||
"""
|
||||
model = CustomerHostingPackage
|
||||
customer = None
|
||||
|
||||
def get_customer_object(self):
|
||||
if self.customer is None:
|
||||
self.customer = get_object_or_404(
|
||||
get_user_model(), username=self.kwargs['user'])
|
||||
return self.customer
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(CustomerHostingPackageList, self).get_context_data(
|
||||
**kwargs)
|
||||
context['customer'] = self.get_customer_object()
|
||||
return context
|
||||
|
||||
def get_queryset(self):
|
||||
return super(CustomerHostingPackageList, self).get_queryset().filter(
|
||||
customer__username=self.kwargs['user'])
|
||||
|
||||
|
||||
class HostingOptionChoices(
|
||||
LoginRequiredMixin, StaffuserRequiredMixin, DetailView
|
||||
):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue