add 2 new fields city & province in device - fix bug of filter_by_region
This commit is contained in:
@@ -8,18 +8,14 @@ class RequestFormatter(logging.Formatter):
|
|||||||
request = getattr(record, 'request', None)
|
request = getattr(record, 'request', None)
|
||||||
|
|
||||||
if isinstance(request, HttpRequest):
|
if isinstance(request, HttpRequest):
|
||||||
# مرحله ۱: از X-Forwarded-For (در صورت وجود)
|
|
||||||
ip = request.META.get('HTTP_X_FORWARDED_FOR')
|
ip = request.META.get('HTTP_X_FORWARDED_FOR')
|
||||||
|
|
||||||
# مرحله ۲: از REMOTE_ADDR
|
|
||||||
if not ip:
|
if not ip:
|
||||||
ip = request.META.get('REMOTE_ADDR')
|
ip = request.META.get('REMOTE_ADDR')
|
||||||
|
|
||||||
# مرحله ۳: اگر هنوز چیزی نیست، مقدار پیشفرض بده (مثلاً localhost)
|
|
||||||
if not ip:
|
if not ip:
|
||||||
ip = '127.0.0.1'
|
ip = '127.0.0.1'
|
||||||
|
|
||||||
# تمیزکاری برای لیست آیپیها
|
|
||||||
if ',' in ip:
|
if ',' in ip:
|
||||||
ip = ip.split(',')[0].strip()
|
ip = ip.split(',')[0].strip()
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# Generated by Django 5.0 on 2025-10-27 10:38
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('authentication', '0038_organizationtype_region_scope'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='organizationtype',
|
||||||
|
name='region_scope',
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -26,7 +26,7 @@ class RegionFilterMixin:
|
|||||||
if hasattr(queryset.model, 'province_id'):
|
if hasattr(queryset.model, 'province_id'):
|
||||||
queryset = queryset.filter(province_id=id(province_id))
|
queryset = queryset.filter(province_id=id(province_id))
|
||||||
elif hasattr(queryset.model, 'user'):
|
elif hasattr(queryset.model, 'user'):
|
||||||
queryset = queryset.filter(user__province=organization.city)
|
queryset = queryset.filter(user__province=id(province_id))
|
||||||
|
|
||||||
# filter by organization type region
|
# filter by organization type region
|
||||||
if org:
|
if org:
|
||||||
@@ -42,7 +42,7 @@ class RegionFilterMixin:
|
|||||||
if hasattr(queryset.model, 'province_id'):
|
if hasattr(queryset.model, 'province_id'):
|
||||||
queryset = queryset.filter(province=organization.province)
|
queryset = queryset.filter(province=organization.province)
|
||||||
elif hasattr(queryset.model, 'user'):
|
elif hasattr(queryset.model, 'user'):
|
||||||
queryset = queryset.filter(user__province=organization.city)
|
queryset = queryset.filter(user__province=organization.province)
|
||||||
|
|
||||||
# if organization is admin of system
|
# if organization is admin of system
|
||||||
elif scope == 'CO':
|
elif scope == 'CO':
|
||||||
|
|||||||
@@ -153,7 +153,4 @@ class UserRelationViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewSet, D
|
|||||||
return self.get_paginated_response(serializer.data)
|
return self.get_paginated_response(serializer.data)
|
||||||
|
|
||||||
serializer = self.get_serializer(queryset, many=True)
|
serializer = self.get_serializer(queryset, many=True)
|
||||||
|
|
||||||
print(request.META.get('HTTP_X_FORWARDED_FOR'))
|
|
||||||
print(request.META.get('REMOTE_ADDR'))
|
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# Generated by Django 5.0 on 2025-10-27 10:38
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('authentication', '0039_remove_organizationtype_region_scope'),
|
||||||
|
('pos_device', '0075_posfreeproducts_company_fee'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='device',
|
||||||
|
name='city',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='devices', to='authentication.city'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='device',
|
||||||
|
name='province',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='devices', to='authentication.province'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
from apps.product.models import Product, Broker, QuotaBrokerValue, QuotaDistribution
|
|
||||||
from django.contrib.postgres.fields import ArrayField
|
|
||||||
from apps.authorization.models import UserRelations
|
|
||||||
from apps.authentication.models import Organization
|
|
||||||
from apps.core.models import BaseModel
|
|
||||||
from django.db import models
|
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
|
|
||||||
|
from django.contrib.postgres.fields import ArrayField
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
from apps.authentication.models import Organization, City, Province
|
||||||
|
from apps.authorization.models import UserRelations
|
||||||
|
from apps.core.models import BaseModel
|
||||||
|
from apps.product.models import Product, Broker, QuotaBrokerValue, QuotaDistribution
|
||||||
|
|
||||||
|
|
||||||
class ProviderCompany(BaseModel):
|
class ProviderCompany(BaseModel):
|
||||||
user_relation = models.ForeignKey(
|
user_relation = models.ForeignKey(
|
||||||
@@ -40,6 +42,18 @@ class Device(BaseModel):
|
|||||||
server_in = models.BooleanField(default=False)
|
server_in = models.BooleanField(default=False)
|
||||||
latitude = models.FloatField(default=0)
|
latitude = models.FloatField(default=0)
|
||||||
longitude = models.FloatField(default=0)
|
longitude = models.FloatField(default=0)
|
||||||
|
city = models.ForeignKey(
|
||||||
|
City,
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
related_name='devices',
|
||||||
|
null=True
|
||||||
|
)
|
||||||
|
province = models.ForeignKey(
|
||||||
|
Province,
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
related_name='devices',
|
||||||
|
null=True
|
||||||
|
)
|
||||||
is_activated = models.BooleanField(default=False)
|
is_activated = models.BooleanField(default=False)
|
||||||
pre_registered = models.BooleanField(default=False)
|
pre_registered = models.BooleanField(default=False)
|
||||||
organization = models.ForeignKey(
|
organization = models.ForeignKey(
|
||||||
|
|||||||
@@ -11,3 +11,11 @@
|
|||||||
[2025-10-27 12:51:33,606] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\api.py changed, reloading.
|
[2025-10-27 12:51:33,606] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\api.py changed, reloading.
|
||||||
[2025-10-27 12:51:36,841] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
|
[2025-10-27 12:51:36,841] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
|
||||||
[2025-10-27 12:58:13,543] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\api.py changed, reloading.
|
[2025-10-27 12:58:13,543] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\api.py changed, reloading.
|
||||||
|
[2025-10-27 12:58:15,775] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
|
||||||
|
[2025-10-27 13:36:41,271] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authorization\api\v1\api.py changed, reloading.
|
||||||
|
[2025-10-27 13:36:48,841] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
|
||||||
|
[2025-10-27 14:08:43,751] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\pos_device\models.py changed, reloading.
|
||||||
|
[2025-10-27 14:08:47,580] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
|
||||||
|
[2025-10-27 14:18:07,772] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\Rasaddam_Backend\request_formatter.py changed, reloading.
|
||||||
|
[2025-10-27 14:18:11,698] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
|
||||||
|
[2025-10-27 14:42:16,070] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\mixins\region_filter.py changed, reloading.
|
||||||
|
|||||||
Reference in New Issue
Block a user