def getListData(self): """Returns the list data as requested by the current request. If the lists as requested is not supported by this component None is returned. """ if lists.getListIndex(self.data.request) != 0: return None q = OrgAppRecord.all() q.filter('survey', self.survey) q.filter('main_admin', self.data.ndb_user.key.to_old_key()) records = q.fetch(1000) q = OrgAppRecord.all() q.filter('survey', self.survey) q.filter('backup_admin', self.data.ndb_user.key.to_old_key()) records.extend(q.fetch(1000)) response = lists.ListContentResponse(self.data.request, self._list_config) for record in records: response.addRow(record) response.next = 'done' return response
def getListData(self): """Returns the list data as requested by the current request. If the lists as requested is not supported by this component None is returned. """ if lists.getListIndex(self.request) != 0: return None q = OrgAppRecord.all() q.filter("survey", self.survey) q.filter("main_admin", self.data.user) records = q.fetch(1000) q = OrgAppRecord.all() q.filter("survey", self.survey) q.filter("backup_admin", self.data.user) records.extend(q.fetch(1000)) response = lists.ListContentResponse(self.request, self._list_config) for record in records: response.addRow(record) response.next = "done" return response
def convertCIOrganization(org_key): """Converts the specified Code In organization by creating a new organization entity that inherits from NDB model. Args: org_key: Organization key. """ organization = GCIOrganization.get(org_key) entity_id = '%s/%s' % (organization.program.key().name(), organization.link_id) org_properties = {} org_properties.update(_generalProperties(organization)) org_properties.update(_ciSpecificProperties(organization)) new_organization = ci_org_model.CIOrganization(id=entity_id, **org_properties) to_put = [new_organization] # find organization application record corresponding to this organization app_record = OrgAppRecord.all().filter('org_id', organization.link_id).filter( 'program', organization.program).get() if app_record: to_put.append(_convertSurveyResponse(app_record, new_organization)) persistEntitiesTxn(to_put) operation.counters.Increment('Organizations converted')
def convertCIOrganization(org_key): """Converts the specified Code In organization by creating a new organization entity that inherits from NDB model. Args: org_key: Organization key. """ organization = GCIOrganization.get(org_key) entity_id = '%s/%s' % ( organization.program.key().name(), organization.link_id) org_properties = {} org_properties.update(_generalProperties(organization)) org_properties.update(_ciSpecificProperties(organization)) new_organization = ci_org_model.CIOrganization( id=entity_id, **org_properties) to_put = [new_organization] # find organization application record corresponding to this organization app_record = OrgAppRecord.all().filter( 'org_id', organization.link_id).filter( 'program', organization.program).get() if app_record: to_put.append(_convertSurveyResponse(app_record, new_organization)) persistEntitiesTxn(to_put) operation.counters.Increment('Organizations converted')
def _getMyOrgApplicationsComponent(self): """Returns MyOrgApplicationsComponent iff this user is main_admin or backup_admin in an application. """ survey = org_app_logic.getForProgram(self.data.program) # Test if this user is main admin or backup admin q = OrgAppRecord.all() q.filter("survey", survey) q.filter("main_admin", self.data.user) record = q.get() q = OrgAppRecord.all() q.filter("survey", survey) q.filter("backup_admin", self.data.user) if record or q.get(): # add a component showing the organization application of the user return MyOrgApplicationsComponent(self.request, self.data, survey) return None
def _getMyOrgApplicationsComponent(self, data): """Returns MyOrgApplicationsComponent iff this user is main_admin or backup_admin in an application. """ survey = org_app_logic.getForProgram(data.program) # Test if this user is main admin or backup admin q = OrgAppRecord.all() q.filter('survey', survey) q.filter('main_admin', data.ndb_user.key.to_old_key()) record = q.get() q = OrgAppRecord.all() q.filter('survey', survey) q.filter('backup_admin', data.ndb_user.key.to_old_key()) if record or q.get(): # add a component showing the organization application of the user return MyOrgApplicationsComponent(data, survey) return None
def orgAppFromOrgId(self): org_id = self.data.GET.get('org_id') if not org_id: raise exception.BadRequest(message='Missing org_id') q = OrgAppRecord.all() q.filter('survey', self.data.org_app) q.filter('org_id', org_id) self.data.org_app_record = q.get() if not self.data.org_app_record: raise exception.NotFound( message="There is no org_app for the org_id %s" % org_id)
def orgAppFromOrgId(self): org_id = self.data.GET.get('org_id') if not org_id: raise BadRequest('Missing org_id') q = OrgAppRecord.all() q.filter('survey', self.data.org_app) q.filter('org_id', org_id) self.data.org_app_record = q.get() if not self.data.org_app_record: raise NotFound("There is no org_app for the org_id %s" % org_id) if self.data.org_app_record.status != 'accepted': raise AccessViolation(DEF_ORG_APP_REJECTED)
def orgAppRecord(self, org_id): """Sets the org app record corresponding to the given org id. Args: org_id: The link_id of the organization. """ assert access_checker.isSet(self.data.program) q = OrgAppRecord.all() q.filter('org_id', org_id) q.filter('program', self.data.program) record = q.get() if not record: raise exception.NotFound(message=DEF_NO_ORG_APP_RECORD_FOUND) self.data.org_app_record = record
def testOrgAppSurveyTakePage(self): """Tests organizationn application survey take/retake page. """ self.updateOrgAppSurvey() self.data.createOrgAdmin(self.org) backup_admin = GCIProfileHelper(self.gci, self.dev_test) backup_admin.createMentor(self.org) response = self.get(self.take_url) self.assertTemplatesUsed(response) params = { 'admin_id': self.data.user.link_id, 'backup_admin_id': backup_admin.user.link_id } params.update(self.post_params) response = self.post(self.take_url, params) query = OrgAppRecord.all() query.filter('main_admin = ', self.data.user) self.assertEqual(query.count(), 1, 'Survey record is not created.') record = query.get() self.assertEqual(record.org_id, self.post_params['org_id']) self.assertEqual(record.name, self.post_params['name']) self.assertEqual(record.description, self.post_params['description']) self.assertEqual(record.license, self.post_params['license']) self.assertEqual(record.main_admin.key(), self.data.user.key()) self.assertEqual(record.backup_admin.key(), backup_admin.user.key()) retake_url = self.retake_url_raw % (self.gci.key().name(), record.key().id()) self.assertResponseRedirect(response, retake_url + '?validated') response = self.get(retake_url) self.assertResponseOK(response) params = {'backup_admin_id': backup_admin.user.link_id} params.update(self.post_params) params['name'] = 'New title' response = self.post(retake_url, params) self.assertResponseRedirect(response, retake_url + '?validated') record = OrgAppRecord.get_by_id(record.key().id()) self.assertEqual(record.name, params['name'])
def testOrgAppSurveyTakePage(self): """Tests organizationn application survey take/retake page. """ self.updateOrgAppSurvey() self.data.createOrgAdmin(self.org) backup_admin = GCIProfileHelper(self.gci, self.dev_test) backup_admin.createMentor(self.org) response = self.get(self.take_url) self.assertTemplatesUsed(response) params = {'admin_id': self.data.user.link_id, 'backup_admin_id': backup_admin.user.link_id} params.update(self.post_params) response = self.post(self.take_url, params) query = OrgAppRecord.all() query.filter('main_admin = ', self.data.user) self.assertEqual(query.count(), 1, 'Survey record is not created.') record = query.get() self.assertEqual(record.org_id, self.post_params['org_id']) self.assertEqual(record.name, self.post_params['name']) self.assertEqual(record.description, self.post_params['description']) self.assertEqual(record.license, self.post_params['license']) self.assertEqual(record.main_admin.key(), self.data.user.key()) self.assertEqual(record.backup_admin.key(), backup_admin.user.key()) retake_url = self.retake_url_raw % (self.gci.key().name(), record.key().id()) self.assertResponseRedirect(response, retake_url + '?validated') response = self.get(retake_url) self.assertResponseOK(response) params = {'backup_admin_id': backup_admin.user.link_id} params.update(self.post_params) params['name'] = 'New title' response = self.post(retake_url, params) self.assertResponseRedirect(response, retake_url + '?validated') record = OrgAppRecord.get_by_id(record.key().id()) self.assertEqual(record.name, params['name'])
def clean_org_id(self): org_id = cleaning.clean_link_id('org_id')(self) if not org_id: # manual required check, see Issue 1291 raise django_forms.ValidationError('This field is required.') q = OrgAppRecord.all() q.filter('survey', self.survey) q.filter('org_id', org_id) org_app = q.get() if org_app: # If we are creating a new org app it is a duplicate, if we are editing # an org app we must check if the one we found has a different key. if (not self.instance) or (org_app.key() != self.instance.key()): raise django_forms.ValidationError('This ID has already been taken.') return org_id