def edit_debate(request, space_url, debate_id): """ """ pk = debate_id place = get_object_or_404(Space, url=space_url) instance = Debate.objects.get(pk=debate_id) if (request.user.has_perm('admin_space', place) or request.user.has_perm('admin_debate', instance) or request.user == instance.author): RowFormSet = inlineformset_factory(Debate, Row, extra=1) ColumnFormSet = inlineformset_factory(Debate, Column, extra=1) debate_form = DebateForm(request.POST or None, instance=instance) row_formset = RowFormSet(request.POST or None, instance=instance, prefix="rowform") column_formset = ColumnFormSet(request.POST or None, instance=instance, prefix="colform") if request.method == 'POST': if debate_form.is_valid() and row_formset.is_valid() \ and column_formset.is_valid(): debate_form_uncommited = debate_form.save(commit=False) debate_form_uncommited.space = place debate_form_uncommited.author = request.user saved_debate = debate_form_uncommited.save() debate_instance = get_object_or_404(Debate, pk=debate_id) row = row_formset.save(commit=False) for form in row: form.debate = instance form.save() column = column_formset.save(commit=False) for form in column: form.debate = instance form.save() return HttpResponseRedirect( reverse(urln.DEBATE_VIEW, kwargs={ 'space_url': space_url, 'debate_id': str(debate_form_uncommited.id) })) return render_to_response('debate/debate_add.html', { 'form': debate_form, 'rowform': row_formset, 'colform': column_formset, 'get_place': place, 'debateid': debate_id }, context_instance=RequestContext(request)) else: raise PermissionDenied
def edit_debate(request, space_url, debate_id): """ """ pk = debate_id place = get_object_or_404(Space, url=space_url) instance = Debate.objects.get(pk=debate_id) if (request.user.has_perm('admin_space', place) or request.user.has_perm('admin_debate', instance) or request.user == instance.author): RowFormSet = inlineformset_factory(Debate, Row, extra=1) ColumnFormSet = inlineformset_factory(Debate, Column, extra=1) debate_form = DebateForm(request.POST or None, instance=instance) row_formset = RowFormSet(request.POST or None, instance=instance, prefix="rowform") column_formset = ColumnFormSet(request.POST or None, instance=instance, prefix="colform") if request.method == 'POST': if debate_form.is_valid() and row_formset.is_valid() \ and column_formset.is_valid(): debate_form_uncommited = debate_form.save(commit=False) debate_form_uncommited.space = place debate_form_uncommited.author = request.user saved_debate = debate_form_uncommited.save() debate_instance = get_object_or_404(Debate, pk=debate_id) row = row_formset.save(commit=False) for form in row: form.debate = instance form.save() column = column_formset.save(commit=False) for form in column: form.debate = instance form.save() return HttpResponseRedirect(reverse(urln.DEBATE_VIEW, kwargs={'space_url': space_url, 'debate_id': str(debate_form_uncommited.id)})) return render_to_response('debate/debate_add.html', {'form': debate_form, 'rowform': row_formset, 'colform': column_formset, 'get_place': place, 'debateid': debate_id}, context_instance=RequestContext(request)) else: raise PermissionDenied
def add_new_debate(request, space_url): """ Create a new debate. This function returns two forms to create a complete debate, debate form and phases formset. .. versionadded:: 0.1.5 :attributes: debate_form, row_formset, column_formset :context: form, rowform, colform, get_place, debateid """ place = get_object_or_404(Space, url=space_url) if has_space_permission(request.user, place, allow=['admins']) \ or has_all_permissions(request.user): RowFormSet = inlineformset_factory(Debate, Row, extra=1) ColumnFormSet = inlineformset_factory(Debate, Column, extra=1) debate_form = DebateForm(request.POST or None) row_formset = RowFormSet(request.POST or None, prefix="rowform") column_formset = ColumnFormSet(request.POST or None, prefix="colform") # Get the last PK and add 1 to get the current PK try: last_debate_id = Debate.objects.latest('id') current_debate_id = last_debate_id.pk + 1 except ObjectDoesNotExist: current_debate_id = 1 if request.user.has_perm('debate.debate_add') \ or has_all_permissions(request.user): if request.method == 'POST': if debate_form.is_valid() and row_formset.is_valid() \ and column_formset.is_valid(): debate_form_uncommited = debate_form.save(commit=False) debate_form_uncommited.space = place debate_form_uncommited.author = request.user saved_debate = debate_form_uncommited.save() debate_instance = get_object_or_404(Debate, pk=current_debate_id) row = row_formset.save(commit=False) for form in row: form.debate = debate_instance form.save() column = column_formset.save(commit=False) for form in column: form.debate = debate_instance form.save() return HttpResponseRedirect(reverse(urln.DEBATE_VIEW, kwargs={'space_url': space_url, 'debate_id': str(debate_form_uncommited.id)})) return render_to_response('debate/debate_add.html', {'form': debate_form, 'rowform': row_formset, 'colform': column_formset, 'get_place': place, 'debateid': current_debate_id}, context_instance=RequestContext(request)) return render_to_response('not_allowed.html', context_instance=RequestContext(request))
def add_new_debate(request, space_url): """ Create a new debate. This function returns two forms to create a complete debate, debate form and phases formset. .. versionadded:: 0.1.5 :attributes: debate_form, row_formset, column_formset :context: form, rowform, colform, get_place, debateid """ place = get_object_or_404(Space, url=space_url) if request.user in place.admins.all( ) or request.user.is_staff or request.user.is_superuser: # Define FormSets # This class is used to make empty formset forms required # See http://stackoverflow.com/questions/2406537/django-formsets-make-first-required/4951032#4951032 class RequiredFormSet(BaseFormSet): """ """ def __init__(self, *args, **kwargs): super(RequiredFormSet, self).__init__(*args, **kwargs) for form in self.forms: form.empty_permitted = False RowFormSet = formset_factory(RowForm, max_num=10, formset=RequiredFormSet, can_delete=True) ColumnFormSet = formset_factory(ColumnForm, max_num=10, formset=RequiredFormSet, can_delete=True) debate_form = DebateForm(request.POST or None) row_formset = RowFormSet(request.POST or None, prefix="rowform") column_formset = ColumnFormSet(request.POST or None, prefix="colform") # Get the last PK and add 1 to get the current PK try: last_debate_id = Debate.objects.latest('id') current_debate_id = last_debate_id.pk + 1 except ObjectDoesNotExist: current_debate_id = 1 if request.user.has_perm('debate_add') or request.user.is_staff: if request.method == 'POST': if debate_form.is_valid() and row_formset.is_valid( ) and column_formset.is_valid(): debate_form_uncommited = debate_form.save(commit=False) debate_form_uncommited.space = place debate_form_uncommited.author = request.user saved_debate = debate_form_uncommited.save() debate_instance = get_object_or_404(Debate, pk=current_debate_id) for form in row_formset.forms: row = form.save(commit=False) row.debate = debate_instance row.save() for form in column_formset.forms: column = form.save(commit=False) column.debate = debate_instance column.save() return redirect('/spaces/' + space_url + '/debate/' + str(debate_form_uncommited.id)) return render_to_response('debate/debate_add.html', { 'form': debate_form, 'rowform': row_formset, 'colform': column_formset, 'get_place': place, 'debateid': current_debate_id }, context_instance=RequestContext(request)) return render_to_response('not_allowed.html', context_instance=RequestContext(request))
def add_new_debate(request, space_url): """ Create a new debate. This function returns two forms to create a complete debate, debate form and phases formset. .. versionadded:: 0.1.5 :attributes: debate_form, row_formset, column_formset :context: form, rowform, colform, get_place, debateid """ place = get_object_or_404(Space, url=space_url) if has_space_permission(request.user, place, allow=['admins']) \ or has_all_permissions(request.user): # Define FormSets # This class is used to make empty formset forms required # See http://stackoverflow.com/questions/2406537/django-formsets-make # -first-required/4951032#4951032 class RequiredFormSet(BaseFormSet): """ """ def __init__(self, *args, **kwargs): super(RequiredFormSet, self).__init__(*args, **kwargs) for form in self.forms: form.empty_permitted = False RowFormSet = formset_factory(RowForm, max_num=10, formset=RequiredFormSet, can_delete=True) ColumnFormSet = formset_factory(ColumnForm, max_num=10, formset=RequiredFormSet, can_delete=True) debate_form = DebateForm(request.POST or None) row_formset = RowFormSet(request.POST or None, prefix="rowform") column_formset = ColumnFormSet(request.POST or None, prefix="colform") # Get the last PK and add 1 to get the current PK try: last_debate_id = Debate.objects.latest('id') current_debate_id = last_debate_id.pk + 1 except ObjectDoesNotExist: current_debate_id = 1 if request.user.has_perm('debate.debate_add') or has_all_permissions(): if request.method == 'POST': if debate_form.is_valid() and row_formset.is_valid() \ and column_formset.is_valid(): debate_form_uncommited = debate_form.save(commit=False) debate_form_uncommited.space = place debate_form_uncommited.author = request.user saved_debate = debate_form_uncommited.save() debate_instance = get_object_or_404(Debate, pk=current_debate_id) for form in row_formset.forms: row = form.save(commit=False) row.debate = debate_instance row.save() for form in column_formset.forms: column = form.save(commit=False) column.debate = debate_instance column.save() return HttpResponseRedirect(reverse(urln.DEBATE_VIEW, kwargs={'space_url': space_url, 'debate_id': str(debate_form_uncommited.id)})) return render_to_response('debate/debate_add.html', {'form': debate_form, 'rowform': row_formset, 'colform': column_formset, 'get_place': place, 'debateid': current_debate_id}, context_instance=RequestContext(request)) return render_to_response('not_allowed.html', context_instance=RequestContext(request))
def add_new_debate(request, space_url): """ Create a new debate. This function returns two forms to create a complete debate, debate form and phases formset. .. versionadded:: 0.1.5 :attributes: debate_form, row_formset, column_formset :context: form, rowform, colform, get_place, debateid """ place = get_object_or_404(Space, url=space_url) if request.user in place.admins.all() or request.user.is_staff or request.user.is_superuser: # Define FormSets # This class is used to make empty formset forms required # See http://stackoverflow.com/questions/2406537/django-formsets-make-first-required/4951032#4951032 class RequiredFormSet(BaseFormSet): """ """ def __init__(self, *args, **kwargs): super(RequiredFormSet, self).__init__(*args, **kwargs) for form in self.forms: form.empty_permitted = False RowFormSet = formset_factory(RowForm, max_num=10, formset=RequiredFormSet, can_delete=True) ColumnFormSet = formset_factory(ColumnForm, max_num=10, formset=RequiredFormSet, can_delete=True) debate_form = DebateForm(request.POST or None) row_formset = RowFormSet(request.POST or None, prefix="rowform") column_formset = ColumnFormSet(request.POST or None, prefix="colform") # Get the last PK and add 1 to get the current PK try: last_debate_id = Debate.objects.latest("id") current_debate_id = last_debate_id.pk + 1 except ObjectDoesNotExist: current_debate_id = 1 if request.user.has_perm("debate_add") or request.user.is_staff: if request.method == "POST": if debate_form.is_valid() and row_formset.is_valid() and column_formset.is_valid(): debate_form_uncommited = debate_form.save(commit=False) debate_form_uncommited.space = place debate_form_uncommited.author = request.user saved_debate = debate_form_uncommited.save() debate_instance = get_object_or_404(Debate, pk=current_debate_id) for form in row_formset.forms: row = form.save(commit=False) row.debate = debate_instance row.save() for form in column_formset.forms: column = form.save(commit=False) column.debate = debate_instance column.save() return redirect("/spaces/" + space_url + "/debate/" + str(debate_form_uncommited.id)) return render_to_response( "debate/debate_add.html", { "form": debate_form, "rowform": row_formset, "colform": column_formset, "get_place": place, "debateid": current_debate_id, }, context_instance=RequestContext(request), ) return render_to_response("not_allowed.html", context_instance=RequestContext(request))