Created
March 3, 2010 22:16
-
-
Save vbmendes/321110 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import forms | |
class Form1(forms.Form): | |
arquivo = forms.FileField() | |
def ler_conteudo_do_arquivo(self): | |
return self.cleaned_data['arquivo'].read() | |
class Form2(forms.Form): | |
texto = forms.TextField() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="form_action" method="post"> | |
<ul> | |
{{ form.as_ul }} | |
<input type="submit"/> | |
</ul> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="" method="post"> | |
<ul> | |
{{ form.as_ul }} | |
<input type="submit"/> | |
</ul> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from forms import Form1, Form2 | |
def ler_arquivo(request): | |
form_action = '' | |
if request.method == 'POST': | |
form = Form1(request.POST, request.FILES) | |
if form.is_valid(): | |
form = Form2(initial={'texto': form.ler_conteudo_do_arquivo()}) | |
form_action = reverse('salvar_arquivo') | |
else: | |
form = Form1() | |
return direct_to_template(request, "nome_do_template_form1.html", {'form': form, 'form_action': form_action}) | |
def salvar_arquivo(request): | |
if request.method == 'POST': | |
form = Form2(request.POST) | |
if form.is_valid(): | |
(faz o que quiser com o form) | |
else: | |
form = Form2() | |
return direct_to_template(request, "nome_do_template_form2.html", {'form': form}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment