commit 95a51cdc25749b73f4f4475da8eb47e476ff09e1
Author: Sofia Papagiannaki <papagian@gmail.com>
Date:   Wed Aug 29 13:30:24 2012 +0300

    fix group join view

diff --git a/snf-astakos-app/astakos/im/forms.py b/snf-astakos-app/astakos/im/forms.py
index 0698457..d9d2b5e 100644
--- a/snf-astakos-app/astakos/im/forms.py
+++ b/snf-astakos-app/astakos/im/forms.py
@@ -529,26 +529,4 @@ class AstakosGroupCreationForm(forms.ModelForm):
                 yield (suffix, value)
 
 class AstakosGroupSearchForm(forms.Form):
-    q = forms.CharField(max_length=200, label='')
-
-class MembershipCreationForm(forms.ModelForm):
-    # TODO check not to hit the db
-    group = forms.ModelChoiceField(
-        queryset=AstakosGroup.objects.all(),
-        widget=forms.HiddenInput()
-    )
-    person = forms.ModelChoiceField(
-        queryset=AstakosUser.objects.all(),
-        widget=forms.HiddenInput()
-    )
-    date_requested = forms.DateField(
-        widget=forms.HiddenInput(),
-        input_formats="%d/%m/%Y"
-    )
-    
-    class Meta:
-        model = Membership
-        exclude = ('date_joined',)
-    
-    def __init__(self, *args, **kwargs):
-        super(MembershipCreationForm, self).__init__(*args, **kwargs)
\ No newline at end of file
+    q = forms.CharField(max_length=200, label='')
\ No newline at end of file
diff --git a/snf-astakos-app/astakos/im/templates/im/astakosgroup_list.html b/snf-astakos-app/astakos/im/templates/im/astakosgroup_list.html
index cd48734..341d6c2 100644
--- a/snf-astakos-app/astakos/im/templates/im/astakosgroup_list.html
+++ b/snf-astakos-app/astakos/im/templates/im/astakosgroup_list.html
@@ -112,18 +112,10 @@
 			                        <td>Pending</td>
 			                    {% else %}
 			                        <td>Not member 
-			                        {% if join_forms %}
-			                         
 			                            <form action="{% url group_join o.id %}" method="post" class="link-like">{% csrf_token %}
-			                                {% with join_forms|lookup:o.name as form %}
-			                                    {% include "im/form_render.html" %}
-			                                {% endwith %}
-			                                
 			                                <input type="submit"   value="JOIN GROUP" />
-			                                 
 			                            </form>
 			                        </td>
-			                        {% endif %}
 			                    {% endif %}
 			                {% endif %}
 			              </tr>
diff --git a/snf-astakos-app/astakos/im/views.py b/snf-astakos-app/astakos/im/views.py
index c4dd581..dac566d 100644
--- a/snf-astakos-app/astakos/im/views.py
+++ b/snf-astakos-app/astakos/im/views.py
@@ -704,8 +704,7 @@ def group_approval_request(request, group_id):
 
 @signed_terms_required
 @login_required
-def group_search(request, extra_context={}, **kwargs):
-    join_forms = {}
+def group_search(request, extra_context=None, **kwargs):
     if request.method == 'GET':
         form = AstakosGroupSearchForm()
     else:
@@ -714,43 +713,40 @@ def group_search(request, extra_context={}, **kwargs):
             q = form.cleaned_data['q'].strip()
             q = URLField().to_python(q)
             queryset = AstakosGroup.objects.select_related().filter(name=q)
-            f = MembershipCreationForm
-            for g in queryset:
-                join_forms[g.name] = f(
-                    dict(
-                        group=g,
-                        person=request.user,
-                        date_requested=datetime.now().strftime("%d/%m/%Y")
-                    )
-                )
             return object_list(
                 request,
                 queryset,
                 template_name='im/astakosgroup_list.html',
                 extra_context=dict(
                     form=form,
-                    is_search=True,
-                    join_forms=join_forms
+                    is_search=True
                 )
             )
     return render_response(
         template='im/astakosgroup_list.html',
         form = form,
-        context_instance=get_context(request)
+        context_instance=get_context(request, extra_context)
     )
 
 @signed_terms_required
 @login_required
 def group_join(request, group_id):
-    return create_object(
-        request,
-        model=Membership,
-        template_name='im/astakosgroup_list.html',
+    m = Membership(group_id=group_id,
+        person=request.user,
+        date_requested=datetime.now()
+    )
+    try:
+        m.save()
         post_save_redirect = reverse(
             'group_detail',
             kwargs=dict(group_id=group_id)
         )
-    )
+        return HttpResponseRedirect(post_save_redirect)
+    except IntegrityError, e:
+        logger.exception(e)
+        msg = _('Failed to join group.')
+        messages.error(request, msg)
+        return group_search(request)
 
 @signed_terms_required
 @login_required
