def _editPost(self, request, entity, fields): """See base.View._editPost(). Processes POST request items to add new dynamic field names, question types, and default prompt values to SurveyContent model. """ user = user_logic.getForCurrentAccount() schema = {} survey_fields = {} if not entity: # new Survey if 'serialized' in request.POST: fields, schema, survey_fields = self.importSerialized(request, fields, user) fields['author'] = user else: fields['author'] = entity.author schema = self.loadSurveyContent(schema, survey_fields, entity) # remove deleted properties from the model self.deleteQuestions(schema, survey_fields, request.POST) # add new text questions and re-build choice questions self.getRequestQuestions(schema, survey_fields, request.POST) # get schema options for choice questions self.getSchemaOptions(schema, survey_fields, request.POST) survey_content = getattr(entity,'survey_content', None) # create or update a SurveyContent for this Survey survey_content = survey_logic.createSurvey(survey_fields, schema, survey_content=survey_content) # save survey_content for existent survey or pass for creating a new one if entity: entity.modified_by = user entity.survey_content = survey_content db.put(entity) else: fields['survey_content'] = survey_content fields['modified_by'] = user super(View, self)._editPost(request, entity, fields)
def _editPost(self, request, entity, fields): """See base.View._editPost(). Processes POST request items to add new dynamic field names, question types, and default prompt values to SurveyContent model. """ user = user_logic.getCurrentUser() schema = {} survey_fields = {} if not entity: # new Survey if 'serialized' in request.POST: fields, schema, survey_fields = self.importSerialized( request, fields, user) fields['author'] = user else: fields['author'] = entity.author schema = self.loadSurveyContent(schema, survey_fields, entity) # remove deleted properties from the model self.deleteQuestions(schema, survey_fields, request.POST) # add new text questions and re-build choice questions self.getRequestQuestions(schema, survey_fields, request.POST) # get schema options for choice questions self.getSchemaOptions(schema, survey_fields, request.POST) survey_content = getattr(entity, 'survey_content', None) # create or update a SurveyContent for this Survey survey_content = survey_logic.createSurvey( survey_fields, schema, survey_content=survey_content) # save survey_content for existent survey or pass for creating a new one if entity: entity.modified_by = user entity.survey_content = survey_content db.put(entity) else: fields['survey_content'] = survey_content fields['modified_by'] = user super(View, self)._editPost(request, entity, fields)
def seed_many(request, *args, **kwargs): """Seeds many instances of the specified type. Understands the following GET args: start: where to start adding new users at end: where to stop adding new users at goal: how many users to add in total, implies user_only step: how many users to add per request, defaults to 15 seed_type: the type of entity to seed, should be one of: user, org, org_app, mentor, student_proposal Redirects if end < goal, incrementing both start and end with step. """ get_args = request.GET if not dicts.containsAll(get_args, ['goal', 'start', 'end', 'seed_type']): return http.HttpResponse('Missing get args.') seed_types = { 'user': (seed_user, User), 'org': (seed_org, GSoCOrganization), 'org_app': (seed_org_app, OrgApplication), 'mentor': (seed_mentor, GSoCMentor), 'student': (seed_student, GSoCStudent), 'student_proposal': (seed_student_proposal, StudentProposal), 'survey': (seed_survey, Survey), 'survey_answer': (seed_survey_answer, SurveyRecord), } goal = int(get_args['goal']) start = int(get_args['start']) end = int(get_args['end']) step = int(get_args.get('step', '15')) seed_type = get_args['seed_type'] if not seed_type in seed_types: return http.HttpResponse('Unknown seed_type: "%s".' % seed_type) action, model = seed_types[seed_type] for i in range(start, end): try: props = action(request, i) except Error, error: return http.HttpResponse(error.message) for properties in props if isinstance(props, list) else [props]: entity = model(**properties) if seed_type == 'survey': survey_content = survey_logic.createSurvey( properties['fields'], properties['schema'], this_survey=None) entity.this_survey = survey_content elif seed_type == 'survey_answer': record = SurveyRecord.gql( "WHERE user = :1 AND this_survey = :2", properties['user'], properties['_survey']).get() entity = survey_logic.updateSurveyRecord( properties['user'], properties['_survey'], record, properties['_fields']) entity.put() if seed_type == 'survey': survey_logic._onCreate(entity)