示例#1
0
文件: survey.py 项目: jamslevy/gsoc
  def create_survey_record(self, user, survey_entity, survey_fields):
    """ Create a new survey record
    """

    survey_record = SurveyRecord.gql("WHERE user = :1 AND this_survey = :2", user, survey_entity).get() 
    if survey_record:
    	for prop in survey_record.dynamic_properties(): 
    	    delattr(survey_record, prop) 
    if not survey_record: survey_record = SurveyRecord(
                     user = user,
                     this_survey = survey_entity
                     )
    for name, value in survey_fields.items(): setattr(survey_record, name, value)
    from google.appengine.ext import db
    db.put(survey_record)
    return survey_record
示例#2
0
文件: surveys.py 项目: jamslevy/gsoc
   def render(self, this_survey):
	#check if user has already submitted form. If so, show existing form 
	import soc.models.user
	from soc.logic.models.user import logic as user_logic
	user = user_logic.getForCurrentAccount()
	survey_record = SurveyRecord.gql("WHERE user = :1 AND this_survey = :2", user, this_survey.survey_parent.get()).get()
	survey = SurveyForm(this_survey=this_survey, survey_record=survey_record) 
	if survey_record: 
	   help_text = "Edit and re-submit this survey."
	   status = "edit"
	else: 
	   help_text = "Please complete this survey."
	   status = "create"
	  
	result = self.WIDGET_HTML % {'survey': str(survey), 'help_text': help_text, 
	                             'status': status } 
	return result