Advertisement
Guest User

Untitled

a guest
Nov 13th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. replaceafill@system76:~/dev/sandboxes/merge/schooltool.cando$ bzr diff
  2. === modified file 'src/schooltool/cando/gradebook.py'
  3. --- src/schooltool/cando/gradebook.py 2013-09-25 18:30:52 +0000
  4. +++ src/schooltool/cando/gradebook.py 2013-11-12 21:38:43 +0000
  5. @@ -18,6 +18,7 @@
  6. """CanDo Gradebook."""
  7.  
  8. from zope.annotation.interfaces import IAnnotations
  9. +from zope.cachedescriptors.property import Lazy
  10. from zope.component import adapts, adapter, queryMultiAdapter
  11. from zope.component import getMultiAdapter
  12. from zope.interface import implements, implementer, implementsOnly
  13. @@ -152,41 +153,30 @@
  14. score = super(SkillsGradebook, self).getScore(student, activity)
  15. if score is not None:
  16. return score
  17. - return self.getPreviousScore(student, activity)
  18. -
  19. - def getPreviousScore(self, student, activity):
  20. - equivalent = activity.findAllEquivalent()
  21. - previous = self.getPreviousSections(self.section)
  22. - for section in previous:
  23. - filtered = self.filterEquivalent(equivalent, section)
  24. - if filtered:
  25. - # XXX: could there be more than one equivalent
  26. - # in a linked section?
  27. - skill = proxy.removeSecurityProxy(filtered[0])
  28. - worksheet = skill.__parent__
  29. - gradebook = ISkillsGradebook(worksheet, None)
  30. - if gradebook is not None:
  31. - try:
  32. - score = gradebook.getScore(student, skill)
  33. - except (ValueError,):
  34. - score = None
  35. - if score is not None:
  36. - return score
  37. -
  38. - def getPreviousSections(self, section):
  39. - result = []
  40. - previous = section.previous
  41. - while previous:
  42. - result.append(previous)
  43. - previous = previous.previous
  44. - return result
  45. -
  46. - def filterEquivalent(self, equivalent, section):
  47. - # select only equivalent skills that belong to this section
  48. - equivalent = [proxy.removeSecurityProxy(e) for e in equivalent]
  49. - return filter(
  50. - lambda e: ISection(e.__parent__, None) is section,
  51. - equivalent)
  52. + if self.section.previous is not None:
  53. + return self.getPreviousScore(student, activity, self.section.previous)
  54. +
  55. + def getPreviousScore(self, student, activity, section):
  56. + equivalent = self.findEquivalent(activity, section)
  57. + if equivalent is not None:
  58. + skill = proxy.removeSecurityProxy(equivalent)
  59. + worksheet = skill.__parent__
  60. + gradebook = ISkillsGradebook(worksheet, None)
  61. + if gradebook is not None:
  62. + try:
  63. + score = gradebook.getScore(student, skill)
  64. + except (ValueError,):
  65. + score = None
  66. + if score is not None:
  67. + return score
  68. +
  69. + def findEquivalent(self, activity, section):
  70. + equivalent = set(activity.equivalent)
  71. + skillsets = ISectionSkills(section)
  72. + for skillset in skillsets.values():
  73. + for skill in skillset.values():
  74. + if set(skill.equivalent).intersection(equivalent):
  75. + return skill
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement