-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58b9ee5
commit 17d4fec
Showing
28 changed files
with
357 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from django import forms | ||
from .models import UserProfile | ||
|
||
|
||
class UserProfileForm(forms.ModelForm): | ||
class Meta: | ||
model = UserProfile | ||
exclude = ('user',) | ||
|
||
def __init__(self, *args, **kwargs): | ||
""" | ||
Add placeholders and classes, remove auto-generated | ||
labels and set autofocus on first field | ||
""" | ||
super().__init__(*args, **kwargs) | ||
placeholders = { | ||
'default_phone_number': 'Phone Number', | ||
'default_postcode': 'Postal Code', | ||
'default_town_or_city': 'Town or City', | ||
'default_street_address1': 'Street Address 1', | ||
'default_street_address2': 'Street Address 2', | ||
'default_county': 'County, State or Locality', | ||
} | ||
|
||
self.fields['default_phone_number'].widget.attrs['autofocus'] = True | ||
for field in self.fields: | ||
if field != 'default_country': | ||
if self.fields[field].required: | ||
placeholder = f'{placeholders[field]} *' | ||
else: | ||
placeholder = placeholders[field] | ||
self.fields[field].widget.attrs['placeholder'] = placeholder | ||
self.fields[field].widget.attrs['class'] = ('border-black ' | ||
'rounded-0 ' | ||
'profile-form-input') | ||
self.fields[field].label = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.order-history { | ||
max-height: 416px; /* height of profile form + submit button */ | ||
overflow-y: auto; | ||
} | ||
|
||
#profile-update-form .form-control { | ||
color: #000; | ||
} | ||
|
||
#profile-update-form input::placeholder { | ||
color: #aab7c4; | ||
} | ||
|
||
#id_default_country, | ||
#id_default_country option:not(:first-child) { | ||
color: #000; | ||
} | ||
|
||
#id_default_country option:first-child { | ||
color: #aab7c4; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
let countrySelected = $('#id_default_country').val(); | ||
if(!countrySelected) { | ||
$('#id_default_country').css('color', '#aab7c4'); | ||
}; | ||
$('#id_default_country').change(function() { | ||
countrySelected = $(this).val(); | ||
if(!countrySelected) { | ||
$(this).css('color', '#aab7c4'); | ||
} else { | ||
$(this).css('color', '#000'); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,52 @@ | ||
from django.shortcuts import render | ||
from django.shortcuts import render, get_object_or_404 | ||
from django.contrib import messages | ||
from django.contrib.auth.decorators import login_required | ||
from .models import UserProfile | ||
from .forms import UserProfileForm | ||
|
||
from checkout.models import Order | ||
|
||
|
||
@login_required | ||
def profile(request): | ||
""" Display the user's profile. """ | ||
profile = get_object_or_404(UserProfile, user=request.user) | ||
|
||
if request.method == 'POST': | ||
form = UserProfileForm(request.POST, instance=profile) | ||
if form.is_valid(): | ||
form.save() | ||
messages.success(request, 'Profile updated successfully') | ||
else: | ||
messages.error(request, | ||
('Update failed. Please ensure ' | ||
'the form is valid.')) | ||
else: | ||
form = UserProfileForm(instance=profile) | ||
orders = profile.orders.all() | ||
|
||
template = 'profile.html' | ||
context = {} | ||
context = { | ||
'form': form, | ||
'orders': orders, | ||
'on_profile_page': True | ||
} | ||
|
||
return render(request, template, context) | ||
|
||
|
||
def order_history(request, order_number): | ||
order = get_object_or_404(Order, order_number=order_number) | ||
|
||
messages.info(request, ( | ||
f'This is a past confirmation for order number {order_number}. ' | ||
'A confirmation email was sent on the order date.' | ||
)) | ||
|
||
template = 'checkout/checkout_success.html' | ||
context = { | ||
'order': order, | ||
'from_profile': True, | ||
} | ||
|
||
return render(request, template, context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.