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 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 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 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 _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 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 getListRankingDetailsData(self, request, params, student): """Returns the list data for Ranking Details 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 """ filter = { 'student': student, 'status': 'Closed', } visibility = 'public' args = [] params['logic'] = gci_task_logic contents = lists.getListData(request, params, filter, visibility=visibility, args=args) 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 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 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 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 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 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 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 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 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 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 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 reviewOverview(self, request, access_type, page_name=None, params=None, **kwargs): """Displays a list of applications that are in a different status of the application process. """ survey_logic = params['logic'] entity = survey_logic.getFromKeyFieldsOr404(kwargs) if request.POST: # POST request received, check and respond to button actions post_dict = request.POST if post_dict.get('button_id') == 'bulk_process': params['bulk_process_task'].start(entity.scope) if post_dict.get( 'button_id') == 'save_status' and 'data' in request.POST: self.processSaveReview(request.POST['data']) return http.HttpResponse() list_params = params['record_list_params'].copy() list_params['list_description'] = ( 'List of all the Organization Applications made to the %s program. ' 'Click an application to review it, or use the buttons on the top of ' 'the list for bulk actions.' % (entity.scope.name)) info = {'url_name': params['url_name'], 'survey': entity} choices = org_app_record.OrgAppRecord.status.choices values = ";".join("%s:%s" % (i, i.capitalize()) for i in choices) list_params['overview_field_props'] = { 'status': { 'editable': True, 'edittype': "select", 'editoptions': { 'value': values } } } # define the basic fields for the overview list list_params['overview_field_keys'] = [ 'name', 'home_page', 'details', 'status', ] list_params['overview_field_names'] = [ 'Organization Name', 'Home Page', 'Details', 'Application Status', ] list_params['overview_field_extra'] = lambda entity: { 'home_page': lists.urlize(entity.home_page), 'status': entity.status.capitalize(), 'details': lists.urlize(redirects.getReviewOrgAppSurvey(entity, info), name="[details]"), } list_params['overview_button_global'] = [ { 'bounds': [0, 'all'], 'id': 'bulk_process', 'caption': 'Bulk Accept/Reject Organizations', 'type': 'post', 'parameters': { 'url': '' }, }, { 'id': 'save_status', 'caption': 'Save status', 'type': 'post_edit', 'parameters': { 'url': '', 'keys': ['key'], 'refresh': 'current', }, }, ] list_params['overview_row_action'] = { "type": "redirect_custom", "parameters": dict(new_window=False), } self._extendListWithSurveyAnswers(list_params, entity, 'overview') if lists.isDataRequest(request): # get all records for the entity specified in the URL fields = {'survey': entity} # use the overview visibility to show the correct columns to the Host contents = lists.getListData(request, list_params, fields, visibility='overview') return lists.getResponse(request, contents) overview_list = lists.getListGenerator(request, list_params, visibility='overview', idx=0) contents = [overview_list] return self._list(request, list_params, contents, page_name)
def reviewOverview(self, request, access_type, page_name=None, params=None, **kwargs): """Displays a list of applications that are in a different status of the application process. """ survey_logic = params['logic'] entity = survey_logic.getFromKeyFieldsOr404(kwargs) if request.POST: # POST request received, check and respond to button actions post_dict = request.POST if post_dict.get('button_id') == 'bulk_process': params['bulk_process_task'].start(entity.scope) if post_dict.get('button_id') == 'save_status' and 'data' in request.POST: self.processSaveReview(request.POST['data']) return http.HttpResponse() list_params = params['record_list_params'].copy() list_params['list_description'] = ( 'List of all the Organization Applications made to the %s program. ' 'Click an application to review it, or use the buttons on the top of ' 'the list for bulk actions.' %(entity.scope.name)) info = {'url_name': params['url_name'], 'survey':entity} choices = org_app_record.OrgAppRecord.status.choices values = ";".join("%s:%s" % (i, i.capitalize()) for i in choices) list_params['overview_field_props'] = {'status': { 'editable': True, 'edittype': "select", 'editoptions': { 'value': values } }} # define the basic fields for the overview list list_params['overview_field_keys'] = [ 'name', 'home_page', 'details', 'status', ] list_params['overview_field_names'] = [ 'Organization Name', 'Home Page', 'Details', 'Application Status', ] list_params['overview_field_extra'] = lambda entity: { 'home_page': lists.urlize(entity.home_page), 'status': entity.status.capitalize(), 'details': lists.urlize( redirects.getReviewOrgAppSurvey(entity, info), name="[details]"), } list_params['overview_button_global'] = [ { 'bounds': [0,'all'], 'id': 'bulk_process', 'caption': 'Bulk Accept/Reject Organizations', 'type': 'post', 'parameters': {'url': ''}, }, { 'id': 'save_status', 'caption': 'Save status', 'type': 'post_edit', 'parameters': { 'url': '', 'keys': ['key'], 'refresh': 'current', }, }, ] list_params['overview_row_action'] = { "type": "redirect_custom", "parameters": dict(new_window=False), } self._extendListWithSurveyAnswers(list_params, entity, 'overview') if lists.isDataRequest(request): # get all records for the entity specified in the URL fields = {'survey': entity} # use the overview visibility to show the correct columns to the Host contents = lists.getListData(request, list_params, fields, visibility='overview') return lists.getResponse(request, contents) overview_list = lists.getListGenerator(request, list_params, visibility='overview', idx=0) contents = [overview_list] return self._list(request, list_params, contents, page_name)
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 showRanking(self, request, access_type, page_name=None, params=None, **kwargs): """Shows the ranking for the program specified by **kwargs. Args: request: the standard Django HTTP request object access_type : the name of the access type which should be checked page_name: the page name displayed in templates as page and header title params: a dict with params for this View kwargs: the Key Fields for the specified entity """ from soc.modules.gci.views.models.student_ranking import view as ranking_view from soc.modules.gci.views.models.student import view as student_view sparams = student_view.getParams() user_account = user_logic.getCurrentUser() user_fields = { 'user': user_account, 'status': 'active' } host_entity = host_logic.getForFields(user_fields, unique=True) is_host = host_entity or user_logic.isDeveloper(user=user_account) logic = params['logic'] program = logic.getFromKeyFieldsOr404(kwargs) list_params = ranking_view.getParams().copy() list_params['list_description'] = self.DEF_LIST_RANKING_MSG_FMT % ( program.name) list_params['public_field_keys'] = ["student", "points", "number"] list_params['public_field_names'] = ["Student", "Points", "Number of tasks"] list_params['public_conf_extra'] = { "rowNum": -1, "rowList": [], } list_params['public_field_prefetch'] = ['student'] def getExtraFields(entity, *args): res = { 'student': entity.student.user.name, 'number': len(entity.tasks) } if is_host: fields = sparams['admin_field_keys'] extra = dicts.toDict(entity.student, fields) res.update(extra) res['group_name'] = entity.student.scope.name res['birth_date'] = entity.student.birth_date.isoformat() res['account_name'] = accounts.normalizeAccount(entity.student.user.account).email() res['forms_submitted'] = "Yes" if (entity.student.consent_form and entity.student.student_id_form) else "No" return res list_params['public_field_extra'] = getExtraFields list_params['public_row_extra'] = lambda entity, *args: { 'link': gci_redirects.getShowRankingDetails(entity, list_params) } list_params['public_field_props'] = { 'points': { 'sorttype': 'integer', }, 'number': { 'sorttype': 'integer', }, } if is_host: list_params['public_field_keys'] += ["forms_submitted"] list_params['public_field_names'] += ["Forms submitted"] list_params['public_field_hidden'] = sparams['admin_field_hidden'] + sparams['admin_field_keys'] list_params['public_field_keys'].extend(sparams['admin_field_keys']) list_params['public_field_names'].extend(sparams['admin_field_names']) ranking_filter = { 'scope': program } order = ['-points'] if lists.isDataRequest(request): contents = lists.getListData(request, list_params, ranking_filter) return lists.getResponse(request, contents) contents = [lists.getListGenerator( request, list_params, order=order, idx=0)] return self._list(request, list_params, contents=contents, page_name=page_name)
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 showRanking(self, request, access_type, page_name=None, params=None, **kwargs): """Shows the ranking for the program specified by **kwargs. Args: request: the standard Django HTTP request object access_type : the name of the access type which should be checked page_name: the page name displayed in templates as page and header title params: a dict with params for this View kwargs: the Key Fields for the specified entity """ from soc.modules.gci.views.models.student_ranking import view as ranking_view from soc.modules.gci.views.models.student import view as student_view sparams = student_view.getParams() user_account = user_logic.getCurrentUser() user_fields = {'user': user_account, 'status': 'active'} host_entity = host_logic.getForFields(user_fields, unique=True) is_host = host_entity or user_logic.isDeveloper(user=user_account) logic = params['logic'] program = logic.getFromKeyFieldsOr404(kwargs) list_params = ranking_view.getParams().copy() list_params['list_description'] = self.DEF_LIST_RANKING_MSG_FMT % ( program.name) list_params['public_field_keys'] = ["student", "points", "number"] list_params['public_field_names'] = [ "Student", "Points", "Number of tasks" ] list_params['public_conf_extra'] = { "rowNum": -1, "rowList": [], } list_params['public_field_prefetch'] = ['student'] def getExtraFields(entity, *args): res = { 'student': entity.student.user.name, 'number': len(entity.tasks) } if is_host: fields = sparams['admin_field_keys'] extra = dicts.toDict(entity.student, fields) res.update(extra) res['group_name'] = entity.student.scope.name res['birth_date'] = entity.student.birth_date.isoformat() res['account_name'] = accounts.normalizeAccount( entity.student.user.account).email() res['forms_submitted'] = "Yes" if ( entity.student.consent_form and entity.student.student_id_form) else "No" return res list_params['public_field_extra'] = getExtraFields list_params['public_row_extra'] = lambda entity, *args: { 'link': gci_redirects.getShowRankingDetails(entity, list_params) } list_params['public_field_props'] = { 'points': { 'sorttype': 'integer', }, 'number': { 'sorttype': 'integer', }, } if is_host: list_params['public_field_keys'] += ["forms_submitted"] list_params['public_field_names'] += ["Forms submitted"] list_params['public_field_hidden'] = sparams[ 'admin_field_hidden'] + sparams['admin_field_keys'] list_params['public_field_keys'].extend( sparams['admin_field_keys']) list_params['public_field_names'].extend( sparams['admin_field_names']) ranking_filter = {'scope': program} order = ['-points'] if lists.isDataRequest(request): contents = lists.getListData(request, list_params, ranking_filter) return lists.getResponse(request, contents) contents = [ lists.getListGenerator(request, list_params, order=order, idx=0) ] return self._list(request, list_params, contents=contents, page_name=page_name)