-
Notifications
You must be signed in to change notification settings - Fork 9
add 'ordered_by' method to QuerySet class. #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
xtuml/meta.py
Outdated
if not hasattr(y, attr): | ||
raise MetaException("Class '%s' has no attribute '%s'" % (get_metaclass(y).kind, attr)) | ||
|
||
return cmp( tuple(getattr(x, attr) for attr in self), tuple(getattr(y, attr) for attr in self) ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
superfluous spaces within parenthesis group
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
def test_select_many_ordered_by(self): | ||
m = self.metamodel | ||
q = m.select_many('S_DT', None, order_by('Name', 'DT_ID')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking, it should be possible to to make the where_clause and order_by argument less independent on the order in the parameter list. Something like this:
def select_many(kind, set_modifiers*):
s = map(apply_set_operator, set_modifiers)
return s
then you could type:
q = m.select_many('S_DT', order_by('Name', 'DT_ID'), where(...))
or
q = m.select_many('S_DT', where(...), order_by('Name', 'DT_ID'))
or
q = m.select_many('S_DT', order_by('Name', 'DT_ID'))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm. I will give this some thought. Of course the difficulty is how to implement the 'apply_set_operator' part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
map() might have been a bad idea. I slapped together a gist demonstrating one way of doing it. needs some cleaning though...
See https://gist.github.com/john-tornblom/21eca04788c3980778039bf91866e7dd
xtuml/meta.py
Outdated
>>> from xtuml import order_by | ||
>>> m = xtuml.load_metamodel('db.sql') | ||
>>> inst = m.select_many('My_Modeled_Class', None, order_by( 'Name', 'Number' ) ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, superfluous spaces within parenthesis group.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Python3 seems to fail on travis, see https://api.travis-ci.org/v3/job/391935957/log.txt I was thinking of altering your patch a bit anyway to something like this: https://gist.github.com/john-tornblom/21eca04788c3980778039bf91866e7dd). I can accept the patch and rework it myself, or do you wanna give it a go? |
You can either accept mine and alter as you wish or you could submit a PR to my fork and I will service it (and then this PR would get automatically updated). |
…rators. This also fixes python3 issues due to deprecation of the cmp key to sorted()
My repo was created before xtuml/pyxtuml, and cort did not fork via github so not sure how to send a PR directly. But I've pushed to https://github.com/john-tornblom/pyxtuml/tree/ordered_by |
this method returns a sorted set based upon the specified attribute name.
if the class has no attribute by that name, an exception is raised.