Commit 76048fc2 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

Backend implementation of group creation summary

parent a77b0073
......@@ -538,7 +538,8 @@ class AstakosGroupCreationForm(forms.ModelForm):
name = forms.URLField()
moderation_enabled = forms.BooleanField(
help_text="Check if you want to approve members participation manually",
required=False
required=False,
initial=True
)
max_participants = forms.IntegerField(
widget=forms.HiddenInput(), label='', required=False
......@@ -564,28 +565,43 @@ class AstakosGroupCreationForm(forms.ModelForm):
'issue_date', 'expiration_date',
'moderation_enabled', 'max_participants']
def add_field((k, v)):
def add_fields((k, v)):
self.fields[k] = forms.IntegerField(
required=False,
widget=forms.HiddenInput()
)
map(add_field,
map(add_fields,
((k, v) for k,v in qd.iteritems() if k.endswith('_uplimit'))
)
def add_fields((k, v)):
self.fields[k] = forms.BooleanField(
required=False,
widget=forms.HiddenInput()
)
map(add_fields,
((k, v) for k,v in qd.iteritems() if k.startswith('is_selected_'))
)
def clean(self):
super(AstakosGroupCreationForm, self).clean()
self.cleaned_data['policies'] = []
append = self.cleaned_data['policies'].append
tbd = []
tbd = [f for f in self.fields if f.startswith('is_selected_')]
for name, uplimit in self.cleaned_data.iteritems():
subs = name.split('_uplimit')
if len(subs) == 2:
tbd.append(name)
prefix, suffix = subs
s, r = prefix.split(RESOURCE_SEPARATOR)
append(dict(service=s, resource=r, uplimit=uplimit))
for name in tbd:
del self.cleaned_data[name]
resource = Resource.objects.get(service__name=s, name=r)
# keep only resource limits for selected resource groups
if self.cleaned_data.get(
'is_selected_%s' % resource.group, True
):
append(dict(service=s, resource=r, uplimit=uplimit))
(self.cleaned_data.pop(name, None) for name in tbd)
return self.cleaned_data
......
......@@ -8,7 +8,7 @@
{% block page.body %}
<form action="{% url group_summary %}" method="post" class="withlabels quotas-form">{% csrf_token %}
<form action="" method="post" class="withlabels quotas-form">{% csrf_token %}
<fieldset>
<legend>
......
......@@ -4,10 +4,11 @@
{% block page.body %}
{{ data }}
<div class="projects summary">
<h2>GROUP REQUEST SUMMARY</h2>
<p>Lorem ipsum</p>
<form class="quotas-form">
<form action="{% url group_add_complete %}" class="quotas-form">
<div class="full-dotted">
<h3>DETAILS:</h3>
<dl class="alt-style">
......
......@@ -63,7 +63,9 @@ urlpatterns = patterns('astakos.im.views',
'resource_list', {}, name='resource_list'),
url(r'^billing/?$', 'billing', {}, name='billing'),
url(r'^timeline/?$', 'timeline', {}, name='timeline'),
url(r'^group/add/(?P<kind_name>\w+)?$',
url(r'^group/add/complete/?$', 'group_add_complete', {},
name='group_add_complete'),
url(r'^group/add/(?P<kind_name>\w+)?$',
'group_add', {}, name='group_add'),
url(r'^group/list/?$',
'group_list', {}, name='group_list'),
......@@ -85,8 +87,6 @@ urlpatterns = patterns('astakos.im.views',
'disapprove_member', {}, name='disapprove_member'),
url(r'^group/create/?$', 'group_create_list', {},
name='group_create_list'),
url(r'^group/add/summary/?$', 'group_summary', {},
name='group_summary'),
)
if EMAILCHANGE_ENABLED:
......
......@@ -664,6 +664,7 @@ def change_email(request, activation_key=None,
extra_context))
@require_http_methods(["GET", "POST"])
@signed_terms_required
@login_required
def group_add(request, kind_name='default'):
......@@ -725,33 +726,11 @@ def group_add(request, kind_name='default'):
if request.method == 'POST':
form = form_class(request.POST, request.FILES)
if form.is_valid():
d = form.cleaned_data.copy()
d['owners'] = [request.user]
result = callpoint.create_groups((d,)).next()
if result.is_success:
new_object = result.data[0]
msg = _("The %(verbose_name)s was created successfully.") %\
{"verbose_name": model._meta.verbose_name}
messages.success(request, msg, fail_silently=True)
# # send notification
# try:
# send_group_creation_notification(
# template_name='im/group_creation_notification.txt',
# dictionary={
# 'group': new_object,
# 'owner': request.user,
# 'policies': list(form.cleaned_data['policies']),
# }
# )
# except SendNotificationError, e:
# messages.error(request, e, fail_silently=True)
return HttpResponseRedirect(post_save_redirect % new_object)
else:
msg = _("The %(verbose_name)s creation failed: %(reason)s.") %\
{"verbose_name": model._meta.verbose_name,
"reason":result.reason}
messages.error(request, msg, fail_silently=True)
return render_response(
template='im/astakosgroup_form_summary.html',
context_instance=get_context(request),
data=form.cleaned_data
)
else:
now = datetime.now()
data = {
......@@ -773,6 +752,47 @@ def group_add(request, kind_name='default'):
}, context_processors)
return HttpResponse(t.render(c))
# @require_http_methods(["POST"])
# @signed_terms_required
# @login_required
def group_add_complete(request):
d = dict(request.POST)
d['owners'] = [request.user]
result = callpoint.create_groups((d,)).next()
if result.is_success:
new_object = result.data[0]
model = AstakosGroup
msg = _("The %(verbose_name)s was created successfully.") %\
{"verbose_name": model._meta.verbose_name}
messages.success(request, msg, fail_silently=True)
# # send notification
# try:
# send_group_creation_notification(
# template_name='im/group_creation_notification.txt',
# dictionary={
# 'group': new_object,
# 'owner': request.user,
# 'policies': list(form.cleaned_data['policies']),
# }
# )
# except SendNotificationError, e:
# messages.error(request, e, fail_silently=True)
post_save_redirect = '/im/group/%(id)s/'
return HttpResponseRedirect(post_save_redirect % new_object)
else:
msg = _("The %(verbose_name)s creation failed: %(reason)s.") %\
{"verbose_name": model._meta.verbose_name,
"reason":result.reason}
messages.error(request, msg, fail_silently=True)
return render_response(
template='im/astakosgroup_form_summary.html',
context_instance=get_context(request))
@require_http_methods(["GET"])
@signed_terms_required
@login_required
def group_list(request):
......@@ -828,6 +848,7 @@ def group_list(request):
})
@require_http_methods(["GET", "POST"])
@signed_terms_required
@login_required
def group_detail(request, group_id):
......@@ -904,6 +925,7 @@ def group_detail(request, group_id):
return response
@require_http_methods(["GET", "POST"])
@signed_terms_required
@login_required
def group_search(request, extra_context=None, **kwargs):
......@@ -959,6 +981,7 @@ def group_search(request, extra_context=None, **kwargs):
sorting=sorting))
@require_http_methods(["GET"])
@signed_terms_required
@login_required
def group_all(request, extra_context=None, **kwargs):
......@@ -996,6 +1019,7 @@ def group_all(request, extra_context=None, **kwargs):
sorting=sorting))
@require_http_methods(["POST"])
@signed_terms_required
@login_required
def group_join(request, group_id):
......@@ -1015,6 +1039,7 @@ def group_join(request, group_id):
return group_search(request)
@require_http_methods(["POST"])
@signed_terms_required
@login_required
def group_leave(request, group_id):
......@@ -1053,6 +1078,7 @@ def handle_membership(func):
return wrapper
@require_http_methods(["POST"])
@signed_terms_required
@login_required
@handle_membership
......@@ -1084,6 +1110,7 @@ def disapprove_member(request, membership):
messages.error(request, msg)
@require_http_methods(["GET"])
@signed_terms_required
@login_required
def resource_list(request):
......@@ -1139,6 +1166,7 @@ def group_create_list(request):
context_instance=get_context(request),)
@require_http_methods(["GET"])
@signed_terms_required
@login_required
def billing(request):
......@@ -1200,6 +1228,7 @@ def _clear_billing_data(data):
return data
@require_http_methods(["GET"])
@signed_terms_required
@login_required
def timeline(request):
......@@ -1226,10 +1255,4 @@ def timeline(request):
form=form,
timeline_header=timeline_header,
timeline_body=timeline_body)
return data
def group_summary(request):
return render_response(
template='im/astakosgroup_form_summary.html',
context_instance=get_context(request) )
return data
\ No newline at end of file
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