Hi,
I got a problem manipulating Dates...
I create a model sith a DateCol column:
class Jour(SQLObject):
classe = UnicodeCol (length = 10)
jour = DateCol(alternateID=True)
texte = UnicodeCol()
In the controller, I use CalendarDatePicker widget to select a date and
try to update the database with the form:
class DayForm(widgets.WidgetsList):
Date = widgets.CalendarDatePicker(
label = _('Jour'),
format = '%d/%m/%Y',
validator = validators.DateTimeConverter(format='%d/%m/%Y',
not_empty=True))
Texte = widgets.TextArea(
label = _('Texte'),
rows = 10,
cols = 60,
validator = validators.NotEmpty()
)
dayformulaire= widgets.TableForm(
'Un jour',
fields = DayForm(),
action = 'save',
submit_text = "Valider"
)
class Root(controllers.RootController):
@expose(template="cahier_texte.templates.jour")
def index(self):
jourlist = []
for day in Jour.select(orderBy=Jour.q.jour):
jourlist.append([day.jour,day.texte])
return dict(jourlist=jourlist)
@expose(template="cahier_texte.templates.edit")
def edit(self, tg_errors=None):
if tg_errors:
flash('il y a un probleme dans le formulaire')
return dict(form=dayformulaire)
@expose()
@error_handler(edit)
@validate(form=dayformulaire)
def save(self, Date, Texte):
from sqlobject import SQLObjectNotFound
try:
day = Jour.byJour(Date)
day.texte = Texte
except SQLObjectNotFound:
Jour(classe="", jour=Date, texte=Texte)
flash('Entree mise a jour!')
redirect('/')
Even if the date exist, Jour.byJour(Date) does not find it, I get the
except case. And the error:
File "/usr/lib/python2.4/site-packages/sqlobject/sqlite/sqliteconnection.py",
line 187, in _executeRetry
raise DuplicateEntryError(msg)
DuplicateEntryError: column jour is not unique
If I use DateConverter, it tells me the month is not between 1 and 12
which means it interprets the entry as %m/%d and not %d/%m as expected.
I do not really see the problem? validators? Date format for sqlobject?
Thanks for help
Mike
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---