Finally, I figured out what causes the 'ModelController' error in the TG2.1 Admin System Page. Thanks to Eclipse (Aptana Studio 3) and PyDev, I was able to debug and spot the cause of the trouble.
I was kind of surprised that Sprox, the module that is responsible for form-model binding, could not handle unique constraint in one to many relationship.
Due to this, all other kind of constraints on relationship will probably fail too. Perhaps UniqueConstraint also get effected.
So, mainly all other constraints that are not applied directly to the fields of the sqlalchemy models could not be handled properly by TG2.1 (sprox).
Since, unique constraint is very common in DB design, I really hope that this functionality could be handled not just in simple field but also in relationship and multi-columns unique contraint.
As for the 'elegant' solution, I have not yet find a way to do it. Perhaps, I could add validator in the relationship field/attribute (in sqlalchemy declarative model class), but no clue on how to implement it. Another thing is that even if I could do that, I am not sure it would work, since I am not even sure if relationship field would be registered to be checked by the framework.
It would be a good thing if in sprox the relationship field and the foreignkey field both are being checked as one.
As for now, I just need to do a work around to prevent adding duplicate one to many relationship.
Pretty impressed with TG2.1. This is by far the most flexible web framework that I have worked with. My suggestion to those who would use this framework is, be prepared to swim and dive in the source codes, as you definitely need to extend functionalities by overriding methods and sub-classing.
Showing posts with label sprox. Show all posts
Showing posts with label sprox. Show all posts
Thursday, May 5, 2011
Friday, April 8, 2011
TurboGears 2 Editable Primary Key Field
TG2.1, nice web app framework. I just with it has better documentations. Compare to django, TG2.1 documentations are way behind. But, still it is much more flexible.
I encountered problem that TG2 Admin Page, created with TG Administration System, automatically set the (html) input field of the model's PK to disabled. Sprox assumes that your model's PK is auto-generated.
Some one already reported the issue here
and then created the proper tickets to sprox here
Got a good clue where to check, so after taking a look inside sprox.formbase source code, below is the reason why PK fields are non-editable.
class EditableForm(FormBase):
"..."
def _do_get_disabled_fields(self): fields = self.disable_fields[:]
fields.append(self.provider.get_primary_field(self.entity))
# automatically set PK field disabled return fields
same goes with: class AddRecordForm(FormBase)
I wrote it in here.
Hopefully useful for those who need it.
I encountered problem that TG2 Admin Page, created with TG Administration System, automatically set the (html) input field of the model's PK to disabled. Sprox assumes that your model's PK is auto-generated.
Some one already reported the issue here
and then created the proper tickets to sprox here
Got a good clue where to check, so after taking a look inside sprox.formbase source code, below is the reason why PK fields are non-editable.
class EditableForm(FormBase):
"..."
def _do_get_disabled_fields(self): fields = self.disable_fields[:]
fields.append(self.provider.get_primary_field(self.entity))
# automatically set PK field disabled return fields
same goes with: class AddRecordForm(FormBase)
I wrote it in here.
Hopefully useful for those who need it.
Subscribe to:
Posts (Atom)