testing without ip field

This commit is contained in:
Parsa Nazer
2025-02-21 02:01:01 +03:30
parent 944158fa81
commit 4f0060f0ae
4 changed files with 29 additions and 6 deletions
+2 -2
View File
@@ -112,7 +112,7 @@ class SecurityBreachAttemptAdmin(ModelAdmin, ImportExportModelAdmin):
compressed_fields = True compressed_fields = True
warn_unsaved_form = True warn_unsaved_form = True
change_form_template = 'loction_chagne_form.html' change_form_template = 'loction_chagne_form.html'
list_display = ['ip', 'country', 'region_name', 'city', 'zip_code', 'isp', 'created_at', 'trys', 'display_viewd'] list_display = ['ip_address', 'country', 'region_name', 'city', 'zip_code', 'isp', 'created_at', 'trys', 'display_viewd']
def change_view(self, request, object_id, form_url='', extra_context=None): def change_view(self, request, object_id, form_url='', extra_context=None):
extra_context = extra_context or {} extra_context = extra_context or {}
@@ -120,7 +120,7 @@ class SecurityBreachAttemptAdmin(ModelAdmin, ImportExportModelAdmin):
if obj and obj.lat and obj.lon: if obj and obj.lat and obj.lon:
m = Map(location=[obj.lat, obj.lon], zoom_start=10) m = Map(location=[obj.lat, obj.lon], zoom_start=10)
Marker([obj.lat, obj.lon], popup=f"Location: {obj.ip}").add_to(m) Marker([obj.lat, obj.lon], popup=f"Location: {obj.ip_address}").add_to(m)
map_html = m._repr_html_() map_html = m._repr_html_()
extra_context['map_html'] = map_html extra_context['map_html'] = map_html
return super().change_view(request, object_id, form_url, extra_context) return super().change_view(request, object_id, form_url, extra_context)
@@ -0,0 +1,23 @@
# Generated by Django 5.1.2 on 2025-02-20 22:30
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('account', '0021_securitybreachattemptmodel_ip'),
]
operations = [
migrations.RemoveField(
model_name='securitybreachattemptmodel',
name='ip',
),
migrations.AddField(
model_name='securitybreachattemptmodel',
name='ip_address',
field=models.CharField(default='', max_length=100, verbose_name='آدرس آی\u200cپی'),
preserve_default=False,
),
]
+2 -2
View File
@@ -217,7 +217,7 @@ def get_location_from_ip(ip_address):
return None return None
class SecurityBreachAttemptModel(models.Model): class SecurityBreachAttemptModel(models.Model):
ip = models.CharField(max_length=100, verbose_name="آدرس آی‌پی") ip_address = models.CharField(max_length=100, verbose_name="آدرس آی‌پی")
country = models.CharField(max_length=40, verbose_name="کشور", blank=True, null=True) country = models.CharField(max_length=40, verbose_name="کشور", blank=True, null=True)
region_name = models.CharField(max_length=40, verbose_name="منطقه", blank=True, null=True) region_name = models.CharField(max_length=40, verbose_name="منطقه", blank=True, null=True)
city = models.CharField(max_length=40, verbose_name="شهر", blank=True, null=True) city = models.CharField(max_length=40, verbose_name="شهر", blank=True, null=True)
@@ -231,7 +231,7 @@ class SecurityBreachAttemptModel(models.Model):
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
if not self.id: if not self.id:
location_data = get_location_from_ip(self.ip) location_data = get_location_from_ip(self.ip_address)
if location_data: if location_data:
self.country, self.region_name, self.city, self.zip_code, self.lat, self.lon, self.isp = location_data self.country, self.region_name, self.city, self.zip_code, self.lat, self.lon, self.isp = location_data
+2 -2
View File
@@ -275,7 +275,7 @@ class FakeAdminLoginView(View):
print(ip) print(ip)
print(len(ip)) print(len(ip))
print(type(ip)) print(type(ip))
hacker, created = SecurityBreachAttemptModel.objects.get_or_create(ip=ip) hacker, created = SecurityBreachAttemptModel.objects.get_or_create(ip_address=ip)
return render(request, 'admin/fake_login.html', self.get_context(request)) return render(request, 'admin/fake_login.html', self.get_context(request))
def post(self, request): def post(self, request):
@@ -285,7 +285,7 @@ class FakeAdminLoginView(View):
else: else:
ip = request.META.get("REMOTE_ADDR") ip = request.META.get("REMOTE_ADDR")
print(ip) print(ip)
hacker, created = SecurityBreachAttemptModel.objects.get_or_create(ip=ip) hacker, created = SecurityBreachAttemptModel.objects.get_or_create(ip_address=ip)
hacker.trys += 1 hacker.trys += 1
hacker.save() hacker.save()
messages.error(request, "Please correct the error below.") messages.error(request, "Please correct the error below.")