Renamed rankerroot to ranker_root and made some changes due to comments.
authorLennard de Rijk <ljvderijk@gmail.com>
Wed, 04 Mar 2009 17:04:25 +0000
changeset 1623 8b70d6bb3f8f
parent 1622 1ecd37ddc145
child 1624 1fc2089f4bc9
Renamed rankerroot to ranker_root and made some changes due to comments. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
app/soc/logic/models/organization.py
app/soc/logic/models/ranker_root.py
app/soc/logic/models/rankerroot.py
app/soc/logic/models/student_proposal.py
app/soc/models/ranker_root.py
app/soc/models/rankerroot.py
app/soc/models/seed_db.py
--- a/app/soc/logic/models/organization.py	Wed Mar 04 16:54:17 2009 +0000
+++ b/app/soc/logic/models/organization.py	Wed Mar 04 17:04:25 2009 +0000
@@ -27,8 +27,8 @@
 from soc.logic.models import group
 from soc.logic.models import org_app as org_app_logic
 from soc.logic.models import program as program_logic
-from soc.logic.models import rankerroot as ranker_root_logic
 from soc.logic.models import request as request_logic
+from soc.logic.models.ranker_root import logic as ranker_root_logic
 
 import soc.models.group
 import soc.models.organization
@@ -52,13 +52,13 @@
 
 
   def _onCreate(self, entity):
-    """Invites the group admin and backup admin and creates a rankerroot entity.
+    """Invites the group admin and backup admin and creates a RankerRoot entity.
     """
 
     from soc.models import student_proposal
 
     # create a new ranker
-    ranker_root_logic.logic.create(student_proposal.DEF_RANKER_NAME, entity,
+    ranker_root_logic.create(student_proposal.DEF_RANKER_NAME, entity,
         student_proposal.DEF_SCORE, 100)
 
     fields = {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/logic/models/ranker_root.py	Wed Mar 04 17:04:25 2009 +0000
@@ -0,0 +1,80 @@
+#!/usr/bin/python2.5
+#
+# Copyright 2009 the Melange authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""RankerRoot (Model) query functions.
+"""
+
+__authors__ = [
+  '"Lennard de Rijk" <ljvderijk@gmail.com>',
+  ]
+
+from google.appengine.api import datastore
+
+from ranklist.ranker import Ranker
+
+from soc.logic.models import base
+
+import soc.models.ranker_root
+
+
+class Logic(base.Logic):
+  """Logic methods for the RankerRoot model.
+  """
+
+  def __init__(self, model=soc.models.ranker_root.RankerRoot, 
+               base_model=None, scope_logic=None):
+    """Defines the name, key_name and model for this entity.
+    """
+
+    super(Logic, self).__init__(model=model, base_model=base_model,
+                                scope_logic=scope_logic)
+
+  def create(self, name, scope, scores, branching_factor):
+    """Creates a new RankerRoot with a new Ranker.
+
+    Args:
+      name: the Link ID of the ranker root
+      scope: the entity owning the ranker
+      score_range: A list showing the range of valid scores, in the form:
+          [most_significant_score_min, most_significant_score_max,
+          less_significant_score_min, less_significant_score_max, ...]
+          Ranges are [inclusive, exclusive)
+      branching_factor: The branching factor of the tree.  The number of
+          datastore Gets is Theta(1/log(branching_factor)), and the amount of data
+          returned by each Get is Theta(branching_factor). 
+
+    """
+    ranker = Ranker.Create(scores, branching_factor)
+
+    fields = {'link_id': name,
+        'scope': scope,
+        'scope_path': scope.key().name(),
+        'root': ranker.rootkey}
+
+    key_name = self.getKeyNameFromFields(fields)
+    self.updateOrCreateFromKeyName(fields, key_name)
+
+  def getRootFromEntity(self, entity):
+    """Returns a Ranker object created from a RankerRoot entity.
+
+    Args:
+      entity: A RankerRoot entity which the root should be retrieved of
+    """
+
+    return Ranker(datastore.Get(entity.key())['root'])
+
+
+logic = Logic()
--- a/app/soc/logic/models/rankerroot.py	Wed Mar 04 16:54:17 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,80 +0,0 @@
-#!/usr/bin/python2.5
-#
-# Copyright 2009 the Melange authors.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""RankerRoot (Model) query functions.
-"""
-
-__authors__ = [
-  '"Lennard de Rijk" <ljvderijk@gmail.com>',
-  ]
-
-from google.appengine.api import datastore
-
-from ranklist.ranker import Ranker
-
-from soc.logic.models import base
-
-import soc.models.rankerroot
-
-
-class Logic(base.Logic):
-  """Logic methods for the RankerRoot model.
-  """
-
-  def __init__(self, model=soc.models.rankerroot.RankerRoot, 
-               base_model=None, scope_logic=None):
-    """Defines the name, key_name and model for this entity.
-    """
-
-    super(Logic, self).__init__(model=model, base_model=base_model,
-                                scope_logic=scope_logic)
-
-  def create(self, name, scope, scores, branching_factor):
-    """Creates a new RankerRoot with a new Ranker.
-
-    Args:
-      name: the Link ID of the ranker root
-      scope: the entity owning the ranker
-      score_range: A list showing the range of valid scores, in the form:
-          [most_significant_score_min, most_significant_score_max,
-          less_significant_score_min, less_significant_score_max, ...]
-          Ranges are [inclusive, exclusive)
-      branching_factor: The branching factor of the tree.  The number of
-          datastore Gets is Theta(1/log(branching_factor)), and the amount of data
-          returned by each Get is Theta(branching_factor). 
-
-    """
-    ranker = Ranker.Create(scores, branching_factor)
-
-    fields = {'link_id': name,
-        'scope': scope,
-        'scope_path': scope.key().name(),
-        'root': ranker.rootkey}
-
-    key_name = self.getKeyNameFromFields(fields)
-    self.updateOrCreateFromKeyName(fields, key_name)
-
-  def getRootFromEntity(self, entity):
-    """Returns a Ranker object created from a RankerRoot entity.
-
-    Args:
-      entity: A RankerRoot entity which the root should be retrieved of
-    """
-
-    return Ranker(datastore.Get(entity.key())['root'])
-
-
-logic = Logic()
--- a/app/soc/logic/models/student_proposal.py	Wed Mar 04 16:54:17 2009 +0000
+++ b/app/soc/logic/models/student_proposal.py	Wed Mar 04 17:04:25 2009 +0000
@@ -23,8 +23,8 @@
 
 
 from soc.logic.models import base
-from soc.logic.models import rankerroot as ranker_logic
 from soc.logic.models import student as student_logic
+from soc.logic.models.ranker_root import logic as ranker_root_logic
 from soc.models import student_proposal
 
 import soc.models.linkable
@@ -44,14 +44,14 @@
                                 scope_logic=scope_logic)
 
   def _onCreate(self, entity):
-    """Adds this proposal to the organization ranker entity
+    """Adds this proposal to the organization ranker entity.
     """
 
     fields = {'link_id': student_proposal.DEF_RANKER_NAME,
               'scope': entity.org}
 
