--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Or what inconvenience do you see with web2py for this project?
Maybe I misunderstood your question... do you want to cut an other module out of web2py to end up with a new lighter modular framework alternative ?
otherwise all well known alternative python web frameworks are there to try pydal with.
Guess in Django you could build custom model on top of pydal, ORM tight integration, documentation, external app and default contrib modules will not help somebody who don't know very well the framework already.
I've no experience with flask, but it would look like an easier candidate as it is more independent from a db backend.
Thanks
Bernard
Hi Ramos,
What's your project ?
Because if you do some console, desktop or Python notebook doc.
standalone pydal is there.
But if you're looking at developing a web app or rest api
Web2py Is quite good at it and quite well integrated with pydal ;)
Or what inconvenience do you see with web2py for this project?
Thanks
Bernard
my inconvenients:1 - Bootstrap, i need layout.html but dont want bootstrap. How do i get rid of bootstrap or change it to semantic ?Bootstrap should not be a constraint but just an add-on.
Well, the only thing that I really want right now, is a layer for object oriented use, something like the weppy pyDAL layer should be enough, it will be a impressive improvement to pydal (will convince to many users to use pydal and web2py)
Well, the only thing that I really want right now, is a layer for object oriented use, something like the weppy pyDAL layer should be enough, it will be a impressive improvement to pydal (will convince to many users to use pydal and web2py)
What are some examples of things you would envision doing with a "layer for object oriented use" that are more difficult with the pyDAL as is?
We could use object oriented modeling,
we could save our objects directly to the database
, we could declare non persistent variables in objects
, we could have a better code structure in our apps, we could maintain large models easily
, we could reuse or extend model classes easily
, we don't will need to worry about the class models files order
, we could even load only the models that we need in controllers without write modules...
Object oriented programming is not just use an object oriented programming language, and sadly, with web2py is difficult follow the object oriented paradigm when we develop applications
Well, the only thing that I really want right now, is a layer for object oriented use, something like the weppy pyDAL layer should be enough, it will be a impressive improvement to pydal (will convince to many users to use pydal and web2py)
What are some examples of things you would envision doing with a "layer for object oriented use" that are more difficult with the pyDAL as is?
--
The best scenario I see is defining methods to model classes.For example, centralising queries and business actions like: create_customer(), get_active_employees(), register_student() and so on.
@db.employee.add_method.get_active_employees
@db.contractor.add_method.get_active_contractors
def get_active(self):
return self._db(self.is_active == True).select()
active_employees = db.employee.get_active_employees()db.define_table('review', Field('author'), Field('valuea', 'int'), Field('valueb', 'int'), Field('valuec', 'int'), Field('place','reference place')) db.define_table('place', Field('name'), Field('description'))It's clean, there is no problem, but now we need to get the average on a review values, and the average of all places reviews, the we get something like this:
def get_review_average(row): # all the code... # ... return value db.define_table('review', Field('author'), Field('valuea', 'int'), Field('valueb', 'int'), Field('valuec', 'int'), Field('place','reference place')) Field.Virtual('value', get_review_average)) def get_place_reviews_average(row): # all the code calling review.value # ... return value db.define_table('place', Field('name'), Field('description'), Field.Virtual('value', get_place_reviews_average))ok, now is not so clean, the "functions" are before the "variables" declarations, we could add some validations, and we get functions code, fields declarations, and validation code, in that order, when the model grows, the code becomes more difficult to maintain, hardly if the person is not who wrote the code.
class Review: author = Field() value = Field('int') valuea = Field('int') valueb = Field('int') place = Field('reference place') def get_average(row): # all the code... # ... return value class Place: name = Field() description = Field() def get_place_reviews_average(row): # all the code # ... return value db.define_models(Review, Place)Now the code has a more natural structure, first variables and later functions, we dont care the order, because at the end we declare it using the define_models() function, and we can use inheritance simply like this:
class OtherReview(Review): valuebc = Field('int')Now the code is easier to maintain, and easier to reuse, we only need to copy class files, and extend from them.
object = db.mytable[id] object.name = "the name" object.save()or
db.mytable.save(object)
The non persistent variables is other thing, in some cases we need
to use non persistent variables, like flags, with the virtual or
method fields, we can define non persistent values, but we can't
edit them.ok, now is not so clean, the "functions" are before the "variables" declarations,
class Review:
author = Field()
value = Field('int')
valuea = Field('int')
valueb = Field('int')
place = Field('reference place')
@virtualfield('value')
def get_average(row):
# all the code...
# ...
return valuedb.define_table('review',
Field('author'),
Field('valuea', 'int'),
Field('valueb', 'int'),
Field('valuec', 'int'),
Field('place','reference place'))
def get_review_average(row):
# all the code...
# ...
return value
db.review.value = Field.Virtual('value', get_review_average)we could add some validations, and we get functions code, fields declarations, and validation code, in that order
About the objects, if we could have real orm functionality, we could do things like:
object = db.mytable[id]
object.name = "the name"
object.save()
row = db.mytable[id]
row.name = 'the name'
row.update_record()
The non persistent variables is other thing, in some cases we need to use non persistent variables, like flags, with the virtual or method fields, we can define non persistent values, but we can't edit them.
row = db.mytable(id)
row.my_non_persistent_variable = 'some value' row.my_virtual_field = 'new value'
db.define_table('review',
Field('author'),
Field('valuea', 'int'),
Field('valueb', 'int'),
Field('valuec', 'int'),
Field('place','reference
place'))
def
get_review_average(row):
# all the code...
# ...
return value
db.review.value = Field.Virtual('value',
get_review_average),
value
db.review.value = Field.Virtual('value', get_review_average),
Same number of lines in the same order. I agree, though, that the first approach looks a little nicer (mainly because the virtual field method is namespaced inside the class), but it's not a dramatic difference (and it would be easy to write a simple decorator to add the virtual field to the table in order to eliminate that last line). Also, the second approach makes it easier to share the virtual field function across multiple tables if needed (without having to worry about multiple inheritance, etc.).
we could add some validations, and we get functions code, fields declarations, and validation code, in that order
As noted above, you can put these in any order you want in web2py. I also find it easier to keep all the attributes (e.g., validators, represent function, etc.) of a given field together, but I suppose that could vary depending on the situation.
I agree that table inheritance is more flexible with the class based method. You can do some basic inheritance with web2py, but it becomes trickier if you need to override specific fields or copy attributes other than fields. I suppose this could be improved in web2py even without using classes -- perhaps it has not been done because there hasn't been much demand.
About the objects, if we could have real orm functionality, we could do things like:
object = db.mytable[id] object.name = "the name" object.save()
I don't think we need an ORM for that:
row = db.mytable[id]
row.name = 'the name'
row.update_record()
The non persistent variables is other thing, in some cases we need to use non persistent variables, like flags, with the virtual or method fields, we can define non persistent values, but we can't edit them.
First, you can simply do:
row = db.mytable(id)
row.my_non_persistent_variable = 'some value'
Second, you can update virtual field values:
row.my_virtual_field = 'new value'
Anthony
Antony, thanks for your answer, there were some things I did not know you could do, but there is just a problem with:
db.define_table('review',
Field('author'),
Field('valuea', 'int'),
Field('valueb', 'int'),
Field('valuec', 'int'),
Field('place','reference place'))
def get_review_average(row):
# all the code...
# ...
return value
db.review.value = Field.Virtual('value', get_review_average),
As you can see in https://github.com/web2py/pydal/issues/304 there is a problem setting method and field attributes directly.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.