diff --git a/core/__pycache__/admin.cpython-311.pyc b/core/__pycache__/admin.cpython-311.pyc index ab1cbbb..63ef292 100644 Binary files a/core/__pycache__/admin.cpython-311.pyc and b/core/__pycache__/admin.cpython-311.pyc differ diff --git a/core/__pycache__/forms.cpython-311.pyc b/core/__pycache__/forms.cpython-311.pyc index c527124..9dfcf9b 100644 Binary files a/core/__pycache__/forms.cpython-311.pyc and b/core/__pycache__/forms.cpython-311.pyc differ diff --git a/core/__pycache__/models.cpython-311.pyc b/core/__pycache__/models.cpython-311.pyc index 29a3374..63bd88a 100644 Binary files a/core/__pycache__/models.cpython-311.pyc and b/core/__pycache__/models.cpython-311.pyc differ diff --git a/core/__pycache__/views.cpython-311.pyc b/core/__pycache__/views.cpython-311.pyc index f76538a..ea8c7f4 100644 Binary files a/core/__pycache__/views.cpython-311.pyc and b/core/__pycache__/views.cpython-311.pyc differ diff --git a/core/admin.py b/core/admin.py index ee7d00e..eeb9c21 100644 --- a/core/admin.py +++ b/core/admin.py @@ -3,7 +3,7 @@ from .models import Profile, Truck, Shipment, Bid, Message, WhatsAppConfig @admin.register(Profile) class ProfileAdmin(admin.ModelAdmin): - list_display = ('user', 'role', 'phone_number') + list_display = ('user', 'role', 'country_code', 'phone_number') list_filter = ('role',) search_fields = ('user__username', 'phone_number') diff --git a/core/forms.py b/core/forms.py index f3bf8df..cd392a4 100644 --- a/core/forms.py +++ b/core/forms.py @@ -8,6 +8,7 @@ class UserRegistrationForm(UserCreationForm): email = forms.EmailField(required=True, widget=forms.EmailInput(attrs={'class': 'form-control'})) confirm_email = forms.EmailField(required=True, widget=forms.EmailInput(attrs={'class': 'form-control'}), label=_("Confirm Email")) role = forms.ChoiceField(choices=Profile.ROLE_CHOICES, widget=forms.Select(attrs={'class': 'form-select'})) + country_code = forms.CharField(max_length=5, required=True, initial='966', widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': '966'})) phone_number = forms.CharField(max_length=20, required=False, widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': '+1234567890'})) class Meta(UserCreationForm.Meta): diff --git a/core/migrations/0007_profile_country_code.py b/core/migrations/0007_profile_country_code.py new file mode 100644 index 0000000..24039a9 --- /dev/null +++ b/core/migrations/0007_profile_country_code.py @@ -0,0 +1,18 @@ +# Generated by Django 5.2.7 on 2026-01-23 12:10 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0006_whatsappconfig'), + ] + + operations = [ + migrations.AddField( + model_name='profile', + name='country_code', + field=models.CharField(blank=True, default='966', max_length=5), + ), + ] diff --git a/core/migrations/__pycache__/0007_profile_country_code.cpython-311.pyc b/core/migrations/__pycache__/0007_profile_country_code.cpython-311.pyc new file mode 100644 index 0000000..a8947f5 Binary files /dev/null and b/core/migrations/__pycache__/0007_profile_country_code.cpython-311.pyc differ diff --git a/core/models.py b/core/models.py index 209eb65..3eb0964 100644 --- a/core/models.py +++ b/core/models.py @@ -13,8 +13,18 @@ class Profile(models.Model): ) user = models.OneToOneField(User, on_delete=models.CASCADE) role = models.CharField(max_length=20, choices=ROLE_CHOICES, default='SHIPPER') + country_code = models.CharField(max_length=5, blank=True, default="966") phone_number = models.CharField(max_length=20, blank=True) + @property + def full_phone_number(self): + if not self.phone_number: + return "" + # Remove any existing leading + from country code and phone number + cc = str(self.country_code).replace("+", "").strip() + pn = str(self.phone_number).replace("+", "").strip() + return f"{cc}{pn}" + def __str__(self): return f"{self.user.username} - {self.role}" @@ -46,6 +56,15 @@ class Truck(models.Model): is_approved = models.BooleanField(_('Is Approved'), default=False) created_at = models.DateTimeField(auto_now_add=True) + @property + def full_phone_number(self): + if not self.phone_number: + return "" + # Remove any existing leading + from country code and phone number + cc = str(self.country_code).replace("+", "").strip() + pn = str(self.phone_number).replace("+", "").strip() + return f"{cc}{pn}" + def __str__(self): return f"{self.display_truck_type} - {self.plate_no}" @@ -92,6 +111,15 @@ class Shipment(models.Model): created_at = models.DateTimeField(auto_now_add=True) + @property + def full_phone_number(self): + if not self.phone_number: + return "" + # Remove any existing leading + from country code and phone number + cc = str(self.country_code).replace("+", "").strip() + pn = str(self.phone_number).replace("+", "").strip() + return f"{cc}{pn}" + def __str__(self): return f"{self.origin} to {self.destination} - {self.status}" @@ -110,6 +138,15 @@ class Bid(models.Model): created_at = models.DateTimeField(auto_now_add=True) + @property + def full_phone_number(self): + if not self.phone_number: + return "" + # Remove any existing leading + from country code and phone number + cc = str(self.country_code).replace("+", "").strip() + pn = str(self.phone_number).replace("+", "").strip() + return f"{cc}{pn}" + def __str__(self): return f"Bid by {self.truck_owner.username} for {self.shipment}" @@ -119,6 +156,15 @@ class Message(models.Model): content = models.TextField() timestamp = models.DateTimeField(auto_now_add=True) + @property + def full_phone_number(self): + if not self.phone_number: + return "" + # Remove any existing leading + from country code and phone number + cc = str(self.country_code).replace("+", "").strip() + pn = str(self.phone_number).replace("+", "").strip() + return f"{cc}{pn}" + def __str__(self): return f"From {self.sender.username} at {self.timestamp}" @@ -131,6 +177,15 @@ class WhatsAppConfig(models.Model): verbose_name = _('WhatsApp Configuration') verbose_name_plural = _('WhatsApp Configuration') + @property + def full_phone_number(self): + if not self.phone_number: + return "" + # Remove any existing leading + from country code and phone number + cc = str(self.country_code).replace("+", "").strip() + pn = str(self.phone_number).replace("+", "").strip() + return f"{cc}{pn}" + def __str__(self): return str(_("WhatsApp Configuration")) diff --git a/core/templates/registration/register.html b/core/templates/registration/register.html index 6e0ea86..099c746 100644 --- a/core/templates/registration/register.html +++ b/core/templates/registration/register.html @@ -22,18 +22,40 @@ {% endif %} {% for field in form %} -