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 post(self): """Edits records from commands received by the list code. """ post_data = self.request.POST if not post_data.get('button_id', None) == 'save': raise BadRequest('No valid POST data found') data = self.data.POST.get('data') if not data: raise BadRequest('Missing data') parsed = simplejson.loads(data) self.data.redirect.program() url = self.data.redirect.urlOf('create_gci_org_profile', full=True) for id, properties in parsed.iteritems(): record = OrgAppRecord.get_by_id(long(id)) if not record: logging.warning('%s is an invalid OrgAppRecord ID' %id) continue if record.survey.key() != self.data.org_app.key(): logging.warning('%s is not a record for the Org App in the URL' %record.key()) continue new_status = properties['status'] org_app_logic.setStatus(self.data, record, new_status, url) self.response.set_status(200)
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 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 _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 orgAppRecordIfIdInKwargs(self): """Sets the organization application in RequestData object. """ assert self.data.org_app self.data.org_app_record = None id = self.data.kwargs.get('id') if id: self.data.org_app_record = OrgAppRecord.get_by_id(int(id)) if not self.data.org_app_record: raise NotFound(DEF_NO_ORG_APP % self.data.program.name)
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 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 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 post(self, data, check, mutator): """Edits records from commands received by the list code.""" post_dict = data.request.POST data.redirect.program() if (post_dict.get('process', '') == org_app.PROCESS_ORG_APPS_FORM_BUTTON_VALUE): mapreduce_control.start_map( 'ProcessOrgApp', { 'program_type': 'gsoc', 'program_key': data.program.key().name() }) return data.redirect.to('gsoc_list_org_app_records', validated=True) if post_dict.get('button_id', None) != 'save': raise exception.BadRequest(message='No valid POST data found') post_data = post_dict.get('data') if not post_data: raise exception.BadRequest(message='Missing data') parsed = json.loads(post_data) url = 'TODO(daniel): remove this part as it is not used anymore' for oaid, properties in parsed.iteritems(): record = OrgAppRecord.get_by_id(long(oaid)) if not record: logging.warning('%s is an invalid OrgAppRecord ID', oaid) continue if record.survey.key() != data.org_app.key(): logging.warning( '%s is not a record for the Org App in the URL', record.key()) continue new_status = properties['status'] org_app_logic.setStatus(data, record, new_status, url) return http.HttpResponse()
def post(self, data, check, mutator): """Edits records from commands received by the list code.""" post_dict = data.request.POST data.redirect.program() if (post_dict.get('process', '') == org_app.PROCESS_ORG_APPS_FORM_BUTTON_VALUE): mapreduce_control.start_map('ProcessOrgApp', { 'program_type': 'gci', 'program_key': data.program.key().name() }) return data.redirect.to( url_names.GCI_LIST_ORG_APP_RECORDS, validated=True) if post_dict.get('button_id', None) != 'save': raise exception.BadRequest(message='No valid POST data found') post_data = post_dict.get('data') if not post_data: raise exception.BadRequest(message='Missing data') parsed = json.loads(post_data) data.redirect.program() url = data.redirect.urlOf('create_gci_org_profile', full=True) for oaid, properties in parsed.iteritems(): record = OrgAppRecord.get_by_id(long(oaid)) if not record: logging.warning('%s is an invalid OrgAppRecord ID', oaid) continue if record.survey.key() != data.org_app.key(): logging.warning( '%s is not a record for the Org App in the URL', record.key()) continue new_status = properties['status'] org_app_logic.setStatus(data, record, new_status, url) return http.HttpResponse()
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