def getRankerFor(self, entity): """Returns the ranker for the given Student Proposal. Args: entity: Student Proposal entity for which the ranker should be returned Returns: Ranker object which is used to rank the given entity """ from soc.modules.gsoc.logic.models.ranker_root import logic \ as ranker_root_logic fields = { 'link_id': soc.modules.gsoc.models.student_proposal.DEF_RANKER_NAME, 'scope': entity.org } ranker_root = ranker_root_logic.getForFields(fields, unique=True) ranker = ranker_root_logic.getRootFromEntity(ranker_root) return ranker
def getListProposalsData(self, request, rp_params, mp_params, p_params, org_entity): """Returns the list data for listProposals. """ from soc.modules.gsoc.logic.models.ranker_root import logic \ as ranker_root_logic from soc.modules.gsoc.logic.models.student_proposal import logic \ as sp_logic from soc.modules.gsoc.models import student_proposal from soc.modules.gsoc.views.helper import list_info as list_info_helper from soc.modules.gsoc.views.models import student_proposal \ as student_proposal_view idx = request.GET.get('idx', '') idx = int(idx) if idx.isdigit() else -1 args = order = [] if idx == 0: # 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) keys = [] # only when the program allows allocations # to be seen we should color the list if org_entity.scope.allocations_visible: proposals = sp_logic.getProposalsToBeAcceptedForOrg(org_entity) keys = [i.key() for i in proposals] # show the amount of slots assigned on the webpage context['slots_visible'] = True # TODO(ljvderijk) once sorting with IN operator is fixed, # make this list show more filter = {'org': org_entity, 'status': 'pending'} params = rp_params # order by descending score order = ['-score'] args = [ranker, keys] elif idx == 1: # check if the current user is a mentor user_entity = user_logic.getForCurrentAccount() fields = { 'user': user_entity, 'scope': org_entity, } mentor_entity = mentor_logic.getForFields(fields, unique=True) filter = { 'org': org_entity, 'mentor': mentor_entity, 'status': 'pending' } params = mp_params elif idx == 2: filter = {'org': org_entity} params = p_params else: return responses.jsonErrorResponse(request, "idx not valid") contents = helper.lists.getListData(request, params, filter, 'public', order=order, args=args) json = simplejson.dumps(contents) return responses.jsonResponse(request, json)
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)