Esempio n. 1
0
    def post(self, request, *args, **kwargs):
        form_inscricao = InscricaoForm(request.POST)

        formset = CachorroFormset(request.POST,
                                  request.FILES,
                                  instance=Inscricao())

        if form_inscricao.is_valid():

            inscricao = form_inscricao.save(commit=False)
            formset = CachorroFormset(request.POST,
                                      request.FILES,
                                      instance=inscricao)

            if formset.is_valid():
                form_inscricao.save(commit=True)
                formset.save()

                request.session['save_form'] = "subs"
                return HttpResponseRedirect('/#six')

        expositores = []
        objs = Expositor.objects.filter(ativo=True).all()
        for expo in objs:
            expositores.append({
                'nome_marca':
                expo.nome_marca,
                'descricao':
                expo.descricao,
                'foto':
                str(expo.foto.build_url(width=600, height=400,
                                        crop='fill')).replace(
                                            'http://', 'https://')
            })

        context = {}

        context['numero_inscricao'] = Cachorro.objects.count()

        context['form_inscricao'] = form_inscricao
        context['form_expositores'] = ExpositorForm()
        context['form_patrocinadores'] = PatrocinadorForm()
        context['cachorro_form'] = formset
        context['expositores'] = expositores

        return self.render_to_response(context)
def inscricao(request):
    inscricao_form = InscricaoForm()
    if request.method == 'POST':
        inscricao_form = InscricaoForm(request.POST, request.FILES)
        if inscricao_form.is_valid():
            inscricao = inscricao_form.save()
            inscricao.save()
            return render_to_response(
                'inscricao_finalizada.html',
            )
    return render_to_response(
        'inscricao.html',
        {'inscricao_form': inscricao_form},
        context_instance=RequestContext(request)
    )