Skip to content

Commit 7a0cf37

Browse files
committed
Added Complete Supplier,Customer,Staff and Admin Management
1 parent 71b3ae7 commit 7a0cf37

25 files changed

+587
-20
lines changed

Backend/EcommerceInventory/EcommerceInventory/Helpers.py

+64-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def getDynamicFormModels():
1616
'warehouse':'InventoryServices.Warehouse',
1717
'supplier':'UserServices.Users',
1818
'rackShelfFloor':'InventoryServices.RackAndShelvesAndFloor',
19+
'users':'UserServices.Users',
1920
}
2021

2122
def getSuperAdminDynamicFormModels():
@@ -24,10 +25,10 @@ def getSuperAdminDynamicFormModels():
2425
}
2526

2627
def checkisFileField(field):
27-
return field in ['image','file','path','video','audio']
28+
return field in ['image','file','path','video','audio','profile_pic']
2829

2930
def getExludeFields():
30-
return ['id','created_at','updated_at','domain_user_id','added_by_user_id','created_by_user_id','updated_by_user_id']
31+
return ['id','created_at','updated_at','domain_user_id','added_by_user_id','created_by_user_id','updated_by_user_id','is_staff','is_superuser','is_active','plan_type','last_login','last_device','date_joined','last_ip','domain_name']
3132

3233
def getDynamicFormFields(model_instance,domain_user_id):
3334
fields={'text':[],'select':[],'checkbox':[],'radio':[],'textarea':[],'json':[],'file':[]}
@@ -164,6 +165,67 @@ def wrapped_list_method(self,request,*args,**kwargs):
164165
return decorator
165166

166167

168+
class CommonListAPIMixinWithFilter:
169+
serializer_class=None
170+
pagination_class=CustomPageNumberPagination
171+
172+
def get_queryset(self):
173+
raise NotImplementedError('get_queryset method not implemented')
174+
175+
def common_list_decorator(serializer_class):
176+
def decorator(list_method):
177+
@wraps(list_method)
178+
def wrapped_list_method(self,request,*args,**kwargs):
179+
queryset=self.get_queryset()
180+
search_query=self.request.query_params.get('search',None)
181+
182+
filtered_params=self.request.query_params.dict()
183+
key_to_remove=['search','ordering','pageSize','page']
184+
for key in key_to_remove:
185+
if key in filtered_params:
186+
filtered_params.pop(key,None)
187+
188+
if filtered_params:
189+
search_conditions=Q()
190+
for key,value in filtered_params.items():
191+
search_conditions|=Q(**{f"{key}":value})
192+
queryset=queryset.filter(search_conditions)
193+
194+
if search_query:
195+
search_conditions=Q()
196+
197+
for field in serializer_class.Meta.model._meta.get_fields():
198+
if isinstance(field,(models.CharField,models.TextField)):
199+
search_conditions|=Q(**{f"{field.name}__icontains":search_query})
200+
queryset=queryset.filter(search_conditions)
201+
202+
ordering=self.request.query_params.get('ordering',None)
203+
204+
if ordering:
205+
queryset=queryset.order_by(ordering)
206+
207+
page=self.paginate_queryset(queryset)
208+
209+
if page is not None:
210+
serializer=self.get_serializer(page,many=True)
211+
data=serializer.data
212+
total_pages=self.paginator.page.paginator.num_pages
213+
current_page=self.paginator.page.number
214+
page_size=self.paginator.page.paginator.per_page
215+
total_items=self.paginator.page.paginator.count
216+
else:
217+
serializer=self.get_serializer(queryset,many=True)
218+
data=serializer.data
219+
total_pages=1
220+
current_page=1
221+
page_size=len(data)
222+
total_items=len(data)
223+
filterFields=[{"key":field.name,"option":[{"id":choice[0],'value':choice[1]} for choice in field.choices] if field.choices else None } for field in serializer_class.Meta.model._meta.fields if field.name in serializer_class.Meta.fields]
224+
return renderResponse(data={'filterFields':filterFields,'data':data,'totalPages':total_pages,'currentPage':current_page,'pageSize':page_size,'totalItems':total_items},message='Data Retrieved Successfully',status=200)
225+
return wrapped_list_method
226+
return decorator
227+
228+
167229
def createParsedCreatedAtUpdatedAt(cls):
168230
cls.formatted_created_at=serializers.SerializerMethodField()
169231
cls.formatted_updated_at=serializers.SerializerMethodField()
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,62 @@
1-
from EcommerceInventory.Helpers import renderResponse
1+
from EcommerceInventory.Helpers import CommonListAPIMixin, CommonListAPIMixinWithFilter, CustomPageNumberPagination, createParsedCreatedAtUpdatedAt, renderResponse
22
from UserServices.models import Users
33
from rest_framework.views import APIView
44
from rest_framework.permissions import IsAuthenticated
55
from rest_framework_simplejwt.authentication import JWTAuthentication
66
from rest_framework import serializers
7+
from rest_framework import generics
78

