IRC log of #schooltool for Thursday, 2011-02-03

aelknerreplaceafill, ayt?03:55
replaceafillaelkner, yes03:55
aelkneri'm having difficluty using IColator to sort03:56
aelknerthe list i'm sorting has three columns03:56
aelkner1) an index03:56
aelkner2) a translated string03:56
aelkner3) a tuple03:56
aelknerwhen i call sorted() passing cmp=collator.cmp03:57
aelknerit gives me an exception:03:57
aelknerTypeError: exceptions must be strings, classes, or instances, not exceptions.TypeError03:57
aelkneri created the collator with:03:57
aelknercollator = ICollator(self.request.locale)03:57
replaceafilli suppose you haven't pushed your code yet03:57
replaceafillcan you paste the sorting part somewhere?03:58
replaceafillso i can take a look?03:58
aelkneri can push it, i don't mind03:58
replaceafillah ok03:58
replaceafillcool, push it, i'll pull03:58
aelknerbtw, the changin of index to a string is probably not necessayr04:00
aelknerbut that shoudln't matter04:00
replaceafillhhmm i'll better check the code in launchpad, branching will take too much 50 MB :(04:01
replaceafillok, looking at report.browser.report04:02
replaceafillaelkner, when you do: sorted(rows, cmp=collator.cmp)04:05
replaceafillyour sending every two elements of rows, correct?04:05
replaceafillcollator.cmp expects two strings04: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 are04:05
replaceafill        equal, and positive if text1 > text2.04:05
replaceafill        """04:05
aelknerso how could i use collator to sort this list of tuples?04:06
replaceafillyou need to send only the texts you want to compare04:06
aelkneri can't04:06
replaceafillevery element in rows is a dictionary, correct?04:06
aelknerbut i can't sort them as they are04:07
replaceafilli think you should use sorted(..., key) instead04:07
aelknerthe index of the catogory key is the highest part of the sort04:07
aelkneryou can see by looking at the pre-seroted rows that they are three-tuples04:07
aelkneri need to sort the rows by the index of the catogory key first04:08
aelknerad the title second04:08
replaceafilllists actually  ['%02d' % index, ref.title, row]04:08
aelkneryeah, but it could ust as easily be index, ...04:08
aelknerwhat difference does it make?04:08
replaceafillhold on, let me code what i think i'd write04:09
replaceafillreturn [row for index, title, row in sorted(rows,04:11
replaceafill                                            key=lamda x:(x[0],collator.key(x[1])))]04:11
replaceafilloops, lambda04:11
replaceafilllambda takes the list of three items (index, title, row)04:11
replaceafilland creates a tuple with (index, and the "collated" key for the string)04:12
replaceafillICollator also provides:04:12
replaceafill    def key(text):04:12
replaceafill        """Return a collation key for the given text.04:12
replaceafill        """04:12
aelknerlet me try that04:13
replaceafillbtw, why do you convert key to a string_04:14
replaceafillsorry, index04:14
replaceafillto a string?04:14
aelkneri was trying to fix the problem04:15
aelknerwhy not add the collator key to the orginal row?04:15
replaceafilli guess you could do that04:15
aelknerindex, collator.key(ref.title), row04:15
replaceafilla key is generated for each title anyway04:15
replaceafillyou dont need the lambda anymore04:16
aelknerit worked!04:16
aelknerit's reall simple now04:17
aelkneri'll push it so you can see04:17
replaceafillah ok04:17
aelknersimple, eh?04:18
replaceafill[index, collator.key(ref.title), row]04:18
replaceafillnice :)04:18
aelknersimple is always pretty :)04:18
replaceafillaelkner, is IReportReference.title set by the user?04:26
replaceafillor is it a _(...) string?04:26
aelknerit's a translatable string set in the adapter04:26
aelknerif we allow the user to crete reports in the future04:26
aelknerthen it would be a user-created title04:27
replaceafilli wonder if that collator.key(ref.title) should be collator.key(translate(ref.title, context=self.request))?04:27
replaceafilli mean, get the key for the translated version04:27
aelknerdo you think i need to do the translation before collating?04:28
replaceafillyou haven't test it yet with localized strings, correct?04:28
aelkneri wouldn't know how either04:28
replaceafillit's just that all the examples that i'm looking at use text entered by the user04:28
replaceafillstudent names04:29
replaceafillgroup names04:29
aelknerwell, the collator key() method shoudl translate the string perhaps?04:29
replaceafillunfortunately, i cannot see zope.ucol code :(04:30
replaceafillwhere the collator comes from04:30
replaceafilli guess it's compiled C04:30
replaceafillbut i dont think so04:30
replaceafilljust put it in your notes :)04:30
replaceafilli can help you testing when youre done04:30
aelknerso, should i make the translate() call just to be safe?04:30
replaceafilli think you should04:31
aelknerok, will do04:31
replaceafillyvl, could you comment on this one when you get back? :D04: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
replaceafillif you give it a i18n _(...) string, it will probably try to convert it to unicode04:37
replaceafilland you will get the 'original' version, not the translated one04:37
*** alga has quit IRC04:41
*** aks has joined #schooltool05:22
*** aks has joined #schooltool05:22
replaceafillaelkner, what demographic data does the StudentDetailReport contain?06:29
replaceafill(in the gradebook)06:29
*** th1a has quit IRC07:38
*** replaceafill has quit IRC10:25
*** aks has quit IRC11:08
*** aks has joined #schooltool11:19
*** menesis has joined #schooltool12:28
*** alga has joined #schooltool13:13
*** aks has quit IRC13:27
*** Aiste has joined #schooltool13:51
*** menesis has quit IRC14:42
*** replaceafill has joined #schooltool15:35
replaceafillyvl, wow! thanks for the great explanation!15:50
replaceafillthat sorting link will help me when sorting Khmer :)15:50
*** th1a has joined #schooltool15:58
*** menesis has joined #schooltool16:00
*** Aiste has quit IRC18:04
*** menesis has quit IRC19:24
*** replaceafill has quit IRC19:40
*** replaceafill has joined #schooltool19:41
*** menesis has joined #schooltool20:57
aelknerreplaceafill, hey21:13
replaceafillhey aelkner21:14
aelkneryou asked about demo data?21:14
aelknerbecause there is none in the report21:14
replaceafillah right21:14
replaceafillit just got my attention :)21:14
aelkneroh, ok21:14

Generated by 2.15.1 by Marius Gedminas - find it at!