Repository: djangopackages/djangopackages

Issue:
Cannot save profile edit form
On https://www.djangopackages.com/profiles/edit/ clicking the Edit button does nothing. Tested on Linux with Firefox and Chromium.



Discussion:

Resolving patch:
diff --git a/profiles/forms.py b/profiles/forms.py
--- a/profiles/forms.py
+++ b/profiles/forms.py
@@ -2,16 +2,33 @@
 
 from profiles.models import Profile
 
+from crispy_forms.helper import FormHelper
+from crispy_forms.layout import Layout, Fieldset, ButtonHolder, Submit, HTML
 
 class ProfileForm(forms.ModelForm):
 
     def __init__(self, *args, **kwargs):
         super(ProfileForm, self).__init__(*args, **kwargs)
 
-    class Meta:
+        self.helper = FormHelper()
+        self.helper.form_action = 'profile_edit'
+        self.helper.layout = Layout(
+            Fieldset(
+                '',
+                HTML("""
+                    <p>Github account, <strong>{{ profile.github_account }}</strong></p>
+                """),
+                'bitbucket_url',
+                'google_code_url',
+            ),
+            ButtonHolder(
+                Submit('edit', 'Edit', css_class='btn btn-default')
+            )
+        )
 
+    class Meta:
         fields = (
-                    'bitbucket_url',
-                    'google_code_url',
-                    )
+            'bitbucket_url',
+            'google_code_url',
+        )
         model = Profile
diff --git a/profiles/urls.py b/profiles/urls.py
--- a/profiles/urls.py
+++ b/profiles/urls.py
@@ -3,7 +3,11 @@
 from profiles import views
 
 urlpatterns = patterns("",
-    url(r"^edit/$", views.profile_edit, name="profile_edit"),
+    url(
+        regex=r"^edit/$",
+        view=views.ProfileEditUpdateView.as_view(),
+        name="profile_edit"
+    ),
     url(r"^$", views.profile_list, name="profile_list"),
     url(r"^(?P<github_account>[-\w]+)/$", views.profile_detail, name="profile_detail"),
 )
diff --git a/profiles/views.py b/profiles/views.py
--- a/profiles/views.py
+++ b/profiles/views.py
@@ -1,12 +1,11 @@
-from django.contrib.auth.decorators import login_required
 from django.contrib.auth.models import User
 from django.contrib import messages
 from django.core.urlresolvers import reverse
 from django.http import HttpResponseRedirect
 from django.shortcuts import render, get_object_or_404
+from django.views.generic.edit import UpdateView
 
-from crispy_forms.helper import FormHelper
-from crispy_forms.layout import Layout, Fieldset, ButtonHolder, Submit, HTML
+from braces.views import LoginRequiredMixin
 
 from social_auth.signals import pre_update
 from social_auth.backends.contrib.github import GithubBackend
@@ -36,45 +35,18 @@ def profile_list(request, template_name="profiles/profiles.html"):
         })
 
 
-@login_required
-def profile_edit(request, template_name="profiles/profile_edit.html"):
+class ProfileEditUpdateView(LoginRequiredMixin, UpdateView):
+    model = Profile
+    form_class = ProfileForm
+    template_name = "profiles/profile_edit.html"
 
-    profile = request.user.get_profile()
-    form = ProfileForm(request.POST or None, instance=profile)
+    def get_object(self):
+        return self.request.user.get_profile()
 
-    if form.is_valid():
+    def form_valid(self, form):
         form.save()
-        msg = 'Profile edited'
-        messages.add_message(request, messages.INFO, msg)
-        return HttpResponseRedirect(reverse("profile_detail", kwargs={"github_account": profile.github_account}))
-
-    # TODO - move this to a template
-    github_account = """
-    <div
-        id="div_id_github_account"
-        class="ctrlHolder"><label for="id_github_account" >Github account</label><strong>{0}</strong></div>
-    """.format(profile.github_account)
-
-    helper = FormHelper()
-    helper.form_class = "profile-edit-form"
-    helper.layout = Layout(
-        Fieldset(
-            '',
-            HTML(github_account),
-            'bitbucket_url',
-            'google_code_url',
-        ),
-        ButtonHolder(
-            Submit('edit', 'Edit', css_class="btn btn-default"),
-        )
-    )
-
-    return render(request, template_name,
-        {
-            "profile": profile,
-            "form": form,
-            "helper": helper,
-        })
+        messages.add_message(self.request, messages.INFO, "Profile Saved")
+        return HttpResponseRedirect(reverse("profile_detail", kwargs={"github_account": self.get_object()}))
 
 
 def github_user_update(sender, user, response, details, **kwargs):


Test patch: