def getRolesListData(self, request, lists_params): """Returns the list data for roles. """ user = user_logic.getCurrentUser() # only select the roles for the current user # pylint: disable=E1103 fields = { 'link_id': user.link_id, 'status': ['active', 'inactive'] } idx = lists.getListIndex(request) if not 0 <= idx < len(lists_params): return lists.getErrorResponse(request, 'idx not valid') list_params = lists_params[idx] if list_params is None: return lists.getErrorResponse( request, 'idx not valid (list not in roles overview)') contents = helper.lists.getListData(request, list_params, fields) return lists.getResponse(request, contents)
def getAcceptedOrgsData(self, request, aa_params, ap_params, org_app_logic, program_entity): """Get acceptedOrgs data. """ idx = lists.getListIndex(request) if idx == 0: params = ap_params fields = { 'scope': program_entity, 'status': ['new', 'active', 'inactive'] } elif idx == 1: params = aa_params org_app = org_app_logic.getForProgram(program_entity) fields = { 'survey': org_app, 'status': 'accepted', } else: return lists.getErrorResponse(request, "idx not valid") contents = lists.getListData(request, params, fields) return lists.getResponse(request, contents)
def _getManageData(self, request, gps_params, ps_params, entity): """Returns the JSONResponse for the Manage page. Args: request: HTTPRequest object gps_params: GradingProjectSurvey list params ps_params: ProjectSurvey list params entity: StudentProject entity """ idx = lists.getListIndex(request) if idx == 0: params = gps_params elif idx == 1: params = ps_params else: return lists.getErrorResponse(request, "idx not valid") fields = {'project': entity} record_logic = params['logic'].getRecordLogic() record_entities = record_logic.getForFields(fields) record_dict = dict( (i.survey.key(), i) for i in record_entities if i.survey) record_getter = lambda entity: record_dict.get(entity.key()) args = [record_getter] fields = {'scope': entity.program, 'prefix': 'gsoc_program'} contents = lists.getListData(request, params, fields, args=args) return lists.getResponse(request, contents)
def getListTasksData(self, request, params, tasks_filter): """Returns the list data for all tasks list for program host and all public tasks for others. Args: request: HTTPRequest object params: params of the task entity for the list tasks_filter: dictionary that must be passed to obtain the tasks data """ idx = lists.getListIndex(request) # default list settings visibility = 'public' if idx == 0: all_d = gci_task_model.TaskDifficultyTag.all().fetch(100) all_t = gci_task_model.TaskTypeTag.all().fetch(100) args = [all_d, all_t] contents = lists.getListData(request, params, tasks_filter, visibility=visibility, args=args) else: return lists.getErrorResponse(request, "idx not valid") return lists.getResponse(request, contents)
def _getManageData(self, request, gps_params, ps_params, entity): """Returns the JSONResponse for the Manage page. Args: request: HTTPRequest object gps_params: GradingProjectSurvey list params ps_params: ProjectSurvey list params entity: StudentProject entity """ idx = lists.getListIndex(request) if idx == 0: params = gps_params elif idx == 1: params = ps_params else: return lists.getErrorResponse(request, "idx not valid") fields = {'project': entity} record_logic = params['logic'].getRecordLogic() record_entities = record_logic.getForFields(fields) record_dict = dict((i.survey.key(), i) for i in record_entities if i.survey) record_getter = lambda entity: record_dict.get(entity.key()) args = [record_getter] fields = {'scope': entity.program, 'prefix': 'gsoc_program'} contents = lists.getListData(request, params, fields, args=args) return lists.getResponse(request, contents)
def getListParticipantsData(self, request, params, program_entity): """Returns the list data. """ from django.utils import simplejson from soc.views.models.role import ROLE_VIEWS idx = lists.getListIndex(request) participants_logic = params['participants_logic'] if idx == -1 or idx > len(participants_logic): return lists.getErrorResponse(request, "idx not valid") # get role params that belong to the given index (role_logic, query_field) = participants_logic[idx] role_view = ROLE_VIEWS[role_logic.role_name] role_params = role_view.getParams().copy() # construct the query for the specific list fields = {query_field: program_entity} # return getListData contents = lists.getListData(request, role_params, fields, visibility='admin') return lists.getResponse(request, contents)
def getListMentorTasksData(self, request, params, filter): """Returns the list data for Organization Tasks list. Args: request: HTTPRequest object params: params of the task entity for the list filter: properties on which the tasks must be listed """ idx = lists.getListIndex(request) # default list settings visibility = 'public' if idx == 0: all_d = gci_task_model.TaskDifficultyTag.all().fetch(100) all_t = gci_task_model.TaskTypeTag.all().fetch(100) args = [all_d, all_t] contents = lists.getListData(request, params, filter, visibility=visibility, args=args) else: return lists.getErrorResponse(request, "idx not valid") return lists.getResponse(request, contents)
def getManageStatisticsData(self, request, params_collection, program): """Returns the list data for manageStats. Args: request: HTTPRequest object params_collection: List of list Params indexed with the idx of the list program: program entity for which the lists are generated """ idx = lists.getListIndex(request) args = order = [] visibility = 'public' if idx == self.DEF_EACH_GSOC_LIST_IDX: fields = {'access_for_other_programs': ['visible', 'collectable']} elif idx == self.DEF_ONE_GSOC_LIST_IDX: fields = { 'scope': program, 'access_for_other_programs': 'invisible' } else: return lists.getErrorResponse(request, "idx not valid") params = params_collection[idx] contents = helper.lists.getListData(request, params, fields) return lists.getResponse(request, contents)
def getListMyTasksData(self, request, task_params, subscription_params, program, user): """Returns the list data for the starred tasks of the current user. Args: request: HTTPRequest object task_params: params of the task entity for the list subscription_params: params for the task subscription entity for the list program: the GCIProgram to show the tasks for user: The user entity to show the tasks for """ idx = lists.getListIndex(request) all_d = gci_task_model.TaskDifficultyTag.all().fetch(100) all_t = gci_task_model.TaskTypeTag.all().fetch(100) args = [all_d, all_t] if idx == 0: filter = { 'program': program, 'user': user, 'status': ['ClaimRequested', 'Claimed', 'ActionNeeded', 'Closed', 'AwaitingRegistration', 'NeedsWork', 'NeedsReview'] } contents = lists.getListData(request, task_params, filter, args=args) elif idx == 1: filter = {'subscribers': user} contents = lists.getListData(request, subscription_params, filter, args=args) else: return lists.getErrorResponse(request, 'idx not valid') return lists.getResponse(request, contents)
def getManageStatisticsData(self, request, params_collection, program): """Returns the list data for manageStats. Args: request: HTTPRequest object params_collection: List of list Params indexed with the idx of the list program: program entity for which the lists are generated """ idx = lists.getListIndex(request) args = order = [] visibility = 'public' if idx == self.DEF_EACH_GSOC_LIST_IDX: fields = { 'access_for_other_programs': ['visible', 'collectable'] } elif idx == self.DEF_ONE_GSOC_LIST_IDX: fields = { 'scope': program, 'access_for_other_programs' : 'invisible' } else: return lists.getErrorResponse(request, "idx not valid") params = params_collection[idx] contents = helper.lists.getListData(request, params, fields) return lists.getResponse(request, contents)
def getRequestsListData(self, request, uh_params, ar_params): """Returns the list data for getRequestsList. """ idx = lists.getListIndex(request) # get the current user user_entity = user_logic.getCurrentUser() # only select the Invites for this user that haven't been handled yet # pylint: disable=E1103 filter = {'user': user_entity} if idx == 0: filter['status'] = 'group_accepted' params = uh_params elif idx == 1: filter['status'] = 'new' params = ar_params else: return lists.getErrorResponse(request, "idx not valid") contents = helper.lists.getListData(request, params, filter, visibility='public') return lists.getResponse(request, contents)
def getListData(self, request, params, visibility, filter): """Returns the list data. """ idx = lists.getListIndex(request) if idx != 0: return lists.getErrorResponse(request, "idx not valid") contents = lists.getListData(request, params, filter, visibility=visibility) return lists.getResponse(request, contents)
def getManageOverviewData(self, request, mo_params, org_entity): """Returns the manageOverview data. """ args = [] fields = {} idx = lists.getListIndex(request) if idx == 0: from soc.modules.gsoc.logic.models.survey import grading_logic as \ grading_survey_logic from soc.modules.gsoc.logic.models.survey import project_logic as \ project_survey_logic from soc.modules.gsoc.logic.models.survey_record import grading_logic from soc.modules.gsoc.logic.models.survey_record import project_logic program_entity = org_entity.scope fields = {'scope_path': program_entity.key().id_or_name()} # count the number of have been active ProjectSurveys project_surveys = project_survey_logic.getForFields(fields) project_survey_count = len(project_surveys) for project_survey in project_surveys: if not project_survey_logic.hasRecord(project_survey): project_survey_count = project_survey_count - 1 # count the number of have been active GradingProjectSurveys grading_surveys = grading_survey_logic.getForFields(fields) grading_survey_count = len(grading_surveys) for grading_survey in grading_surveys: if not grading_survey_logic.hasRecord(grading_survey): grading_survey_count = grading_survey_count - 1 fields = {'scope': org_entity} params = mo_params args = [ project_surveys, project_survey_count, grading_surveys, grading_survey_count ] else: return lists.getErrorResponse(request, 'idx not valid') contents = lists.getListData(request, params, fields, args=args) return lists.getResponse(request, contents)
def getHomeData(self, request, ap_params, entity): """Returns the home data. """ idx = lists.getListIndex(request) if idx == 0: params = ap_params # only show projects that have not failed fields = {'scope': entity, 'status': ['accepted', 'completed']} else: return lists.getErrorResponse(request, "idx not valid") contents = lists.getListData(request, params, fields, 'org_home') return lists.getResponse(request, contents)
def getListRolesData(self, request, list_params, group_entity): """Returns the list data for listRoles. """ idx = lists.getListIndex(request) if not 0 <= idx < len(list_params): return lists.getErrorResponse(request, "idx not valid") # create the filter fields = {'scope': group_entity, 'status': 'active'} params = list_params[idx] contents = lists.getListData(request, params, fields) return lists.getResponse(request, contents)
def getOverviewData(self, request, params, program): """Return data for withdraw. """ fields = { 'program': program, } idx = lists.getListIndex(request) if idx != 0: return lists.getErrorResponse(request, "idx not valid") contents = lists.getListData(request, params, fields, visibility='admin') return lists.getResponse(request, contents)
def getManageOverviewData(self, request, mo_params, org_entity): """Returns the manageOverview data. """ args = [] fields = {} idx = lists.getListIndex(request) if idx == 0: from soc.modules.gsoc.logic.models.survey import grading_logic as \ grading_survey_logic from soc.modules.gsoc.logic.models.survey import project_logic as \ project_survey_logic from soc.modules.gsoc.logic.models.survey_record import grading_logic from soc.modules.gsoc.logic.models.survey_record import project_logic program_entity = org_entity.scope fields = {'scope_path': program_entity.key().id_or_name()} # count the number of have been active ProjectSurveys project_surveys = project_survey_logic.getForFields(fields) project_survey_count = len(project_surveys) for project_survey in project_surveys: if not project_survey_logic.hasRecord(project_survey): project_survey_count = project_survey_count - 1 # count the number of have been active GradingProjectSurveys grading_surveys = grading_survey_logic.getForFields(fields) grading_survey_count = len(grading_surveys) for grading_survey in grading_surveys: if not grading_survey_logic.hasRecord(grading_survey): grading_survey_count = grading_survey_count - 1 fields = {'scope': org_entity} params = mo_params args = [project_surveys, project_survey_count, grading_surveys, grading_survey_count] else: return lists.getErrorResponse(request, 'idx not valid') contents = lists.getListData(request, params, fields, args=args) return lists.getResponse(request, contents)
def getHomeData(self, request, ap_params, entity): """Returns the home data. """ idx = lists.getListIndex(request) if idx == 0: params = ap_params # only show projects that have not failed fields= {'scope': entity, 'status': ['accepted', 'completed']} else: return lists.getErrorResponse(request, "idx not valid") contents = lists.getListData(request, params, fields, 'org_home') return lists.getResponse(request, contents)
def getListRolesData(self, request, list_params, group_entity): """Returns the list data for listRoles. """ idx = lists.getListIndex(request) if not 0 <= idx < len(list_params): return lists.getErrorResponse(request, "idx not valid") # create the filter fields= { 'scope' : group_entity, 'status': 'active' } params = list_params[idx] contents = lists.getListData(request, params, fields) return lists.getResponse(request, contents)
def getListMyTasksData(self, request, task_params, subscription_params, program, user): """Returns the list data for the starred tasks of the current user. Args: request: HTTPRequest object task_params: params of the task entity for the list subscription_params: params for the task subscription entity for the list program: the GCIProgram to show the tasks for user: The user entity to show the tasks for """ idx = lists.getListIndex(request) all_d = gci_task_model.TaskDifficultyTag.all().fetch(100) all_t = gci_task_model.TaskTypeTag.all().fetch(100) args = [all_d, all_t] if idx == 0: filter = { 'program': program, 'user': user, 'status': [ 'ClaimRequested', 'Claimed', 'ActionNeeded', 'Closed', 'AwaitingRegistration', 'NeedsWork', 'NeedsReview' ] } contents = lists.getListData(request, task_params, filter, args=args) elif idx == 1: filter = {'subscribers': user} contents = lists.getListData(request, subscription_params, filter, args=args) else: return lists.getErrorResponse(request, 'idx not valid') return lists.getResponse(request, contents)
def getListSelfData(self, request, list_params, ip_params, scope_path): """Returns the listSelf data. """ student_entity = student_logic.logic.getFromKeyName(scope_path) fields = {'scope' : student_entity} idx = lists.getListIndex(request) if idx == 0: fields['status'] = ['new', 'pending', 'accepted', 'rejected'] params = list_params elif idx == 1: fields['status'] = 'invalid' params = ip_params else: return lists.getErrorResponse(request, "idx not valid") contents = lists.getListData(request, params, fields) return lists.getResponse(request, contents)
def getListTasksData(self, request, params, org_entity): """Returns the list data for Organization Tasks list. Args: request: HTTPRequest object params_collection: List of list Params indexed with the idx of the list org_entity: GCIOrganization entity for which the lists are generated """ idx = lists.getListIndex(request) # default list settings visibility = "home" if idx == 0: filter = { "scope": org_entity, "status": [ "Open", "Reopened", "ClaimRequested", "Claimed", "ActionNeeded", "Closed", "AwaitingRegistration", "NeedsWork", "NeedsReview", ], } else: return lists.getErrorResponse(request, "idx not valid") all_d = gci_task_model.TaskDifficultyTag.all().fetch(100) all_t = gci_task_model.TaskTypeTag.all().fetch(100) args = [all_d, all_t] contents = lists.getListData(request, params, filter, visibility=visibility, args=args) return lists.getResponse(request, contents)
def getListTasksData(self, request, params, org_entity): """Returns the list data for Organization Tasks list. Args: request: HTTPRequest object params_collection: List of list Params indexed with the idx of the list org_entity: GCIOrganization entity for which the lists are generated """ idx = lists.getListIndex(request) # default list settings visibility = 'home' if idx == 0: filter = { 'scope': org_entity, 'status': [ 'Open', 'Reopened', 'ClaimRequested', 'Claimed', 'ActionNeeded', 'Closed', 'AwaitingRegistration', 'NeedsWork', 'NeedsReview' ] } else: return lists.getErrorResponse(request, "idx not valid") all_d = gci_task_model.TaskDifficultyTag.all().fetch(100) all_t = gci_task_model.TaskTypeTag.all().fetch(100) args = [all_d, all_t] contents = lists.getListData(request, params, filter, visibility=visibility, args=args) return lists.getResponse(request, contents)
def _getListSelfData(self, request, entity, ma_params, ba_params): """Returns the listSelf data. """ from soc.logic.models.user import logic as user_logic user_entity = user_logic.getCurrentUser() idx = lists.getListIndex(request) if idx == 0: fields = {'survey': entity, 'main_admin': user_entity} params = ma_params elif idx == 1: fields = {'survey': entity, 'backup_admin': user_entity} params = ba_params else: return lists.getErrorResponse(request, "idx not valid") contents = lists.getListData(request, params, fields, visibility='self') return lists.getResponse(request, contents)
def getListProposalsData(self, request, params_collection, org_entity): """Returns the list data for listProposals. Args: request: HTTPRequest object params_collection: List of list Params indexed with the idx of the list org_entity: GSoCOrganization entity for which the lists are generated """ from soc.modules.gsoc.logic.models.proposal_duplicates import logic \ as pd_logic from soc.modules.gsoc.logic.models.ranker_root import logic \ as ranker_root_logic idx = lists.getListIndex(request) # default list settings args = [] visibility = None if idx == 0: filter = {'org': org_entity, 'status': 'new'} elif idx == 1: # retrieve the ranker fields = {'link_id': student_proposal.DEF_RANKER_NAME, 'scope': org_entity} ranker_root = ranker_root_logic.getForFields(fields, unique=True) ranker = ranker_root_logic.getRootFromEntity(ranker_root) status = {} program_entity = org_entity.scope # only when the program allows allocations # we show that proposals are likely to be # accepted or rejected if program_entity.allocations_visible: proposals = sp_logic.getProposalsToBeAcceptedForOrg(org_entity) duplicate_proposals = [] # get all the duplicate entities if duplicates can be shown # to the organizations and make a list of all such proposals. if program_entity.duplicates_visible: duplicate_properties = { 'orgs': org_entity, 'is_duplicate': True } duplicates = pd_logic.getForFields(duplicate_properties) for duplicate in duplicates: duplicate_proposals.extend(duplicate.duplicates) for proposal in proposals: proposal_key = proposal.key() if proposal.status == 'pending' and proposal_key in duplicate_proposals: status[proposal_key] = """<strong><font color="red"> Duplicate</font></strong>""" else: status[proposal_key] = """<strong><font color="green"> Pending acceptance</font><strong>""" filter = {'org': org_entity, 'status': ['accepted','pending','rejected']} # some extras for the list args = [ranker, status] visibility = 'review' elif idx == 2: # check if the current user is a mentor user_entity = user_logic.getCurrentUser() fields = {'user': user_entity, 'scope': org_entity, 'status': ['active', 'inactive']} mentor_entity = mentor_logic.getForFields(fields, unique=True) filter = {'org': org_entity, 'mentor': mentor_entity, 'status': ['pending', 'accepted', 'rejected']} elif idx == 3: filter = {'org': org_entity, 'status': 'invalid'} else: return lists.getErrorResponse(request, "idx not valid") params = params_collection[idx] contents = helper.lists.getListData(request, params, filter, visibility=visibility, args=args) return lists.getResponse(request, contents)
def getListProposalsData(self, request, params_collection, org_entity): """Returns the list data for listProposals. Args: request: HTTPRequest object params_collection: List of list Params indexed with the idx of the list org_entity: GSoCOrganization entity for which the lists are generated """ from soc.modules.gsoc.logic.models.proposal_duplicates import logic \ as pd_logic from soc.modules.gsoc.logic.models.ranker_root import logic \ as ranker_root_logic idx = lists.getListIndex(request) # default list settings args = [] visibility = None if idx == 0: filter = {'org': org_entity, 'status': 'new'} elif idx == 1: # retrieve the ranker fields = { 'link_id': student_proposal.DEF_RANKER_NAME, 'scope': org_entity } ranker_root = ranker_root_logic.getForFields(fields, unique=True) ranker = ranker_root_logic.getRootFromEntity(ranker_root) status = {} program_entity = org_entity.scope # only when the program allows allocations # we show that proposals are likely to be # accepted or rejected if program_entity.allocations_visible: proposals = sp_logic.getProposalsToBeAcceptedForOrg(org_entity) duplicate_proposals = [] # get all the duplicate entities if duplicates can be shown # to the organizations and make a list of all such proposals. if program_entity.duplicates_visible: duplicate_properties = { 'orgs': org_entity, 'is_duplicate': True } duplicates = pd_logic.getForFields(duplicate_properties) for duplicate in duplicates: duplicate_proposals.extend(duplicate.duplicates) for proposal in proposals: proposal_key = proposal.key() if proposal.status == 'pending' and proposal_key in duplicate_proposals: status[proposal_key] = """<strong><font color="red"> Duplicate</font></strong>""" else: status[proposal_key] = """<strong><font color="green"> Pending acceptance</font><strong>""" filter = { 'org': org_entity, 'status': ['accepted', 'pending', 'rejected'] } # some extras for the list args = [ranker, status] visibility = 'review' elif idx == 2: # check if the current user is a mentor user_entity = user_logic.getCurrentUser() fields = { 'user': user_entity, 'scope': org_entity, 'status': ['active', 'inactive'] } mentor_entity = mentor_logic.getForFields(fields, unique=True) filter = { 'org': org_entity, 'mentor': mentor_entity, 'status': ['pending', 'accepted', 'rejected'] } elif idx == 3: filter = {'org': org_entity, 'status': 'invalid'} else: return lists.getErrorResponse(request, "idx not valid") params = params_collection[idx] contents = helper.lists.getListData(request, params, filter, visibility=visibility, args=args) return lists.getResponse(request, contents)