[Checkins] SVN: lovely.rating/trunk/src/lovely/rating/ Removed
dependencies on schooltool.
Jürgen Kartnaller
juergen at kartnaller.at
Thu Mar 22 12:09:20 EDT 2007
Log message for revision 73462:
Removed dependencies on schooltool.
Please see generations/helper.py on how to migrate to the new
simple score system.
Changed:
U lovely.rating/trunk/src/lovely/rating/README.txt
A lovely.rating/trunk/src/lovely/rating/generations/helper.py
A lovely.rating/trunk/src/lovely/rating/generations/helper.txt
U lovely.rating/trunk/src/lovely/rating/interfaces.py
U lovely.rating/trunk/src/lovely/rating/rating.py
A lovely.rating/trunk/src/lovely/rating/scoresystem.py
U lovely.rating/trunk/src/lovely/rating/tests.py
-=-
Modified: lovely.rating/trunk/src/lovely/rating/README.txt
===================================================================
--- lovely.rating/trunk/src/lovely/rating/README.txt 2007-03-22 16:02:08 UTC (rev 73461)
+++ lovely.rating/trunk/src/lovely/rating/README.txt 2007-03-22 16:09:20 UTC (rev 73462)
@@ -56,9 +56,9 @@
create a score system for the ratings:
>>> from decimal import Decimal
- >>> from schooltool.requirement import scoresystem
+ >>> from lovely.rating import scoresystem
- >>> fiveSteps = scoresystem.DiscreteValuesScoreSystem(
+ >>> fiveSteps = scoresystem.SimpleScoreSystem(
... u'Five Steps', u' A five step scoring system',
... [(u'Awesome', Decimal(4)), (u'Good', Decimal(3)),
... (u'Okay', Decimal(2)), (u'Poor', Decimal(1)),
Added: lovely.rating/trunk/src/lovely/rating/generations/helper.py
===================================================================
--- lovely.rating/trunk/src/lovely/rating/generations/helper.py 2007-03-22 16:02:08 UTC (rev 73461)
+++ lovely.rating/trunk/src/lovely/rating/generations/helper.py 2007-03-22 16:09:20 UTC (rev 73462)
@@ -0,0 +1,38 @@
+##############################################################################
+#
+# Copyright (c) 2006 Lovely Systems and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+from zope.app.zopeappgenerations import getRootFolder
+from zope.app.generations.utility import findObjectsProviding
+
+from lovely.rating.interfaces import IRatingDefinition
+from lovely.rating.scoresystem import SimpleScoreSystem
+
+
+def evolveToSimpleScoreSystem(context):
+ """This is a help to migrate existing rating definitions.
+
+ It only works if you use a score system which is compatible with
+ SimpleScoreSystem.
+ It is meant to be used from your application evolve script.
+ """
+ for definition in findObjectsProviding(
+ getRootFolder(context), IRatingDefinition):
+ old = definition.scoreSystem
+ new = SimpleScoreSystem(old.title, old.description, old.scores)
+ definition.scoreSystem = new
+
Property changes on: lovely.rating/trunk/src/lovely/rating/generations/helper.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: lovely.rating/trunk/src/lovely/rating/generations/helper.txt
===================================================================
--- lovely.rating/trunk/src/lovely/rating/generations/helper.txt 2007-03-22 16:02:08 UTC (rev 73461)
+++ lovely.rating/trunk/src/lovely/rating/generations/helper.txt 2007-03-22 16:09:20 UTC (rev 73462)
@@ -0,0 +1,52 @@
+===========================
+Evolve To SimpleScoreSystem
+===========================
+
+To eveolve to the simple score system we replace existing score systems in all
+rating definitions.
+
+Instead of providing an automatic evolve script we provide a helper to migrate
+to the simple score system. If your score system can be migrated to the simple
+score system you can use this helper in your application evolve script.
+
+We provide a dummy rating definition.
+
+ >>> from zope import interface
+ >>> class OldScoreSystem(object):
+ ... title = u'old title'
+ ... description = u'old description'
+ ... scores = [(u'1', 1), (u'2', 2)]
+ >>> from lovely.rating.interfaces import IRatingDefinition
+ >>> class OldRatingDefinition(object):
+ ... interface.implements(IRatingDefinition)
+ ... scoreSystem = OldScoreSystem()
+
+ >>> root['rating'] = OldRatingDefinition()
+
+To run the evolve script we provide a context for the helper.
+
+ >>> from zope.app.publication.zopepublication import ZopePublication
+ >>> class DummyConnection(object):
+ ... def __init__(self, root):
+ ... self.data = {ZopePublication.root_name: root}
+ ... def root(self):
+ ... return self.data
+ >>> class EvolveContext(object):
+ ... def __init__(self, root):
+ ... self.connection = DummyConnection(root)
+
+Now we run the evolve helper.
+
+ >>> from lovely.rating.generations.helper import evolveToSimpleScoreSystem
+ >>> evolveToSimpleScoreSystem(EvolveContext(root))
+
+ >>> scoreSystem = root['rating'].scoreSystem
+ >>> scoreSystem
+ <lovely.rating.scoresystem.SimpleScoreSystem object at ...>
+ >>> scoreSystem.title
+ u'old title'
+ >>> scoreSystem.description
+ u'old description'
+ >>> scoreSystem.scores
+ [(u'1', 1), (u'2', 2)]
+
Property changes on: lovely.rating/trunk/src/lovely/rating/generations/helper.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: lovely.rating/trunk/src/lovely/rating/interfaces.py
===================================================================
--- lovely.rating/trunk/src/lovely/rating/interfaces.py 2007-03-22 16:02:08 UTC (rev 73461)
+++ lovely.rating/trunk/src/lovely/rating/interfaces.py 2007-03-22 16:09:20 UTC (rev 73462)
@@ -20,8 +20,40 @@
import zope.interface
import zope.schema
-from schooltool.requirement import interfaces
+class IScoreSystem(zope.interface.Interface):
+ """The score system."""
+
+ title = zope.schema.TextLine(
+ title=u'Title',
+ description=u'The name of the score system.',
+ required=False)
+
+ description = zope.schema.TextLine(
+ title=u'Description',
+ description=u'A description of the score system.',
+ required=False)
+
+ scores = zope.schema.List(
+ title = u'The scores',
+ description = u"""
+ A list containing tuples with (value, numerical).
+ value is the external repesentation.
+ numerical is stored in the rating
+ """,
+ default = [],
+ )
+
+ def isValidScore(value):
+ """Check if the value is a valid score for the scoring system.
+
+ value must be a value from `scores`.
+ """
+
+ def getNumericalValue(value):
+ """Return a numerical value representing the value"""
+
+
class IRatingDefinition(zope.interface.Interface):
"""Defines the a rating.
@@ -38,7 +70,7 @@
scoreSystem = zope.schema.Object(
title=u'Score System',
description=u'The score system used for rating.',
- schema=interfaces.IScoreSystem,
+ schema=IScoreSystem,
required=True)
description = zope.schema.Text(
Modified: lovely.rating/trunk/src/lovely/rating/rating.py
===================================================================
--- lovely.rating/trunk/src/lovely/rating/rating.py 2007-03-22 16:02:08 UTC (rev 73461)
+++ lovely.rating/trunk/src/lovely/rating/rating.py 2007-03-22 16:09:20 UTC (rev 73462)
@@ -46,3 +46,4 @@
return cmp(super(Rating, self), other)
return cmp((self.id, self.value, self.user),
(other.id, other.value, other.user))
+
Added: lovely.rating/trunk/src/lovely/rating/scoresystem.py
===================================================================
--- lovely.rating/trunk/src/lovely/rating/scoresystem.py 2007-03-22 16:02:08 UTC (rev 73461)
+++ lovely.rating/trunk/src/lovely/rating/scoresystem.py 2007-03-22 16:09:20 UTC (rev 73462)
@@ -0,0 +1,37 @@
+##############################################################################
+#
+# Copyright (c) 2007 Lovely Systems and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+from zope import interface
+
+from lovely.rating import IScoreSystem
+
+
+class SimpleScoreSystem(object):
+ interface.implements(IScoreSystem)
+
+ def __init__(self, title, description, scores):
+ self.title = title
+ self.description = description
+ self.scores = scores
+
+ def isValidScore(self, value):
+ return value in dict(self.scores)
+
+ def getNumericalValue(self, value):
+ return dict(self.scores)[value]
+
Property changes on: lovely.rating/trunk/src/lovely/rating/scoresystem.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: lovely.rating/trunk/src/lovely/rating/tests.py
===================================================================
--- lovely.rating/trunk/src/lovely/rating/tests.py 2007-03-22 16:02:08 UTC (rev 73461)
+++ lovely.rating/trunk/src/lovely/rating/tests.py 2007-03-22 16:09:20 UTC (rev 73462)
@@ -22,7 +22,8 @@
from zope.app.testing import setup
def setUp(test):
- setup.placefulSetUp()
+ root = setup.placefulSetUp(True)
+ test.globs['root'] = root
def tearDown(test):
setup.placefulTearDown()
@@ -35,6 +36,11 @@
tearDown=tearDown,
optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
),
+ DocFileSuite('generations/helper.txt',
+ setUp=setUp,
+ tearDown=tearDown,
+ optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
+ ),
))
if __name__ == '__main__':
More information about the Checkins
mailing list