Take advantage of the Model inheritance provided by polymodel.PolyModel to
authorTodd Larsen <tlarsen@google.com>
Mon, 29 Sep 2008 15:34:40 +0000
changeset 207 8ecc2e4198cd
parent 206 832335761384
child 208 e076aee6e90f
Take advantage of the Model inheritance provided by polymodel.PolyModel to have create a class hierarchy rooted at Person. Also, add some missing Role classes, such as Role, (Organization) Mentor, (Club) Member, (School) Student. Make (Organization) Administrator be a Reviewer like Mentor is. Patch by: Todd Larsen Review by: Pawel Solyga, Sverre Rabbelier, Augie Fackler Review URL: http://codereviews.googleopensourceprograms.com/607
app/soc/models/administrator.py
app/soc/models/contributor.py
app/soc/models/host.py
app/soc/models/member.py
app/soc/models/mentor.py
app/soc/models/person.py
app/soc/models/reviewer.py
app/soc/models/role.py
app/soc/models/student.py
--- a/app/soc/models/administrator.py	Mon Sep 29 15:31:50 2008 +0000
+++ b/app/soc/models/administrator.py	Mon Sep 29 15:34:40 2008 +0000
@@ -21,26 +21,14 @@
   '"Sverre Rabbelier" <sverre@rabbelier.nl>',
 ]
 
+
 from google.appengine.ext import db
 
-from soc import models
-from soc.models import base
-import soc.models.org
-import soc.models.person
+import soc.models.reviewer
 
 
-class Administrator(base.ModelWithFieldAttributes):
+class Administrator(soc.models.reviewer.Reviewer):
   """Administrator details for a specific Program.
   """
-  
-  #: A 1:1 relationship associating an Administrator with specific
-  #: Person details and capabilities. The back-reference in the
-  #: Person model is a Query named 'admin'.
-  person = db.ReferenceProperty(reference_class=soc.models.person.Person,
-          required=True, collection_name="admin")
+  pass
 
-  #: A many:1 relationship associating Administrators with specific
-  #: Organization details and capabilities. The back-reference in the
-  #: Organization model is a Query named 'admins'.
-  org = db.ReferenceProperty(reference_class=soc.models.org.Organization, 
-          required=True, collection_name="admins")
--- a/app/soc/models/contributor.py	Mon Sep 29 15:31:50 2008 +0000
+++ b/app/soc/models/contributor.py	Mon Sep 29 15:34:40 2008 +0000
@@ -21,14 +21,13 @@
   '"Sverre Rabbelier" <sverre@rabbelier.nl>',
 ]
 
+
 from google.appengine.ext import db
 
-from soc import models
-from soc.models import base
-import soc.models.person
+import soc.models.role
 
 
-class Contributor(base.ModelWithFieldAttributes):
+class Contributor(soc.models.role.Role):
   """Contributor details for a specific Program.
 
   Some Contributor workflows have the Contributor (acting as an author)
@@ -44,10 +43,5 @@
      a specific Contributor has contributed with that Contributor.  See
      the TasksContributors model for details.
   """
-  
-  #: a 1:1 relationship associating a Contributor with generic Author
-  #: details and capabilities. The back-reference in the Author
-  #: model is a Query named 'contributor'.
-  person = db.ReferenceProperty(reference_class=models.person.Person, 
-                                required=True, 
-                                collection_name="contributor")
+  pass 
+
--- a/app/soc/models/host.py	Mon Sep 29 15:31:50 2008 +0000
+++ b/app/soc/models/host.py	Mon Sep 29 15:34:40 2008 +0000
@@ -21,26 +21,20 @@
   '"Sverre Rabbelier" <sverre@rabbelier.nl>',
 ]
 
+
 from google.appengine.ext import db
 
-from soc.models import base
-from soc import models
-import soc.models.person
+import soc.models.role
 import soc.models.sponsor
 
 
