[sqlalchemy] Re: Using ORM Object as an intermadiate holder

2007-12-17 Thread Utku Altinkaya



On 16 Aralık, 22:22, Michael Bayer [EMAIL PROTECTED] wrote:
 On Dec 15, 11:02 pm, Utku Altinkaya [EMAIL PROTECTED] wrote:



  I do not want to lose invalid values, becouse I want to send them to
  the user again, so while using object as intermediate holder I have to
  set attributes invalid values... So Autoflush = False, and if
  invalid values are existed the object is reloaded from DB before
  commit step of web request cycle.

  But while using SQLAlchemy I had the impression that it is not
  designed to to that, It designers thought objects are direct
  representation of the data in the database.  I can do this ofcouse
  some kind of holder class copies attributes from data objects etc, but
  it is cumbersome, and will force me to write longer code.

  I am expecting someone to tell me the way I am doing is perfectly
  valid, or another advice

 the usual way people handle form validation is using a package like
 FormEncode:  http://formencode.org/Validator.html

OK, I have started implementing widgets to do this, I would do things
like that some place anyway, I will not use data objects for self
validation etc anymore.


 i.e. you wouldn't have the invalid data on your ORM object at any
 point. theres nothing wrong with how you're doing it, it just has
 disadvantages.  namely, that your ORM objects have to look just like
 your web forms (such as, a web form with three dropdowns, month, day
 and year...

Actullay, I was using mako templates, and setting a context variable
to the model(single thread for a single template instance ofcourse),
and using some of my helper components to write the html, so
converting data to the representable form to the user via html form
had been done there. It was short and simple, I liked it.

 but your ORM object only has date on it), and you also
 have to ensure the ORM objects dont get flushed with the invalid data
 (easily breakable).

And looks bad, expriding the object I mean, thanks for the advice.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Using ORM Object as an intermadiate holder

2007-12-16 Thread sdobrev

the expire() is requesting a reload.
try moving that after the sending back stuff to user.

Utku Altinkaya wrote:
 Hi,
 
 I am using SQLAlchemy on a web application, I have used a base class
 for ORM clases which provides soem web related things like validation
 and loading data from forms etc. When the form is submitted:
 Here is the current life cycle:
 
 object.loadFromForm()
 if object.Validate():
   session.save_or_update(object)
 else
   render_form(object)
   session.expire(object)
 session.commit()
 
 I do not want to lose invalid values, becouse I want to send them to
 the user again, so while using object as intermediate holder I have to
 set attributes invalid values... So Autoflush = False, and if
 invalid values are existed the object is reloaded from DB before
 commit step of web request cycle.
 
 But while using SQLAlchemy I had the impression that it is not
 designed to to that, It designers thought objects are direct
 representation of the data in the database.  I can do this ofcouse
 some kind of holder class copies attributes from data objects etc, but
 it is cumbersome, and will force me to write longer code.
 
 I am expecting someone to tell me the way I am doing is perfectly
 valid, or another advice
 
 regards
 
  


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Using ORM Object as an intermadiate holder

2007-12-16 Thread Utku Altinkaya



On 16 Aralık, 17:46, [EMAIL PROTECTED] wrote:
 the expire() is requesting a reload.
 try moving that after the sending back stuff to user.

The documents says it does not reload until it is accessed if the
object is expired, I think what does the thing you have mantioned is
the refresh method of session.
http://www.sqlalchemy.org/docs/04/session.html#unitofwork_using_refreshing




 Utku Altinkaya wrote:
  Hi,

  I am using SQLAlchemy on a web application, I have used a base class
  for ORM clases which provides soem web related things like validation
  and loading data from forms etc. When the form is submitted:
  Here is the current life cycle:

  object.loadFromForm()
  if object.Validate():
session.save_or_update(object)
  else
render_form(object)
session.expire(object)
  session.commit()

  I do not want to lose invalid values, becouse I want to send them to
  the user again, so while using object as intermediate holder I have to
  set attributes invalid values... So Autoflush = False, and if
  invalid values are existed the object is reloaded from DB before
  commit step of web request cycle.

  But while using SQLAlchemy I had the impression that it is not
  designed to to that, It designers thought objects are direct
  representation of the data in the database.  I can do this ofcouse
  some kind of holder class copies attributes from data objects etc, but
  it is cumbersome, and will force me to write longer code.

  I am expecting someone to tell me the way I am doing is perfectly
  valid, or another advice

  regards- Alıntıyı gizle -

 - Alıntıyı göster -

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Using ORM Object as an intermadiate holder

2007-12-16 Thread sdobrev

expiring the obj has the effect that any further access to the object will 
auto-refresh it. so if u expire(x) and then say x.a. x will be reloaded 
first then u get x.a

Utku Altinkaya wrote:
 
 
 On 16 Aralık, 17:46, [EMAIL PROTECTED] wrote:
 the expire() is requesting a reload.
 try moving that after the sending back stuff to user.
 
 The documents says it does not reload until it is accessed if the
 object is expired, I think what does the thing you have mantioned is
 the refresh method of session.
 http://www.sqlalchemy.org/docs/04/session.html#unitofwork_using_refreshing
 


 Utku Altinkaya wrote:
 Hi,
 I am using SQLAlchemy on a web application, I have used a base class
 for ORM clases which provides soem web related things like validation
 and loading data from forms etc. When the form is submitted:
 Here is the current life cycle:
 object.loadFromForm()
 if object.Validate():
   session.save_or_update(object)
 else
   render_form(object)
   session.expire(object)
 session.commit()
 I do not want to lose invalid values, becouse I want to send them to
 the user again, so while using object as intermediate holder I have to
 set attributes invalid values... So Autoflush = False, and if
 invalid values are existed the object is reloaded from DB before
 commit step of web request cycle.
 But while using SQLAlchemy I had the impression that it is not
 designed to to that, It designers thought objects are direct
 representation of the data in the database.  I can do this ofcouse
 some kind of holder class copies attributes from data objects etc, but
 it is cumbersome, and will force me to write longer code.
 I am expecting someone to tell me the way I am doing is perfectly
 valid, or another advice
 regards- Alıntıyı gizle -
 - Alıntıyı göster -
 
  



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Using ORM Object as an intermadiate holder

2007-12-16 Thread Michael Bayer



On Dec 15, 11:02 pm, Utku Altinkaya [EMAIL PROTECTED] wrote:

 I do not want to lose invalid values, becouse I want to send them to
 the user again, so while using object as intermediate holder I have to
 set attributes invalid values... So Autoflush = False, and if
 invalid values are existed the object is reloaded from DB before
 commit step of web request cycle.

 But while using SQLAlchemy I had the impression that it is not
 designed to to that, It designers thought objects are direct
 representation of the data in the database.  I can do this ofcouse
 some kind of holder class copies attributes from data objects etc, but
 it is cumbersome, and will force me to write longer code.

 I am expecting someone to tell me the way I am doing is perfectly
 valid, or another advice

the usual way people handle form validation is using a package like
FormEncode:  http://formencode.org/Validator.html

i.e. you wouldn't have the invalid data on your ORM object at any
point. theres nothing wrong with how you're doing it, it just has
disadvantages.  namely, that your ORM objects have to look just like
your web forms (such as, a web form with three dropdowns, month, day
and year...but your ORM object only has date on it), and you also
have to ensure the ORM objects dont get flushed with the invalid data
(easily breakable).
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---