Edit SurveyRecord model to not make use of different Survey property for each subclass.
This does mean that a simple query needs to be constructed by hand whenever you want to query for every SurveyRecord for a specific Survey. However the naming is now the same over each SurveyRecord and it fits well into the rest of the design of Melange.
--- a/app/soc/models/grading_project_survey.py Thu Jul 02 17:08:10 2009 +0200
+++ b/app/soc/models/grading_project_survey.py Thu Jul 02 17:47:24 2009 +0200
@@ -33,8 +33,3 @@
def __init__(self, *args, **kwargs):
super(GradingProjectSurvey, self).__init__(*args, **kwargs)
self.taking_access = 'mentor'
-
- def getRecords(self):
- """Returns all GradingProjectSurveyRecords belonging to this survey.
- """
- return self.grading_survey_records
--- a/app/soc/models/grading_project_survey_record.py Thu Jul 02 17:08:10 2009 +0200
+++ b/app/soc/models/grading_project_survey_record.py Thu Jul 02 17:47:24 2009 +0200
@@ -39,14 +39,5 @@
Student's) one by a project.
"""
- #: The survey for which this entity is a record.
- grading_survey = db.ReferenceProperty(GradingProjectSurvey,
- collection_name="grading_survey_records")
-
#: Required grade given to the project that this survey is about.
grade = db.BooleanProperty(required=True)
-
- def getSurvey(self):
- """Returns the GradingProjectSurvey that belongs to this record.
- """
- return self.grading_survey
--- a/app/soc/models/project_survey.py Thu Jul 02 17:08:10 2009 +0200
+++ b/app/soc/models/project_survey.py Thu Jul 02 17:47:24 2009 +0200
@@ -34,8 +34,3 @@
super(ProjectSurvey, self).__init__(*args, **kwargs)
self.prefix = 'program'
self.taking_access = 'student'
-
- def getRecords(self):
- """Returns all ProjectSurveyRecords belonging to this survey.
- """
- return self.project_survey_records
--- a/app/soc/models/project_survey_record.py Thu Jul 02 17:08:10 2009 +0200
+++ b/app/soc/models/project_survey_record.py Thu Jul 02 17:47:24 2009 +0200
@@ -30,22 +30,12 @@
import soc.models.student_project
-#TODO decide if this should inherit from BaseSurveyRecord
class ProjectSurveyRecord(SurveyRecord):
"""Record linked to a Project, enabling to store which Projects had their
Survey done.
"""
- #: The survey for which this entity is a record.
- project_survey = db.ReferenceProperty(ProjectSurvey,
- collection_name="project_survey_records")
-
#: Reference to the Project that this record belongs to.
project = db.ReferenceProperty(soc.models.student_project.StudentProject,
required=True,
collection_name="survey_records")
-
- def getSurvey(self):
- """Returns the ProjectSurvey that belongs to this record.
- """
- return self.project_survey
--- a/app/soc/models/survey.py Thu Jul 02 17:08:10 2009 +0200
+++ b/app/soc/models/survey.py Thu Jul 02 17:47:24 2009 +0200
@@ -155,8 +155,3 @@
#: Referenceproperty that specifies the content of this survey.
survey_content = db.ReferenceProperty(SurveyContent,
collection_name="survey_parent")
-
- def getRecords(self):
- """Returns all SurveyRecords belonging to this survey.
- """
- return self.survey_records
--- a/app/soc/models/survey_record.py Thu Jul 02 17:08:10 2009 +0200
+++ b/app/soc/models/survey_record.py Thu Jul 02 17:47:24 2009 +0200
@@ -39,10 +39,9 @@
corresponding to the fields of the survey.
"""
- #: Reference to the User entity which took this survey.
- user = db.ReferenceProperty(reference_class=soc.models.user.User,
- required=True, collection_name="surveys_taken",
- verbose_name=ugettext('Created by'))
+ #: The survey for which this entity is a record.
+ survey = db.ReferenceProperty(Survey,
+ collection_name="survey_records")
#: Date when this record was created.
created = db.DateTimeProperty(auto_now_add=True)
@@ -56,20 +55,16 @@
Right now it gets all dynamic values, but it could also be confined to
the SurveyContent entity linked to the survey entity.
"""
- survey_order = self.getSurvey().survey_content.getSurveyOrder()
+ survey_order = self.survey.survey_content.getSurveyOrder()
values = []
for position, property in survey_order.items():
values.insert(position, getattr(self, property, None))
return values
-# TODO(ajaksu) think of a better way to handle the survey reference
class SurveyRecord(BaseSurveyRecord):
- #: The survey for which this entity is a record.
- survey = db.ReferenceProperty(Survey, collection_name="survey_records")
-
- def getSurvey(self):
- """Returns the Survey belonging to this record.
- """
- return self.survey
+ #: Reference to the User entity which took this survey.
+ user = db.ReferenceProperty(reference_class=soc.models.user.User,
+ required=True, collection_name="surveys_taken",
+ verbose_name=ugettext('Taken by'))
--- a/app/soc/views/models/survey.py Thu Jul 02 17:08:10 2009 +0200
+++ b/app/soc/views/models/survey.py Thu Jul 02 17:47:24 2009 +0200
@@ -493,7 +493,6 @@
user_entity = user_logic.getForCurrentAccount()
# try to get an existing SurveyRecord for the current user
- # TODO(ljvderijk) deal with the SurveyProperty name in subclasses
filter = {'survey': entity,
'user': user_entity}