89
class UserSerializer(serializers.ModelSerializer):
910
class Meta:
1011
model=Users
1112
fields=['id','username','first_name','last_name','email','profile_pic']
1213

14+
@createParsedCreatedAtUpdatedAt
15+
class UserSerializerWithFilters(serializers.ModelSerializer):
16+
date_joined=serializers.DateTimeField(format="%dth %B %Y, %H:%M", read_only=True)
17+
last_login=serializers.DateTimeField(format="%dth %B %Y, %H:%M", read_only=True)
18+
added_by_user_id=serializers.SerializerMethodField()
19+
domain_user_id=serializers.SerializerMethodField()
20+
class Meta:
21+
model=Users
22+
fields=['id', 'first_name', 'last_name', 'date_joined', 'email', 'phone', 'address', 'city', 'state', 'pincode', 'country', 'profile_pic', 'account_status', 'role', 'dob', 'username', 'social_media_links', 'addition_details', 'language', 'departMent', 'designation', 'time_zone', 'last_login', 'last_device', 'last_ip', 'currency', 'domain_name', 'plan_type', 'created_at', 'updated_at', 'domain_user_id', 'added_by_user_id']
23+
24+
def get_domain_user_id(self,obj):
25+
return "#"+str(obj.domain_user_id.id) +" "+obj.domain_user_id.username if obj.domain_user_id!=None else ''
26+
27+
def get_added_by_user_id(self,obj):
28+
return "#"+str(obj.added_by_user_id.id) +" "+obj.added_by_user_id.username if obj.added_by_user_id!=None else ''
29+
1330
class UserListView(APIView):
1431
permission_classes = [IsAuthenticated]
1532
authentication_classes = [JWTAuthentication]
1633
def get(self,request):
1734
users=Users.objects.filter(domain_user_id=request.user.domain_user_id.id)
1835
serializer=UserSerializer(users,many=True)
1936
return renderResponse(data=serializer.data,message="All Users",status=200)
37+
38+
class UserWithFilterListView(generics.ListAPIView):
39+
serializer_class = UserSerializerWithFilters
40+
authentication_classes = [JWTAuthentication]
41+
permission_classes = [IsAuthenticated]
42+
pagination_class = CustomPageNumberPagination
43+
44+
def get_queryset(self):
45+
queryset=Users.objects.filter(domain_user_id=self.request.user.domain_user_id.id)
46+
return queryset
47+
48+
@CommonListAPIMixinWithFilter.common_list_decorator(UserSerializerWithFilters)
49+
def list(self,request,*args,**kwargs):
50+
return super().list(request,*args,**kwargs)
51+
52+
53+
class UpdateUsers(generics.UpdateAPIView):
54+
serializer_class = UserSerializerWithFilters
55+
authentication_classes = [JWTAuthentication]
56+
permission_classes = [IsAuthenticated]
57+
58+
def get_queryset(self):
59+
return Users.objects.filter(domain_user_id=self.request.user.domain_user_id.id,id=self.kwargs['pk'])
60+
61+
def perform_update(self,serializer):
62+
serializer.save()
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Generated by Django 5.0.6 on 2024-07-30 08:30
2+
3+
import django.db.models.deletion
4+
from django.conf import settings
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('UserServices', '0003_alter_modules_module_description_and_more'),
12+
]
13+
14+
operations = [
15+
migrations.AddField(
16+
model_name='users',
17+
name='added_by_user_id',
18+
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='added_by_user_id_user', to=settings.AUTH_USER_MODEL),
19+
),
20+
migrations.AlterField(
21+
model_name='users',
22+
name='account_status',
23+
field=models.CharField(blank=True, choices=[('Active', 'Active'), ('Inactive', 'Inactive'), ('Blocked', 'Blocked')], default='Active', max_length=50, null=True),
24+
),
25+
migrations.AlterField(
26+
model_name='users',
27+
name='country',
28+
field=models.CharField(blank=True, choices=[('India', 'India'), ('USA', 'USA'), ('UK', 'UK'), ('Australia', 'Australia'), ('Canada', 'Canada'), ('Germany', 'Germany'), ('France', 'France'), ('Italy', 'Italy'), ('Japan', 'Japan'), ('China', 'China'), ('Russia', 'Russia'), ('Brazil', 'Brazil'), ('South Africa', 'South Africa'), ('Nigeria', 'Nigeria'), ('Mexico', 'Mexico'), ('Argentina', 'Argentina'), ('Spain', 'Spain'), ('Portugal', 'Portugal'), ('Greece', 'Greece'), ('Sweden', 'Sweden'), ('Norway', 'Norway'), ('Finland', 'Finland'), ('Denmark', 'Denmark'), ('Netherlands', 'Netherlands'), ('Belgium', 'Belgium'), ('Switzerland', 'Switzerland'), ('Austria', 'Austria'), ('Poland', 'Poland'), ('Czech Republic', 'Czech Republic'), ('Turkey', 'Turkey'), ('Ukraine', 'Ukraine'), ('Hungary', 'Hungary'), ('Romania', 'Romania'), ('Bulgaria', 'Bulgaria'), ('Croatia', 'Croatia'), ('Slovenia', 'Slovenia'), ('Slovakia', 'Slovakia'), ('Lithuania', 'Lithuania'), ('Latvia', 'Latvia'), ('Estonia', 'Estonia'), ('Ireland', 'Ireland'), ('Scotland', 'Scotland'), ('Wales', 'Wales'), ('Northern Ireland', 'Northern Ireland'), ('New Zealand', 'New Zealand'), ('Singapore', 'Singapore'), ('Malaysia', 'Malaysia'), ('Thailand', 'Thailand'), ('Indonesia', 'Indonesia'), ('Philippines', 'Philippines'), ('Vietnam', 'Vietnam'), ('South Korea', 'South Korea'), ('North Korea', 'North Korea'), ('Taiwan', 'Taiwan'), ('Hong Kong', 'Hong Kong'), ('Macau', 'Macau'), ('Bangladesh', 'Bangladesh'), ('Pakistan', 'Pakistan'), ('Sri Lanka', 'Sri Lanka'), ('Nepal', 'Nepal'), ('Bhutan', 'Bhutan'), ('Maldives', 'Maldives'), ('Afghanistan', 'Afghanistan'), ('Iran', 'Iran'), ('Iraq', 'Iraq'), ('Syria', 'Syria'), ('Lebanon', 'Lebanon')], default='India', max_length=50, null=True),
29+
),
30+
migrations.AlterField(
31+
model_name='users',
32+
name='currency',
33+
field=models.CharField(blank=True, choices=[('USD', 'USD'), ('INR', 'INR'), ('EUR', 'EUR'), ('GBP', 'GBP'), ('AUD', 'AUD'), ('CAD', 'CAD'), ('JPY', 'JPY'), ('CNY', 'CNY'), ('RUB', 'RUB'), ('BRL', 'BRL'), ('ZAR', 'ZAR'), ('NGN', 'NGN'), ('MXN', 'MXN'), ('ARS', 'ARS'), ('CHF', 'CHF'), ('SEK', 'SEK'), ('NOK', 'NOK'), ('DKK', 'DKK'), ('PLN', 'PLN'), ('CZK', 'CZK'), ('TRY', 'TRY'), ('UAH', 'UAH'), ('HUF', 'HUF'), ('RON', 'RON'), ('BGN', 'BGN'), ('HRK', 'HRK'), ('SLO', 'SLO'), ('SK', 'SK'), ('LT', 'LT'), ('LV', 'LV'), ('EE', 'EE'), ('IE', 'IE'), ('SC', 'SC'), ('WL', 'WL'), ('NI', 'NI'), ('NZ', 'NZ'), ('SGD', 'SGD'), ('MYR', 'MYR'), ('THB', 'THB'), ('IDR', 'IDR'), ('PHP', 'PHP'), ('VND', 'VND'), ('KRW', 'KRW'), ('KPW', 'KPW'), ('TWD', 'TWD'), ('HKD', 'HKD'), ('MOP', 'MOP'), ('BDT', 'BDT'), ('PKR', 'PKR'), ('LKR', 'LKR'), ('NPR', 'NPR'), ('BTN', 'BTN'), ('MVR', 'MVR'), ('AFN', 'AFN'), ('IRR', 'IRR'), ('IQD', 'IQD'), ('SYP', 'SYP'), ('LBN', 'LBN')], default='INR', max_length=50, null=True),
34+
),
35+
migrations.AlterField(
36+
model_name='users',
37+
name='language',
38+
field=models.CharField(blank=True, choices=[('English', 'English'), ('Hindi', 'Hindi'), ('Spanish', 'Spanish'), ('French', 'French'), ('German', 'German'), ('Italian', 'Italian'), ('Portuguese', 'Portuguese'), ('Russian', 'Russian'), ('Chinese', 'Chinese'), ('Japanese', 'Japanese'), ('Korean', 'Korean'), ('Arabic', 'Arabic'), ('Turkish', 'Turkish'), ('Dutch', 'Dutch'), ('Polish', 'Polish'), ('Swedish', 'Swedish'), ('Danish', 'Danish'), ('Norwegian', 'Norwegian'), ('Finnish', 'Finnish'), ('Greek', 'Greek'), ('Czech', 'Czech'), ('Hungarian', 'Hungarian'), ('Romanian', 'Romanian'), ('Bulgarian', 'Bulgarian'), ('Croatian', 'Croatian'), ('Slovak', 'Slovak'), ('Slovenian', 'Slovenian'), ('Lithuanian', 'Lithuanian'), ('Latvian', 'Latvian'), ('Estonian', 'Estonian'), ('Ukrainian', 'Ukrainian'), ('Belarusian', 'Belarusian'), ('Serbian', 'Serbian'), ('Macedonian', 'Macedonian'), ('Bosnian', 'Bosnian'), ('Albanian', 'Albanian'), ('Montenegrin', 'Montenegrin'), ('Catalan', 'Catalan'), ('Basque', 'Basque'), ('Galician', 'Galician'), ('Welsh', 'Welsh'), ('Irish', 'Irish'), ('Scots Gaelic', 'Scots Gaelic'), ('Manx', 'Manx'), ('Cornish', 'Cornish'), ('Breton', 'Breton')], default='English', max_length=50, null=True),
39+
),
40+
migrations.AlterField(
41+
model_name='users',
42+
name='plan_type',
43+
field=models.CharField(blank=True, choices=[('Free', 'Free'), ('Basic', 'Basic'), ('Standard', 'Standard'), ('Premium', 'Premium'), ('Enterprise', 'Enterprise')], default='Free', max_length=50, null=True),
44+
),
45+
migrations.AlterField(
46+
model_name='users',
47+
name='role',
48+
field=models.CharField(blank=True, choices=[('Admin', 'Admin'), ('Supplier', 'Supplier'), ('Customer', 'Customer'), ('Staff', 'Staff')], default='Admin', max_length=50, null=True),
49+
),
50+
migrations.AlterField(
51+
model_name='users',
52+
name='time_zone',
53+
field=models.CharField(blank=True, choices=[('UTC-12:00', 'UTC-12:00'), ('UTC-11:00', 'UTC-11:00'), ('UTC-10:00', 'UTC-10:00'), ('UTC-09:30', 'UTC-09:30'), ('UTC-09:00', 'UTC-09:00'), ('UTC-08:00', 'UTC-08:00'), ('UTC-07:00', 'UTC-07:00'), ('UTC-06:00', 'UTC-06:00'), ('UTC-05:00', 'UTC-05:00'), ('UTC-04:00', 'UTC-04:00'), ('UTC-03:30', 'UTC-03:30'), ('UTC-03:00', 'UTC-03:00'), ('UTC-02:00', 'UTC-02:00'), ('UTC-01:00', 'UTC-01:00'), ('UTC', 'UTC'), ('UTC+01:00', 'UTC+01:00'), ('UTC+02:00', 'UTC+02:00'), ('UTC+03:00', 'UTC+03:00'), ('UTC+03:30', 'UTC+03:30'), ('UTC+04:00', 'UTC+04:00'), ('UTC+04:30', 'UTC+04:30'), ('UTC+05:00', 'UTC+05:00'), ('UTC+05:30', 'UTC+05:30'), ('UTC+05:45', 'UTC+05:45'), ('UTC+06:00', 'UTC+06:00'), ('UTC+06:30', 'UTC+06:30'), ('UTC+07:00', 'UTC+07:00'), ('UTC+08:00', 'UTC+08:00'), ('UTC+08:45', 'UTC+08:45'), ('UTC+09:00', 'UTC+09:00'), ('UTC+09:30', 'UTC+09:30'), ('UTC+10:00', 'UTC+10:00'), ('UTC+10:30', 'UTC+10:30'), ('UTC+11:00', 'UTC+11:00'), ('UTC+12:00', 'UTC+12:00'), ('UTC+12:45', 'UTC+12:45'), ('UTC+13:00', 'UTC+13:00'), ('UTC+14:00', 'UTC+14:00')], default='UTC+05:30', max_length=50, null=True),
54+
),
55+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generated by Django 5.0.6 on 2024-07-30 08:34
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('UserServices', '0004_users_added_by_user_id_alter_users_account_status_and_more'),
10+
]
11+
12+
operations = [
13+
migrations.RemoveField(
14+
model_name='users',
15+
name='name',
16+
),
17+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.0.6 on 2024-07-30 09:16
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('UserServices', '0005_remove_users_name'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='users',
15+
name='profile_pic',
16+
field=models.JSONField(),
17+
),
18+
]

0 commit comments

Comments
 (0)