Thank you !! i was overdoing it ! 2 lines of code.
however the validator upon image_file doest seem to work.
print recettes.AddManipulator().fields (thks for the trick) give me :
[FormField "nom", FormField "categorie", FormField "auteur", FormField
"ingredients", FormField "etapes", FormField "conseils", FormField
"dure", FormField "difficulte", FormField "quantite", FormField "prix",
FormField "pub_date", FormField "image_file", FormField "image"]
image_file being in position 11 (if start from 0) or 12 i tried both.
but the validation doest happen, tested with a 250 km image.
Otherwise it posted it well.
here is my view.py
# Create your views here.
from django.core.exceptions import Http404
from django.utils.httpwrappers import HttpResponse,
HttpResponseRedirect
from django.models.recettes import recettes, notes
from django.core.extensions import get_object_or_404,
render_to_response
from django.core import formfields
from manipulators import RecetteManipulator
def detail(request, recettes_id):
r = get_object_or_404(recettes, pk=recettes_id)
n = notes.get_list(recette__pk=recettes_id)
return render_to_response('recettes/detail', {'recette': r,
'id':recettes_id, 'note':n},)
def printable(request, recettes_id):
r = get_object_or_404(recettes, pk=recettes_id)
return render_to_response('recettes/printable', {'recette': r},)
#Validator
def isValideImageWeight(self, field_data, all_data):
print field_data
if len(field_data["content"] > 100000) : # 500,000 bytes (100kB)
raise validators.ValidationError, "Le fichier ne dois pas
depasser
100kb"
#Ajouter
def create_recette(request):
manipulator = recettes.AddManipulator()
#12 being image_fil , recettes.AddManipulator().fields
manipulator.fields[11].validator_list.append(isValideImageWeight)
if request.POST:
# If data was POSTed, we're trying to create a new Place.
new_data = request.POST.copy()
# Check for errors.
errors = manipulator.get_validation_errors(new_data)
if not errors:
# No errors. This means we can save the data!
manipulator.do_html2python(new_data)
new_recette = manipulator.save(new_data)
# Redirect to the object's "edit" page. Always use a
redirect
# after POST data, so that reloads don't accidently
create
# duplicate entires, and so users don't see the
confusing
# "Repost POST data?" alert box in their browsers.
return HttpResponseRedirect("/cefinban/recette/%i/" %
new_recette.id)
else:
# No POST, so we want a brand new form without any data or
errors.
errors = new_data = {}
# Create the FormWrapper, template, context, response.
form = formfields.FormWrapper(manipulator, new_data, errors)
return render_to_response('recettes/recettes_form', {'form': form})
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---