dem13
This commit is contained in:
parent
cdfcd5f4e8
commit
53e281bd22
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,5 +1,10 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from .models import Profile, Truck, Shipment, Bid, Message, WhatsAppConfig
|
from .models import Profile, Truck, Shipment, Bid, Message, WhatsAppConfig, Country
|
||||||
|
|
||||||
|
@admin.register(Country)
|
||||||
|
class CountryAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ('name', 'code', 'is_default')
|
||||||
|
list_editable = ('is_default',)
|
||||||
|
|
||||||
@admin.register(Profile)
|
@admin.register(Profile)
|
||||||
class ProfileAdmin(admin.ModelAdmin):
|
class ProfileAdmin(admin.ModelAdmin):
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
from .models import Truck, Shipment, Bid, Profile
|
from .models import Truck, Shipment, Bid, Profile, Country
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.contrib.auth.forms import UserCreationForm
|
from django.contrib.auth.forms import UserCreationForm
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
@ -8,8 +8,8 @@ class UserRegistrationForm(UserCreationForm):
|
|||||||
email = forms.EmailField(required=True, widget=forms.EmailInput(attrs={'class': 'form-control'}))
|
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"))
|
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'}))
|
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'}))
|
country_code = forms.ChoiceField(choices=[], widget=forms.Select(attrs={'class': 'form-select'}))
|
||||||
phone_number = forms.CharField(max_length=20, required=False, widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': '+1234567890'}))
|
phone_number = forms.CharField(max_length=20, required=False, widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': '123456789'}))
|
||||||
|
|
||||||
class Meta(UserCreationForm.Meta):
|
class Meta(UserCreationForm.Meta):
|
||||||
model = User
|
model = User
|
||||||
@ -17,6 +17,18 @@ class UserRegistrationForm(UserCreationForm):
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
# Dynamic country codes from the database
|
||||||
|
countries = Country.objects.all()
|
||||||
|
if countries.exists():
|
||||||
|
self.fields['country_code'].choices = [(c.code, str(c)) for c in countries]
|
||||||
|
default_country = countries.filter(is_default=True).first()
|
||||||
|
if default_country:
|
||||||
|
self.fields['country_code'].initial = default_country.code
|
||||||
|
else:
|
||||||
|
# Fallback if no countries are defined yet
|
||||||
|
self.fields['country_code'].choices = [('966', 'Saudi Arabia (+966)')]
|
||||||
|
self.fields['country_code'].initial = '966'
|
||||||
|
|
||||||
for field in self.fields.values():
|
for field in self.fields.values():
|
||||||
if not isinstance(field.widget, (forms.CheckboxInput, forms.Select)):
|
if not isinstance(field.widget, (forms.CheckboxInput, forms.Select)):
|
||||||
field.widget.attrs.update({'class': 'form-control'})
|
field.widget.attrs.update({'class': 'form-control'})
|
||||||
|
|||||||
26
core/migrations/0008_country.py
Normal file
26
core/migrations/0008_country.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# Generated by Django 5.2.7 on 2026-01-23 12:19
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('core', '0007_profile_country_code'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Country',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=100, verbose_name='Country Name')),
|
||||||
|
('code', models.CharField(max_length=10, verbose_name='Country Code')),
|
||||||
|
('is_default', models.BooleanField(default=False, verbose_name='Is Default')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'Country',
|
||||||
|
'verbose_name_plural': 'Countries',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
BIN
core/migrations/__pycache__/0008_country.cpython-311.pyc
Normal file
BIN
core/migrations/__pycache__/0008_country.cpython-311.pyc
Normal file
Binary file not shown.
@ -5,6 +5,18 @@ from django.dispatch import receiver
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.utils.translation import get_language
|
from django.utils.translation import get_language
|
||||||
|
|
||||||
|
class Country(models.Model):
|
||||||
|
name = models.CharField(_('Country Name'), max_length=100)
|
||||||
|
code = models.CharField(_('Country Code'), max_length=10)
|
||||||
|
is_default = models.BooleanField(_('Is Default'), default=False)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = _('Country')
|
||||||
|
verbose_name_plural = _('Countries')
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.name} (+{self.code})"
|
||||||
|
|
||||||
class Profile(models.Model):
|
class Profile(models.Model):
|
||||||
ROLE_CHOICES = (
|
ROLE_CHOICES = (
|
||||||
('SHIPPER', _('Shipper (Need Goods Moved)')),
|
('SHIPPER', _('Shipper (Need Goods Moved)')),
|
||||||
@ -56,15 +68,6 @@ class Truck(models.Model):
|
|||||||
is_approved = models.BooleanField(_('Is Approved'), default=False)
|
is_approved = models.BooleanField(_('Is Approved'), default=False)
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
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):
|
def __str__(self):
|
||||||
return f"{self.display_truck_type} - {self.plate_no}"
|
return f"{self.display_truck_type} - {self.plate_no}"
|
||||||
|
|
||||||
@ -111,15 +114,6 @@ class Shipment(models.Model):
|
|||||||
|
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
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):
|
def __str__(self):
|
||||||
return f"{self.origin} to {self.destination} - {self.status}"
|
return f"{self.origin} to {self.destination} - {self.status}"
|
||||||
|
|
||||||
@ -138,15 +132,6 @@ class Bid(models.Model):
|
|||||||
|
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
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):
|
def __str__(self):
|
||||||
return f"Bid by {self.truck_owner.username} for {self.shipment}"
|
return f"Bid by {self.truck_owner.username} for {self.shipment}"
|
||||||
|
|
||||||
@ -156,15 +141,6 @@ class Message(models.Model):
|
|||||||
content = models.TextField()
|
content = models.TextField()
|
||||||
timestamp = models.DateTimeField(auto_now_add=True)
|
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):
|
def __str__(self):
|
||||||
return f"From {self.sender.username} at {self.timestamp}"
|
return f"From {self.sender.username} at {self.timestamp}"
|
||||||
|
|
||||||
@ -177,15 +153,6 @@ class WhatsAppConfig(models.Model):
|
|||||||
verbose_name = _('WhatsApp Configuration')
|
verbose_name = _('WhatsApp Configuration')
|
||||||
verbose_name_plural = _('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):
|
def __str__(self):
|
||||||
return str(_("WhatsApp Configuration"))
|
return str(_("WhatsApp Configuration"))
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,7 @@
|
|||||||
<label class="form-label">{% trans "Phone Number" %}</label>
|
<label class="form-label">{% trans "Phone Number" %}</label>
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<span class="input-group-text">+</span>
|
<span class="input-group-text">+</span>
|
||||||
<div style="width: 80px;">
|
<div class="flex-grow-0" style="min-width: 150px;">
|
||||||
{{ form.country_code }}
|
{{ form.country_code }}
|
||||||
</div>
|
</div>
|
||||||
{{ form.phone_number }}
|
{{ form.phone_number }}
|
||||||
@ -38,7 +38,7 @@
|
|||||||
{% for error in form.phone_number.errors %}{{ error }} {% endfor %}
|
{% for error in form.phone_number.errors %}{{ error }} {% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="form-text text-muted small">{% trans "Enter country code (e.g. 966) and phone number." %}</div>
|
<div class="form-text text-muted small">{% trans "Select country and enter phone number." %}</div>
|
||||||
</div>
|
</div>
|
||||||
{% elif field.name == 'phone_number' %}
|
{% elif field.name == 'phone_number' %}
|
||||||
{# Handled above #}
|
{# Handled above #}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user