405 |
405 |
406 addOrganizationToSurveyRecords(ProjectSurveyRecord) |
406 addOrganizationToSurveyRecords(ProjectSurveyRecord) |
407 addOrganizationToSurveyRecords(GradingProjectSurveyRecord) |
407 addOrganizationToSurveyRecords(GradingProjectSurveyRecord) |
408 |
408 |
409 |
409 |
410 def acceptedStudentsCSVExport(csv_filename, program_key_name): |
410 def exportStudentsWithProjects(csv_filename, scope_path_start=''): |
411 """Exports all accepted Students for particular program into CSV file. |
411 """Exports all Students who have a project assigned. |
|
412 |
|
413 Args: |
|
414 csv_filename: the name of the file where to save the CSV export |
|
415 scope_path_start: The string with which the scope_path of the project |
|
416 should start with. Can be used to select which sponsor, program or org |
|
417 the projects should belong to. |
412 """ |
418 """ |
413 # TODO(Pawel.Solyga): Add additional Program parameter to this method |
419 # TODO(Pawel.Solyga): Add additional Program parameter to this method |
414 # so we export students from different programs |
420 # so we export students from different programs |
415 # TODO(Pawel.Solyga): Make it universal so it works with both GHOP |
421 # TODO(Pawel.Solyga): Make it universal so it works with both GHOP |
416 # and GSoC programs |
422 # and GSoC programs |
417 |
423 |
418 from soc.models.student_project import StudentProject |
424 from soc.models.student_project import StudentProject |
419 from soc.models.student import Student |
425 from soc.models.student import Student |
420 from soc.models.organization import Organization |
426 from soc.models.organization import Organization |
421 |
427 |
|
428 # get all projects |
422 getStudentProjects = getEntities(StudentProject) |
429 getStudentProjects = getEntities(StudentProject) |
423 student_projects = getStudentProjects() |
430 student_projects = getStudentProjects() |
|
431 |
424 student_projects_amount = len(student_projects) |
432 student_projects_amount = len(student_projects) |
425 print "Fetched %d Student Projects." % student_projects_amount |
433 print "Fetched %d Student Projects." % student_projects_amount |
|
434 |
426 print "Fetching Student entities from Student Projects." |
435 print "Fetching Student entities from Student Projects." |
427 accepted_students = {} |
436 accepted_students = {} |
428 student_extra_data = {} |
437 student_extra_data = {} |
429 counter = 0 |
438 counter = 0 |
430 |
439 |
431 for sp_key in student_projects.keys(): |
440 for student_project in student_projects.values(): |
432 key = student_projects[sp_key].student.key().name() |
|
433 accepted_students[key] = student_projects[sp_key].student |
|
434 org_name = student_projects[sp_key].scope.name |
|
435 student_extra_data[key] = {} |
|
436 student_extra_data[key]['organization'] = org_name |
|
437 student_extra_data[key]['project_status'] = student_projects[sp_key].status |
|
438 counter += 1 |
441 counter += 1 |
439 |
442 |
440 print str(counter) + '/' + str(student_projects_amount) + ' ' + key + ' (' + org_name + ')' |
443 if student_project.status == 'invalid' or not \ |
|
444 student_project.scope_path.startswith(scope_path_start): |
|
445 # no need to export this project |
|
446 continue |
|
447 |
|
448 student_entity = student_project.student |
|
449 |
|
450 student_key = student_entity.key().id_or_name() |
|
451 accepted_students[student_key] = student_entity |
|
452 |
|
453 org_name = student_project.scope.name |
|
454 |
|
455 extra_data = {} |
|
456 extra_data['organization'] = org_name |
|
457 extra_data['project_status'] = student_project.status |
|
458 student_extra_data[student_key] = extra_data |
|
459 |
|
460 print '%s/%s %s (%s)' %(counter, student_projects_amount, |
|
461 student_key, org_name) |
|
462 |
441 print "All Student entities fetched." |
463 print "All Student entities fetched." |
442 |
464 |
443 students_key_order = ['link_id', 'given_name', 'surname', |
465 students_key_order = ['link_id', 'given_name', 'surname', |
444 'name_on_documents', 'email', 'res_street', 'res_city', 'res_state', |
466 'document_name', 'email', 'res_street', 'res_city', 'res_state', |
445 'res_country', 'res_postalcode', 'phone', 'ship_street', 'ship_city', |
467 'res_country', 'res_postalcode', 'phone', 'shipping_street', |
446 'ship_state', 'ship_country', 'ship_postalcode', 'birth_date', |
468 'shipping_city', 'shipping_state', 'shipping_country', |
447 'tshirt_size', 'tshirt_style', 'name', 'school_name', 'school_country', |
469 'shipping_postalcode', 'birth_date', 'tshirt_size', 'tshirt_style', |
448 'major', 'degree'] |
470 'school_name', 'school_country', 'major', 'degree'] |
449 |
471 |
450 print "Preparing Students data for export." |
472 print "Preparing Students data for export." |
451 students_data = [accepted_students[i].toDict(students_key_order) for i in accepted_students.keys()] |
473 students_data = [] |
452 |
474 |
453 print "Adding organization name and project status to Students data." |
475 for student_key, student_entity in accepted_students.iteritems(): |
454 for student in students_data: |
476 # transform the Student into a set of dict entries |
455 extra_data = student_extra_data[program_key_name + '/' + student['link_id']] |
477 prepared_data = student_entity.toDict(students_key_order) |
456 student['organization'] = extra_data['organization'] |
478 |
457 student['project_status'] = extra_data['project_status'] |
479 # add the additional fields |
458 |
480 extra_data = student_extra_data[student_key] |
|
481 prepared_data['organization'] = extra_data['organization'] |
|
482 prepared_data['project_status'] = extra_data['project_status'] |
|
483 |
|
484 # append the prepared data to the collected data |
|
485 students_data.append(prepared_data) |
|
486 |
|
487 # append the extra fields to the key_order |
459 students_key_order.append('organization') |
488 students_key_order.append('organization') |
460 students_key_order.append('project_status') |
489 students_key_order.append('project_status') |
461 |
490 |
462 saveDataToCSV(csv_filename, students_data, students_key_order) |
491 saveDataToCSV(csv_filename, students_data, students_key_order) |
463 print "Accepted Students exported to %s file." % csv_filename |
492 print "Students with Projects exported to %s file." % csv_filename |
464 |
493 |
465 |
494 |
466 def exportUniqueOrgAdminsAndMentors(csv_filename, scope_path_start): |
495 def exportUniqueOrgAdminsAndMentors(csv_filename, scope_path_start=''): |
467 """Exports Org Admins and Mentors to a CSV file, one per User. |
496 """Exports Org Admins and Mentors to a CSV file, one per User. |
468 |
497 |
469 Args: |
498 Args: |
470 csv_filename: the name of the csv file to save |
499 csv_filename: the name of the csv file to save |
471 scope_path_start: the start of the scope path of the roles to get could be |
500 scope_path_start: the start of the scope path of the roles to get could be |
503 'res_country', 'res_postalcode', 'phone', 'shipping_street', |
532 'res_country', 'res_postalcode', 'phone', 'shipping_street', |
504 'shipping_city', 'shipping_state', 'shipping_country', |
533 'shipping_city', 'shipping_state', 'shipping_country', |
505 'shipping_postalcode', 'birth_date', 'tshirt_size', 'tshirt_style'] |
534 'shipping_postalcode', 'birth_date', 'tshirt_size', 'tshirt_style'] |
506 |
535 |
507 print 'Preparing the data for export' |
536 print 'Preparing the data for export' |
508 data = [user.toDict(field_names=export_fields) for user in unique_users.values()] |
537 data = [user.toDict(field_names=export_fields) for user in \ |
|
538 unique_users.values()] |
509 |
539 |
510 print 'Exporting the data to CSV' |
540 print 'Exporting the data to CSV' |
511 saveDataToCSV(csv_filename, data, export_fields) |
541 saveDataToCSV(csv_filename, data, export_fields) |
|
542 print "Exported Org admins and Mentors (1 per User) to %s file." % csv_filename |
512 |
543 |
513 |
544 |
514 def saveDataToCSV(csv_filename, data, key_order): |
545 def saveDataToCSV(csv_filename, data, key_order): |
515 """Saves data in order into CSV file. |
546 """Saves data in order into CSV file. |
516 |
547 |