-    ranker_root = ranker_logic.logic.getForFields(fields, unique=True)
-    ranker = ranker_logic.logic.getRootFromEntity(ranker_root) 
+    ranker_root = ranker_root_logic.getForFields(fields, unique=True)
+    ranker = ranker_root_logic.getRootFromEntity(ranker_root) 
     ranker.SetScore(entity.key().name(), [entity.score])
 
     super(Logic, self)._onCreate(entity)
@@ -73,8 +73,8 @@
       fields = {'link_id': student_proposal.DEF_RANKER_NAME,
                 'scope': entity.org}
 
-      ranker_root = ranker_logic.logic.getForFields(fields, unique=True)
-      ranker = ranker_logic.logic.getRootFromEntity(ranker_root)
+      ranker_root = ranker_root_logic.getForFields(fields, unique=True)
+      ranker = ranker_root_logic.getRootFromEntity(ranker_root)
       ranker.SetScore(entity.key().name(), [value])
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/models/ranker_root.py	Wed Mar 04 17:04:25 2009 +0000
@@ -0,0 +1,36 @@
+#!/usr/bin/python2.5
+#
+# Copyright 2009 the Melange authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""This module contains the RankerRoot model
+"""
+
+__authors__ = [
+  '"Lennard de Rijk" <ljvderijk@gmail.com>',
+]
+
+
+from google.appengine.ext import db
+
+import soc.models.linkable
+
+
+class RankerRoot(soc.models.linkable.Linkable):
+  """Links the Root of a RankList tree to an owner and also gives it an unique ID.
+  """
+
+  #: A required reference property to the root of the RankList tree
+  root = db.ReferenceProperty(required=True,
+      collection_name='roots')
--- a/app/soc/models/rankerroot.py	Wed Mar 04 16:54:17 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-#!/usr/bin/python2.5
-#
-# Copyright 2009 the Melange authors.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-# 
-#   http://www.apache.org/licenses/LICENSE-2.0
-# 
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""This module contains the RankerRoot model
-"""
-
-__authors__ = [
-  '"Lennard de Rijk" <ljvderijk@gmail.com>',
-]
-
-
-from google.appengine.ext import db
-
-import soc.models.linkable
-
-class RankerRoot(soc.models.linkable.Linkable):
-  """Links the Root of a RankList tree to an owner and also gives it an unique ID.
-  """
-
-  #: A required reference property to the root of the RankList tree
-  root = db.ReferenceProperty(required=True,
-      collection_name='roots')
--- a/app/soc/models/seed_db.py	Wed Mar 04 16:54:17 2009 +0000
+++ b/app/soc/models/seed_db.py	Wed Mar 04 17:04:25 2009 +0000
@@ -29,7 +29,7 @@
 from google.appengine.api import memcache
 from google.appengine.ext import db
 
-from soc.logic.models import rankerroot
+from soc.logic.models.ranker_root import logic as ranker_root_logic
 from soc.models import student_proposal
 from soc.models.document import Document
 from soc.models.host import Host
@@ -246,7 +246,7 @@
   melange = Organization(**group_properties)
   melange.put()
   # create a new ranker
-  rankerroot.logic.create(student_proposal.DEF_RANKER_NAME, melange,
+  ranker_root_logic.create(student_proposal.DEF_RANKER_NAME, melange,
       student_proposal.DEF_SCORE, 100)
 
   group_properties.update({
@@ -266,7 +266,7 @@
     entity = Organization(**group_properties)
     entity.put()
     # create a new ranker
-    rankerroot.logic.create(student_proposal.DEF_RANKER_NAME, entity,
+    ranker_root_logic.create(student_proposal.DEF_RANKER_NAME, entity,
         student_proposal.DEF_SCORE, 100)