diff --git a/Rasaddam_Backend/request_formatter.py b/Rasaddam_Backend/request_formatter.py index 19a48aa..e082ce6 100644 --- a/Rasaddam_Backend/request_formatter.py +++ b/Rasaddam_Backend/request_formatter.py @@ -8,18 +8,14 @@ class RequestFormatter(logging.Formatter): request = getattr(record, 'request', None) if isinstance(request, HttpRequest): - # مرحله ۱: از X-Forwarded-For (در صورت وجود) ip = request.META.get('HTTP_X_FORWARDED_FOR') - # مرحله ۲: از REMOTE_ADDR if not ip: ip = request.META.get('REMOTE_ADDR') - # مرحله ۳: اگر هنوز چیزی نیست، مقدار پیش‌فرض بده (مثلاً localhost) if not ip: ip = '127.0.0.1' - # تمیزکاری برای لیست آی‌پی‌ها if ',' in ip: ip = ip.split(',')[0].strip() diff --git a/apps/authentication/migrations/0039_remove_organizationtype_region_scope.py b/apps/authentication/migrations/0039_remove_organizationtype_region_scope.py new file mode 100644 index 0000000..7c5cd0a --- /dev/null +++ b/apps/authentication/migrations/0039_remove_organizationtype_region_scope.py @@ -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', + ), + ] diff --git a/apps/authentication/mixins/region_filter.py b/apps/authentication/mixins/region_filter.py index 197157b..58e5d8f 100644 --- a/apps/authentication/mixins/region_filter.py +++ b/apps/authentication/mixins/region_filter.py @@ -26,7 +26,7 @@ class RegionFilterMixin: if hasattr(queryset.model, 'province_id'): queryset = queryset.filter(province_id=id(province_id)) 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 if org: @@ -42,7 +42,7 @@ class RegionFilterMixin: if hasattr(queryset.model, 'province_id'): queryset = queryset.filter(province=organization.province) 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 elif scope == 'CO': diff --git a/apps/authorization/api/v1/api.py b/apps/authorization/api/v1/api.py index 23c9ee4..b3a2419 100644 --- a/apps/authorization/api/v1/api.py +++ b/apps/authorization/api/v1/api.py @@ -153,7 +153,4 @@ class UserRelationViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewSet, D return self.get_paginated_response(serializer.data) 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) diff --git a/apps/pos_device/migrations/0076_device_city_device_province.py b/apps/pos_device/migrations/0076_device_city_device_province.py new file mode 100644 index 0000000..fb6d561 --- /dev/null +++ b/apps/pos_device/migrations/0076_device_city_device_province.py @@ -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'), + ), + ] diff --git a/apps/pos_device/models.py b/apps/pos_device/models.py index 7048847..4fefe51 100644 --- a/apps/pos_device/models.py +++ b/apps/pos_device/models.py @@ -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 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): user_relation = models.ForeignKey( @@ -40,6 +42,18 @@ class Device(BaseModel): server_in = models.BooleanField(default=False) latitude = 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) pre_registered = models.BooleanField(default=False) organization = models.ForeignKey( diff --git a/logs/django_requests.log b/logs/django_requests.log index 1b28bfd..0e3d3aa 100644 --- a/logs/django_requests.log +++ b/logs/django_requests.log @@ -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: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: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.