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 _getOrgMemberComponents(self): """Get the dashboard components for Organization members. """ components = [] if self.data.mentor_for: if timeline_helper.isAfterEvent( self.data.program_timeline, 'accepted_students_announced_deadline'): # add a component to show all projects a user is mentoring components.append( ProjectsIMentorComponent(self.request, self.data)) if timeline_helper.isAfterEvent( self.data.program_timeline, 'student_signup_start'): # Add the submitted proposals component components.append( SubmittedProposalsComponent(self.request, self.data)) components.append(OrganizationsIParticipateInComponent(self.request, self.data)) if self.data.org_admin_for: # add a component for all organization that this user administers components.append(RequestComponent(self.request, self.data, True)) components.append(ParticipantsComponent(self.request, self.data)) return components
def _getStudentEntries(self, program_entity, student_entity, params, id, user, prefix): """Returns a list with menu items for students in a specific program. """ items = [] timeline_entity = program_entity.timeline if timeline_helper.isActivePeriod(timeline_entity, 'student_signup') and \ student_entity.status == 'active': items += [('/gsoc/student_proposal/list_orgs/%s' % (student_entity.key().id_or_name()), "Submit your Student Proposal", 'any_access')] if timeline_helper.isAfterEvent(timeline_entity, 'student_signup_start'): items += [(redirects.getListSelfRedirect( student_entity, {'url_name': prefix + '/student_proposal'}), "List my Student Proposals", 'any_access')] if timeline_helper.isAfterEvent( timeline_entity, 'accepted_students_announced_deadline'): # add a link to show all projects items += [(redirects.getListProjectsRedirect( program_entity, {'url_name': prefix + '/student'}), "List my Student Projects", 'any_access')] items += super(View, self)._getStudentEntries(program_entity, student_entity, params, id, user, prefix) return items
def _getStudentEntries(self, program_entity, student_entity, params, id, user): """Returns a list with menu items for students in a specific program. """ items = [] timeline_entity = program_entity.timeline if timeline_helper.isActivePeriod(timeline_entity, 'student_signup'): items += [('/student_proposal/list_orgs/%s' % ( student_entity.key().id_or_name()), "Submit your Student Proposal", 'any_access')] if timeline_helper.isAfterEvent(timeline_entity, 'student_signup_start'): items += [(redirects.getListSelfRedirect(student_entity, {'url_name':'student_proposal'}), "List my Student Proposals", 'any_access')] items += [(redirects.getEditRedirect(student_entity, {'url_name': 'student'}), "Edit my Student Profile", 'any_access')] if timeline_helper.isAfterEvent(timeline_entity, 'accepted_students_announced_deadline'): # add a link to show all projects items += [(redirects.getListProjectsRedirect(program_entity, {'url_name':'student'}), "List my Student Projects", 'any_access')] return items
def _getOrgMemberComponents(self): """Get the dashboard components for Organization members. """ components = [] if self.data.mentor_for: if timeline_helper.isAfterEvent( self.data.program_timeline, 'accepted_students_announced_deadline'): # add a component to show all projects a user is mentoring components.append( ProjectsIMentorComponent(self.request, self.data)) if timeline_helper.isAfterEvent(self.data.program_timeline, 'student_signup_start'): # Add the submitted proposals component components.append( SubmittedProposalsComponent(self.request, self.data)) components.append( OrganizationsIParticipateInComponent(self.request, self.data)) if self.data.org_admin_for: # add a component for all organization that this user administers components.append(RequestComponent(self.request, self.data, True)) components.append(ParticipantsComponent(self.request, self.data)) return components
def testIsAfterEvent(self): """Tests if True is returned if current DateTime is after the given event. """ #program has started. self.timeline.program_start = datetime.utcnow() - timedelta(10) self.assertTrue(timeline.isAfterEvent(self.timeline, 'program_start')) #program is yet to start. self.timeline.program_start = datetime.utcnow() + timedelta(10) self.assertFalse(timeline.isAfterEvent(self.timeline, 'program_start')) #program has ended. self.timeline.program_start = datetime.utcnow() - timedelta(30) self.timeline.program_end = datetime.utcnow() - timedelta(20) self.assertTrue(timeline.isAfterEvent(self.timeline, 'program_end')) #the deadline to announce accepted organizations has not passed. self.timeline.accepted_organization_announced_deadline = ( datetime.utcnow() + timedelta(20)) self.assertFalse( timeline.isAfterEvent(self.timeline, "accepted_organization_announced_deadline")) #the deadline to announce accepted organizations has been passed. self.timeline.accepted_organization_announced_deadline = ( datetime.utcnow() - timedelta(20)) self.assertTrue( timeline.isAfterEvent(self.timeline, "accepted_organization_announced_deadline")) #student sign up period has not started. self.timeline.student_signup_start = datetime.utcnow() + timedelta(20) self.assertFalse( timeline.isAfterEvent(self.timeline, 'student_signup_start')) #student sign up period has already started. self.timeline.student_signup_start = datetime.utcnow() - timedelta(20) self.assertTrue( timeline.isAfterEvent(self.timeline, 'student_signup_start')) #student sign up period has not ended. self.timeline.student_signup_end = datetime.utcnow() + timedelta(20) self.assertFalse( timeline.isAfterEvent(self.timeline, 'student_signup_end')) #student sign up period has already ended. self.timeline.student_signup_end = datetime.utcnow() - timedelta(20) self.assertTrue( timeline.isAfterEvent(self.timeline, 'student_signup_end')) #event not in the Timeline. self.assertFalse( timeline.isAfterEvent(self.timeline, 'some_other_event'))
def testIsAfterEvent(self): """Tests if True is returned if current DateTime is after the given event. """ #program has started. self.timeline.program_start = datetime.utcnow() - timedelta(10) self.assertTrue(timeline.isAfterEvent(self.timeline, 'program_start')) #program is yet to start. self.timeline.program_start = datetime.utcnow() + timedelta(10) self.assertFalse(timeline.isAfterEvent(self.timeline, 'program_start')) #program has ended. self.timeline.program_start = datetime.utcnow() - timedelta(30) self.timeline.program_end = datetime.utcnow() - timedelta(20) self.assertTrue(timeline.isAfterEvent(self.timeline, 'program_end')) #the deadline to announce accepted organizations has not passed. self.timeline.accepted_organization_announced_deadline = (datetime.utcnow() + timedelta(20)) self.assertFalse(timeline.isAfterEvent( self.timeline, "accepted_organization_announced_deadline")) #the deadline to announce accepted organizations has been passed. self.timeline.accepted_organization_announced_deadline = (datetime.utcnow() - timedelta(20)) self.assertTrue(timeline.isAfterEvent( self.timeline, "accepted_organization_announced_deadline")) #student sign up period has not started. self.timeline.student_signup_start = datetime.utcnow() + timedelta(20) self.assertFalse(timeline.isAfterEvent(self.timeline, 'student_signup_start')) #student sign up period has already started. self.timeline.student_signup_start = datetime.utcnow() - timedelta(20) self.assertTrue(timeline.isAfterEvent(self.timeline, 'student_signup_start')) #student sign up period has not ended. self.timeline.student_signup_end = datetime.utcnow() + timedelta(20) self.assertFalse(timeline.isAfterEvent(self.timeline, 'student_signup_end')) #student sign up period has already ended. self.timeline.student_signup_end = datetime.utcnow() - timedelta(20) self.assertTrue(timeline.isAfterEvent(self.timeline, 'student_signup_end')) #event not in the Timeline. self.assertFalse(timeline.isAfterEvent(self.timeline, 'some_other_event'))
def recalculateGCIRanking(request, entities, context, *args, **kwargs): """Recalculates student ranking for a program with the specified key_name. """ program = gci_program_logic.getFromKeyName(kwargs['key_name']) if not program: return responses.terminateTask() # prefetch all task difficulties all_d = gci_task_model.TaskDifficultyTag.all().fetch(100) for entity in entities: # check if the entity refers to the program in scope if entity.scope.key() != program.key(): continue # get all the tasks that the student has completed filter = { 'student': entity, 'status': 'Closed', } tasks = gci_task_logic.getForFields(filter=filter) # calculate ranking with all the tasks gci_student_ranking_logic.calculateRankingForStudent( entity, tasks, all_d) # this task should not be repeated after the program is over timeline = program.timeline if timeline_helper.isAfterEvent(timeline, 'program_end'): raise responses.DoNotRepeatException()
def recalculateGCIRanking(request, entities, context, *args, **kwargs): """Recalculates student ranking for a program with the specified key_name. """ program = gci_program_logic.getFromKeyName(kwargs['key_name']) if not program: return responses.terminateTask() # prefetch all task difficulties all_d = gci_task_model.TaskDifficultyTag.all().fetch(100) for entity in entities: # check if the entity refers to the program in scope if entity.scope.key() != program.key(): continue # get all the tasks that the student has completed filter = { 'student': entity, 'status': 'Closed', } tasks = gci_task_logic.getForFields(filter=filter) # calculate ranking with all the tasks gci_student_ranking_logic.calculateRankingForStudent(entity, tasks, all_d) # this task should not be repeated after the program is over timeline = program.timeline if timeline_helper.isAfterEvent(timeline, 'program_end'): raise responses.DoNotRepeatException()
def checkIsAfterEvent(self, django_args, event_name, key_name_arg): """Checks if the given event has taken place for the given program. Args: django_args: a dictionary with django's arguments event_name: the name of the event which is checked key_name_arg: the entry in django_args that specifies the given program keyname. If none is given the key_name is constructed from django_args itself. Raises: AccessViolationResponse: * if no active Program is found * if the event has not taken place yet """ if key_name_arg and key_name_arg in django_args: key_name = django_args[key_name_arg] else: key_name = program_logic.getKeyNameFromFields(django_args) program_entity = program_logic.getFromKeyName(key_name) if not program_entity or ( program_entity.status in ['inactive', 'invalid']): raise out_of_band.AccessViolation(message_fmt=DEF_SCOPE_INACTIVE_MSG) if timeline_helper.isAfterEvent(program_entity.timeline, event_name): return raise out_of_band.AccessViolation(message_fmt=DEF_PAGE_INACTIVE_MSG)
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 checkStatusForTask(self, django_args): """Checks if the current user has access to the given task. This method checks if the current user is either an GCI Org Admin or a Mentor and is active, if yes it allows them to view the task page at any task state. If the user is none of the above, it checks the status of the task, and if it is in one of the valid published states it allows access to view the task page. Args: django_args: a dictionary with django's arguments Raises: AccessViolationResponse: - If there is no task found - If the task is not in one of the required states. """ user_entity = self.user # bail out with 404 if no task is found task_entity = gci_task_logic.logic.getFromKeyFieldsOr404(django_args) if (user_entity and task_entity.user and task_entity.user.key() == user_entity.key()): return filter = { 'user': user_entity, 'status': 'active', } if host_logic.logic.getForFields(filter, unique=True): return filter['scope_path'] = django_args['scope_path'] if gci_org_admin_logic.logic.getForFields(filter, unique=True): return if gci_mentor_logic.logic.getForFields(filter, unique=True): return org_entity = gci_org_logic.logic.getFromKeyNameOr404( django_args['scope_path']) if not timeline_helper.isAfterEvent(org_entity.scope.timeline, 'tasks_publicly_visible'): raise out_of_band.AccessViolation(message_fmt=DEF_PAGE_INACTIVE_MSG) if task_entity.status in ['Unapproved', 'Unpublished', 'Invalid']: # this proposal can not be task at the moment raise out_of_band.AccessViolation( message_fmt=DEF_NO_PUB_TASK_MSG)
def checkStatusForTask(self, django_args): """Checks if the current user has access to the given task. This method checks if the current user is either an GCI Org Admin or a Mentor and is active, if yes it allows them to view the task page at any task state. If the user is none of the above, it checks the status of the task, and if it is in one of the valid published states it allows access to view the task page. Args: django_args: a dictionary with django's arguments Raises: AccessViolationResponse: - If there is no task found - If the task is not in one of the required states. """ user_entity = self.user # bail out with 404 if no task is found task_entity = gci_task_logic.logic.getFromKeyFieldsOr404(django_args) if (user_entity and task_entity.user and task_entity.user.key() == user_entity.key()): return filter = { 'user': user_entity, 'status': 'active', } if host_logic.logic.getForFields(filter, unique=True): return filter['scope_path'] = django_args['scope_path'] if gci_org_admin_logic.logic.getForFields(filter, unique=True): return if gci_mentor_logic.logic.getForFields(filter, unique=True): return org_entity = gci_org_logic.logic.getFromKeyNameOr404( django_args['scope_path']) if not timeline_helper.isAfterEvent(org_entity.scope.timeline, 'tasks_publicly_visible'): raise out_of_band.AccessViolation( message_fmt=DEF_PAGE_INACTIVE_MSG) if task_entity.status in ['Unapproved', 'Unpublished', 'Invalid']: # this proposal can not be task at the moment raise out_of_band.AccessViolation(message_fmt=DEF_NO_PUB_TASK_MSG)
def _public(self, request, entity, context): """See base.View._public(). """ # TODO: This needs to be moved to the GSoC module from soc.modules.gsoc.views.models import student_project as \ student_project_view program_entity = entity.scope if timeline_helper.isAfterEvent( program_entity.timeline, 'accepted_students_announced_deadline'): # accepted projects ap_params = student_project_view.view.getParams().copy() # define the list redirect action to show the notification ap_params['public_row_extra'] = lambda entity: { 'link': (redirects.getPublicRedirect, ap_params) } ap_params[ 'list_description'] = self.DEF_ACCEPTED_PROJECTS_MSG_FMT % ( entity.name) ap_params['list_heading'] = 'soc/student_project/list/heading.html' ap_params['list_row'] = 'soc/student_project/list/row.html' # TODO(LIST) # only show projects that have not failed filter = {'scope': entity, 'status': ['accepted', 'completed']} ap_list = lists.getListContent(request, ap_params, filter, idx=0, need_content=True) contents = [] if ap_list: # this is a temporary fix for sorting Student Projects # by Student name until we have a view that default # sorts it self by name (right now we can't do such query) ap_list['data'].sort(key=lambda sp: sp.student.name().lower()) contents.append(ap_list) # construct the list and put it into the context context['list'] = soc.logic.lists.Lists(contents) # obtain data to construct the organization map as json object context['org_map_data'] = self._getMapData(filter) return super(View, self)._public(request=request, entity=entity, context=context)
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 _getStudentEntries(self, program_entity, student_entity, params, id, user, prefix): """Returns a list with menu items for students in a specific program. """ items = [] timeline_entity = program_entity.timeline if timeline_helper.isActivePeriod(timeline_entity, 'student_signup') and \ student_entity.status == 'active': items += [('/gsoc/student_proposal/list_orgs/%s' % ( student_entity.key().id_or_name()), "Submit your Student Proposal", 'any_access')] if timeline_helper.isAfterEvent(timeline_entity, 'student_signup_start'): items += [(redirects.getListSelfRedirect(student_entity, {'url_name': prefix + '/student_proposal'}), "List my Student Proposals", 'any_access')] if timeline_helper.isAfterEvent(timeline_entity, 'accepted_students_announced_deadline'): # add a link to show all projects items += [(redirects.getListProjectsRedirect(program_entity, {'url_name': prefix + '/student'}), "List my Student Projects", 'any_access')] if timeline_helper.isBeforeEvent(program_entity.timeline, 'program_end') \ and student_entity.status == 'active': items += [(redirects.getManageRedirect(student_entity, {'url_name': prefix + '/student'}), "Resign as a Student", 'any_access')] items += super(View, self)._getStudentEntries(program_entity, student_entity, params, id, user, prefix) return items
def _public(self, request, entity, context): """See base.View._public(). """ from soc.views.models import student_project as student_project_view program_entity = entity.scope if timeline_helper.isAfterEvent(program_entity.timeline, 'accepted_students_announced_deadline'): # accepted projects ap_params = student_project_view.view.getParams().copy() # define the list redirect action to show the notification ap_params['list_action'] = (redirects.getPublicRedirect, ap_params) ap_params['list_description'] = self.DEF_ACCEPTED_PROJECTS_MSG_FMT %( entity.name) ap_params['list_heading'] = 'soc/student_project/list/heading.html' ap_params['list_row'] = 'soc/student_project/list/row.html' # only show projects that have not failed filter = {'scope': entity, 'status': ['accepted', 'completed']} ap_list = lists.getListContent(request, ap_params, filter, idx=0, need_content=True) contents = [] if ap_list: # this is a temporary fix for sorting Student Projects # by Student name until we have a view that default # sorts it self by name (right now we can't do such query) ap_list['data'].sort(key=lambda sp: sp.student.name().lower()) contents.append(ap_list) # construct the list and put it into the context context['list'] = soc.logic.lists.Lists(contents) # obtain data to construct the organization map as json object context['org_map_data'] = self._getMapData(filter) news_feed = NewsFeed(entity) context['news_feed'] = news_feed.getFeed() return super(View, self)._public(request=request, entity=entity, context=context)
def _getHostEntries(self, entity, params, prefix): """Returns a list with menu items for program host. Args: entity: program entity to get the entries for params: view specific params prefix: module prefix for the program entity """ items = [] # add link to edit Program Profile items += [(redirects.getEditRedirect(entity, params), 'Edit Program Profile', 'any_access')] # add link to edit Program Timeline items += [ (redirects.getEditRedirect(entity, {'url_name': prefix + '/timeline'}), "Edit Program Timeline", 'any_access') ] # add link to create a new Program Document items += [ (redirects.getCreateDocumentRedirect(entity, params['document_prefix']), "Create a New Document", 'any_access') ] # add link to list all Program Document items += [ (redirects.getListDocumentsRedirect(entity, params['document_prefix']), "List Documents", 'any_access') ] timeline_entity = entity.timeline if not timeline_helper.isAfterEvent(timeline_entity, 'org_signup'): # add link to create/edit OrgAppSurvey org_app_survey = org_app_logic.getForProgram(entity) items += [ (redirects.getCreateSurveyRedirect(entity, params['document_prefix'], prefix + '/org_app'), 'Edit Org Application Survey', 'any_access') ] return items
def _getOrganizationEntries(self, gci_program_entity, org_admin_entity, mentor_entity, params, id, user): """Returns a list with menu items for org admins and mentors in a specific program. Note: this method is called only after the accepted organizations are announced """ items = [] timeline_entity = gci_program_entity.timeline if mentor_entity and timeline_helper.isAfterEvent( timeline_entity, 'accepted_organization_announced_deadline'): # add a link to show all tasks that the mentor is assigned to items += [(gci_redirects.getListMentorTasksRedirect( mentor_entity, {'url_name':'gci/mentor'}), "List starred tasks", 'any_access')] return items
def _getOrganizationEntries(self, gci_program_entity, org_admin_entity, mentor_entity, params, id, user): """Returns a list with menu items for org admins and mentors in a specific program. Note: this method is called only after the accepted organizations are announced """ items = [] timeline_entity = gci_program_entity.timeline if mentor_entity and timeline_helper.isAfterEvent( timeline_entity, 'accepted_organization_announced_deadline'): # add a link to show all tasks that the mentor is assigned to items += [(gci_redirects.getListMentorTasksRedirect( mentor_entity, {'url_name': 'gci/mentor'}), "List starred tasks", 'any_access')] return items
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 _getStudentEntries(self, program_entity, student_entity, params, id, user, prefix): """Returns a list with menu items for students in a specific program. """ items = [] timeline_entity = program_entity.timeline if timeline_helper.isAfterEvent(timeline_entity, 'student_signup_start'): # add a link to show all projects items += [(ghop_redirects.getListStudentTasksRedirect( program_entity, {'url_name': 'ghop/student'}), "List my Tasks", 'any_access')] items += super(View, self)._getStudentEntries(program_entity, student_entity, params, id, user, prefix) return items
def _public(self, request, entity, context): """See base.View._public(). """ from soc.views.models import student_project as student_project_view program_entity = entity.scope if timeline_helper.isAfterEvent(program_entity.timeline, 'accepted_students_announced_deadline'): # accepted projects ap_params = student_project_view.view.getParams().copy() # define the list redirect action to show the notification ap_params['list_action'] = (redirects.getPublicRedirect, ap_params) ap_params['list_description'] = self.DEF_ACCEPTED_PROJECTS_MSG_FMT % ( entity.name) ap_params['list_heading'] = 'soc/student_project/list/heading.html' ap_params['list_row'] = 'soc/student_project/list/row.html' # only show projects that have not failed filter = {'scope': entity, 'status': ['accepted', 'mid_term_passed', 'passed']} ap_list = lists.getListContent(request, ap_params, filter, idx=0, need_content=True) contents = [] if ap_list: contents.append(ap_list) # construct the list and put it into the context context['list'] = soc.logic.lists.Lists(contents) # obtain data to construct the organization map as json object context['org_map_data'] = self._getMapData(ap_params, filter) return super(View, self)._public(request=request, entity=entity, context=context)
def _getTimeDependentEntries(self, program_entity, params, id, user): """Returns a list with time dependent menu items. """ items = [] timeline_entity = program_entity.timeline org_app_survey = org_app_logic.getForProgram(program_entity) if org_app_survey and \ timeline_helper.isActivePeriod(org_app_survey, 'survey'): # add the organization signup link items += [ (redirects.getTakeSurveyRedirect( org_app_survey, {'url_name': 'gsoc/org_app'}), "Apply to become an Organization", 'any_access')] if user and org_app_survey and timeline_helper.isAfterEvent( org_app_survey, 'survey_start'): main_admin_fields = { 'main_admin': user, 'survey': org_app_survey, } backup_admin_fields = { 'backup_admin': user, 'survey': org_app_survey } org_app_record_logic = org_app_logic.getRecordLogic() if org_app_record_logic.getForFields(main_admin_fields, unique=True) or \ org_app_record_logic.getForFields(backup_admin_fields, unique=True): # add the 'List my Organization Applications' link items += [ (redirects.getListSelfRedirect(org_app_survey, {'url_name' : 'gsoc/org_app'}), "List My Organization Applications", 'any_access')] # get the student entity for this user and program filter = { 'user': user, 'scope': program_entity, 'status': ['active', 'inactive'] } student_entity = student_logic.getForFields(filter, unique=True) if student_entity: items += self._getStudentEntries(program_entity, student_entity, params, id, user, 'gsoc') # get mentor and org_admin entity for this user and program filter = { 'user': user, 'program': program_entity, 'status': ['active', 'inactive'] } mentor_entity = mentor_logic.getForFields(filter, unique=True) org_admin_entity = org_admin_logic.getForFields(filter, unique=True) if mentor_entity or org_admin_entity: items += self._getOrganizationEntries(program_entity, org_admin_entity, mentor_entity, params, id, user) if not (student_entity or mentor_entity or org_admin_entity): if timeline_helper.isActivePeriod(timeline_entity, 'student_signup'): # this user does not have a role yet for this program items += [ ('/gsoc/student/apply/%s' % (program_entity.key().id_or_name()), "Register as a Student", 'any_access')] deadline = 'accepted_organization_announced_deadline' if timeline_helper.isAfterEvent(timeline_entity, deadline): url = redirects.getAcceptedOrgsRedirect(program_entity, params) # add a link to list all the organizations items += [(url, "List participating Organizations", 'any_access')] if not student_entity and \ timeline_helper.isBeforeEvent(timeline_entity, 'program_end'): # add apply to become a mentor link items += [ ('/gsoc/org/apply_mentor/%s' % (program_entity.key().id_or_name()), "Apply to become a Mentor", 'any_access')] deadline = 'accepted_students_announced_deadline' if timeline_helper.isAfterEvent(timeline_entity, deadline): items += [(redirects.getListProjectsRedirect(program_entity, {'url_name':'gsoc/program'}), "List all Student Projects", 'any_access')] return items
def _getTimeDependentEntries(self, program_entity, params, id, user): """Returns a list with time dependent menu items. """ from soc.modules.gsoc.logic.models.org_app_survey import logic as \ org_app_logic items = [] timeline_entity = program_entity.timeline org_app_survey = org_app_logic.getForProgram(program_entity) if org_app_survey and \ timeline_helper.isActivePeriod(timeline_entity, 'org_signup'): # add the organization signup link items += [ (redirects.getTakeSurveyRedirect(org_app_survey, {'url_name': 'gsoc/org_app'}), "Apply to become an Organization", 'any_access') ] if user and org_app_survey and timeline_helper.isAfterEvent( timeline_entity, 'org_signup_start'): main_admin_fields = { 'main_admin': user, 'survey': org_app_survey, } backup_admin_fields = { 'backup_admin': user, 'survey': org_app_survey } org_app_record_logic = org_app_logic.getRecordLogic() if org_app_record_logic.getForFields(main_admin_fields, unique=True) or \ org_app_record_logic.getForFields(backup_admin_fields, unique=True): # add the 'List my Organization Applications' link items += [(redirects.getListSelfRedirect( org_app_survey, {'url_name': 'gsoc/org_app'}), "List My Organization Applications", 'any_access')] # get the student entity for this user and program filter = { 'user': user, 'scope': program_entity, 'status': ['active', 'inactive'] } student_entity = student_logic.getForFields(filter, unique=True) if student_entity: items += self._getStudentEntries(program_entity, student_entity, params, id, user, 'gsoc') # get mentor and org_admin entity for this user and program filter = { 'user': user, 'program': program_entity, 'status': ['active', 'inactive'] } mentor_entity = mentor_logic.getForFields(filter, unique=True) org_admin_entity = org_admin_logic.getForFields(filter, unique=True) if mentor_entity or org_admin_entity: items += self._getOrganizationEntries(program_entity, org_admin_entity, mentor_entity, params, id, user) if user and not (student_entity or mentor_entity or org_admin_entity): if timeline_helper.isActivePeriod(timeline_entity, 'student_signup'): # this user does not have a role yet for this program items += [('/gsoc/student/apply/%s' % (program_entity.key().id_or_name()), "Register as a Student", 'any_access')] deadline = 'accepted_organization_announced_deadline' if timeline_helper.isAfterEvent(timeline_entity, deadline): url = redirects.getAcceptedOrgsRedirect(program_entity, params) # add a link to list all the organizations items += [(url, "List participating Organizations", 'any_access')] if not student_entity and \ timeline_helper.isBeforeEvent(timeline_entity, 'program_end'): # add apply to become a mentor link items += [('/gsoc/org/apply_mentor/%s' % (program_entity.key().id_or_name()), "Apply to become a Mentor", 'any_access')] deadline = 'accepted_students_announced_deadline' if timeline_helper.isAfterEvent(timeline_entity, deadline): items += [(redirects.getListProjectsRedirect( program_entity, {'url_name': 'gsoc/program'}), "List all Student Projects", 'any_access')] return items
def _getTimeDependentEntries(self, program_entity, params, id, user): """Returns a list with time dependent menu items. """ items = [] #TODO(ljvderijk) Add more timeline dependent entries timeline_entity = program_entity.timeline if timeline_helper.isActivePeriod(timeline_entity, 'org_signup'): # add the organization signup link items += [ (redirects.getApplyRedirect(program_entity, {'url_name': 'org_app'}), "Apply to become an Organization", 'any_access')] if user and timeline_helper.isAfterEvent(timeline_entity, 'org_signup_start'): filter = { 'applicant': user, 'scope': program_entity, } if org_app_logic.logic.getForFields(filter, unique=True): # add the 'List my Organization Applications' link items += [ (redirects.getListSelfRedirect(program_entity, {'url_name' : 'org_app'}), "List My Organization Applications", 'any_access')] # get the student entity for this user and program filter = {'user': user, 'scope': program_entity, 'status': 'active'} student_entity = student_logic.logic.getForFields(filter, unique=True) if student_entity: items += self._getStudentEntries(program_entity, student_entity, params, id, user) # get mentor and org_admin entity for this user and program filter = {'user': user, 'program': program_entity, 'status': 'active'} mentor_entity = mentor_logic.logic.getForFields(filter, unique=True) org_admin_entity = org_admin_logic.logic.getForFields(filter, unique=True) if mentor_entity or org_admin_entity: items += self._getOrganizationEntries(program_entity, org_admin_entity, mentor_entity, params, id, user) if user and not (student_entity or mentor_entity or org_admin_entity): if timeline_helper.isActivePeriod(timeline_entity, 'student_signup'): # this user does not have a role yet for this program items += [('/student/apply/%s' % (program_entity.key().id_or_name()), "Register as a Student", 'any_access')] deadline = 'accepted_organization_announced_deadline' if timeline_helper.isAfterEvent(timeline_entity, deadline): url = redirects.getAcceptedOrgsRedirect(program_entity, params) # add a link to list all the organizations items += [(url, "List participating Organizations", 'any_access')] if not student_entity: # add apply to become a mentor link items += [('/org/apply_mentor/%s' % (program_entity.key().id_or_name()), "Apply to become a Mentor", 'any_access')] deadline = 'accepted_students_announced_deadline' if timeline_helper.isAfterEvent(timeline_entity, deadline): items += [(redirects.getListProjectsRedirect(program_entity, {'url_name':'program'}), "List all student projects", 'any_access')] return items
def _public(self, request, entity, context): """See base.View._public(). """ #TODO(LIST) from soc.modules.ghop.views.models import task as ghop_task_view contents = [] ghop_program_entity = entity.scope is_after_student_signup = timeline_helper.isAfterEvent( ghop_program_entity.timeline, 'student_signup_start') is_after_tasks_become_public = timeline_helper.isAfterEvent( ghop_program_entity.timeline, 'tasks_publicly_visible') if is_after_student_signup and is_after_tasks_become_public: # open tasks to_params = ghop_task_view.view.getParams().copy() # define the list redirect action to show the task public page to_params['public_row_extra'] = lambda entity: { 'link': redirects.getPublicRedirect(entity, to_params) } to_params['list_description'] = self.DEF_OPEN_PROJECTS_MSG_FMT % ( entity.name) to_params['list_heading'] = 'modules/ghop/task/list/heading.html' to_params['list_row'] = 'modules/ghop/task/list/row.html' filter = {'scope': entity, 'status': ['Open', 'Reopened']} to_list = lists.getListContent(request, to_params, filter, idx=0, need_content=True) if to_list: to_list['data'].sort(key=lambda task: task.modified_on) contents.append(to_list) # claimed tasks tc_params = to_params.copy() tc_params[ 'list_description'] = self.DEF_CLAIMED_PROJECTS_MSG_FMT % ( entity.name) filter = { 'scope': entity, 'status': [ 'ClaimRequested', 'Claimed', 'NeedsAction', 'NeedsReview', 'NeedsWork' ] } tc_list = lists.getListContent(request, tc_params, filter, idx=1, need_content=True) if tc_list: tc_list['data'].sort(key=lambda task: task.modified_on) contents.append(tc_list) # closed tasks tcs_params = to_params.copy() tcs_params[ 'list_description'] = self.DEF_CLOSED_PROJECTS_MSG_FMT % ( entity.name) filter = { 'scope': entity, 'status': ['AwaitingRegistration', 'Closed'] } tcs_list = lists.getListContent(request, tcs_params, filter, idx=2, need_content=True) if tcs_list: tcs_list['data'].sort(key=lambda task: task.modified_on) contents.append(tcs_list) # construct the list and put it into the context context['list'] = soc.logic.lists.Lists(contents) return super(View, self)._public(request=request, entity=entity, context=context)
def _getTimeDependentEntries(self, gci_program_entity, params, id, user): """Returns a list with time dependent menu items. """ items = [] timeline_entity = gci_program_entity.timeline # add show ranking item if timeline_helper.isAfterEvent(timeline_entity, 'tasks_publicly_visible'): items += [(gci_redirects.getShowRankingRedirect( gci_program_entity, {'url_name': 'gci/program'}), 'Show Ranking', 'any_access')] mentor_entity = None org_admin_entity = None org_app_survey = org_app_logic.getForProgram(gci_program_entity) if org_app_survey and \ timeline_helper.isActivePeriod(org_app_survey, 'survey'): # add the organization signup link items += [ (redirects.getTakeSurveyRedirect( org_app_survey, {'url_name': 'gci/org_app'}), "Apply to become an Organization", 'any_access')] if user and org_app_survey and timeline_helper.isAfterEvent( org_app_survey, 'survey_start'): main_admin_fields = { 'main_admin': user, 'survey': org_app_survey, } backup_admin_fields = { 'backup_admin': user, 'survey': org_app_survey } org_app_record_logic = org_app_logic.getRecordLogic() if org_app_record_logic.getForFields(main_admin_fields, unique=True) or \ org_app_record_logic.getForFields(backup_admin_fields, unique=True): # add the 'List my Organization Applications' link items += [ (redirects.getListSelfRedirect(org_app_survey, {'url_name' : 'gci/org_app'}), "List My Organization Applications", 'any_access')] # get the student entity for this user and program filter = {'user': user, 'scope': gci_program_entity, 'status': ['active', 'inactive']} student_entity = gci_student_logic.logic.getForFields(filter, unique=True) # students can register after successfully completing their first # task. So if a user has completed one task he is still a student filter = { 'user': user, 'program': gci_program_entity, } has_completed_task = gci_task_logic.logic.getForFields( filter, unique=True) if student_entity or (user and has_completed_task): items += self._getStudentEntries(gci_program_entity, student_entity, params, id, user, 'gci') else: # get mentor and org_admin entity for this user and program filter = { 'user': user, 'program': gci_program_entity, 'status': 'active' } mentor_entity = gci_mentor_logic.logic.getForFields(filter, unique=True) org_admin_entity = gci_org_admin_logic.logic.getForFields( filter, unique=True) if timeline_helper.isAfterEvent( timeline_entity, 'accepted_organization_announced_deadline'): if mentor_entity or org_admin_entity: items += self._getOrganizationEntries( gci_program_entity, org_admin_entity, mentor_entity, params, id, user) if timeline_helper.isBeforeEvent(timeline_entity, 'program_end'): # add apply to become a mentor link items += [ ('/gci/org/apply_mentor/%s' % ( gci_program_entity.key().id_or_name()), "Apply to become a Mentor", 'any_access')] if timeline_helper.isAfterEvent( timeline_entity, 'accepted_organization_announced_deadline'): url = redirects.getAcceptedOrgsRedirect( gci_program_entity, params) # add a link to list all the organizations items += [(url, "List participating Organizations", 'any_access')] user_fields = { 'user': user, 'status': 'active' } host_entity = host_logic.getForFields(user_fields, unique=True) # for org admins this link should be visible only after accepted # organizations are announced and for other public after the tasks # are public but for program host it must be visible always if (host_entity or ((org_admin_entity or mentor_entity) and timeline_helper.isAfterEvent( timeline_entity, 'tasks_publicly_visible')) or (timeline_helper.isAfterEvent( timeline_entity, 'tasks_publicly_visible'))): url = gci_redirects.getListAllTasksRedirect( gci_program_entity, params) # add a link to list all the organizations items += [(url, "List all tasks", 'any_access')] if user: # add a link to show all tasks of interest items += [(gci_redirects.getListMyTasksRedirect( gci_program_entity, params), 'List my Tasks', 'any_access')] return items
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('mentor') admin_entity = roles.get('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), "View all Student Proposals", 'any_access') submenus.append(submenu) if admin_entity: # 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['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['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['mentor'], {'url_name': 'gsoc/mentor'}), "Resign as Mentor", 'any_access') submenus.append(submenu) # add a link to the edit page submenu = (redirects.getEditRedirect(roles['mentor'], {'url_name': 'gsoc/mentor'}), "Edit My Mentor Profile", 'any_access') submenus.append(submenu) return submenus
except out_of_band.Error, error: return helper.responses.errorResponse( error, request, template=params['error_public']) # 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.scope.name()) context['entity'] = entity context['entity_type'] = params['name'] context['entity_type_url'] = params['url_name'] program_entity = entity.program if timeline_helper.isAfterEvent(program_entity.timeline, 'accepted_students_announced_deadline'): return self.reviewAfterDeadline(request, context, params, entity, **kwargs) # get the roles important for reviewing an application filter = {'user': user_logic.logic.getForCurrentAccount(), 'scope': entity.org, 'status': 'active'} org_admin_entity = org_admin_logic.logic.getForFields(filter, unique=True) mentor_entity = mentor_logic.logic.getForFields(filter, unique=True) # decide which form to use if org_admin_entity: form = params['admin_review_form'] else:
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 _getTimeDependentEntries(self, ghop_program_entity, params, id, user): """Returns a list with time dependent menu items. """ from soc.modules.ghop.logic.models.org_app_survey import logic as \ org_app_logic items = [] timeline_entity = ghop_program_entity.timeline org_app_survey = org_app_logic.getForProgram(ghop_program_entity) if org_app_survey and \ timeline_helper.isActivePeriod(timeline_entity, 'org_signup'): # add the organization signup link items += [ (redirects.getTakeSurveyRedirect(org_app_survey, {'url_name': 'ghop/org_app'}), "Apply to become an Organization", 'any_access') ] if user and org_app_survey and timeline_helper.isAfterEvent( timeline_entity, 'org_signup_start'): main_admin_fields = { 'main_admin': user, 'survey': org_app_survey, } backup_admin_fields = { 'backup_admin': user, 'survey': org_app_survey } org_app_record_logic = org_app_logic.getRecordLogic() if org_app_record_logic.getForFields(main_admin_fields, unique=True) or \ org_app_record_logic.getForFields(backup_admin_fields, unique=True): # add the 'List my Organization Applications' link items += [(redirects.getListSelfRedirect( org_app_survey, {'url_name': 'ghop/org_app'}), "List My Organization Applications", 'any_access')] # get the student entity for this user and program filter = { 'user': user, 'scope': ghop_program_entity, 'status': ['active', 'inactive'] } student_entity = ghop_student_logic.logic.getForFields(filter, unique=True) if student_entity: items += self._getStudentEntries(ghop_program_entity, student_entity, params, id, user, 'ghop') else: # if a user has a task assigned, he or she still may list it filter = { 'user': user, 'program': ghop_program_entity, } if user and ghop_task_logic.logic.getForFields(filter, unique=True): items += [(ghop_redirects.getListStudentTasksRedirect( ghop_program_entity, {'url_name': 'ghop/student'}), "List my Tasks", 'any_access')] filter['status'] = 'AwaitingRegistration' if ghop_task_logic.logic.getForFields(filter, unique=True): if timeline_helper.isActivePeriod(timeline_entity, 'student_signup'): # this user does not have a role yet for this program items += [('/ghop/student/apply/%s' % (ghop_program_entity.key().id_or_name()), "Register as a Student", 'any_access')] # get mentor and org_admin entity for this user and program filter = { 'user': user, 'program': ghop_program_entity, 'status': 'active' } mentor_entity = ghop_mentor_logic.logic.getForFields(filter, unique=True) org_admin_entity = ghop_org_admin_logic.logic.getForFields( filter, unique=True) if mentor_entity or org_admin_entity: items += self._getOrganizationEntries(ghop_program_entity, org_admin_entity, mentor_entity, params, id, user) if timeline_helper.isAfterEvent(timeline_entity, 'org_signup_start'): url = redirects.getAcceptedOrgsRedirect(ghop_program_entity, params) # add a link to list all the organizations items += [(url, "List participating Organizations", 'any_access')] return items
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'] if roles.get('org_admin') or roles.get('mentor'): # add a link to view all the student proposals submenu = (redirects.getListProposalsRedirect(group_entity, params), "View all Student Proposals", 'any_access') submenus.append(submenu) if roles.get('org_admin'): # 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': 'student_project'}), "Manage Student Projects", 'any_access') submenus.append(submenu) # 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, 'org_admin'), "Invite an Admin", 'any_access') submenus.append(submenu) # add a link to invite a member submenu = (redirects.getInviteRedirectForRole(group_entity, '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 roles.get('org_admin') or roles.get('mentor'): submenu = (redirects.getCreateDocumentRedirect(group_entity, 'org'), "Create a New Document", 'any_access') submenus.append(submenu) submenu = (redirects.getListDocumentsRedirect(group_entity, 'org'), "List Documents", 'any_access') submenus.append(submenu) if roles.get('org_admin'): # add a link to the resign page submenu = (redirects.getManageRedirect(roles['org_admin'], {'url_name': 'org_admin'}), "Resign as Admin", 'any_access') submenus.append(submenu) # add a link to the edit page submenu = (redirects.getEditRedirect(roles['org_admin'], {'url_name': 'org_admin'}), "Edit My Admin Profile", 'any_access') submenus.append(submenu) if roles.get('mentor'): # add a link to the resign page submenu = (redirects.getManageRedirect(roles['mentor'], {'url_name' : 'mentor'}), "Resign as Mentor", 'any_access') submenus.append(submenu) # add a link to the edit page submenu = (redirects.getEditRedirect(roles['mentor'], {'url_name': 'mentor'}), "Edit My Mentor Profile", 'any_access') submenus.append(submenu) return submenus
def _getTimeDependentEntries(self, gci_program_entity, params, id, user): """Returns a list with time dependent menu items. """ items = [] timeline_entity = gci_program_entity.timeline # add show ranking item if timeline_helper.isAfterEvent(timeline_entity, 'tasks_publicly_visible'): items += [(gci_redirects.getShowRankingRedirect( gci_program_entity, {'url_name': 'gci/program'}), 'Show Ranking', 'any_access')] mentor_entity = None org_admin_entity = None org_app_survey = org_app_logic.getForProgram(gci_program_entity) if org_app_survey and \ timeline_helper.isActivePeriod(org_app_survey, 'survey'): # add the organization signup link items += [ (redirects.getTakeSurveyRedirect(org_app_survey, {'url_name': 'gci/org_app'}), "Apply to become an Organization", 'any_access') ] if user and org_app_survey and timeline_helper.isAfterEvent( org_app_survey, 'survey_start'): main_admin_fields = { 'main_admin': user, 'survey': org_app_survey, } backup_admin_fields = { 'backup_admin': user, 'survey': org_app_survey } org_app_record_logic = org_app_logic.getRecordLogic() if org_app_record_logic.getForFields(main_admin_fields, unique=True) or \ org_app_record_logic.getForFields(backup_admin_fields, unique=True): # add the 'List my Organization Applications' link items += [(redirects.getListSelfRedirect( org_app_survey, {'url_name': 'gci/org_app'}), "List My Organization Applications", 'any_access')] # get the student entity for this user and program filter = { 'user': user, 'scope': gci_program_entity, 'status': ['active', 'inactive'] } student_entity = gci_student_logic.logic.getForFields(filter, unique=True) # students can register after successfully completing their first # task. So if a user has completed one task he is still a student filter = { 'user': user, 'program': gci_program_entity, } has_completed_task = gci_task_logic.logic.getForFields(filter, unique=True) if student_entity or (user and has_completed_task): items += self._getStudentEntries(gci_program_entity, student_entity, params, id, user, 'gci') else: # get mentor and org_admin entity for this user and program filter = { 'user': user, 'program': gci_program_entity, 'status': 'active' } mentor_entity = gci_mentor_logic.logic.getForFields(filter, unique=True) org_admin_entity = gci_org_admin_logic.logic.getForFields( filter, unique=True) if timeline_helper.isAfterEvent( timeline_entity, 'accepted_organization_announced_deadline'): if mentor_entity or org_admin_entity: items += self._getOrganizationEntries( gci_program_entity, org_admin_entity, mentor_entity, params, id, user) if timeline_helper.isBeforeEvent(timeline_entity, 'program_end'): # add apply to become a mentor link items += [('/gci/org/apply_mentor/%s' % (gci_program_entity.key().id_or_name()), "Apply to become a Mentor", 'any_access')] if timeline_helper.isAfterEvent( timeline_entity, 'accepted_organization_announced_deadline'): url = redirects.getAcceptedOrgsRedirect(gci_program_entity, params) # add a link to list all the organizations items += [(url, "List participating Organizations", 'any_access')] user_fields = {'user': user, 'status': 'active'} host_entity = host_logic.getForFields(user_fields, unique=True) # for org admins this link should be visible only after accepted # organizations are announced and for other public after the tasks # are public but for program host it must be visible always if (host_entity or ((org_admin_entity or mentor_entity) and timeline_helper.isAfterEvent( timeline_entity, 'tasks_publicly_visible')) or (timeline_helper.isAfterEvent(timeline_entity, 'tasks_publicly_visible'))): url = gci_redirects.getListAllTasksRedirect( gci_program_entity, params) # add a link to list all the organizations items += [(url, "List all tasks", 'any_access')] if user: # add a link to show all tasks of interest items += [(gci_redirects.getListMyTasksRedirect( gci_program_entity, params), 'List my Tasks', 'any_access')] return items
return helper.responses.errorResponse( error, request, template=params['error_public']) # 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.scope.name()) context['entity'] = entity context['entity_type'] = params['name'] context['entity_type_url'] = params['url_name'] program_entity = entity.program if timeline_helper.isAfterEvent( program_entity.timeline, 'accepted_students_announced_deadline'): return self.reviewAfterDeadline(request, context, params, entity, **kwargs) # get the roles important for reviewing an application filter = { 'user': user_logic.logic.getForCurrentAccount(), 'scope': entity.org, 'status': 'active' } org_admin_entity = org_admin_logic.logic.getForFields(filter, unique=True) mentor_entity = mentor_logic.logic.getForFields(filter, unique=True)