-class Host(base.ModelWithFieldAttributes):
-  """Host details for a specific Program."""
-
-  #: A 1:1 relationship associating a Host with specific
-  #: Person details and capabilities.  The back-reference in
-  #: the Person model is a Query named 'host'.
-  person = db.ReferenceProperty(reference_class=models.person.Person, 
-                               required=True, collection_name="host")
+class Host(soc.models.role.Role):
+  """Host details for a specific Program.
+  """
 
   #: A 1:1 relationship associating a Host with specific
   #: Sponsor details and capabilities. The back-reference in
   #: the Sponsor model is a Query named 'host'.  
   sponsor = db.ReferenceProperty(reference_class=models.sponsor.Sponsor,
-                                 required=True, collection_name="host")
+                                 required=True, collection_name='hosts')
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/models/member.py	Mon Sep 29 15:34:40 2008 +0000
@@ -0,0 +1,40 @@
+#!/usr/bin/python2.5
+#
+# Copyright 2008 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 Contributor Model."""
+
+__authors__ = [
+  '"Todd Larsen" <tlarsen@google.com>',
+]
+
+
+from google.appengine.ext import db
+
+import soc.models.role
+import soc.models.club
+
+
+class Member(soc.models.role.Role):
+  """Club member details.
+  """
+
+  #: A required many:1 relationship that ties multiple Members to the
+  #: Club in which they participate.  A Member cannot exist unassociated
+  #: with a Club.  The back-reference in the Club model is a Query
+  #: named 'members'.
+  club = db.ReferenceProperty(reference_class=soc.models.club.Club,
+                              required=True, collection_name='members')
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/models/mentor.py	Mon Sep 29 15:34:40 2008 +0000
@@ -0,0 +1,33 @@
+#!/usr/bin/python2.5
+#
+# Copyright 2008 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 Reviewer Model."""
+
+__authors__ = [
+  '"Todd Larsen" <tlarsen@google.com>',
+]
+
+
+from google.appengine.ext import db
+
+import soc.models.reviewer
+
+
+class Mentor(soc.models.reviewer.Reviewer):
+  """Organization Mentor.
+  """
+  pass
+
--- a/app/soc/models/person.py	Mon Sep 29 15:31:50 2008 +0000
+++ b/app/soc/models/person.py	Mon Sep 29 15:34:40 2008 +0000
@@ -21,64 +21,32 @@
   '"Sverre Rabbelier" <sverre@rabbelier.nl>',
 ]
 
+
 from google.appengine.ext import db
+
+import polymodel
+
 from django.utils.translation import ugettext_lazy
 
-from soc import models
-from soc.models import base
 from soc.models import countries
 import soc.models.user
 
 
-class Person(base.ModelWithFieldAttributes):
-  """Common data fields for all Roles.
-
-  A Person can only participate in a single Program.  To avoid duplication of
-  data entry, facilities will be available for selecting an existing Person
-  associated with a particular User to be duplicated for participation in a
-  new Program.
+class Person(polymodel.PolyModel):
+  """Common data fields for all persons on the site.
 
   Some details of a Person are considered "public" information, and nearly
   all of these are optional (except for given_name, surname, and email).
   Other details of a Person are kept "private" and are only provided to
   other Persons in roles that "need to know" this information.  How these
   fields are revealed is usually covered by Program terms of service.
-
-  A Person entity participates in the following relationships implemented
-  as a db.ReferenceProperty elsewhere in another db.Model:
-
-   docs) a 1:many relationship of documents (Documentation) associated
-     with the Person by Administrators.  This relation is implemented as
-     the 'docs' back-reference Query of the Documentation model 'person'
-     reference.
-
-   works) a many:many relationship with Works, stored in a separate
-     WorksPersons model.  See the WorksPersons model class for details.
-
-   contributor) a 1:1 relationship associating a Contributor with generic
-     Person details and capabilities.  This relation is implemented as the
-     'contributor' back-reference Query of the Contributor model 'person'
-     reference.
-
-   reviewer) a 1:1 relationship associating a Reviewer with generic
-     Person details and capabilities.  This relation is implemented as the
-     'reviewer' back-reference Query of the Reviewer model 'person' reference.
-
-   admin) a 1:1 relationship associating an Administrator with specific
-     Person details and capabilities.  This relation is implemented as the
-     'admin' back-reference Query of the Administrator model 'person'
-     reference.
-
-   host) a 1:1 relationship accociating a Host with specific Person
-     Person details and capabilities. This relation is implemented as the
-     'host' back-reference Query of the Host model 'person' reference.
   """
 
   #: A required many:1 relationship that ties (possibly multiple
   #: entities of) Person details to a unique User.  A Person cannot
   #: exist unassociated from a login identity and credentials.  The
   #: back-reference in the User model is a Query named 'persons'.
-  user = db.ReferenceProperty(reference_class=models.user.User,
+  user = db.ReferenceProperty(reference_class=soc.models.user.User,
                               required=True, collection_name='persons')
 
   #====================================================================
--- a/app/soc/models/reviewer.py	Mon Sep 29 15:31:50 2008 +0000
+++ b/app/soc/models/reviewer.py	Mon Sep 29 15:34:40 2008 +0000
@@ -18,16 +18,16 @@
 
 __authors__ = [
   '"Todd Larsen" <tlarsen@google.com>',
-  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
 ]
 
+
 from google.appengine.ext import db
 
-from soc import models
-import soc.models.author
+import soc.models.role
+import soc.models.organization
 
 
-class Reviewer(db.Model):
+class Reviewer(soc.models.role.Role):
   """Reviewer details for a specific Program.
 
   A Reviewer entity participates in the following relationships implemented 
