def context(self): assert isSet(self.data.project) r = self.data.redirect.project() featured_project = ToggleButtonTemplate( self.data, 'on_off', 'Featured', 'project-featured', r.urlOf('gsoc_featured_project'), checked=self.data.project.is_featured, help_text=self.DEF_FEATURED_PROJECT_HELP, labels={ 'checked': 'Yes', 'unchecked': 'No'}) self.toggle_buttons.append(featured_project) context = { 'title': 'Project Actions', 'toggle_buttons': self.toggle_buttons, } r = self.data.redirect all_mentors_keys = profile_logic.queryAllMentorsKeysForOrg( self.data.project.org) context['assign_mentor'] = assign_mentor.AssignMentorFields( self.data, self.data.project.mentors, r.project().urlOf('gsoc_project_assign_mentors'), all_mentors=all_mentors_keys, mentor_required=True) return context
def context(self): """See template.Template.context for specification.""" featured_project_url = links.LINKER.userId( self.data.url_ndb_profile.key, self.data.url_project.key().id(), 'gsoc_featured_project') featured_project = ToggleButtonTemplate( self.data, 'on_off', 'Featured', 'project-featured', featured_project_url, checked=self.data.url_project.is_featured, help_text=self.DEF_FEATURED_PROJECT_HELP, labels={ 'checked': 'Yes', 'unchecked': 'No'}) self.toggle_buttons.append(featured_project) context = { 'title': 'Project Actions', 'toggle_buttons': self.toggle_buttons, } assign_mentor_url = links.LINKER.userId( self.data.url_ndb_profile.key, self.data.url_project.key().id(), 'gsoc_project_assign_mentors') org_key = ndb.Key.from_old_key( GSoCProject.org.get_value_for_datastore(self.data.url_project)) all_mentors_keys = profile_logic.queryAllMentorsKeysForOrg(org_key) context['assign_mentor'] = assign_mentor.AssignMentorFields( self.data, self.data.url_project.mentors, assign_mentor_url, all_mentors=all_mentors_keys, mentor_required=True, allow_multiple=True) return context
def runTest(org, mentors, org_admins): """Runs the test. """ mentor_keys = [entity.key() for entity in mentors] org_admin_keys = [entity.key() for entity in org_admins] expected_keys = set(mentor_keys + org_admin_keys) actual_keys = set(profile_logic.queryAllMentorsKeysForOrg(org)) self.assertEqual(expected_keys, actual_keys)
def _orgAdminContext(self): """Construct the context needed for org admin actions. """ context = {} r = self.data.redirect.review() ignore_button_checked = False if self.data.proposal.status == "ignored": ignore_button_checked = True if self.data.proposal.status in ["pending", "withdrawn", "ignored"]: ignore_proposal = ToggleButtonTemplate( self.data, "on_off", "Ignore Proposal", "proposal-ignore", r.urlOf("gsoc_proposal_ignore"), checked=ignore_button_checked, help_text=self.DEF_IGNORE_PROPOSAL_HELP, note=self.DEF_IGNORE_PROPOSAL_NOTE, labels={"checked": "Yes", "unchecked": "No"}, ) self.toggle_buttons.append(ignore_proposal) if not self.proposal_ignored: accept_proposal = ToggleButtonTemplate( self.data, "on_off", "Accept proposal", "accept-proposal", r.urlOf("gsoc_proposal_accept"), checked=self.data.proposal.accept_as_project, help_text=self.DEF_ACCEPT_PROPOSAL_HELP, labels={"checked": "Yes", "unchecked": "No"}, ) self.toggle_buttons.append(accept_proposal) r = self.data.redirect possible_mentors_keys = self.data.proposal.possible_mentors all_mentors_keys = profile_logic.queryAllMentorsKeysForOrg(self.data.proposal_org) context["assign_mentor"] = assign_mentor.AssignMentorFields( self.data, self.data.proposal.mentor, r.review().urlOf("gsoc_proposal_assign_mentor"), possible_mentors_keys, all_mentors_keys, ) return context
def validate(self): mentor_key = self.data.POST.get("assign_mentor") if mentor_key: mentor_entity = db.get(mentor_key) org = self.data.proposal.org if ( mentor_entity and self.data.isPossibleMentorForProposal(mentor_entity) or (org.list_all_mentors and db.Key(mentor_key) in profile_logic.queryAllMentorsKeysForOrg(org)) ): return mentor_entity else: raise BadRequest("Invalid post data.") return None
def validate(self, data): str_mentor_keys = data.POST.getlist('assign_mentor') if str_mentor_keys: org_key = GSoCProject.org.get_value_for_datastore(data.url_project) # need the list to set conversion and back to list conversion # to ensure that same mentor doesn't get assigned to the # project more than once mentor_keys = set([db.Key(k) for k in str_mentor_keys if k]) if mentor_keys < set( profile_logic.queryAllMentorsKeysForOrg(org_key)): return list(mentor_keys) else: raise exception.BadRequest(message="Invalid post data.") return None
def validate(self): str_mentor_keys = self.data.POST.getlist('assign_mentor') if str_mentor_keys: org = self.data.project.org # need the list to set conversion and back to list conversion # to ensure that same mentor doesn't get assigned to the # project more than once mentor_keys = set([db.Key(k) for k in str_mentor_keys if k]) if mentor_keys < set( profile_logic.queryAllMentorsKeysForOrg(org)): return list(mentor_keys) raise BadRequest("Invalid post data.") return None
def validate(self, data): mentor_key = data.POST.get('assign_mentor') if mentor_key: mentor_entity = db.get(mentor_key) org_key = proposal_model.GSoCProposal.org.get_value_for_datastore( data.url_proposal) org = ndb.Key.from_old_key(org_key).get() if mentor_entity and data.isPossibleMentorForProposal( mentor_entity) or ( org.list_all_mentors and db.Key(mentor_key) in profile_logic.queryAllMentorsKeysForOrg(org_key)): return mentor_entity else: raise exception.BadRequest(message="Invalid post data.") return None
def validate(self, data): mentor_key = data.POST.get('assign_mentor') if mentor_key: mentor_entity = db.get(mentor_key) org_key = proposal_model.GSoCProposal.org.get_value_for_datastore( data.url_proposal) org = ndb.Key.from_old_key(org_key).get() if mentor_entity and data.isPossibleMentorForProposal( mentor_entity) or (org.list_all_mentors and db.Key(mentor_key) in profile_logic.queryAllMentorsKeysForOrg( org_key)): return mentor_entity else: raise exception.BadRequest(message="Invalid post data.") return None
def context(self): """See template.Template.context for specification.""" featured_project_url = links.LINKER.userId( self.data.url_ndb_profile.key, self.data.url_project.key().id(), 'gsoc_featured_project') featured_project = ToggleButtonTemplate( self.data, 'on_off', 'Featured', 'project-featured', featured_project_url, checked=self.data.url_project.is_featured, help_text=self.DEF_FEATURED_PROJECT_HELP, labels={ 'checked': 'Yes', 'unchecked': 'No' }) self.toggle_buttons.append(featured_project) context = { 'title': 'Project Actions', 'toggle_buttons': self.toggle_buttons, } assign_mentor_url = links.LINKER.userId( self.data.url_ndb_profile.key, self.data.url_project.key().id(), 'gsoc_project_assign_mentors') org_key = ndb.Key.from_old_key( GSoCProject.org.get_value_for_datastore(self.data.url_project)) all_mentors_keys = profile_logic.queryAllMentorsKeysForOrg(org_key) context['assign_mentor'] = assign_mentor.AssignMentorFields( self.data, self.data.url_project.mentors, assign_mentor_url, all_mentors=all_mentors_keys, mentor_required=True, allow_multiple=True) return context
def _orgAdminContext(self): """Construct the context needed for org admin actions. """ context = {} ignore_proposal_url = links.LINKER.userId( self.data.url_ndb_profile.key, self.data.kwargs['id'], url_names.PROPOSAL_IGNORE) ignore_button_checked = False if self.data.url_proposal.status == 'ignored': ignore_button_checked = True if self.data.url_proposal.status in ['pending', 'ignored']: ignore_proposal = ToggleButtonTemplate( self.data, 'on_off', 'Ignore Proposal', 'proposal-ignore', ignore_proposal_url, checked=ignore_button_checked, help_text=self.DEF_IGNORE_PROPOSAL_HELP, note=self.DEF_IGNORE_PROPOSAL_NOTE, labels={ 'checked': 'Yes', 'unchecked': 'No' }) self.toggle_buttons.append(ignore_proposal) if not self.proposal_ignored: accept_proposal = ToggleButtonTemplate( self.data, 'on_off', 'Accept proposal', 'accept-proposal', links.LINKER.userId(self.data.url_ndb_profile.key, self.data.kwargs['id'], 'gsoc_proposal_accept'), checked=self.data.url_proposal.accept_as_project, help_text=self.DEF_ACCEPT_PROPOSAL_HELP, labels={ 'checked': 'Yes', 'unchecked': 'No', }) self.toggle_buttons.append(accept_proposal) possible_mentors_keys = self.data.url_proposal.possible_mentors org_key = proposal_model.GSoCProposal.org.get_value_for_datastore( self.data.url_proposal) org = ndb.Key.from_old_key(org_key).get() if org.list_all_mentors: all_mentors_keys = profile_logic.queryAllMentorsKeysForOrg( org_key) else: all_mentors_keys = [] current_mentors = [] mentor_key = ( proposal_model.GSoCProposal.mentor.get_value_for_datastore( self.data.url_proposal)) if mentor_key: current_mentors.append(mentor_key) assign_mentor_url = links.LINKER.userId( self.data.url_ndb_profile.key, self.data.kwargs['id'], 'gsoc_proposal_assign_mentor') context['assign_mentor'] = assign_mentor.AssignMentorFields( self.data, current_mentors, assign_mentor_url, all_mentors_keys, possible_mentors_keys) return context
def _orgAdminContext(self): """Construct the context needed for org admin actions. """ context = {} ignore_proposal_url = links.LINKER.userId( self.data.url_ndb_profile.key, self.data.kwargs['id'], url_names.PROPOSAL_IGNORE) ignore_button_checked = False if self.data.url_proposal.status == 'ignored': ignore_button_checked = True if self.data.url_proposal.status in ['pending', 'ignored']: ignore_proposal = ToggleButtonTemplate( self.data, 'on_off', 'Ignore Proposal', 'proposal-ignore', ignore_proposal_url, checked=ignore_button_checked, help_text=self.DEF_IGNORE_PROPOSAL_HELP, note=self.DEF_IGNORE_PROPOSAL_NOTE, labels={ 'checked': 'Yes', 'unchecked': 'No'}) self.toggle_buttons.append(ignore_proposal) if not self.proposal_ignored: accept_proposal = ToggleButtonTemplate( self.data, 'on_off', 'Accept proposal', 'accept-proposal', links.LINKER.userId( self.data.url_ndb_profile.key, self.data.kwargs['id'], 'gsoc_proposal_accept'), checked=self.data.url_proposal.accept_as_project, help_text=self.DEF_ACCEPT_PROPOSAL_HELP, labels={ 'checked': 'Yes', 'unchecked': 'No',}) self.toggle_buttons.append(accept_proposal) possible_mentors_keys = self.data.url_proposal.possible_mentors org_key = proposal_model.GSoCProposal.org.get_value_for_datastore( self.data.url_proposal) org = ndb.Key.from_old_key(org_key).get() if org.list_all_mentors: all_mentors_keys = profile_logic.queryAllMentorsKeysForOrg(org_key) else: all_mentors_keys = [] current_mentors = [] mentor_key = ( proposal_model.GSoCProposal.mentor.get_value_for_datastore( self.data.url_proposal)) if mentor_key: current_mentors.append(mentor_key) assign_mentor_url = links.LINKER.userId( self.data.url_ndb_profile.key, self.data.kwargs['id'], 'gsoc_proposal_assign_mentor') context['assign_mentor'] = assign_mentor.AssignMentorFields( self.data, current_mentors, assign_mentor_url, all_mentors_keys, possible_mentors_keys) return context