mirror of
https://github.com/TrentSPalmer/trentpalmerdotorg.git
synced 2024-11-21 09:01:31 -08:00
add twitter_handle to account model
This commit is contained in:
parent
fc98f1c6ce
commit
206886f5d6
@ -58,6 +58,7 @@ class EditProfileForm(forms.Form):
|
||||
|
||||
first_name = UsernameField(required=False)
|
||||
last_name = UsernameField(required=False)
|
||||
twitter_handle = forms.CharField(max_length=64)
|
||||
|
||||
password = forms.CharField(
|
||||
label="confirm password",
|
||||
@ -67,6 +68,7 @@ class EditProfileForm(forms.Form):
|
||||
|
||||
def __init__(self, user, *args, **kwargs):
|
||||
self.user = user
|
||||
self.account = user.account
|
||||
super(EditProfileForm, self).__init__(*args, **kwargs)
|
||||
|
||||
def clean(self):
|
||||
@ -74,6 +76,7 @@ class EditProfileForm(forms.Form):
|
||||
first_name = self.cleaned_data.get('first_name')
|
||||
last_name = self.cleaned_data.get('last_name')
|
||||
password = self.cleaned_data["password"]
|
||||
t_handle = self.cleaned_data['twitter_handle']
|
||||
if not self.user.check_password(password):
|
||||
raise ValidationError("password is incorrect.")
|
||||
if email != self.user.email:
|
||||
@ -83,12 +86,15 @@ class EditProfileForm(forms.Form):
|
||||
'email': email,
|
||||
'first_name': first_name,
|
||||
'last_name': last_name,
|
||||
'twitter_handle': t_handle,
|
||||
}
|
||||
|
||||
def save(self, commit=True):
|
||||
self.user.email = self.cleaned_data['email']
|
||||
self.user.first_name = self.cleaned_data['first_name']
|
||||
self.user.last_name = self.cleaned_data['last_name']
|
||||
self.account.twitter_handle = self.cleaned_data['twitter_handle']
|
||||
if commit:
|
||||
self.user.save()
|
||||
self.account.save()
|
||||
return self.user
|
||||
|
18
accounts/migrations/0003_account_twitter_handle.py
Normal file
18
accounts/migrations/0003_account_twitter_handle.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.1.7 on 2021-03-28 22:02
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounts', '0002_emailwhitelist'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='account',
|
||||
name='twitter_handle',
|
||||
field=models.CharField(default='@Twitter', max_length=64),
|
||||
),
|
||||
]
|
@ -14,6 +14,7 @@ class Account(UUIDAsIDModel):
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE, unique=True)
|
||||
totp_key = models.CharField(max_length=16, null=True)
|
||||
use_totp = models.BooleanField(default=False)
|
||||
twitter_handle = models.CharField(max_length=64, default='@Twitter')
|
||||
|
||||
def __str__(self):
|
||||
return str(self.user)
|
||||
|
@ -59,5 +59,6 @@ def edit_profile(request):
|
||||
'email': request.user.email,
|
||||
'first_name': request.user.first_name,
|
||||
'last_name': request.user.last_name,
|
||||
'twitter_handle': request.user.account.twitter_handle,
|
||||
})
|
||||
return render(request, 'base_form.html', {'form': form})
|
||||
|
Loading…
Reference in New Issue
Block a user