Commit eff121e3 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

fix group join view

parent 167e2faf
......@@ -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
......@@ -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>
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment