# HG changeset patch # User Pawel Solyga # Date 1247335833 -7200 # Node ID 040359ccd20b8d148f714f662b91a76414d4f4ab # Parent 6c57c482f913238dce68fefa77c5449e58d3824e Add setOrganizationInSurveyRecords function to stats.py script. setOrganizationInSurveyRecords will iterate thru all ProjectSurveyRecords and GradingProjectSurveyRecords and set the organization property in the record model.This will be useful later for showing Org admins their mentors and students surveys list and results. diff -r 6c57c482f913 -r 040359ccd20b scripts/stats.py --- a/scripts/stats.py Sat Jul 11 19:54:23 2009 +0200 +++ b/scripts/stats.py Sat Jul 11 20:10:33 2009 +0200 @@ -84,7 +84,7 @@ gen = lambda: model.all() it = interactive.deepFetch(gen) - entities = [(i.key().name(), i) for i in it] + entities = [(i.key().id_or_name(), i) for i in it] return dict(entities) return wrapped @@ -356,6 +356,7 @@ print "Done" + def loadPickle(name): """Loads a pickle. """ @@ -372,12 +373,46 @@ cPickle.dump(target, f) +def addOrganizationToSurveyRecords(survey_record_model): + """Set Organization in SurveyRecords entities of a given model. + """ + + print "Fetching %s." % survey_record_model.__name__ + getSurveyRecord = getEntities(survey_record_model) + survey_records = getSurveyRecord() + survey_records_amount = len(survey_records) + print "Fetched %d %s." % (survey_records_amount, survey_record_model.__name__) + + counter = 0 + + for key in survey_records.keys(): + survey_records[key].org = survey_records[key].project.scope + survey_records[key].put() + + counter += 1 + print str(counter) + '/' + str(survey_records_amount) + ' ' + str(key) + + print "Organization added to all %s." % survey_record_model.__name__ + + +def setOrganizationInSurveyRecords(): + """Sets Organization property in ProjectSurveyRecords + and GradingProjectSurveyRecords entities. + """ + from soc.models.project_survey_record import ProjectSurveyRecord + from soc.models.grading_project_survey_record \ + import GradingProjectSurveyRecord + + addOrganizationToSurveyRecords(ProjectSurveyRecord) + addOrganizationToSurveyRecords(GradingProjectSurveyRecord) + + def acceptedStudentsCSVExport(csv_filename, program_key_name): """Exports all accepted Students for particular program into CSV file. """ # TODO(Pawel.Solyga): Add additional Program parameter to this method # so we export students from different programs - # TODO(Pawel.SOlyga): Make it universal so it works with both GHOP + # TODO(Pawel.Solyga): Make it universal so it works with both GHOP # and GSoC programs from soc.models.student_project import StudentProject @@ -491,6 +526,7 @@ 'getStudentProjects': getEntities(StudentProject), 'getProps': getProps, 'countStudentsWithProposals': countStudentsWithProposals, + 'setOrganizationInSurveyRecords': setOrganizationInSurveyRecords, 'convertProposals': convertProposals, 'addFollower': addFollower, 'Organization': Organization,