From 6804dc4e99d17a2821dfb0ae11b0086ca3aee2ce Mon Sep 17 00:00:00 2001 From: NIKHIL RAVI Date: Mon, 21 Aug 2023 17:25:49 +0530 Subject: [PATCH] [FIX]pylint fix --- asset/admin.py | 17 ++- asset/apps.py | 17 ++- asset/filters.py | 214 ++++++++++++++++++++++-------- asset/forms.py | 315 ++++++++++++++++++++++++++++++++++++--------- asset/models.py | 53 +++++++- asset/resources.py | 15 ++- asset/urls.py | 3 + 7 files changed, 506 insertions(+), 128 deletions(-) diff --git a/asset/admin.py b/asset/admin.py index 3a58b4da9..cc047e630 100644 --- a/asset/admin.py +++ b/asset/admin.py @@ -1,5 +1,18 @@ +""" +Module: admin.py +Description: This module is responsible for registering models + to be managed through the Django admin interface. +Models Registered: +- Asset: Represents a physical asset with relevant details. +- AssetCategory: Categorizes assets for better organization. +- AssetRequest: Manages requests for acquiring assets. +- AssetAssignment: Tracks the assets assigned to employees. +- AssetLot: Represents a collection of assets under a lot number. +""" + from django.contrib import admin -from .models import Asset,AssetCategory,AssetRequest,AssetAssignment,AssetLot +from .models import Asset, AssetCategory, AssetRequest, AssetAssignment, AssetLot + # Register your models here. @@ -7,4 +20,4 @@ admin.site.register(Asset) admin.site.register(AssetRequest) admin.site.register(AssetCategory) admin.site.register(AssetAssignment) -admin.site.register(AssetLot) \ No newline at end of file +admin.site.register(AssetLot) diff --git a/asset/apps.py b/asset/apps.py index 46953e747..942273168 100644 --- a/asset/apps.py +++ b/asset/apps.py @@ -1,6 +1,19 @@ +""" +Module: apps.py +Description: Configuration for the 'asset' app. +""" from django.apps import AppConfig class AssetConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'asset' + """ + Class: AssetConfig + Description: Configuration class for the 'asset' app. + + Attributes: + default_auto_field (str): Default auto-generated field type for primary keys. + name (str): Name of the app. + """ + + default_auto_field = "django.db.models.BigAutoField" + name = "asset" diff --git a/asset/filters.py b/asset/filters.py index 219d4dbf6..c0acfa48c 100644 --- a/asset/filters.py +++ b/asset/filters.py @@ -1,91 +1,195 @@ -from django_filters import FilterSet -from django_filters import FilterSet, CharFilter -import django_filters -from .models import Asset,AssetAssignment,AssetCategory,AssetRequest,AssetLot -from django import forms -import uuid +""" +Module containing custom filter classes for various models. +""" + +import uuid +import django_filters +from django import forms +from django_filters import FilterSet +from .models import Asset, AssetAssignment, AssetCategory, AssetRequest - class CustomFilterSet(FilterSet): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - + for field_name, field in self.filters.items(): filter_widget = self.filters[field_name] widget = filter_widget.field.widget - if isinstance(widget, (forms.NumberInput, forms.EmailInput,forms.TextInput)): - filter_widget.field.widget.attrs.update({'class': 'oh-input w-100'}) - elif isinstance(widget,(forms.Select,)): - filter_widget.field.widget.attrs.update({'class': 'oh-select oh-select-2',}) - elif isinstance(widget,(forms.Textarea)): - filter_widget.field.widget.attrs.update({'class': 'oh-input w-100'}) - elif isinstance(widget, (forms.CheckboxInput,forms.CheckboxSelectMultiple,)): - filter_widget.field.widget.attrs.update({'class': 'oh-switch__checkbox'}) - elif isinstance(widget,(forms.ModelChoiceField)): - filter_widget.field.widget.attrs.update({'class': 'oh-select oh-select-2 ',}) - elif isinstance(widget,(forms.DateField)): - filter_widget.field.widget.attrs.update({'type': 'date','class':'oh-input w-100'}) + if isinstance( + widget, (forms.NumberInput, forms.EmailInput, forms.TextInput) + ): + filter_widget.field.widget.attrs.update({"class": "oh-input w-100"}) + elif isinstance(widget, (forms.Select,)): + filter_widget.field.widget.attrs.update( + { + "class": "oh-select oh-select-2", + } + ) + elif isinstance(widget, (forms.Textarea)): + filter_widget.field.widget.attrs.update({"class": "oh-input w-100"}) + elif isinstance( + widget, + ( + forms.CheckboxInput, + forms.CheckboxSelectMultiple, + ), + ): + filter_widget.field.widget.attrs.update( + {"class": "oh-switch__checkbox"} + ) + elif isinstance(widget, (forms.ModelChoiceField)): + filter_widget.field.widget.attrs.update( + { + "class": "oh-select oh-select-2 ", + } + ) + elif isinstance(widget, (forms.DateField)): + filter_widget.field.widget.attrs.update( + {"type": "date", "class": "oh-input w-100"} + ) if isinstance(field, django_filters.CharFilter): - field.lookup_expr='icontains' - - + field.lookup_expr = "icontains" + + class AssetExportFilter(CustomFilterSet): - + """ + Custom filter class for exporting filtered Asset data. + """ + class Meta: + """ + A nested class that specifies the configuration for the filter. + model(class): The Asset model is used to filter. + fields (str): A special value "__all__" to include all fields + of the model in the filter. + """ + model = Asset - fields = '__all__' + fields = "__all__" def __init__(self, *args, **kwargs): super(AssetExportFilter, self).__init__(*args, **kwargs) - self.form.fields['asset_purchase_date'].widget.attrs.update({'type':'date'}) - + self.form.fields["asset_purchase_date"].widget.attrs.update({"type": "date"}) + + class AssetFilter(CustomFilterSet): + """ + Custom filter set for Asset instances. + """ + class Meta: + """ + A nested class that specifies the configuration for the filter. + model(class): The Asset model is used to filter. + fields (str): A special value "__all__" to include all fields + of the model in the filter. + """ + model = Asset - fields = '__all__' - def __init__(self,*args,**kwargs): - super(AssetFilter,self).__init__(*args,**kwargs) + fields = "__all__" + + def __init__(self, *args, **kwargs): + super(AssetFilter, self).__init__(*args, **kwargs) for visible in self.form.visible_fields(): - visible.field.widget.attrs['id'] = str(uuid.uuid4()) - + visible.field.widget.attrs["id"] = str(uuid.uuid4()) + class CustomAssetFilter(CustomFilterSet): - asset_id__asset_name = django_filters.CharFilter(lookup_expr='icontains') + """ + Custom filter set for asset assigned to employees instances. + """ + + asset_id__asset_name = django_filters.CharFilter(lookup_expr="icontains") class Meta: - model = AssetAssignment - fields =['asset_id__asset_name','asset_id__asset_status',] - def __init__(self,*args,**kwargs): - super(CustomAssetFilter,self).__init__(*args,**kwargs) - for visible in self.form.visible_fields(): - visible.field.widget.attrs['id'] = str(uuid.uuid4()) + """ + Specifies the model and fields to be used for filtering AssetAssignment instances. + + Attributes: + model (class): The model class AssetAssignment to be filtered. + fields (list): The fields to include in the filter, referring to + related AssetAssignment fields. + """ + + model = AssetAssignment + fields = [ + "asset_id__asset_name", + "asset_id__asset_status", + ] + + def __init__(self, *args, **kwargs): + super(CustomAssetFilter, self).__init__(*args, **kwargs) + for visible in self.form.visible_fields(): + visible.field.widget.attrs["id"] = str(uuid.uuid4()) + - class AssetRequestFilter(CustomFilterSet): + """ + Custom filter set for AssetRequest instances. + """ + class Meta: + """ + Specifies the model and fields to be used for filtering AssetRequest instances. + + Attributes: + model (class): The model class AssetRequest to be filtered. + fields (str): A special value "__all__" to include all fields of the model in the filter. + """ + model = AssetRequest - fields = '__all__' - def __init__(self,*args,**kwargs): - super(AssetRequestFilter,self).__init__(*args,**kwargs) + fields = "__all__" + + def __init__(self, *args, **kwargs): + super(AssetRequestFilter, self).__init__(*args, **kwargs) for visible in self.form.visible_fields(): - visible.field.widget.attrs['id'] = str(uuid.uuid4()) - + visible.field.widget.attrs["id"] = str(uuid.uuid4()) + + class AssetAllocationFilter(CustomFilterSet): + """ + Custom filter set for AssetAllocation instances. + """ + class Meta: + """ + Specifies the model and fields to be used for filtering AssetAllocation instances. + + Attributes: + model (class): The model class AssetAssignment to be filtered. + fields (str): A special value "__all__" to include all fields + of the model in the filter. + """ + model = AssetAssignment - fields = '__all__' - def __init__(self,*args,**kwargs): - super(AssetAllocationFilter,self).__init__(*args,**kwargs) + fields = "__all__" + + def __init__(self, *args, **kwargs): + super(AssetAllocationFilter, self).__init__(*args, **kwargs) for visible in self.form.visible_fields(): - visible.field.widget.attrs['id'] = str(uuid.uuid4()) - + visible.field.widget.attrs["id"] = str(uuid.uuid4()) + + class AssetCategoryFilter(CustomFilterSet): + """ + Custom filter set for AssetCategory instances. + """ + class Meta: + """ + Specifies the model and fields to be used for filtering AssetCategory instances. + + Attributes: + model (class): The model class AssetCategory to be filtered. + fields (str): A special value "__all__" to include all fields + of the model in the filter. + """ + model = AssetCategory - fields = '__all__' - def __init__(self,*args,**kwargs): - super(AssetCategoryFilter,self).__init__(*args,**kwargs) + fields = "__all__" + + def __init__(self, *args, **kwargs): + super(AssetCategoryFilter, self).__init__(*args, **kwargs) for visible in self.form.visible_fields(): - visible.field.widget.attrs['id'] = str(uuid.uuid4()) - + visible.field.widget.attrs["id"] = str(uuid.uuid4()) diff --git a/asset/forms.py b/asset/forms.py index 321200ad0..12bd4c547 100644 --- a/asset/forms.py +++ b/asset/forms.py @@ -1,47 +1,95 @@ -from .models import Asset, AssetRequest, AssetAssignment,AssetCategory,AssetLot -from django.forms import ModelForm, DateInput -from django.core.exceptions import ValidationError -from django import forms +""" +Asset Management Forms + +This module contains Django ModelForms for handling various aspects of asset management, +including asset creation, allocation, return, category assignment, and batch handling. +""" import uuid -from employee.models import Employee +from django import forms +from django.forms import ModelForm +from django.core.exceptions import ValidationError from django.utils.translation import gettext_lazy as _ +from employee.models import Employee +from .models import Asset, AssetRequest, AssetAssignment, AssetCategory, AssetLot def set_date_field_initial(instance): - """ this is used to update change the date value format """ + """this is used to update change the date value format""" initial = {} if instance.asset_purchase_date is not None: - initial['asset_purchase_date'] = instance.asset_purchase_date.strftime('%Y-%m-%d') - + initial["asset_purchase_date"] = instance.asset_purchase_date.strftime( + "%Y-%m-%d" + ) + return initial class AssetForm(ModelForm): + """ + A ModelForm for creating and updating asset information. + """ class Meta: - model = Asset - fields = '__all__' - widgets = { - 'asset_name': forms.TextInput(attrs={'placeholder': 'Macbook Pro.', 'class': 'oh-input w-100'}), - 'asset_description': forms.Textarea(attrs={"type": "text","placeholder": _("A powerful laptop for business use."), "class": "oh-input oh-input--textarea oh-input--block","rows":3,"cols":40}), - 'asset_tracking_id': forms.TextInput(attrs={'placeholder': 'LPT001', 'class': 'oh-input w-100'}), - 'asset_purchase_date': forms.DateInput(attrs={"type": "date", "class": "oh-input w-100"}), - 'asset_purchase_cost':forms.NumberInput(attrs={'class': 'oh-input w-100',"placeholder": "1200.00."}), - 'asset_category_id':forms.Select(attrs={ "class":"oh-select oh-select-2 select2-hidden-accessible",},), - 'asset_status': forms.Select(attrs={"class": "oh-select oh-select--lg oh-select-no-search "}), - 'asset_lot_number_id': forms.Select(attrs={"class": "oh-select oh-select-2 select2-hidden-accessible ","placeholder":"LOT001",}), + """ + Specifies the model and fields to be used for the AssetForm. + Attributes: + model (class): The model class Asset to be used for the form. + fields (str): A special value "__all__" to include all fields + of the model in the form. + """ + model = Asset + fields = "__all__" + widgets = { + "asset_name": forms.TextInput( + attrs={"placeholder": "Macbook Pro.", "class": "oh-input w-100"} + ), + "asset_description": forms.Textarea( + attrs={ + "type": "text", + "placeholder": _("A powerful laptop for business use."), + "class": "oh-input oh-input--textarea oh-input--block", + "rows": 3, + "cols": 40, + } + ), + "asset_tracking_id": forms.TextInput( + attrs={"placeholder": "LPT001", "class": "oh-input w-100"} + ), + "asset_purchase_date": forms.DateInput( + attrs={"type": "date", "class": "oh-input w-100"} + ), + "asset_purchase_cost": forms.NumberInput( + attrs={"class": "oh-input w-100", "placeholder": "1200.00."} + ), + "asset_category_id": forms.Select( + attrs={ + "class": "oh-select oh-select-2 select2-hidden-accessible", + }, + ), + "asset_status": forms.Select( + attrs={"class": "oh-select oh-select--lg oh-select-no-search "} + ), + "asset_lot_number_id": forms.Select( + attrs={ + "class": "oh-select oh-select-2 select2-hidden-accessible ", + "placeholder": "LOT001", + } + ), } + def __init__(self, *args, **kwargs): - instance = kwargs.get('instance') + instance = kwargs.get("instance") if instance: - kwargs['initial'] = set_date_field_initial(instance) + kwargs["initial"] = set_date_field_initial(instance) super(AssetForm, self).__init__(*args, **kwargs) - self.fields['asset_category_id'].widget.attrs.update({'id':str(uuid.uuid4())}) - self.fields['asset_lot_number_id'].widget.attrs.update({'id':str(uuid.uuid4())}) - self.fields['asset_status'].widget.attrs.update({'id':str(uuid.uuid4())}) - + self.fields["asset_category_id"].widget.attrs.update({"id": str(uuid.uuid4())}) + self.fields["asset_lot_number_id"].widget.attrs.update( + {"id": str(uuid.uuid4())} + ) + self.fields["asset_status"].widget.attrs.update({"id": str(uuid.uuid4())}) + def clean(self): instance = self.instance if instance.pk: @@ -49,75 +97,214 @@ class AssetForm(ModelForm): return_status__isnull=True ): raise ValidationError('Asset in use you can"t change the status') - if Asset.objects.filter(asset_tracking_id=self.data["asset_tracking_id"]).exclude(id=instance.pk).exists(): - raise ValidationError({"asset_tracking_id":'Already asset with this tracking id exists.'}) + if ( + Asset.objects.filter(asset_tracking_id=self.data["asset_tracking_id"]) + .exclude(id=instance.pk) + .exists() + ): + raise ValidationError( + {"asset_tracking_id": "Already asset with this tracking id exists."} + ) + + class AssetCategoryForm(ModelForm): + """ + A form for creating and updating AssetCategory instances. + """ + class Meta: + """ + Specifies the model and fields to be used for the AssetForm. + Attributes: + model (class): The model class AssetCategory to be used for the form. + fields (str): A special value "__all__" to include all fields + of the model in the form. + widgets (dict): A dictionary containing widget configurations for + specific form fields. + """ + model = AssetCategory - fields = '__all__' + fields = "__all__" widgets = { - 'asset_category_name': forms.TextInput(attrs={'placeholder': _('Computers.'), 'class': 'oh-input w-100'}), - 'asset_category_description': forms.Textarea(attrs={"type": "text", "placeholder": _("A category for all types of laptops."), "class": "oh-input oh-input--textarea oh-input--block","rows":3,"cols":40}), + "asset_category_name": forms.TextInput( + attrs={"placeholder": _("Computers."), "class": "oh-input w-100"} + ), + "asset_category_description": forms.Textarea( + attrs={ + "type": "text", + "placeholder": _("A category for all types of laptops."), + "class": "oh-input oh-input--textarea oh-input--block", + "rows": 3, + "cols": 40, + } + ), } - + class AssetRequestForm(ModelForm): - + """ + A Django ModelForm for creating and updating AssetRequest instances. + """ + class Meta: + """ + Specifies the model and fields to be used for the AssetRequestForm. + Attributes: + model (class): The model class AssetRequest to be used for the form. + fields (str): A special value "__all__" to include all fields + of the model in the form. + widgets (dict): A dictionary containing widget configurations for + specific form fields. + """ + model = AssetRequest - fields = '__all__' + fields = "__all__" widgets = { - 'requested_employee_id':forms.Select(attrs={ "class":"oh-select oh-select-2 select2-hidden-accessible",}), - 'asset_category_id':forms.Select(attrs={ "class":"oh-select oh-select-2 select2-hidden-accessible",}), - 'description': forms.Textarea(attrs={"type": "text", "id": "objective_description", "placeholder": _("Requesting a laptop for software development purposes."), "class": "oh-input oh-input--textarea oh-input--block","rows":3,"cols":40}), - + "requested_employee_id": forms.Select( + attrs={ + "class": "oh-select oh-select-2 select2-hidden-accessible", + } + ), + "asset_category_id": forms.Select( + attrs={ + "class": "oh-select oh-select-2 select2-hidden-accessible", + } + ), + "description": forms.Textarea( + attrs={ + "type": "text", + "id": "objective_description", + "placeholder": _( + "Requesting a laptop for software development purposes." + ), + "class": "oh-input oh-input--textarea oh-input--block", + "rows": 3, + "cols": 40, + } + ), } - def __init__(self,*args, **kwargs): - user = kwargs.pop('user',None) - super(AssetRequestForm, self).__init__(*args, **kwargs,) - if user is not None and user.has_perm('asset.add_assetrequest'): - self.fields['requested_employee_id'].queryset = Employee.objects.all() - self.fields['requested_employee_id'].initial = Employee.objects.filter(id=user.employee_get.id).first() - else: - self.fields['requested_employee_id'].queryset = Employee.objects.filter(employee_user_id = user) - self.fields['requested_employee_id'].initial = user.employee_get - self.fields['asset_category_id'].widget.attrs.update({'id':str(uuid.uuid4())}) - + def __init__(self, *args, **kwargs): + user = kwargs.pop("user", None) + super(AssetRequestForm, self).__init__( + *args, + **kwargs, + ) + if user is not None and user.has_perm("asset.add_assetrequest"): + self.fields["requested_employee_id"].queryset = Employee.objects.all() + self.fields["requested_employee_id"].initial = Employee.objects.filter( + id=user.employee_get.id + ).first() + else: + self.fields["requested_employee_id"].queryset = Employee.objects.filter( + employee_user_id=user + ) + self.fields["requested_employee_id"].initial = user.employee_get + + self.fields["asset_category_id"].widget.attrs.update({"id": str(uuid.uuid4())}) class AssetAllocationForm(ModelForm): + """ + A Django ModelForm for creating and updating AssetAssignment instances. + """ class Meta: + """ + Specifies the model and fields to be used for the AssetAllocationForm. + Attributes: + model (class): The model class AssetAssignment to be used for the form. + fields (str): A special value "__all__" to include all fields + of the model in the form. + widgets (dict): A dictionary containing widget configurations for + specific form fields. + """ + model = AssetAssignment - fields = '__all__' - exclude=['return_date','return_condition','assigned_date'] + fields = "__all__" + exclude = ["return_date", "return_condition", "assigned_date"] widgets = { - 'asset_id':forms.Select(attrs={ "class":"oh-select oh-select-2 "}), - 'assigned_to_employee_id':forms.Select(attrs={ "class":"oh-select oh-select-2 "}), - 'assigned_by_employee_id':forms.Select(attrs={ "class":"oh-select oh-select-2 ",},), + "asset_id": forms.Select(attrs={"class": "oh-select oh-select-2 "}), + "assigned_to_employee_id": forms.Select( + attrs={"class": "oh-select oh-select-2 "} + ), + "assigned_by_employee_id": forms.Select( + attrs={ + "class": "oh-select oh-select-2 ", + }, + ), } class AssetReturnForm(ModelForm): - + """ + A Django ModelForm for updating AssetAssignment instances during asset return. + """ + class Meta: + """ + Specifies the model and fields to be used for the AssetReturnForm. + Attributes: + model (class): The model class AssetAssignment to be used for the form. + fields (list): The fields to include in the form, referring to + related AssetAssignment fields. + widgets (dict): A dictionary containing widget configurations for + specific form fields. + """ + model = AssetAssignment - fields=['return_date','return_condition','return_status'] + fields = ["return_date", "return_condition", "return_status"] widgets = { - 'return_date':forms.DateInput(attrs={ "type":"date","class":"oh-input w-100","required":"true"}), - 'return_condition':forms.Textarea(attrs={ "class": "oh-input oh-input--textarea oh-input--block","rows":3,"cols":40,"placeholder":_("ohn returns the laptop. However, it has suffered minor damage.")}), - 'return_status':forms.Select(attrs={ "class":"oh-select oh-select-2","required":"true"},) + "return_date": forms.DateInput( + attrs={"type": "date", "class": "oh-input w-100", "required": "true"} + ), + "return_condition": forms.Textarea( + attrs={ + "class": "oh-input oh-input--textarea oh-input--block", + "rows": 3, + "cols": 40, + "placeholder": _( + "ohn returns the laptop. However, it has suffered minor damage." + ), + } + ), + "return_status": forms.Select( + attrs={"class": "oh-select oh-select-2", "required": "true"}, + ), } class AssetBatchForm(ModelForm): - + """ + A Django ModelForm for creating or updating AssetLot instances. + """ + class Meta: + """ + Specifies the model and fields to be used for the AssetBatchForm. + Attributes: + model (class): The model class AssetLot to be used for the form. + fields (str): A special value "__all__" to include all fields + of the model in the form. + widgets (dict): A dictionary containing widget configurations for + specific form fields. + """ + model = AssetLot - fields='__all__' + fields = "__all__" widgets = { - 'lot_number': forms.TextInput(attrs={'placeholder': 'A12345.', 'class': 'oh-input w-100'}), - 'lot_description': forms.Textarea(attrs={"type": "text","placeholder": _("A batch of 50 laptops, consisting of Lenovo ThinkPad T480s and Dell XPS 13."), "class": "oh-input oh-input--textarea oh-input--block","rows":3,"cols":40}), - } - \ No newline at end of file + "lot_number": forms.TextInput( + attrs={"placeholder": "A12345.", "class": "oh-input w-100"} + ), + "lot_description": forms.Textarea( + attrs={ + "type": "text", + "placeholder": _( + "A batch of 50 laptops, consisting of Lenovo ThinkPad T480s and Dell XPS 13." + ), + "class": "oh-input oh-input--textarea oh-input--block", + "rows": 3, + "cols": 40, + } + ), + } diff --git a/asset/models.py b/asset/models.py index c36c88f87..de2ebd90e 100644 --- a/asset/models.py +++ b/asset/models.py @@ -1,28 +1,46 @@ +""" +Models for Asset Management System + +This module defines Django models to manage assets, their categories, assigning, and requests +within an Asset Management System. +""" from django.db import models -from django.contrib.auth.models import User -from employee.models import Employee -from datetime import datetime -import django +from django.core.exceptions import ValidationError from django.utils.translation import gettext_lazy as _ +from employee.models import Employee class AssetCategory(models.Model): + """ + Represents a category for different types of assets. + """ + asset_category_name = models.CharField(max_length=255, unique=True) asset_category_description = models.TextField() + objects = models.Manager() def __str__(self): return f"{self.asset_category_name}" class AssetLot(models.Model): + """ + Represents a lot associated with a collection of assets. + """ + lot_number = models.CharField(max_length=30, null=False, blank=False, unique=True) lot_description = models.TextField(null=True, blank=True) + objects = models.Manager() def __str__(self): return f"{self.lot_number}" class Asset(models.Model): + """ + Represents a asset with various attributes. + """ + ASSET_STATUS = [ ("In use", _("In use")), ("Available", _("Available")), @@ -40,12 +58,33 @@ class Asset(models.Model): asset_lot_number_id = models.ForeignKey( AssetLot, on_delete=models.CASCADE, null=True, blank=True ) + objects = models.Manager() def __str__(self): return f"{self.asset_name}-{self.asset_tracking_id}" + def clean(self): + existing_asset = Asset.objects.filter( + asset_tracking_id=self.asset_tracking_id + ).exclude( + id=self.pk + ) # Exclude the current instance if updating + if existing_asset.exists(): + raise ValidationError( + { + "asset_description": _( + "An asset with this tracking ID already exists." + ) + } + ) + return super().clean() + class AssetAssignment(models.Model): + """ + Represents the allocation and return of assets to and from employees. + """ + STATUS = [ ("Minor damage", _("Minor damage")), ("Major damage", _("Major damage")), @@ -66,9 +105,14 @@ class AssetAssignment(models.Model): return_status = models.CharField( choices=STATUS, max_length=30, null=True, blank=True ) + objects = models.Manager() class AssetRequest(models.Model): + """ + Represents a request for assets made by employees. + """ + STATUS = [ ("Requested", _("Requested")), ("Approved", _("Approved")), @@ -87,3 +131,4 @@ class AssetRequest(models.Model): asset_request_status = models.CharField( max_length=30, choices=STATUS, default="Requested", null=True, blank=True ) + objects = models.Manager() diff --git a/asset/resources.py b/asset/resources.py index 490994b4c..88b5ccec2 100644 --- a/asset/resources.py +++ b/asset/resources.py @@ -1,6 +1,19 @@ +""" +Module: resources.py +This module defines classes for handling resources related to assets. +""" from import_export import resources from .models import Asset + class AssetResource(resources.ModelResource): + """ + This class is used to import and export Asset data using the import_export library. + """ + class Meta: - model = Asset \ No newline at end of file + """ + Specifies the model to be used for import and export. + """ + + model = Asset diff --git a/asset/urls.py b/asset/urls.py index 48c27ea68..21eb0bc87 100644 --- a/asset/urls.py +++ b/asset/urls.py @@ -1,3 +1,6 @@ +""" +URL configuration for asset-related views. +""" from django.urls import path from django import views from . import views