@@ -37,10 +37,11 @@
      Reviewer.  This relation is implemented as the 'reviews'
      back-reference Query of the Review model 'reviewer' reference.
   """
-  
-  #: A 1:1 relationship associating a Contributor with Person
-  #: details and capabilities. The back-reference in the Person model
-  #: is a Query named 'reviewer'.
-  person = db.ReferenceProperty(reference_class=models.person.Person,
-                                required=True, collection_name="reviewer")
 
+  #: A many:1 relationship associating Reviewers with specific Organization
+  #: details and capabilities. The back-reference in the Organization model
+  #: is a Query named 'reviewers'.
+  org = db.ReferenceProperty(
+      reference_class=soc.models.organization.Organization, 
+      required=True, collection_name='reviewers')
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/models/role.py	Mon Sep 29 15:34:40 2008 +0000
@@ -0,0 +1,58 @@
+#!/usr/bin/python2.5
+#
+# Copyright 2008 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 Administrator Model."""
+
+__authors__ = [
+  '"Todd Larsen" <tlarsen@google.com>',
+]
+
+
+from google.appengine.ext import db
+
+import soc.models.person
+
+
+class Role(soc.models.person.Person):
+  """Information common to Program participation for all Roles.
+
+  Role is the entity that is created when a Person actually participates
+  in some fashion in a Program.  Person details could *possibly* be collected
+  without actual participation (voluntary, opt-in, of course).
+
+  A Role is a Person's participation in a single Program.  To avoid
+  duplication of data entry, facilities will be available for selecting
+  an existing Role associated with a particular User to be duplicated for
+  participation in a new Program.
+
+  A Person has to have at least one Role in order to be able to create
+  any Work (such as a Document) on the site.  The easiest-to-obtain Role is
+  probably Club Member (though Clubs can set their own membership criteria).
+
+  A Role entity participates in the following relationships implemented
+  as a db.ReferenceProperty elsewhere in another db.Model:
+
+   documentation) a 1:many relationship of Documentation (tax forms,
+     letters from schools, etc.) associated with the Role by Hosts.  This
+     relation is implemented as the 'documentation' back-reference Query of
+     the Documentation model 'role' reference.
+
+   works) a many:many relationship with Works, stored in a separate
+     WorksRoles model, representing the Work authored by this Role.
+     See the WorksRoles model class for details.
+  """
+  pass
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/models/student.py	Mon Sep 29 15:34:40 2008 +0000
@@ -0,0 +1,50 @@
+#!/usr/bin/python2.5
+#
+# Copyright 2008 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 Contributor Model."""
+
+__authors__ = [
+  '"Todd Larsen" <tlarsen@google.com>',
+]
+
+
+from google.appengine.ext import db
+
+import soc.models.contributor
+import soc.models.school
+
+
+class Student(soc.models.contributor.Contributor):
+  """Student Contributor details for a specific Program.
+
+  Some Students author Proposals to be reviewed by Reviewers (Mentors),
+  followed by Hosts, who then convert them into Tasks (usually a single
+  Task, in the case of GSoC).  In GSoC, this conversion of a Proposal into
+  a Task grants the Student entry into the Program for that year, and is
+  referred to as being "accepted".
+
+  Other Students claim Proposals that were written by Reviewers (Mentors),
+  converting them into Tasks (but only a single Task at a time can be
+  claimed by a Student, in the case of GHOP).
+  """
+
+  #: A required many:1 relationship that ties multiple Students to the
+  #: School that they attend.  A Student cannot exist unassociated with
+  #: a School.  The back-reference in the School model is a Query
+  #: named 'students'.
+  school = db.ReferenceProperty(reference_class=soc.models.school.School,
+                                required=True, collection_name='students')
+