Skip to content

Commit

Permalink
Add docstrings in store.views module and remove unused import
Browse files Browse the repository at this point in the history
  • Loading branch information
munuhee committed Jan 4, 2024
1 parent faf847e commit c3fdea2
Showing 1 changed file with 114 additions and 2 deletions.
116 changes: 114 additions & 2 deletions store/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
"""
Module: store.views
Contains Django views for managing items, profiles, and deliveries in the store application.
Classes handle product listing, creation, updating, deletion, and delivery management.
The module integrates with Django's authentication and querying functionalities.
"""
import operator
from functools import reduce
from django.shortcuts import render
from django.urls import reverse
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.views.generic import (
ListView,
DetailView,
CreateView,
UpdateView,
Expand All @@ -27,6 +34,15 @@

@login_required
def dashboard(request):
"""
View function to render the dashboard with item and profile data.
Args:
- request: HttpRequest object.
Returns:
- Rendered template with dashboard data.
"""
profiles = Profile.objects.all()
Category.objects.annotate(nitem=Count('item'))
items = Item.objects.all()
Expand Down Expand Up @@ -66,6 +82,16 @@ def dashboard(request):
}
return render(request, 'store/dashboard.html', context)
class ProductListView(LoginRequiredMixin, ExportMixin, tables.SingleTableView):
"""
View class to display a list of products.
Attributes:
- model: The model associated with the view.
- table_class: The table class used for rendering.
- template_name: The HTML template used for rendering the view.
- context_object_name: The variable name for the context object.
- paginate_by: Number of items per page for pagination.
"""
model = Item
table_class = ItemTable
template_name = 'store/productslist.html'
Expand All @@ -74,6 +100,12 @@ class ProductListView(LoginRequiredMixin, ExportMixin, tables.SingleTableView):
SingleTableView.table_pagination = False

class ItemSearchListView(ProductListView):
"""
View class to search and display a filtered list of items.
Attributes:
- paginate_by: Number of items per page for pagination.
"""
paginate_by = 10

def get_queryset(self):
Expand All @@ -89,13 +121,29 @@ def get_queryset(self):
return result

class ProductDetailView(LoginRequiredMixin, FormMixin, DetailView):
"""
View class to display detailed information about a product.
Attributes:
- model: The model associated with the view.
- template_name: The HTML template used for rendering the view.
"""
model = Item
template_name = 'store/productdetail.html'

def get_success_url(self):
return reverse('product-detail', kwargs={'slug': self.object.slug})

class ProductCreateView(LoginRequiredMixin, CreateView):
"""
View class to create a new product.
Attributes:
- model: The model associated with the view.
- template_name: The HTML template used for rendering the view.
- form_class: The form class used for data input.
- success_url: The URL to redirect to upon successful form submission.
"""
model = Item
template_name = 'store/productcreate.html'
form_class = ProductForm
Expand All @@ -109,6 +157,15 @@ def test_func(self):
return True

class ProductUpdateView(LoginRequiredMixin, UserPassesTestMixin, UpdateView):
"""
View class to update product information.
Attributes:
- model: The model associated with the view.
- template_name: The HTML template used for rendering the view.
- fields: The fields to be updated.
- success_url: The URL to redirect to upon successful form submission.
"""
model = Item
template_name = 'store/productupdate.html'
fields = ['name','category','quantity','selling_price', 'expiring_date', 'vendor']
Expand All @@ -122,6 +179,14 @@ def test_func(self):


class ProductDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):
"""
View class to delete a product.
Attributes:
- model: The model associated with the view.
- template_name: The HTML template used for rendering the view.
- success_url: The URL to redirect to upon successful deletion.
"""
model = Item
template_name = 'store/productdelete.html'
success_url = '/products'
Expand All @@ -133,14 +198,28 @@ def test_func(self):
else:
return False

# Delivery
class DeliveryListView(LoginRequiredMixin, ExportMixin, tables.SingleTableView):
"""
View class to display a list of deliveries.
Attributes:
- model: The model associated with the view.
- pagination: Number of items per page for pagination.
- template_name: The HTML template used for rendering the view.
- context_object_name: The variable name for the context object.
"""
model = Delivery
pagination = 10
template_name = 'store/deliveries.html'
context_object_name = 'deliveries'

class DeliverySearchListView(DeliveryListView):
"""
View class to search and display a filtered list of deliveries.
Attributes:
- paginate_by: Number of items per page for pagination.
"""
paginate_by = 10

def get_queryset(self):
Expand All @@ -156,21 +235,54 @@ def get_queryset(self):
return result

class DeliveryDetailView(LoginRequiredMixin, DetailView):
"""
View class to display detailed information about a delivery.
Attributes:
- model: The model associated with the view.
- template_name: The HTML template used for rendering the view.
"""
model = Delivery
template_name = 'store/deliverydetail.html'
class DeliveryCreateView(LoginRequiredMixin, CreateView):
"""
View class to create a new delivery.
Attributes:
- model: The model associated with the view.
- fields: The fields to be included in the form.
- template_name: The HTML template used for rendering the view.
- success_url: The URL to redirect to upon successful form submission.
"""
model = Delivery
fields = ['item', 'customer_name', 'phone_number', 'location', 'date','is_delivered']
template_name = 'store/deliveriescreate.html'
success_url = '/deliveries'

class DeliveryUpdateView(LoginRequiredMixin, UpdateView):
"""
View class to update delivery information.
Attributes:
- model: The model associated with the view.
- fields: The fields to be updated.
- template_name: The HTML template used for rendering the view.
- success_url: The URL to redirect to upon successful form submission.
"""
model = Delivery
fields = ['item', 'customer_name', 'phone_number', 'location', 'date','is_delivered']
template_name = 'store/deliveryupdate.html'
success_url = '/deliveries'

class DeliveryDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):
"""
View class to delete a delivery.
Attributes:
- model: The model associated with the view.
- template_name: The HTML template used for rendering the view.
- success_url: The URL to redirect to upon successful deletion.
"""
model = Delivery
template_name = 'store/productdelete.html'
success_url = '/deliveries'
Expand Down

0 comments on commit c3fdea2

Please sign in to comment.