Repository: saleor/saleor

Issue:
Improve profile page
Profile page should have 3 sections in tabs:
* Orders
* Account & Password
* Addresses

Orders section should be the default one.
Also we should discuss if address management is really required in separated view on profile page. 



Discussion:

Resolving patch:
diff --git a/saleor/userprofile/urls.py b/saleor/userprofile/urls.py
--- a/saleor/userprofile/urls.py
+++ b/saleor/userprofile/urls.py
@@ -5,13 +5,6 @@
 
 urlpatterns = [
     url(r'^$', views.details, name='details'),
-    url(r'^address/create/$', views.address_create,
-        name='address-create'),
-    url(r'^address/(?P<pk>\d+)/edit/$', views.address_edit,
-        name='address-edit'),
     url(r'^address/(?P<pk>\d+)/delete/$',
         views.address_delete, name='address-delete'),
-    url(r'^address/(?P<pk>\d+)/make-default-for-'
-        r'(?P<purpose>billing|shipping)/$', views.address_make_default,
-        name='address-make-default')
 ]
diff --git a/saleor/userprofile/views.py b/saleor/userprofile/views.py
--- a/saleor/userprofile/views.py
+++ b/saleor/userprofile/views.py
@@ -1,56 +1,35 @@
+from allauth.account.adapter import get_adapter
+from allauth.account.forms import ChangePasswordForm
+from allauth.account.utils import logout_on_password_change
 from django.contrib import messages
 from django.contrib.auth.decorators import login_required
 from django.core.urlresolvers import reverse
-from django.http import HttpResponseRedirect, Http404
-from django.shortcuts import get_object_or_404, redirect
+from django.http import HttpResponseRedirect
+from django.shortcuts import get_object_or_404
 from django.template.response import TemplateResponse
-from django.views.decorators.http import require_POST
 from django.utils.translation import ugettext as _
 
-from .forms import get_address_form
-
 
 @login_required
 def details(request):
+    password_form = get_or_process_password_form(request)
     ctx = {'addresses': request.user.addresses.all(),
-           'orders': request.user.orders.prefetch_related('groups__items')}
+           'orders': request.user.orders.prefetch_related('groups__items'),
+           'change_password_form': password_form}
+
     return TemplateResponse(request, 'userprofile/details.html', ctx)
 
-@login_required
-def address_edit(request, pk):
-    address = get_object_or_404(request.user.addresses, pk=pk)
-    address_form, preview = get_address_form(
-        request.POST or None, instance=address,
-        country_code=address.country.code)
-    if address_form.is_valid() and not preview:
-        address_form.save()
-        message = _('Address successfully updated.')
-        messages.success(request, message)
-        return HttpResponseRedirect(reverse('profile:details'))
-    return TemplateResponse(
-        request, 'userprofile/address-edit.html',
-        {'address_form': address_form})
 
-
-@login_required
-def address_create(request):
-    user = request.user
-    address_form, preview = get_address_form(
-        request.POST or None, initial={'country': request.country},
-        country_code=request.country.code)
-    if address_form.is_valid() and not preview:
-        address = address_form.save()
-        user.addresses.add(address)
-        user.default_shipping_address = address
-        user.default_billing_address = address
-        user.save(update_fields=[
-            'default_shipping_address', 'default_billing_address'])
-        message = _('Address successfully created.')
-        messages.success(request, message)
-        return HttpResponseRedirect(reverse('profile:details'))
-    return TemplateResponse(
-        request, 'userprofile/address-edit.html',
-        {'address_form': address_form})
+def get_or_process_password_form(request):
+    form = ChangePasswordForm(data=request.POST or None, user=request.user)
+    if form.is_valid():
+        form.save()
+        logout_on_password_change(request, form.user)
+        get_adapter(request).add_message(
+            request,
+            messages.SUCCESS,
+            'account/messages/password_changed.txt')
+    return form
 
 
 @login_required
@@ -59,22 +38,6 @@ def address_delete(request, pk):
     if request.method == 'POST':
         address.delete()
         messages.success(request, _('Address successfully deleted.'))
-        return HttpResponseRedirect(reverse('profile:details'))
+        return HttpResponseRedirect(reverse('profile:details') + '#addresses')
     return TemplateResponse(
         request, 'userprofile/address-delete.html', {'address': address})
-
-
-@login_required
-@require_POST
-def address_make_default(request, pk, purpose):
-    user = request.user
-    address = get_object_or_404(user.addresses, pk=pk)
-    if purpose == 'shipping':
-        user.default_shipping_address = address
-        user.save(update_fields=['default_shipping_address'])
-    elif purpose == 'billing':
-        user.default_billing_address = address
-        user.save(update_fields=['default_billing_address'])
-    else:
-        raise Http404('Unknown purpose')
-    return redirect('profile:details')


Test patch: