aelkner | replaceafill, ayt? | 03:55 |
---|---|---|
replaceafill | aelkner, yes | 03:55 |
aelkner | i'm having difficluty using IColator to sort | 03:56 |
aelkner | the list i'm sorting has three columns | 03:56 |
replaceafill | paste? | 03:56 |
aelkner | 1) an index | 03:56 |
aelkner | 2) a translated string | 03:56 |
aelkner | 3) a tuple | 03:56 |
aelkner | when i call sorted() passing cmp=collator.cmp | 03:57 |
aelkner | it gives me an exception: | 03:57 |
aelkner | TypeError: exceptions must be strings, classes, or instances, not exceptions.TypeError | 03:57 |
aelkner | i created the collator with: | 03:57 |
aelkner | collator = ICollator(self.request.locale) | 03:57 |
replaceafill | i suppose you haven't pushed your code yet | 03:57 |
replaceafill | can you paste the sorting part somewhere? | 03:58 |
replaceafill | so i can take a look? | 03:58 |
aelkner | i can push it, i don't mind | 03:58 |
replaceafill | ah ok | 03:58 |
replaceafill | cool, push it, i'll pull | 03:58 |
aelkner | pushed | 03:59 |
replaceafill | checking... | 03:59 |
aelkner | btw, the changin of index to a string is probably not necessayr | 04:00 |
aelkner | but that shoudln't matter | 04:00 |
replaceafill | hhmm i'll better check the code in launchpad, branching will take too much 50 MB :( | 04:01 |
replaceafill | ok, looking at report.browser.report | 04:02 |
replaceafill | aelkner, when you do: sorted(rows, cmp=collator.cmp) | 04:05 |
replaceafill | your sending every two elements of rows, correct? | 04:05 |
replaceafill | collator.cmp expects two strings | 04:05 |
replaceafill | def cmp(text1, text2): | 04:05 |
replaceafill | """Compare two text strings. | 04:05 |
replaceafill | The return value is negative if text1 < text2, 0 is they are | 04:05 |
replaceafill | equal, and positive if text1 > text2. | 04:05 |
replaceafill | """ | 04:05 |
replaceafill | 04:05 | |
aelkner | so how could i use collator to sort this list of tuples? | 04:06 |
replaceafill | you need to send only the texts you want to compare | 04:06 |
aelkner | i can't | 04:06 |
replaceafill | every element in rows is a dictionary, correct? | 04:06 |
aelkner | yes | 04:06 |
aelkner | but i can't sort them as they are | 04:07 |
replaceafill | i think you should use sorted(..., key) instead | 04:07 |
aelkner | the index of the catogory key is the highest part of the sort | 04:07 |
aelkner | listen | 04:07 |
aelkner | you can see by looking at the pre-seroted rows that they are three-tuples | 04:07 |
aelkner | i need to sort the rows by the index of the catogory key first | 04:08 |
aelkner | ad the title second | 04:08 |
replaceafill | lists actually ['%02d' % index, ref.title, row] | 04:08 |
aelkner | yeah, but it could ust as easily be index, ... | 04:08 |
aelkner | what difference does it make? | 04:08 |
replaceafill | hold on, let me code what i think i'd write | 04:09 |
replaceafill | return [row for index, title, row in sorted(rows, | 04:11 |
replaceafill | key=lamda x:(x[0],collator.key(x[1])))] | 04:11 |
replaceafill | oops, lambda | 04:11 |
replaceafill | lambda takes the list of three items (index, title, row) | 04:11 |
replaceafill | and creates a tuple with (index, and the "collated" key for the string) | 04:12 |
replaceafill | ICollator also provides: | 04:12 |
replaceafill | def key(text): | 04:12 |
replaceafill | """Return a collation key for the given text. | 04:12 |
replaceafill | """ | 04:12 |
aelkner | let me try that | 04:13 |
replaceafill | btw, why do you convert key to a string_ | 04:14 |
replaceafill | sorry, index | 04:14 |
replaceafill | to a string? | 04:14 |
aelkner | i was trying to fix the problem | 04:15 |
replaceafill | ah | 04:15 |
aelkner | why not add the collator key to the orginal row? | 04:15 |
replaceafill | i guess you could do that | 04:15 |
aelkner | index, collator.key(ref.title), row | 04:15 |
aelkner | right? | 04:15 |
replaceafill | a key is generated for each title anyway | 04:15 |
replaceafill | right | 04:16 |
replaceafill | you dont need the lambda anymore | 04:16 |
aelkner | right | 04:16 |
aelkner | it worked! | 04:16 |
replaceafill | eeehhhh!!!! | 04:17 |
aelkner | it's reall simple now | 04:17 |
replaceafill | :) | 04:17 |
aelkner | thanks | 04:17 |
aelkner | i'll push it so you can see | 04:17 |
replaceafill | ah ok | 04:17 |
aelkner | pushed | 04:17 |
aelkner | simple, eh? | 04:18 |
replaceafill | [index, collator.key(ref.title), row] | 04:18 |
replaceafill | nice :) | 04:18 |
aelkner | simple is always pretty :) | 04:18 |
replaceafill | :D | 04:19 |
replaceafill | aelkner, is IReportReference.title set by the user? | 04:26 |
replaceafill | or is it a _(...) string? | 04:26 |
aelkner | it's a translatable string set in the adapter | 04:26 |
aelkner | if we allow the user to crete reports in the future | 04:26 |
aelkner | then it would be a user-created title | 04:27 |
replaceafill | i wonder if that collator.key(ref.title) should be collator.key(translate(ref.title, context=self.request))? | 04:27 |
replaceafill | ah | 04:27 |
replaceafill | i mean, get the key for the translated version | 04:27 |
aelkner | do you think i need to do the translation before collating? | 04:28 |
replaceafill | you haven't test it yet with localized strings, correct? | 04:28 |
aelkner | right | 04:28 |
aelkner | i wouldn't know how either | 04:28 |
replaceafill | it's just that all the examples that i'm looking at use text entered by the user | 04:28 |
replaceafill | student names | 04:29 |
replaceafill | group names | 04:29 |
replaceafill | etc | 04:29 |
aelkner | well, the collator key() method shoudl translate the string perhaps? | 04:29 |
replaceafill | unfortunately, i cannot see zope.ucol code :( | 04:30 |
replaceafill | where the collator comes from | 04:30 |
replaceafill | i guess it's compiled C | 04:30 |
replaceafill | but i dont think so | 04:30 |
replaceafill | just put it in your notes :) | 04:30 |
replaceafill | i can help you testing when youre done | 04:30 |
aelkner | so, should i make the translate() call just to be safe? | 04:30 |
replaceafill | i think you should | 04:31 |
aelkner | ok, will do | 04:31 |
replaceafill | yvl, could you comment on this one when you get back? :D | 04:31 |
* replaceafill wishes he understands "static PyObject *__pyx_f_10_zope_ucol_8Collator_key(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds)" :| | 04:35 | |
replaceafill | "Compute a collation key for a unicode string." | 04:37 |
replaceafill | if you give it a i18n _(...) string, it will probably try to convert it to unicode | 04:37 |
replaceafill | and you will get the 'original' version, not the translated one | 04:37 |
*** alga has quit IRC | 04:41 | |
*** aks has joined #schooltool | 05:22 | |
*** aks has joined #schooltool | 05:22 | |
replaceafill | aelkner, what demographic data does the StudentDetailReport contain? | 06:29 |
replaceafill | (in the gradebook) | 06:29 |
*** th1a has quit IRC | 07:38 | |
*** replaceafill has quit IRC | 10:25 | |
*** aks has quit IRC | 11:08 | |
*** aks has joined #schooltool | 11:19 | |
*** menesis has joined #schooltool | 12:28 | |
*** alga has joined #schooltool | 13:13 | |
*** aks has quit IRC | 13:27 | |
*** Aiste has joined #schooltool | 13:51 | |
*** menesis has quit IRC | 14:42 | |
*** replaceafill has joined #schooltool | 15:35 | |
replaceafill | yvl, wow! thanks for the great explanation! | 15:50 |
replaceafill | that sorting link will help me when sorting Khmer :) | 15:50 |
*** th1a has joined #schooltool | 15:58 | |
*** menesis has joined #schooltool | 16:00 | |
*** Aiste has quit IRC | 18:04 | |
*** menesis has quit IRC | 19:24 | |
*** replaceafill has quit IRC | 19:40 | |
*** replaceafill has joined #schooltool | 19:41 | |
*** menesis has joined #schooltool | 20:57 | |
aelkner | replaceafill, hey | 21:13 |
replaceafill | hey aelkner | 21:14 |
aelkner | you asked about demo data? | 21:14 |
aelkner | because there is none in the report | 21:14 |
replaceafill | ah right | 21:14 |
replaceafill | it just got my attention :) | 21:14 |
aelkner | oh, ok | 21:14 |
Generated by irclog2html.py 2.15.1 by Marius Gedminas - find it at mg.pov.lt!