def overviewGet(self, request, page_name, params, program_entity, **kwargs): """Handles the GET request for the Program Admins overview page. Args: request: Django HTTPRequest object page_name: Name for this page params: Params for this view program_entity: GSocProgram entity """ page_name = '%s %s' %(page_name, program_entity.name) list_params = params.copy() list_params['admin_row_extra'] = lambda entity: { 'link': redirects.getPublicRedirect(entity, list_params) } list_params['list_description'] = ugettext( 'An overview of all StudentProjects for %s. Click on an item to view ' 'the project, use the buttons on the list for withdrawing a project.'% (program_entity.name)) if lists.isDataRequest(request): return self.getOverviewData(request, list_params, program_entity) project_list = lists.getListGenerator(request, list_params, idx=0, visibility='admin') # fill contents with the list contents = [project_list] # call the _list method from base to display the list return self._list(request, params, contents, page_name)
def list(self, request, access_type, page_name=None, params=None, filter=None, order=None, visibility=None, context=None, **kwargs): """Displays the list page for the entity type. 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 filter: a dict for the properties that the entities should have Params usage: The params dictionary is passed as argument to getListContent in the soc.views.helper.list module. See the docstring for getListContent on how it uses it. The params dictionary is also passed as argument to the _list method. See the docstring for _list on how it uses it. """ if lists.isDataRequest(request): return self.getListData(request, params, visibility, filter) content = lists.getListGenerator(request, params, order=order, visibility=visibility, idx=0) contents = [content] return self._list(request, params, contents, page_name, context=context)
def home(self, request, access_type, page_name=None, params=None, **kwargs): """See base.View._public(). """ from soc.modules.gci.views.models import task as gci_task_view context = {"list": []} entity = self._params["logic"].getFromKeyFieldsOr404(kwargs) gci_program_entity = entity.scope params = params.copy() if params else {} is_after_student_signup = timeline_helper.isAfterEvent(gci_program_entity.timeline, "student_signup_start") is_after_tasks_become_public = timeline_helper.isAfterEvent( gci_program_entity.timeline, "tasks_publicly_visible" ) if is_after_student_signup and is_after_tasks_become_public: list_params = gci_task_view.view.getParams().copy() list_params["list_description"] = self.DEF_PROJECTS_MSG_FMT % (entity.name) if lists.isDataRequest(request): return self.getListTasksData(request, list_params, entity) content = lists.getListGenerator(request, list_params, visibility="home", idx=0) contents = [content] context["list"] = soc.logic.lists.Lists(contents) params["context"] = context return super(View, self).home(request, "any_access", page_name=page_name, params=params, **kwargs)
def listParticipants(self, request, access_type, page_name=None, params=None, **kwargs): """View that lists the roles of all the participants for a single Program. For args see base.list(). """ from soc.views.models.role import ROLE_VIEWS program_logic = params['logic'] program_entity = program_logic.getFromKeyFieldsOr404(kwargs) if lists.isDataRequest(request): return self.getListParticipantsData(request, params, program_entity) # we need to generate the lists to be shown on this page participants = [] idx = 0 for (role_logic, _) in params['participants_logic']: # retrieve the role view belonging to the logic role_view = ROLE_VIEWS[role_logic.role_name] role_params = role_view.getParams().copy() role_params['list_description'] = 'List of All %s' %( role_params['name_plural']) role_list = lists.getListGenerator(request, role_params, visibility='admin', idx=idx) participants.append(role_list) idx = idx + 1 page_name = '%s %s' %(page_name, program_entity.name) return self._list(request, params, contents=participants, page_name=page_name)
def acceptedOrgs(self, request, page_name, params, program_entity, org_view, org_app_view): """See base.View.list. """ logic = params['logic'] list_params = org_view.getParams().copy() list_params['list_msg'] = program_entity.accepted_orgs_msg fmt = {'name': program_entity.name} org_app_params = org_app_view.getParams() # try to retrieve an accepted record org_app_logic = org_app_params['logic'] org_app = org_app_logic.getForProgram(program_entity) aa_params = org_app_params['record_list_params'].copy( ) # accepted applications aa_params['public_row_extra'] = lambda entity: {} description = self.DEF_ACCEPTED_ORGS_MSG_FMT % fmt aa_params['list_description'] = description aa_params['public_conf_extra'] = { "rowNum": -1, "rowList": [], } description = self.DEF_CREATED_ORGS_MSG_FMT % fmt ap_params = org_view.getParams().copy() ap_params['list_description'] = description ap_params['public_row_extra'] = lambda entity: { 'link': redirects.getHomeRedirect(entity, ap_params), } ap_params['public_conf_extra'] = { "rowNum": -1, "rowList": [], } if lists.isDataRequest(request): return self.getAcceptedOrgsData(request, aa_params, ap_params, org_app_logic, program_entity) contents = [] order = ['name'] ap_list = lists.getListGenerator(request, ap_params, order=order, idx=0) contents.append(ap_list) aa_list = lists.getListGenerator(request, aa_params, order=order, idx=1) contents.append(aa_list) return self._list(request, list_params, contents, page_name)
def roles(self, request, access_type, page_name=None, params=None, **kwargs): """Displays the valid roles for this user. 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: not used """ lists_params = [] for _, loop_view in sorted(role_view.ROLE_VIEWS.iteritems()): list_params = loop_view.getParams() if not list_params['show_in_roles_overview']: # filler for easy indexing lists_params.append(None) continue list_params = list_params.copy() list_params['public_field_keys'] = list_params['public_field_keys'] + ['status'] list_params['public_field_names'] = list_params['public_field_names'] + ['Status'] list_params['list_description'] = self.DEF_ROLE_LIST_MSG_FMT % list_params field_props = list_params.setdefault('public_field_props', {}) field_props['status'] = { 'searchoptions': {'defaultValue': 'Active'}, 'stype': 'select', 'editoptions': {'value': ':All;^active$:Active;^inactive$:Inactive'}, } lists_params.append(list_params) if lists.isDataRequest(request): return self.getRolesListData(request, lists_params) contents = [] for i, list_params in enumerate(lists_params): if list_params is None: continue if not self.getRolesListData(lists.IsNonEmptyRequest(i), lists_params): continue list = lists.getListGenerator(request, list_params, idx=i) contents.append(list) params = params.copy() if not contents: site_name = site_logic.getSingleton().site_name params['list_msg'] = self.DEF_NO_ROLES_MSG_FMT % site_name return self._list(request, params, contents, page_name)
def listRoles(self, request, access_type, page_name=None, params=None, **kwargs): """Gives an overview of all the roles in a specific group. 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 """ # set the pagename to include the link_id page_name = '%s %s' % (page_name, kwargs['link_id']) role_views = params['role_views'] lists_params = [] for role_name in sorted(role_views.keys()): # create the list parameters list_params = role_views[role_name].getParams().copy() # Required because without this the lambda refers to list_params, # which is set to a different value due to the iteration. def getter(list_params): return lambda entity: { 'link': redirects.getManageRedirect(entity, list_params) } list_params['public_row_extra'] = getter(list_params) list_params['list_description'] = ugettext( "An overview of the %s for this %s." % (list_params['name_plural'], params['name'])) lists_params.append(list_params) if lists.isDataRequest(request): group_logic = params['logic'] group_entity = group_logic.getFromKeyFields(kwargs) return self.getListRolesData(request, lists_params, group_entity) contents = [] index = 0 for list_params in lists_params: list = lists.getListGenerator(request, list_params, idx=index) contents.append(list) index += 1 # call the _list method from base.View to show the list return self._list(request, params, contents, page_name)
def listTasks(self, request, access_type, page_name=None, params=None, **kwargs): """View where all the tasks can be searched from. """ from soc.modules.gci.views.models.task import view as task_view logic = params['logic'] program_entity = logic.getFromKeyFieldsOr404(kwargs) page_name = '%s %s' % (page_name, program_entity.name) list_params = task_view.getParams().copy() user_account = user_logic.getCurrentUser() user_fields = { 'user': user_account, 'status': 'active' } host_entity = host_logic.getForFields(user_fields, unique=True) tasks_filter = { 'program': program_entity, 'status': ['Open', 'Reopened', 'ClaimRequested'] } if host_entity: list_params['list_description'] = self.DEF_LIST_VALID_TASKS_MSG_FMT % ( program_entity.name) tasks_filter['status'].extend([ 'Claimed', 'ActionNeeded', 'Closed', 'AwaitingRegistration', 'NeedsWork', 'NeedsReview','Unapproved', 'Unpublished']) else: list_params.setdefault('public_field_ignore', []).append('mentors') list_params['list_description'] = self.DEF_LIST_PUBLIC_TASKS_MSG_FMT % ( program_entity.name) list_params['public_row_extra'] = lambda entity, *args: { 'link': redirects.getPublicRedirect(entity, list_params) } list_params['public_conf_min_num'] = list_params['public_conf_limit'] = 100 if lists.isDataRequest(request): return self.getListTasksData(request, list_params, tasks_filter) contents = [] order = ['-modified_on'] tasks_list = lists.getListGenerator(request, list_params, order=order, idx=0) contents.append(tasks_list) return self._list(request, list_params, contents, page_name)
def listMentorTasks(self, request, access_type, page_name=None, params=None, **kwargs): """Displays a list of all tasks for a given student. See base.View.list() for more details. """ entity = params['logic'].getFromKeyFieldsOr404(kwargs) # obtain program entity based on request params program = entity.program user_account = user_logic.logic.getCurrentUser() filter = {'user': user_account, 'program': program, 'status': 'active'} list_params = gci_task_view.view.getParams().copy() list_params['list_description'] = self.DEF_MENTOR_TASKS_MSG_FMT % ( program.name) filter = { 'program': program, 'mentors': [entity], 'status': [ 'Unapproved', 'Unpublished', 'Open', 'Reopened', 'ClaimRequested', 'Claimed', 'ActionNeeded', 'Closed', 'AwaitingRegistration', 'NeedsWork', 'NeedsReview' ] } if lists.isDataRequest(request): return self.getListMentorTasksData(request, list_params, filter) tasks = gci_task_logic.logic.getForFields(filter=filter, unique=True) contents = [] if tasks: order = ['modified_on'] tasks_list = lists.getListGenerator(request, list_params, order=order, idx=0) contents.append(tasks_list) if contents: return self._list(request, list_params, contents, page_name) else: raise out_of_band.Error(self.DEF_NO_TASKS_MSG)
def home(self, request, access_type, page_name=None, params=None, **kwargs): """See base.View._public(). """ from soc.modules.gsoc.views.models import student_project as \ student_project_view entity = self._logic.getFromKeyFieldsOr404(kwargs) program_entity = entity.scope params = params.copy() if params else {} if timeline_helper.isAfterEvent( program_entity.timeline, 'accepted_students_announced_deadline'): # accepted projects ap_params = student_project_view.view.getParams().copy() ap_params[ 'list_description'] = self.DEF_ACCEPTED_PROJECTS_MSG_FMT % ( entity.name) if lists.isDataRequest(request): return self.getHomeData(request, ap_params, entity) ap_list = lists.getListGenerator(request, ap_params, idx=0, visibility='org_home', order=['name']) contents = [ap_list] extra_context = {} # construct the list and put it into the context extra_context['list'] = soc.logic.lists.Lists(contents) fields = {'scope': entity, 'status': ['accepted', 'completed']} # obtain data to construct the organization map as json object extra_context['org_map_data'] = self._getMapData(fields) params['context'] = extra_context return super(View, self).home(request, 'any_access', page_name=page_name, params=params, **kwargs)
def acceptedOrgs(self, request, page_name, params, program_entity, org_view, org_app_view): """See base.View.list. """ logic = params['logic'] list_params = org_view.getParams().copy() list_params['list_msg'] = program_entity.accepted_orgs_msg fmt = {'name': program_entity.name} org_app_params = org_app_view.getParams() # try to retrieve an accepted record org_app_logic = org_app_params['logic'] org_app = org_app_logic.getForProgram(program_entity) aa_params = org_app_params['record_list_params'].copy() # accepted applications aa_params['public_row_extra'] = lambda entity: {} description = self.DEF_ACCEPTED_ORGS_MSG_FMT % fmt aa_params['list_description'] = description aa_params['public_conf_extra'] = { "rowNum": -1, "rowList": [], } description = self.DEF_CREATED_ORGS_MSG_FMT % fmt ap_params = org_view.getParams().copy() ap_params['list_description'] = description ap_params['public_row_extra'] = lambda entity: { 'link': redirects.getHomeRedirect(entity, ap_params), } ap_params['public_conf_extra'] = { "rowNum": -1, "rowList": [], } if lists.isDataRequest(request): return self.getAcceptedOrgsData( request, aa_params, ap_params, org_app_logic, program_entity) contents = [] order = ['name'] ap_list = lists.getListGenerator(request, ap_params, order=order, idx=0) contents.append(ap_list) aa_list = lists.getListGenerator(request, aa_params, order=order, idx=1) contents.append(aa_list) return self._list(request, list_params, contents, page_name)
def listMentorTasks(self, request, access_type, page_name=None, params=None, **kwargs): """Displays a list of all tasks for a given student. See base.View.list() for more details. """ entity = params['logic'].getFromKeyFieldsOr404(kwargs) # obtain program entity based on request params program = entity.program user_account = user_logic.logic.getCurrentUser() filter = { 'user': user_account, 'program': program, 'status': 'active' } list_params = gci_task_view.view.getParams().copy() list_params['list_description'] = self.DEF_MENTOR_TASKS_MSG_FMT % ( program.name) filter = { 'program': program, 'mentors': [entity], 'status': ['Unapproved', 'Unpublished', 'Open', 'Reopened', 'ClaimRequested', 'Claimed', 'ActionNeeded', 'Closed', 'AwaitingRegistration', 'NeedsWork', 'NeedsReview'] } if lists.isDataRequest(request): return self.getListMentorTasksData(request, list_params, filter) tasks = gci_task_logic.logic.getForFields(filter=filter, unique=True) contents = [] if tasks: order = ['modified_on'] tasks_list = lists.getListGenerator(request, list_params, order=order, idx=0) contents.append(tasks_list) if contents: return self._list(request, list_params, contents, page_name) else: raise out_of_band.Error(self.DEF_NO_TASKS_MSG)
def listMyTasks(self, request, access_type, page_name=None, params=None, **kwargs): """Displays a list of all starred tasks for the current user. If the current user is a student it also lists all tasks claimed by them. See base.View.list() for more details. """ from soc.modules.gci.views.models import task as gci_task_view from soc.modules.gci.views.models import task_subscription as \ gci_subscription_view program = gci_program_logic.logic.getFromKeyFieldsOr404(kwargs) user = user_logic.getCurrentUser() task_params = gci_task_view.view.getParams().copy() task_params['list_description'] = ugettext( 'Tasks that you have claimed.') subscription_params = gci_subscription_view.view.getParams().copy() subscription_params['list_description'] = ugettext( 'Tasks that you have starred.') if lists.isDataRequest(request): return self.getListMyTasksData(request, task_params, subscription_params, program, user) contents = [] fields = { 'user': user, 'status': ['active', 'inactive'], } if gci_student_logic.logic.getForFields(fields, unique=True): order = ['modified_on'] tasks_list = lists.getListGenerator(request, task_params, order=order, idx=0) contents.append(tasks_list) starred_tasks_list = lists.getListGenerator(request, subscription_params, idx=1) contents.append(starred_tasks_list) return self._list(request, task_params, contents, page_name)
def listRoles(self, request, access_type, page_name=None, params=None, **kwargs): """Gives an overview of all the roles in a specific group. 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 """ # set the pagename to include the link_id page_name = '%s %s' % (page_name, kwargs['link_id']) role_views = params['role_views'] lists_params = [] for role_name in sorted(role_views.keys()): # create the list parameters list_params = role_views[role_name].getParams().copy() # Required because without this the lambda refers to list_params, # which is set to a different value due to the iteration. def getter(list_params): return lambda entity: { 'link': redirects.getManageRedirect(entity, list_params) } list_params['public_row_extra'] = getter(list_params) list_params['list_description'] = ugettext( "An overview of the %s for this %s." % ( list_params['name_plural'], params['name'])) lists_params.append(list_params) if lists.isDataRequest(request): group_logic = params['logic'] group_entity = group_logic.getFromKeyFields(kwargs) return self.getListRolesData(request, lists_params, group_entity) contents = [] index = 0 for list_params in lists_params: list = lists.getListGenerator(request, list_params, idx=index) contents.append(list) index += 1 # call the _list method from base.View to show the list return self._list(request, params, contents, page_name)
def showDetails(self, request, access_type, page_name=None, params=None, **kwargs): """Shows ranking details for the entity 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 """ logic = params['logic'] ranking = logic.getFromKeyFieldsOr404(kwargs) student = ranking.student all_d = gci_task_model.TaskDifficultyTag.all().fetch(100) list_params = params.copy() list_params[ 'list_description'] = self.DETAILS_MSG_FMT % student.user.name list_params['public_field_extra'] = lambda entity: { 'task': entity.title, 'org': entity.scope.name, 'points_difficulty': entity.taskDifficulty(all_d).value } list_params['public_field_keys'] = [ 'task', 'org', 'points_difficulty', 'closed_on' ] list_params['public_field_names'] = [ 'Task', 'Organization', 'Points (Difficulty)', 'Completed on' ] list_params['public_row_extra'] = lambda entity: { 'link': redirects.getPublicRedirect(entity, {'url_name': 'gci/task'}), } if lists.isDataRequest(request): return self.getListRankingDetailsData(request, list_params, student) contents = [] order = ['closed_on'] list = lists.getListGenerator(request, list_params, order=order, idx=0) contents.append(list) return self._list(request, list_params, contents, page_name)
def listSelf(self, request, access_type, page_name=None, params=None, **kwargs): """View that lists all the OrgAppRecords you have access to. For Args see base.View().public(). """ survey_logic = params['logic'] entity = survey_logic.getFromKeyFieldsOr404(kwargs) list_params = params['record_list_params'].copy() if timeline_helper.isActivePeriod(entity, 'survey'): info = {'url_name': params['url_name'], 'survey': entity} list_params['self_row_extra'] = lambda entity: { 'link': redirects.getRetakeOrgAppSurveyRedirect(entity, info) } else: list_params['self_row_extra'] = lambda entity: { 'link': redirects.getViewSurveyRecordRedirect(entity, params) } ma_params = list_params.copy() ma_params['list_description'] = \ 'List of Applications for which you are Main Admin.' ba_params = list_params.copy() ba_params['list_description'] = \ 'List of Applications for which your are Backup Admin.' if lists.isDataRequest(request): return self._getListSelfData(request, entity, ma_params, ba_params) ma_list = lists.getListGenerator(request, ma_params, visibility='self', idx=0) ba_list = lists.getListGenerator(request, ba_params, visibility='self', idx=1) contents = [ma_list, ba_list] return self._list(request, list_params, contents, page_name)
def home(self, request, access_type, page_name=None, params=None, **kwargs): """See base.View._public(). """ from soc.modules.gci.views.models import task as gci_task_view context = {'list': []} entity = self._params['logic'].getFromKeyFieldsOr404(kwargs) gci_program_entity = entity.scope params = params.copy() if params else {} is_after_student_signup = timeline_helper.isAfterEvent( gci_program_entity.timeline, 'student_signup_start') is_after_tasks_become_public = timeline_helper.isAfterEvent( gci_program_entity.timeline, 'tasks_publicly_visible') if is_after_student_signup and is_after_tasks_become_public: list_params = gci_task_view.view.getParams().copy() list_params['list_description'] = self.DEF_PROJECTS_MSG_FMT % ( entity.name) if lists.isDataRequest(request): return self.getListTasksData(request, list_params, entity) content = lists.getListGenerator(request, list_params, visibility='home', idx=0) contents = [content] context['list'] = soc.logic.lists.Lists(contents) params['context'] = context return super(View, self).home(request, 'any_access', page_name=page_name, params=params, **kwargs)
def requests(self, request, access_type, page_name=None, params=None, **kwargs): """Displays the unhandled requests for this user. 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: not used """ from soc.views.models.request import view as request_view req_params = request_view.getParams() # construct the Unhandled Invites list uh_params = req_params.copy() uh_params['public_row_extra'] = lambda entity: { "link": redirects.getInviteProcessRedirect(entity, None), } uh_params['list_description'] = ugettext( "An overview of your unhandled invites.") # construct the Open Requests list ar_params = req_params.copy() ar_params['public_row_action'] = {} ar_params['public_row_extra'] = lambda x: {} ar_params['list_description'] = ugettext( "List of your pending requests.") if lists.isDataRequest(request): return self.getRequestsListData(request, uh_params, ar_params) uh_list = helper.lists.getListGenerator(request, uh_params, visibility='public', idx=0) ar_list = helper.lists.getListGenerator(request, ar_params, visibility='public', idx=1) # fill contents with all the needed lists contents = [uh_list, ar_list] # call the _list method from base to display the list return self._list(request, req_params, contents, page_name)
def listParticipants(self, request, access_type, page_name=None, params=None, **kwargs): """View that lists the roles of all the participants for a single Program. For args see base.list(). """ from soc.views.models.role import ROLE_VIEWS program_logic = params['logic'] program_entity = program_logic.getFromKeyFieldsOr404(kwargs) if lists.isDataRequest(request): return self.getListParticipantsData(request, params, program_entity) # we need to generate the lists to be shown on this page participants = [] idx = 0 for (role_logic, _) in params['participants_logic']: # retrieve the role view belonging to the logic role_view = ROLE_VIEWS[role_logic.role_name] role_params = role_view.getParams().copy() role_params['list_description'] = 'List of All %s' % ( role_params['name_plural']) role_list = lists.getListGenerator(request, role_params, visibility='admin', idx=idx) participants.append(role_list) idx = idx + 1 page_name = '%s %s' % (page_name, program_entity.name) return self._list(request, params, contents=participants, page_name=page_name)
def listMyTasks(self, request, access_type, page_name=None, params=None, **kwargs): """Displays a list of all starred tasks for the current user. If the current user is a student it also lists all tasks claimed by them. See base.View.list() for more details. """ from soc.modules.gci.views.models import task as gci_task_view from soc.modules.gci.views.models import task_subscription as \ gci_subscription_view program = gci_program_logic.logic.getFromKeyFieldsOr404(kwargs) user = user_logic.getCurrentUser() task_params = gci_task_view.view.getParams().copy() task_params['list_description'] = ugettext( 'Tasks that you have claimed.') subscription_params = gci_subscription_view.view.getParams().copy() subscription_params['list_description'] = ugettext( 'Tasks that you have starred.') if lists.isDataRequest(request): return self.getListMyTasksData(request, task_params, subscription_params, program, user) contents = [] fields = {'user': user, 'status': ['active', 'inactive'], } if gci_student_logic.logic.getForFields(fields, unique=True): order = ['modified_on'] tasks_list = lists.getListGenerator(request, task_params, order=order, idx=0) contents.append(tasks_list) starred_tasks_list = lists.getListGenerator(request, subscription_params, idx=1) contents.append(starred_tasks_list) return self._list(request, task_params, contents, page_name)
def showDetails(self, request, access_type, page_name=None, params=None, **kwargs): """Shows ranking details for the entity 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 """ logic = params['logic'] ranking = logic.getFromKeyFieldsOr404(kwargs) student = ranking.student all_d = gci_task_model.TaskDifficultyTag.all().fetch(100) list_params = params.copy() list_params['list_description'] = self.DETAILS_MSG_FMT % student.user.name list_params['public_field_extra'] = lambda entity: { 'task': entity.title, 'org': entity.scope.name, 'points_difficulty': entity.taskDifficulty(all_d).value } list_params['public_field_keys'] = [ 'task', 'org', 'points_difficulty', 'closed_on'] list_params['public_field_names'] = [ 'Task', 'Organization', 'Points (Difficulty)', 'Completed on'] list_params['public_row_extra'] = lambda entity: { 'link': redirects.getPublicRedirect(entity, {'url_name': 'gci/task'}), } if lists.isDataRequest(request): return self.getListRankingDetailsData(request, list_params, student) contents = [] order = ['closed_on'] list = lists.getListGenerator(request, list_params, order=order, idx=0) contents.append(list) return self._list(request, list_params, contents, page_name)
def home(self, request, access_type, page_name=None, params=None, **kwargs): """See base.View._public(). """ from soc.modules.gsoc.views.models import student_project as \ student_project_view entity = self._logic.getFromKeyFieldsOr404(kwargs) program_entity = entity.scope params = params.copy() if params else {} if timeline_helper.isAfterEvent(program_entity.timeline, 'accepted_students_announced_deadline'): # accepted projects ap_params = student_project_view.view.getParams().copy() ap_params['list_description'] = self.DEF_ACCEPTED_PROJECTS_MSG_FMT % ( entity.name) if lists.isDataRequest(request): return self.getHomeData(request, ap_params, entity) ap_list = lists.getListGenerator(request, ap_params, idx=0, visibility='org_home', order=['name']) contents = [ap_list] extra_context = {} # construct the list and put it into the context extra_context['list'] = soc.logic.lists.Lists(contents) fields= {'scope': entity, 'status': ['accepted', 'completed']} # obtain data to construct the organization map as json object extra_context['org_map_data'] = self._getMapData(fields) params['context'] = extra_context return super(View, self).home(request, 'any_access', page_name=page_name, params=params, **kwargs)
def listSelf(self, request, access_type, page_name=None, params=None, **kwargs): """View that lists all the OrgAppRecords you have access to. For Args see base.View().public(). """ survey_logic = params['logic'] entity = survey_logic.getFromKeyFieldsOr404(kwargs) list_params = params['record_list_params'].copy() if timeline_helper.isActivePeriod(entity, 'survey'): info = {'url_name': params['url_name'], 'survey':entity} list_params['self_row_extra'] = lambda entity: { 'link': redirects.getRetakeOrgAppSurveyRedirect(entity, info) } else: list_params['self_row_extra'] = lambda entity: { 'link': redirects.getViewSurveyRecordRedirect(entity, params) } ma_params = list_params.copy() ma_params['list_description'] = \ 'List of Applications for which you are Main Admin.' ba_params = list_params.copy() ba_params['list_description'] = \ 'List of Applications for which your are Backup Admin.' if lists.isDataRequest(request): return self._getListSelfData(request, entity, ma_params, ba_params) ma_list = lists.getListGenerator(request, ma_params, visibility='self', idx=0) ba_list = lists.getListGenerator(request, ba_params, visibility='self', idx=1) contents = [ma_list, ba_list] return self._list(request, list_params, contents, page_name)
def listSelf(self, request, access_type, page_name=None, params=None, **kwargs): """Lists all proposals from the current logged-in user for the given student. For params see base.View.public(). """ context = {} list_params = params.copy() list_params['list_description'] = \ 'List of my %(name_plural)s.' % list_params list_params['public_row_extra'] = lambda entity: { 'link': redirects.getStudentPrivateRedirect(entity, list_params) } ip_params = list_params.copy() # ineligible proposals description = ugettext('List of my ineligible/withdrawn %s.') % ( ip_params['name_plural']) ip_params['list_description'] = description ip_params['public_row_extra'] = lambda entity: { 'link': redirects.getPublicRedirect(entity, ip_params) } if lists.isDataRequest(request): scope_path = kwargs['scope_path'] return self.getListSelfData(request, list_params, ip_params, scope_path) valid_list = lists.getListGenerator(request, list_params, idx=0) ip_list = lists.getListGenerator(request, ip_params, idx=1) contents = [valid_list, ip_list] return self._list(request, list_params, contents, page_name, context)
def overviewGet(self, request, page_name, params, program_entity, **kwargs): """Handles the GET request for the Program Admins overview page. Args: request: Django HTTPRequest object page_name: Name for this page params: Params for this view program_entity: GSocProgram entity """ page_name = '%s %s' % (page_name, program_entity.name) list_params = params.copy() list_params['admin_row_extra'] = lambda entity: { 'link': redirects.getPublicRedirect(entity, list_params) } list_params['list_description'] = ugettext( 'An overview of all StudentProjects for %s. Click on an item to view ' 'the project, use the buttons on the list for withdrawing a project.' % (program_entity.name)) if lists.isDataRequest(request): return self.getOverviewData(request, list_params, program_entity) project_list = lists.getListGenerator(request, list_params, idx=0, visibility='admin') # fill contents with the list contents = [project_list] # call the _list method from base to display the list return self._list(request, params, contents, page_name)
def manage(self, request, access_type, page_name=None, params=None, **kwargs): """View that allows Organization Admins to manage their Student Projects. For params see base.View().public() """ import soc.logic.lists from soc.modules.gsoc.views.models.grading_project_survey import view as \ grading_survey_view from soc.modules.gsoc.views.models.project_survey import view as \ project_survey_view entity = self._logic.getFromKeyFieldsOr404(kwargs) template = params['manage_template'] # get the context for this webpage context = responses.getUniversalContext(request) responses.useJavaScript(context, params['js_uses_all']) context['page_name'] = "%s '%s' from %s" % (page_name, entity.title, entity.student.name()) context['entity'] = entity if project_logic.canChangeMentors(entity): # only accepted project can have their mentors managed self._enableMentorManagement(entity, params, context) # list all surveys for this Project's Program gps_params = grading_survey_view.getParams().copy() gps_params['list_description'] = \ 'List of all Mentor Evaluations for this Project' gps_params['public_row_extra'] = lambda entity, *args: {} gps_params['public_row_action'] = {} gps_params['public_field_keys'] = [ "title", "taken_by", "taken_on", "record_url", "take_url" ] gps_params['public_field_names'] = [ "Title", "Taken by", "Taken on", "View", "(Re) Take", ] no_record = self.DEF_NO_RECORD_AVAILABLE_MSG # TODO(SRabbelier): use buttons instead project_entity = entity getExtra = lambda params: lambda entity, re: { "taken_by": no_record if not re(entity) else re(entity).user.name, "taken_on": no_record if not re(entity) else str(re(entity).modified), "record_url": no_record if not re(entity) else lists.urlize( redirects.getViewSurveyRecordRedirect(re(entity), params), name=self.DEF_VIEW_RECORD_MSG), "take_url": lists.urlize(redirects.getTakeProjectSurveyRedirect( project_entity, {'survey': entity, 'params': params}), name=self.DEF_TAKE_SURVEY_MSG), } gps_params['public_field_extra'] = getExtra(gps_params) # get the ProjectSurvey list ps_params = project_survey_view.getParams().copy() ps_params['list_description'] = \ 'List of all Student Evaluations for this Project' ps_params['public_row_extra'] = lambda entity, *args: {} ps_params['public_row_action'] = {} ps_params['public_field_keys'] = gps_params['public_field_keys'] ps_params['public_field_names'] = gps_params['public_field_names'] ps_params['public_field_ignore'] = ["take_url"] ps_params['public_field_extra'] = getExtra(ps_params) if lists.isDataRequest(request): return self._getManageData(request, gps_params, ps_params, entity) gps_list = lists.getListGenerator(request, gps_params, idx=0) ps_list = lists.getListGenerator(request, ps_params, idx=1) # store both lists in the content content = [gps_list, ps_list] context['evaluation_list'] = soc.logic.lists.Lists(content) if request.POST: return self.managePost(request, template, context, params, entity, **kwargs) else: #request.GET return self.manageGet(request, template, context, params, entity, **kwargs)
def manageOverview(self, request, access_type, page_name=None, params=None, **kwargs): """View that allows Organization Admins to see an overview of their Organization's Student Projects. For params see base.View().public() """ 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 # make sure the organization exists org_entity = org_logic.getFromKeyNameOr404(kwargs['scope_path']) page_name = '%s %s' % (page_name, org_entity.name) mo_params = params.copy() #list all active projects mo_params['list_description'] = ugettext( 'List of all %s for %s, if you are an Org Admin you can click ' 'a project for more actions. Such as reassigning mentors or viewing ' 'results of the evaluations.' % (params['name_plural'], org_entity.name)) mo_params['public_field_names'] = params['public_field_names'] + [ 'Mentor evaluation', 'Student Evaluation' ] mo_params['public_field_keys'] = params['public_field_keys'] + [ 'mentor_evaluation', 'student_evaluation' ] fields = {'scope': org_entity, 'status': ['active', 'inactive']} org_admin = org_admin_logic.getForFields(fields, unique=True) # Org Admins get a link to manage the project, others go to public page if org_admin: mo_params['public_row_extra'] = lambda entity, *args: { 'link': redirects.getManageRedirect(entity, mo_params) } else: mo_params['public_row_extra'] = lambda entity, *args: { 'link': redirects.getPublicRedirect(entity, mo_params) } mo_params['public_field_prefetch'] = ['student', 'mentor', 'scope'] mo_params['public_field_extra'] = lambda entity, ps, psc, gs, gsc: { 'org': entity.scope.name, 'student': '%s (%s)' % (entity.student.name(), entity.student.email), 'mentor': entity.mentor.name(), 'mentor_evaluation': '%d/%d' % (grading_logic.getQueryForFields({ 'project': entity }).count(), gsc), 'student_evaluation': '%d/%d' % (project_logic.getQueryForFields({ 'project': entity }).count(), psc), } if lists.isDataRequest(request): return self.getManageOverviewData(request, mo_params, org_entity) mo_list = lists.getListGenerator(request, mo_params, idx=0) contents = [mo_list] # call the _list method from base to display the list return self._list(request, mo_params, contents, page_name)
def manage(self, request, access_type, page_name=None, params=None, **kwargs): """View that allows Organization Admins to manage their Student Projects. For params see base.View().public() """ import soc.logic.lists from soc.modules.gsoc.views.models.grading_project_survey import view as \ grading_survey_view from soc.modules.gsoc.views.models.project_survey import view as \ project_survey_view entity = self._logic.getFromKeyFieldsOr404(kwargs) template = params['manage_template'] # get the context for this webpage context = responses.getUniversalContext(request) responses.useJavaScript(context, params['js_uses_all']) context['page_name'] = "%s '%s' from %s" % (page_name, entity.title, entity.student.name()) context['entity'] = entity if project_logic.canChangeMentors(entity): # only accepted project can have their mentors managed self._enableMentorManagement(entity, params, context) # list all surveys for this Project's Program gps_params = grading_survey_view.getParams().copy() gps_params['list_description'] = \ 'List of all Mentor Evaluations for this Project' gps_params['public_row_extra'] = lambda entity, *args: {} gps_params['public_row_action'] = {} gps_params['public_field_keys'] = [ "title", "taken_by", "taken_on", "record_url", "take_url" ] gps_params['public_field_names'] = [ "Title", "Taken by", "Taken on", "View", "(Re) Take", ] no_record = self.DEF_NO_RECORD_AVAILABLE_MSG # TODO(SRabbelier): use buttons instead project_entity = entity getExtra = lambda params: lambda entity, re: { "taken_by": no_record if not re(entity) else re(entity).user.name, "taken_on": no_record if not re(entity) else str(re(entity).modified), "record_url": no_record if not re(entity) else lists.urlize( redirects.getViewSurveyRecordRedirect(re(entity), params), name=self.DEF_VIEW_RECORD_MSG), "take_url": lists.urlize(redirects.getTakeProjectSurveyRedirect( project_entity, { 'survey': entity, 'params': params }), name=self.DEF_TAKE_SURVEY_MSG), } gps_params['public_field_extra'] = getExtra(gps_params) # get the ProjectSurvey list ps_params = project_survey_view.getParams().copy() ps_params['list_description'] = \ 'List of all Student Evaluations for this Project' ps_params['public_row_extra'] = lambda entity, *args: {} ps_params['public_row_action'] = {} ps_params['public_field_keys'] = gps_params['public_field_keys'] ps_params['public_field_names'] = gps_params['public_field_names'] ps_params['public_field_ignore'] = ["take_url"] ps_params['public_field_extra'] = getExtra(ps_params) if lists.isDataRequest(request): return self._getManageData(request, gps_params, ps_params, entity) gps_list = lists.getListGenerator(request, gps_params, idx=0) ps_list = lists.getListGenerator(request, ps_params, idx=1) # store both lists in the content content = [gps_list, ps_list] context['evaluation_list'] = soc.logic.lists.Lists(content) if request.POST: return self.managePost(request, template, context, params, entity, **kwargs) else: #request.GET return self.manageGet(request, template, context, params, entity, **kwargs)
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 _manageStatisticsGet(self, request, access_type, page_name=None, params=None, **kwargs): """GET method for manage statistics request. """ program = self._getProgramInScopeEntity(kwargs['scope_path']) context = {} list_params = self.getParams().copy() list_params['public_field_props'] = { "unread": { "stype": "select", "editoptions": {"value": ":All;^Read$:Read;^Not Read$:Not Read"} } } list_params['public_conf_extra'] = { "multiselect": True, } list_params['public_button_global'] = [ { 'bounds': [1,'all'], 'id': 'collect_stats', 'caption': 'Collect', 'type': 'post', 'parameters': { 'url': '', 'keys': ['key'], 'refresh': 'current', } }, { 'bounds': [1,'all'], 'id': 'clear_stats', 'caption': 'Clear', 'type': 'post', 'parameters': { 'url': '', 'keys': ['key'], 'refresh': 'current', } }] # statistic entities which are defined for all GSoC programs ep_params = list_params.copy() ep_params['list_description'] = self.DEF_EACH_GSOC_STAT_MSG ep_params['public_row_extra'] = lambda entity: { 'link': redirects.getVisualizeRedirect(entity, ep_params), } # statistic entities which are defined for the specific GSoC program op_params = list_params.copy() op_params['list_description'] = self.DEF_ONE_GSOC_STAT_MSG % program.name op_params['public_row_extra'] = lambda entity: { 'link': redirects.getVisualizeRedirect(entity, op_params), } if lists.isDataRequest(request): # retrieving data for a list return self.getManageStatisticsData(request, [ep_params, op_params], program) # fill contents for all the needed lists contents = [] ep_list = helper.lists.getListGenerator(request, ep_params, idx=self.DEF_EACH_GSOC_LIST_IDX) contents.append(ep_list) op_list = helper.lists.getListGenerator(request, op_params, idx=self.DEF_ONE_GSOC_LIST_IDX) contents.append(op_list) return self._list(request, list_params, contents, page_name, context)
def _manageStatisticsGet(self, request, access_type, page_name=None, params=None, **kwargs): """GET method for manage statistics request. """ program = self._getProgramInScopeEntity(kwargs['scope_path']) context = {} list_params = self.getParams().copy() list_params['public_field_props'] = { "unread": { "stype": "select", "editoptions": { "value": ":All;^Read$:Read;^Not Read$:Not Read" } } } list_params['public_conf_extra'] = { "multiselect": True, } list_params['public_button_global'] = [{ 'bounds': [1, 'all'], 'id': 'collect_stats', 'caption': 'Collect', 'type': 'post', 'parameters': { 'url': '', 'keys': ['key'], 'refresh': 'current', } }, { 'bounds': [1, 'all'], 'id': 'clear_stats', 'caption': 'Clear', 'type': 'post', 'parameters': { 'url': '', 'keys': ['key'], 'refresh': 'current', } }] # statistic entities which are defined for all GSoC programs ep_params = list_params.copy() ep_params['list_description'] = self.DEF_EACH_GSOC_STAT_MSG ep_params['public_row_extra'] = lambda entity: { 'link': redirects.getVisualizeRedirect(entity, ep_params), } # statistic entities which are defined for the specific GSoC program op_params = list_params.copy() op_params[ 'list_description'] = self.DEF_ONE_GSOC_STAT_MSG % program.name op_params['public_row_extra'] = lambda entity: { 'link': redirects.getVisualizeRedirect(entity, op_params), } if lists.isDataRequest(request): # retrieving data for a list return self.getManageStatisticsData(request, [ep_params, op_params], program) # fill contents for all the needed lists contents = [] ep_list = helper.lists.getListGenerator( request, ep_params, idx=self.DEF_EACH_GSOC_LIST_IDX) contents.append(ep_list) op_list = helper.lists.getListGenerator(request, op_params, idx=self.DEF_ONE_GSOC_LIST_IDX) contents.append(op_list) return self._list(request, list_params, contents, page_name, context)
class View(organization.View): """View methods for the Organization model. """ def __init__(self, params=None): """Defines the fields and methods required for the base View class to provide the user with list, public, create, edit and delete views. Params: params: a dict with params for this View """ rights = access.GSoCChecker(params) rights['any_access'] = ['allow'] rights['show'] = ['allow'] rights['create'] = ['checkIsDeveloper'] rights['edit'] = [('checkHasRoleForKeyFieldsAsScope', org_admin_logic), ('checkGroupIsActiveForLinkId', org_logic)] rights['delete'] = ['checkIsDeveloper'] rights['home'] = ['allow'] rights['public_list'] = ['allow'] rights['applicant'] = [('checkIsOrgAppAccepted', org_app_logic)] rights['apply_mentor'] = ['checkIsUser'] rights['list_requests'] = [('checkHasRoleForKeyFieldsAsScope', org_admin_logic)] rights['list_roles'] = [('checkHasRoleForKeyFieldsAsScope', org_admin_logic)] rights['list_proposals'] = [ ('checkHasAny', [[('checkHasRoleForKeyFieldsAsScope', [org_admin_logic, ['active', 'inactive']]), ('checkHasRoleForKeyFieldsAsScope', [mentor_logic, ['active', 'inactive']])]]) ] new_params = {} new_params['logic'] = org_logic new_params['rights'] = rights new_params['scope_view'] = program_view new_params['name'] = "GSoC Organization" new_params['module_name'] = "organization" new_params['sidebar_grouping'] = 'Organizations' new_params['module_package'] = 'soc.modules.gsoc.views.models' new_params['url_name'] = 'gsoc/org' new_params['document_prefix'] = 'gsoc_org' new_params['mentor_role_name'] = 'gsoc_mentor' new_params['mentor_url_name'] = 'gsoc/mentor' new_params['org_admin_role_name'] = 'gsoc_org_admin' patterns = [] patterns += [ (r'^org_tags/(?P<access_type>pick)$', '%(module_package)s.%(module_name)s.pick_suggested_tags', "Pick a list of suggested tags."), ] new_params['extra_django_patterns'] = patterns new_params['extra_dynaexclude'] = [ 'slots', 'slots_calculated', 'nr_applications', 'nr_mentors' ] new_params['create_extra_dynaproperties'] = { 'tags': widgets.ReferenceField( required=False, reference_url='org_tags', label=ugettext('Tags'), help_text=ugettext("A list of comma seperated tags"), example_text="e.g. python, django, appengine", filter=['scope_path'], group="1. Public Info"), 'clean_tags': gsoc_cleaning.cleanTagsList('tags', gsoc_cleaning.COMMA_SEPARATOR), 'contrib_template': forms.fields.CharField(widget=helper.widgets.FullTinyMCE( attrs={ 'rows': 25, 'cols': 100 })), 'clean_contrib_template': cleaning.clean_html_content('contrib_template'), 'clean_facebook': cleaning.clean_url('facebook'), 'clean_twitter': cleaning.clean_url('twitter'), 'clean_blog': cleaning.clean_url('blog'), } new_params['org_app_logic'] = org_app_logic params = dicts.merge(params, new_params, sub_merge=True) super(View, self).__init__(params) self._params['public_field_keys'].append('tags') self._params['public_field_names'].append("Tags") self._params['public_field_extra'] = lambda entity: { 'ideas': lists.urlize(entity.ideas, 'Click Here'), 'tags': entity.tags_string(entity.org_tag), } self._params['select_field_extra'] = self._params['public_field_extra'] def _editGet(self, request, entity, form): """See base.View._editGet(). """ if entity.org_tag: form.fields['tags'].initial = entity.tags_string(entity.org_tag) return super(View, self)._editGet(request, entity, form) def _editPost(self, request, entity, fields): """See base.View._editPost(). """ super(View, self)._editPost(request, entity, fields) fields['org_tag'] = { 'tags': fields['tags'], 'scope': entity.scope if entity else fields['scope'] } @decorators.check_access def pickSuggestedTags(self, request, access_type, page_name=None, params=None, **kwargs): """Returns a JSON representation of a list of organization tags that are suggested for a given GSoCProgram in scope. """ if 'scope_path' not in request.GET: data = [] else: program = program_logic.getFromKeyName( request.GET.get('scope_path')) if not program: data = [] else: fun = soc.cache.logic.cache(OrgTag.get_for_custom_query) suggested_tags = fun(OrgTag, filter={'scope': program}, order=None) # TODO: this should be refactored after the issue with autocompletion # is resolved data = simplejson.dumps({ 'data': [{ 'link_id': item['tag'] } for item in [dicts.toDict(tag, ['tag']) for tag in suggested_tags]], 'autocomplete_options': { 'multiple': True, 'selectFirst': False } }) return self.json(request, data, False) # TODO (dhans): merge common items with the GCI module in a single function def _getExtraMenuItems(self, role_description, params=None): """Used to create the specific Organization menu entries. For args see group.View._getExtraMenuItems(). """ submenus = [] group_entity = role_description['group'] program_entity = group_entity.scope roles = role_description['roles'] mentor_entity = roles.get('gsoc_mentor') admin_entity = roles.get('gsoc_org_admin') is_active_mentor = mentor_entity and mentor_entity.status == 'active' is_active_admin = admin_entity and admin_entity.status == 'active' if admin_entity or mentor_entity: # add a link to view all the student proposals submenu = (redirects.getListProposalsRedirect( group_entity, params), "Manage Student Proposals", 'any_access') submenus.append(submenu) # add a link to manage student projects after they have been announced if timeline_helper.isAfterEvent( program_entity.timeline, 'accepted_students_announced_deadline'): submenu = (redirects.getManageOverviewRedirect( group_entity, {'url_name': 'gsoc/student_project'}), "Manage Student Projects", 'any_access') submenus.append(submenu) if is_active_admin: # add a link to the management page submenu = (redirects.getListRolesRedirect(group_entity, params), "Manage Admins and Mentors", 'any_access') submenus.append(submenu) # add a link to invite an org admin submenu = (redirects.getInviteRedirectForRole( group_entity, 'gsoc/org_admin'), "Invite an Admin", 'any_access') submenus.append(submenu) # add a link to invite a member submenu = (redirects.getInviteRedirectForRole( group_entity, 'gsoc/mentor'), "Invite a Mentor", 'any_access') submenus.append(submenu) # add a link to the request page submenu = (redirects.getListRequestsRedirect(group_entity, params), "List Requests and Invites", 'any_access') submenus.append(submenu) # add a link to the edit page submenu = (redirects.getEditRedirect(group_entity, params), "Edit Organization Profile", 'any_access') submenus.append(submenu) if is_active_admin or is_active_mentor: submenu = (redirects.getCreateDocumentRedirect( group_entity, params['document_prefix']), "Create a New Document", 'any_access') submenus.append(submenu) submenu = (redirects.getListDocumentsRedirect( group_entity, params['document_prefix']), "List Documents", 'any_access') submenus.append(submenu) if is_active_admin: # add a link to the resign page submenu = (redirects.getManageRedirect( roles['gsoc_org_admin'], {'url_name': 'gsoc/org_admin'}), "Resign as Admin", 'any_access') submenus.append(submenu) # add a link to the edit page submenu = (redirects.getEditRedirect( roles['gsoc_org_admin'], {'url_name': 'gsoc/org_admin'}), "Edit My Admin Profile", 'any_access') submenus.append(submenu) if is_active_mentor: # add a link to the resign page submenu = (redirects.getManageRedirect( roles['gsoc_mentor'], {'url_name': 'gsoc/mentor'}), "Resign as Mentor", 'any_access') submenus.append(submenu) # add a link to the edit page submenu = (redirects.getEditRedirect(roles['gsoc_mentor'], {'url_name': 'gsoc/mentor'}), "Edit My Mentor Profile", 'any_access') submenus.append(submenu) return submenus 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) @decorators.merge_params @decorators.check_access def listProposals(self, request, access_type, page_name=None, params=None, **kwargs): """Lists all proposals for the organization given in kwargs. For params see base.View.public(). """ from soc.modules.gsoc.logic.models.proposal_duplicates_status import \ logic as ds_logic try: org_entity = self._logic.getFromKeyFieldsOr404(kwargs) except out_of_band.Error, error: return helper.responses.errorResponse( error, request, template=params['error_public']) program_entity = org_entity.scope is_after_deadline = timeline_helper.isAfterEvent( program_entity.timeline, 'accepted_students_announced_deadline') if is_after_deadline: redirect_fun = redirects.getProposalCommentRedirect else: redirect_fun = redirects.getReviewRedirect context = {} context['entity'] = org_entity # whether or not the amount of slots assigned should be shown context['slots_visible'] = org_entity.scope.allocations_visible # used to check the status of the duplicate process context['duplicate_status'] = ds_logic.getOrCreateForProgram( org_entity.scope) program_entity = org_entity.scope page_name = '%s %s (%s)' % (page_name, org_entity.name, program_entity.short_name) list_params = student_proposal_view.view.getParams().copy() list_params['list_template'] = 'soc/student_proposal/list_for_org.html' np_params = list_params.copy() # new proposals description = ugettext('List of new %s sent to %s') % ( np_params['name_plural'], org_entity.name) np_params['list_description'] = description np_params['public_row_extra'] = lambda entity: { 'link': redirect_fun(entity, np_params), } rp_params = list_params.copy() # ranked proposals rp_params['review_field_keys'] = [ 'rank', 'title', 'student', 'mentor', 'score', 'status', 'last_modified_on', 'abstract', 'content', 'additional_info', 'created_on' ] rp_params['review_field_hidden'] = [ 'abstract', 'content', 'additional_info', 'created_on' ] rp_params['review_field_names'] = [ 'Rank', 'Title', 'Student', 'Mentor', 'Score', 'Status', 'Last Modified On', 'Abstract', 'Content', 'Additional Info', 'Created On' ] rp_params['review_field_no_filter'] = ['status'] rp_params['review_field_prefetch'] = ['scope', 'mentor', 'program'] rp_params['review_field_extra'] = lambda entity, ranker, status: { 'rank': ranker.FindRanks([[entity.score]])[0] + 1, 'student': entity.scope.name(), 'mentor': entity.mentor.name() if entity.mentor else '%s Proposed' % len(entity.possible_mentors), 'status': status.get(entity.key(), '<font color="red">Pending rejection</font>') if ( entity.program.allocations_visible \ and entity.status == 'pending') else entity.status, } rp_params['review_row_action'] = { "type": "redirect_custom", "parameters": dict(new_window=True), } rp_params['review_row_extra'] = lambda entity, *args: { 'link': redirect_fun(entity, rp_params) } rp_params['review_field_props'] = { "score": { "sorttype": "integer", }, "rank": { "sorttype": "integer", }, } rp_params['review_conf_min_num'] = 50 description = ugettext('%s already under review sent to %s') % ( rp_params['name_plural'], org_entity.name) rp_params['list_description'] = description mp_params = list_params.copy() # proposals mentored by current user description = ugettext('List of %s sent to %s you are mentoring') % ( mp_params['name_plural'], org_entity.name) mp_params['list_description'] = description mp_params['public_row_extra'] = lambda entity: { 'link': redirect_fun(entity, mp_params) } ip_params = list_params.copy() # invalid proposals ip_params['list_description'] = ugettext( 'List of invalid %s sent to %s ') % (ip_params['name_plural'], org_entity.name) ip_params['public_row_extra'] = lambda entity: { 'link': redirect_fun(entity, ip_params) } if lists.isDataRequest(request): # retrieving data for a list return self.getListProposalsData( request, [np_params, rp_params, mp_params, ip_params], org_entity) # fill contents for all the needed lists contents = [] # check if there are new proposals if so show them in a separate list fields = {'org': org_entity, 'status': 'new'} new_proposal = sp_logic.getForFields(fields, unique=True) if new_proposal: # we should add this list because there is a new proposal np_list = helper.lists.getListGenerator(request, np_params, idx=0) contents.append(np_list) order = ['-score'] # the list of proposals that have been reviewed should always be shown rp_list = helper.lists.getListGenerator(request, rp_params, order=order, visibility='review', idx=1) contents.append(rp_list) # check whether the current user is a mentor for the organization user_entity = user_logic.getCurrentUser() fields = { 'user': user_entity, 'scope': org_entity, 'status': ['active', 'inactive'] } mentor_entity = mentor_logic.getForFields(fields, unique=True) if mentor_entity: # show the list of all proposals that this user is mentoring mp_list = helper.lists.getListGenerator(request, mp_params, idx=2) contents.append(mp_list) # check if there are invalid proposals if so show them in a separate list fields = {'org': org_entity, 'status': 'invalid'} invalid_proposal = sp_logic.getForFields(fields, unique=True) if invalid_proposal: ip_list = helper.lists.getListGenerator(request, ip_params, idx=3) contents.append(ip_list) return self._list(request, list_params, contents, page_name, context)
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 manageOverview(self, request, access_type, page_name=None, params=None, **kwargs): """View that allows Organization Admins to see an overview of their Organization's Student Projects. For params see base.View().public() """ 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 # make sure the organization exists org_entity = org_logic.getFromKeyNameOr404(kwargs['scope_path']) page_name = '%s %s' % (page_name, org_entity.name) mo_params = params.copy() #list all active projects mo_params['list_description'] = ugettext( 'List of all %s for %s, if you are an Org Admin you can click ' 'a project for more actions. Such as reassigning mentors or viewing ' 'results of the evaluations.' %(params['name_plural'], org_entity.name) ) mo_params['public_field_names'] = params['public_field_names'] + [ 'Mentor evaluation', 'Student Evaluation'] mo_params['public_field_keys'] = params['public_field_keys'] + [ 'mentor_evaluation', 'student_evaluation'] fields = {'scope': org_entity, 'status': ['active', 'inactive']} org_admin = org_admin_logic.getForFields(fields, unique=True) # Org Admins get a link to manage the project, others go to public page if org_admin: mo_params['public_row_extra'] = lambda entity, *args: { 'link': redirects.getManageRedirect(entity, mo_params) } else: mo_params['public_row_extra'] = lambda entity, *args: { 'link': redirects.getPublicRedirect(entity, mo_params) } mo_params['public_field_prefetch'] = ['student', 'mentor', 'scope'] mo_params['public_field_extra'] = lambda entity, ps, psc, gs, gsc: { 'org': entity.scope.name, 'student': '%s (%s)' % (entity.student.name(), entity.student.email), 'mentor': entity.mentor.name(), 'mentor_evaluation': '%d/%d' % ( grading_logic.getQueryForFields({'project': entity}).count(), gsc), 'student_evaluation': '%d/%d' % ( project_logic.getQueryForFields({'project': entity}).count(), psc), } if lists.isDataRequest(request): return self.getManageOverviewData(request, mo_params, org_entity) mo_list = lists.getListGenerator(request, mo_params, idx=0) contents = [mo_list] # call the _list method from base to display the list return self._list(request, mo_params, contents, page_name)
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 listTasks(self, request, access_type, page_name=None, params=None, **kwargs): """View where all the tasks can be searched from. """ from soc.modules.gci.views.models.task import view as task_view logic = params['logic'] program_entity = logic.getFromKeyFieldsOr404(kwargs) page_name = '%s %s' % (page_name, program_entity.name) list_params = task_view.getParams().copy() user_account = user_logic.getCurrentUser() user_fields = {'user': user_account, 'status': 'active'} host_entity = host_logic.getForFields(user_fields, unique=True) tasks_filter = { 'program': program_entity, 'status': ['Open', 'Reopened', 'ClaimRequested'] } if host_entity: list_params[ 'list_description'] = self.DEF_LIST_VALID_TASKS_MSG_FMT % ( program_entity.name) tasks_filter['status'].extend([ 'Claimed', 'ActionNeeded', 'Closed', 'AwaitingRegistration', 'NeedsWork', 'NeedsReview', 'Unapproved', 'Unpublished' ]) else: list_params.setdefault('public_field_ignore', []).append('mentors') list_params[ 'list_description'] = self.DEF_LIST_PUBLIC_TASKS_MSG_FMT % ( program_entity.name) list_params['public_row_extra'] = lambda entity, *args: { 'link': redirects.getPublicRedirect(entity, list_params) } list_params['public_conf_min_num'] = list_params[ 'public_conf_limit'] = 100 if lists.isDataRequest(request): return self.getListTasksData(request, list_params, tasks_filter) contents = [] order = ['-modified_on'] tasks_list = lists.getListGenerator(request, list_params, order=order, idx=0) contents.append(tasks_list) return self._list(request, list_params, contents, page_name)