def canResign(self, entity): """Checks if the Mentor is able to resign. Checks if there are no Student Proposals or Student Projects that have this mentor assigned to it. Args: entity: a Mentor entity """ from soc.modules.gsoc.logic.models.student_project import logic as \ student_project_logic from soc.modules.gsoc.logic.models.student_proposal import logic as \ student_proposal_logic fields = {'mentor': entity} student_project_entity = student_project_logic.getForFields( fields, unique=True) if student_project_entity: return DEF_ALREADY_MENTORING_PROJECT_MSG student_proposal_entity = student_proposal_logic.getForFields( fields, unique=True) if student_proposal_entity: return DEF_ALREADY_MENTORING_PROPOSAL_MSG return super(Logic, self).canResign(entity)
def canResign(self, entity): """Checks if the Mentor is able to resign. Checks if there are no Student Proposals or Student Projects that have this mentor assigned to it. Args: entity: a Mentor entity """ from soc.modules.gsoc.logic.models.student_project import logic as \ student_project_logic from soc.modules.gsoc.logic.models.student_proposal import logic as \ student_proposal_logic fields = {'mentor': entity} student_project_entity = student_project_logic.getForFields(fields, unique=True) if student_project_entity: return DEF_ALREADY_MENTORING_PROJECT_MSG student_proposal_entity = student_proposal_logic.getForFields(fields, unique=True) if student_proposal_entity: return DEF_ALREADY_MENTORING_PROPOSAL_MSG return super(Logic, self).canResign(entity)
def _getMapData(self, filter=None): """Constructs the JSON object required to generate Google Maps on organization home page. Args: filter: a dict for the properties that the entities should have Returns: A JSON object containing map data. """ from soc.modules.gsoc.logic.models.student_project import logic as \ student_project_logic from soc.modules.gsoc.views.models import student_project as \ student_project_view sp_params = student_project_view.view.getParams().copy() people = {} projects = {} # get all the student_project entities for the given filter student_project_entities = student_project_logic.getForFields( filter=filter) # Construct a dictionary of mentors and students. For each mentor construct # a list of 3-tuples containing student name, project title and url. # And for each student a list of 3 tuples containing mentor name, project # title and url. Only students and mentors who have agreed to publish their # locations will be in the dictionary. for entity in student_project_entities: project_key_name = entity.key().id_or_name() project_redirect = redirects.getPublicRedirect(entity, sp_params) student_entity = entity.student student_key_name = student_entity.key().id_or_name() mentor_entity = entity.mentor mentor_key_name = mentor_entity.key().id_or_name() # store the project data in the projects dictionary projects[project_key_name] = { 'title': entity.title, 'redirect': project_redirect, 'student_key': student_key_name, 'student_name': student_entity.name(), 'mentor_key': mentor_key_name, 'mentor_name': mentor_entity.name() } if mentor_entity.publish_location: if mentor_key_name not in people: # we have not stored the information of this mentor yet people[mentor_key_name] = { 'type': 'mentor', 'name': mentor_entity.name(), 'lat': mentor_entity.latitude, 'lon': mentor_entity.longitude, 'projects': [] } # add this project to the mentor's list people[mentor_key_name]['projects'].append(project_key_name) if student_entity.publish_location: if student_key_name not in people: # new student, store the name and location people[student_key_name] = { 'type': 'student', 'name': student_entity.name(), 'lat': student_entity.latitude, 'lon': student_entity.longitude, 'projects': [], } # append the current project to the known student's list of projects people[student_key_name]['projects'].append(project_key_name) # combine the people and projects data into one JSON object data = {'people': people, 'projects': projects} return simplejson.dumps(data)
def updateOrCreateRecordsForSurveyGroup(request, *args, **kwargs): """Updates or creates GradingRecords for the given GradingSurveyGroup. Expects the following to be present in the POST dict: group_key: Specifies the GradingSurveyGroup key name. project_key: optional to specify which project was the last for which this task was run Args: request: Django Request object """ from soc.modules.gsoc.logic.models.grading_record import logic as grading_record_logic from soc.modules.gsoc.logic.models.grading_survey_group import logic as survey_group_logic from soc.modules.gsoc.logic.models.student_project import logic as student_project_logic post_dict = request.POST group_key = post_dict.get('group_key') if not group_key: # invalid task data, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid updateRecordForSurveyGroup data: %s' % post_dict) # get the GradingSurveyGroup for the given keyname survey_group_entity = survey_group_logic.getFromKeyName(group_key) if not survey_group_entity: # invalid GradingSurveyGroup specified, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid GradingSurveyGroup specified: %s' % group_key) # check and retrieve the project_key that has been done last if 'project_key' in post_dict: project_start_key = post_dict['project_key'] else: project_start_key = None # get all valid StudentProjects from starting key fields = { 'program': survey_group_entity.scope, 'status': ['accepted', 'failed', 'completed'] } if project_start_key: # retrieve the last project that was done project_start = student_project_logic.getFromKeyName(project_start_key) if not project_start: # invalid starting project key specified, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid Student Project Key specified: %s' % (project_start_key)) fields['__key__ >'] = project_start.key() # get the first batch_size number of StudentProjects project_entities = student_project_logic.getForFields(fields, limit=DEF_BATCH_SIZE) # update/create and batch put the new GradingRecords grading_record_logic.updateOrCreateRecordsFor(survey_group_entity, project_entities) if len(project_entities) == DEF_BATCH_SIZE: # spawn new task starting from the last new_project_start = project_entities[DEF_BATCH_SIZE - 1].key().id_or_name() # pass along these params as POST to the new task task_params = { 'group_key': group_key, 'project_key': new_project_start } task_url = '/tasks/grading_survey_group/update_records' new_task = taskqueue.Task(params=task_params, url=task_url) new_task.add() else: # task completed, update timestamp for last update complete fields = {'last_update_complete': datetime.datetime.now()} survey_group_logic.updateEntityProperties(survey_group_entity, fields) # task completed, return OK return http.HttpResponse('OK')
def updateOrCreateRecordsForSurveyGroup(request, *args, **kwargs): """Updates or creates GradingRecords for the given GradingSurveyGroup. Expects the following to be present in the POST dict: group_key: Specifies the GradingSurveyGroup key name. project_key: optional to specify which project was the last for which this task was run Args: request: Django Request object """ from soc.modules.gsoc.logic.models.grading_record import logic as grading_record_logic from soc.modules.gsoc.logic.models.grading_survey_group import logic as survey_group_logic from soc.modules.gsoc.logic.models.student_project import logic as student_project_logic post_dict = request.POST group_key = post_dict.get('group_key') if not group_key: # invalid task data, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid updateRecordForSurveyGroup data: %s' % post_dict) # get the GradingSurveyGroup for the given keyname survey_group_entity = survey_group_logic.getFromKeyName(group_key) if not survey_group_entity: # invalid GradingSurveyGroup specified, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid GradingSurveyGroup specified: %s' % group_key) # check and retrieve the project_key that has been done last if 'project_key' in post_dict: project_start_key = post_dict['project_key'] else: project_start_key = None # get all valid StudentProjects from starting key fields = {'program': survey_group_entity.scope, 'status': ['accepted', 'failed', 'completed']} if project_start_key: # retrieve the last project that was done project_start = student_project_logic.getFromKeyName(project_start_key) if not project_start: # invalid starting project key specified, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid Student Project Key specified: %s' %(project_start_key)) fields['__key__ >'] = project_start.key() # get the first batch_size number of StudentProjects project_entities = student_project_logic.getForFields(fields, limit=DEF_BATCH_SIZE) # update/create and batch put the new GradingRecords grading_record_logic.updateOrCreateRecordsFor(survey_group_entity, project_entities) if len(project_entities) == DEF_BATCH_SIZE: # spawn new task starting from the last new_project_start = project_entities[DEF_BATCH_SIZE-1].key().id_or_name() # pass along these params as POST to the new task task_params = {'group_key': group_key, 'project_key': new_project_start} task_url = '/tasks/grading_survey_group/update_records' new_task = taskqueue.Task(params=task_params, url=task_url) new_task.add() else: # task completed, update timestamp for last update complete fields = {'last_update_complete': datetime.datetime.now()} survey_group_logic.updateEntityProperties(survey_group_entity, fields) # task completed, return OK return http.HttpResponse('OK')
def spawnRemindersForProjectSurvey(request, *args, **kwargs): """Spawns tasks for each StudentProject in the given Program. Expects the following to be present in the POST dict: program_key: Specifies the program key name for which to loop over all the StudentProjects for survey_key: specifies the key name for the ProjectSurvey to send reminders for survey_type: either project or grading depending on the type of Survey project_key: optional to specify which project was the last for which a task was spawn Args: request: Django Request object """ from soc.modules.gsoc.logic.models.program import logic as program_logic from soc.modules.gsoc.logic.models.student_project import logic as \ student_project_logic # set default batch size batch_size = 10 post_dict = request.POST # retrieve the program_key and survey_key from POST data program_key = post_dict.get('program_key') survey_key = post_dict.get('survey_key') survey_type = post_dict.get('survey_type') if not (program_key and survey_key and survey_type): # invalid task data, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid sendRemindersForProjectSurvey data: %s' % post_dict) # get the program for the given keyname program_entity = program_logic.getFromKeyName(program_key) if not program_entity: # invalid program specified, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid program specified: %s' % program_key) # check and retrieve the project_key that has been done last if 'project_key' in post_dict: project_start_key = post_dict['project_key'] else: project_start_key = None # get all valid StudentProjects from starting key fields = {'program': program_entity, 'status': 'accepted'} if project_start_key: # retrieve the last project that was done project_start = student_project_logic.getFromKeyName(project_start_key) if not project_start: # invalid starting project key specified, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid Student Project Key specified: %s' % (project_start_key)) fields['__key__ >'] = project_start.key() project_entities = student_project_logic.getForFields(fields, limit=batch_size) for project_entity in project_entities: # pass along these params as POST to the new task task_params = { 'survey_key': survey_key, 'survey_type': survey_type, 'project_key': project_entity.key().id_or_name() } task_url = '/tasks/surveys/projects/send_reminder/send' new_task = taskqueue.Task(params=task_params, url=task_url) new_task.add('mail') if len(project_entities) == batch_size: # spawn new task starting from the last new_project_start = project_entities[batch_size - 1].key().id_or_name() # pass along these params as POST to the new task task_params = { 'program_key': program_key, 'survey_key': survey_key, 'survey_type': survey_type, 'project_key': new_project_start } task_url = '/tasks/surveys/projects/send_reminder/spawn' new_task = taskqueue.Task(params=task_params, url=task_url) new_task.add() # return OK return http.HttpResponse()
def _getMapData(self, filter=None): """Constructs the JSON object required to generate Google Maps on organization home page. Args: filter: a dict for the properties that the entities should have Returns: A JSON object containing map data. """ from soc.modules.gsoc.logic.models.student_project import logic as \ student_project_logic from soc.modules.gsoc.views.models import student_project as \ student_project_view sp_params = student_project_view.view.getParams().copy() people = {} projects = {} # get all the student_project entities for the given filter student_project_entities = student_project_logic.getForFields( filter=filter) # Construct a dictionary of mentors and students. For each mentor construct # a list of 3-tuples containing student name, project title and url. # And for each student a list of 3 tuples containing mentor name, project # title and url. Only students and mentors who have agreed to publish their # locations will be in the dictionary. for entity in student_project_entities: project_key_name = entity.key().id_or_name() project_redirect = redirects.getPublicRedirect(entity, sp_params) student_entity = entity.student student_key_name = student_entity.key().id_or_name() mentor_entity = entity.mentor mentor_key_name = mentor_entity.key().id_or_name() # store the project data in the projects dictionary projects[project_key_name] = {'title': entity.title, 'redirect': project_redirect, 'student_key': student_key_name, 'student_name': student_entity.name(), 'mentor_key': mentor_key_name, 'mentor_name': mentor_entity.name()} if mentor_entity.publish_location: if mentor_key_name not in people: # we have not stored the information of this mentor yet people[mentor_key_name] = { 'type': 'mentor', 'name': mentor_entity.name(), 'lat': mentor_entity.latitude, 'lon': mentor_entity.longitude, 'projects': [] } # add this project to the mentor's list people[mentor_key_name]['projects'].append(project_key_name) if student_entity.publish_location: if student_key_name not in people: # new student, store the name and location people[student_key_name] = { 'type': 'student', 'name': student_entity.name(), 'lat': student_entity.latitude, 'lon': student_entity.longitude, 'projects': [], } # append the current project to the known student's list of projects people[student_key_name]['projects'].append(project_key_name) # combine the people and projects data into one JSON object data = {'people': people, 'projects': projects} return simplejson.dumps(data)
def spawnRemindersForProjectSurvey(request, *args, **kwargs): """Spawns tasks for each StudentProject in the given Program. Expects the following to be present in the POST dict: program_key: Specifies the program key name for which to loop over all the StudentProjects for survey_key: specifies the key name for the ProjectSurvey to send reminders for survey_type: either project or grading depending on the type of Survey project_key: optional to specify which project was the last for which a task was spawn Args: request: Django Request object """ from soc.modules.gsoc.logic.models.program import logic as program_logic from soc.modules.gsoc.logic.models.student_project import logic as \ student_project_logic # set default batch size batch_size = 10 post_dict = request.POST # retrieve the program_key and survey_key from POST data program_key = post_dict.get('program_key') survey_key = post_dict.get('survey_key') survey_type = post_dict.get('survey_type') if not (program_key and survey_key and survey_type): # invalid task data, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid sendRemindersForProjectSurvey data: %s' % post_dict) # get the program for the given keyname program_entity = program_logic.getFromKeyName(program_key) if not program_entity: # invalid program specified, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid program specified: %s' % program_key) # check and retrieve the project_key that has been done last if 'project_key' in post_dict: project_start_key = post_dict['project_key'] else: project_start_key = None # get all valid StudentProjects from starting key fields = {'program': program_entity, 'status': 'accepted'} if project_start_key: # retrieve the last project that was done project_start = student_project_logic.getFromKeyName(project_start_key) if not project_start: # invalid starting project key specified, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid Student Project Key specified: %s' %(project_start_key)) fields['__key__ >'] = project_start.key() project_entities = student_project_logic.getForFields(fields, limit=batch_size) for project_entity in project_entities: # pass along these params as POST to the new task task_params = {'survey_key': survey_key, 'survey_type': survey_type, 'project_key': project_entity.key().id_or_name()} task_url = '/tasks/surveys/projects/send_reminder/send' new_task = taskqueue.Task(params=task_params, url=task_url) new_task.add('mail') if len(project_entities) == batch_size: # spawn new task starting from the last new_project_start = project_entities[batch_size-1].key().id_or_name() # pass along these params as POST to the new task task_params = {'program_key': program_key, 'survey_key': survey_key, 'survey_type': survey_type, 'project_key': new_project_start} task_url = '/tasks/surveys/projects/send_reminder/spawn' new_task = taskqueue.Task(params=task_params, url=task_url) new_task.add() # return OK return http.HttpResponse()