Last active
December 29, 2015 03:33
-
-
Save CapnKernel/d4aaa652f66102de399f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| {% extends "my/base.html" %} | |
| {% load url from future %} | |
| {% block header %}My account{% endblock %} | |
| {% block content %} | |
| <h2>My account</h2> | |
| <p><small>Last login: {{ user.last_login|date:"DATE_FORMAT" }} Date joined: {{ user.date_joined|date:"DATE_FORMAT" }}</small></p> | |
| <p> | |
| <form method="POST" action="{% url 'my.views.account' %}"> | |
| {% csrf_token %} | |
| {{ form.as_p }} | |
| <input type="submit" name="save" value="Save" /> | |
| </form> | |
| </p> | |
| <h3>Addresses</h3> | |
| <p>You currently have {{ address_count }} address{{ address_count|pluralize:"es" }} listed.{% if address_count == 0 %} You'll need to provide that information when you order.{% endif %}</p> | |
| <button type="button" onclick="javascript:window.location='{% url 'my.views.account' %}';">Edit addresses</button> | |
| <p></p> | |
| {% endblock %} |
This file contains hidden or 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
| class AccountForm(forms.ModelForm): | |
| class Meta: | |
| model = Customer | |
| fields = ( | |
| 'firstname', | |
| 'lastname', | |
| 'SYS_familiar_name', | |
| 'email', | |
| 'phone', | |
| ) | |
| @require_http_methods(("GET", "POST")) | |
| @login_required | |
| def account(request): | |
| customer = Customer.get_from_user(request.user) | |
| if request.method == 'POST': | |
| form = AccountForm(request.POST, instance=customer) | |
| if form.is_valid(): | |
| form.save() | |
| messages.success(request, "Account information saved.") | |
| return redirect('my.views.account') | |
| tvars = { | |
| 'c': customer, | |
| 'form': AccountForm(instance=customer), | |
| # 'address_count': AddressBook.objects.filter(customer=customer).count(), | |
| 'address_count': customer.addressbook_set.count(), | |
| } | |
| return render(request, 'my/profile.html', tvars) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment