def seed(self, i, entities=None, current_user=None, gsoc2009=None): properties = { 'key_name': 'google/gsoc2009/org_%04d' % i, 'link_id': 'org_%04d' % i, 'name': 'Organization %04d' % i, 'short_name': 'Org %04d' % i, 'founder': current_user, 'scope_path': 'google/gsoc2009', 'scope': gsoc2009, 'status': 'active', 'email': '*****@*****.**' % i, 'home_page': 'http://code.google.com/p/soc', 'description': 'Melange, share the love!', 'license_name': 'Apache License', 'contact_street': 'Some Street', 'contact_city': 'Some City', 'contact_country': 'United States', 'contact_postalcode': '12345', 'phone': '1-555-BANANA', 'ideas': 'http://code.google.com/p/soc/issues', } org = GSoCOrganization(**properties) if entities is None: org.put() else: entities.append(org)
def testConvertProposals(self): """Tests convert proposal task runs successfully. """ post_data = {'program_key': self.gsoc.key().name()} response = self.post(self.MAIN_URL, post_data) self.assertEqual(response.status_code, httplib.OK) #assert accept task started for first org self.assertTasksInQueue(n=1, url=self.ACCEPT_URL) #assert main task started for next org self.assertTasksInQueue(n=1, url=self.MAIN_URL) #assert parameters to tasks for task in self.get_tasks(): if task['url'] == self.ACCEPT_URL: expected_params = {'org_key': urllib.quote_plus(self.org.key().id_or_name())} self.assertEqual(expected_params, task['params']) elif task['url'] == self.MAIN_URL: q = GSoCOrganization.all() q.filter('scope', self.gsoc) q.filter('status', 'active') q.get() expected_params = {'org_cursor': q.cursor(), 'program_key': urllib.quote_plus( self.gsoc.key().name())} #as we can't know XSRF token, ignore it self.assertNotEqual(task['params'].get('xsrf_token'), None) task_params = task['params'].copy() del task_params['xsrf_token'] self.assertEqual(expected_params, task_params)
def post(self): """Handler for HTTP POST request. """ if not self.validate(): self.get() return link_id = self.data.GET.get("org") if link_id: key_name = "%s/%s" % (self.data.program.name, link_id) organization = GSoCOrganization.get_by_key_name(key_name) else: organization = None if not organization: self.redirect.program() self.redirect.to("edit_gsoc_profile", validated=True) return self.redirect.organization(organization) if self.data.student_info: link = "submit_gsoc_proposal" else: link = "gsoc_org_home" self.redirect.to(link)
def post(self): """Handler for HTTP POST request. """ if not self.validate(): self.get() return link_id = self.data.GET.get('org') if link_id: key_name = '%s/%s' % ( self.data.program.name, link_id ) organization = GSoCOrganization.get_by_key_name(key_name) else: organization = None if not organization: self.redirect.program() self.redirect.to('edit_gsoc_profile', validated=True) return self.redirect.organization(organization) if self.data.student_info: link = 'submit_gsoc_proposal' else: link = 'gsoc_org_home' self.redirect.to(link)
def testAllocateSlots(self): self.data.createHost() url = '/gsoc/admin/slots/' + self.gsoc.key().name() response = self.get(url) self.assertProjectTemplatesUsed(response) data = self.getListData(url, 0) self.assertEqual(1, len(data)) org_data = { "slots": "20", "note": "Great org", } org_name = self.org.key().name() data = simplejson.dumps({org_name: org_data}) postdata = { 'data': data, 'button_id': 'save', 'idx': 0, } response = self.post(url, postdata) self.assertResponseOK(response) org = GSoCOrganization.all().get() org_data["slots"] = 20 self.assertPropertiesEqual(org_data, org)
def testAllocateSlots(self): self.data.createHost() url = '/gsoc/admin/slots/' + self.gsoc.key().name() response = self.get(url) self.assertProjectTemplatesUsed(response) data = self.getListData(url, 0) self.assertEqual(1, len(data)) org_data = { "slots": "20", "note":"Great org", } org_name = self.org.key().name() data = simplejson.dumps({org_name: org_data}) postdata = { 'data': data, 'button_id': 'save', 'idx': 0, } response = self.post(url, postdata) self.assertResponseOK(response) org = GSoCOrganization.all().get() org_data["slots"] = 20 self.assertPropertiesEqual(org_data, org)
def seed_mentor(request, i): """Returns the properties of a new student proposal. """ _, current_user = ensureUser() org = GSoCOrganization.get_by_key_name('google/gsoc2009/org_%d' % i) if not org: raise Error('Run seed_many for at least %d orgs first.' % i) # pylint: disable=E1103 properties = { 'key_name': 'google/gsoc2009/org_%d/mentor' % i, 'link_id': 'mentor', 'scope': org, 'scope_path': org.key().id_or_name(), 'user': current_user, 'given_name': 'Mentor', 'surname': 'Man', 'name_on_documents': 'Mentor Man', 'email': '*****@*****.**', 'res_street': 'Some Street', 'res_city': 'Some City', 'res_state': 'Some State', 'res_country': 'United States', 'res_postalcode': '12345', 'phone': '1-555-BANANA', 'birth_date': db.DateProperty.now(), 'agreed_to_tos': True, 'program': org.scope, } return properties
def post(self): """Handler for HTTP POST request. """ if not self.validate(): self.get() return link_id = self.data.GET.get('org') if link_id: key_name = '%s/%s' % ( self.data.program.key().name(), link_id ) organization = GSoCOrganization.get_by_key_name(key_name) else: organization = None if not organization: self.redirect.program() self.redirect.to('edit_gsoc_profile', validated=True) return self.redirect.organization(organization) if self.data.student_info: link = 'submit_gsoc_proposal' else: link = 'gsoc_org_home' self.redirect.to(link)
def runOrgConversionUpdate(request, entities, context, *args, **kwargs): """AppEngine Task that converts Organizations into GSoCOrganizations. Also updates the RankerRoots that are associated with the Organization. Args: request: Django Request object entities: list of Organization entities to convert context: the context of this task """ from soc.modules.gsoc.logic.models.program import logic as gsoc_program_logic from soc.modules.gsoc.logic.models.ranker_root import logic as \ ranker_root_logic from soc.modules.gsoc.models.organization import GSoCOrganization # get all the properties that are part of each Organization org_model = org_logic.getModel() org_properties = org_model.properties().keys() # use this to store all the new GSoCOrganization gsoc_orgs = [] gsoc_rankers = [] for entity in entities: gsoc_properties = {} for org_property in org_properties: # copy over all the information from the Organization entity gsoc_properties[org_property] = getattr(entity, org_property) # get the Program key belonging to the old Organization program_key = entity.scope.key().id_or_name() # get the new GSoCProgram and set it as scope for the GSoCOrganzation gsoc_program = gsoc_program_logic.getFromKeyName(program_key) gsoc_properties['scope'] = gsoc_program # create the new GSoCOrganization entity and prepare it to be stored gsoc_org_entity = GSoCOrganization(key_name=entity.key().name(), **gsoc_properties) gsoc_orgs.append(gsoc_org_entity) # retrieve the RankerRoots belonging to the Organization fields = {'scope': entity} rankers = ranker_root_logic.getForFields(fields) for ranker in rankers: ranker.scope = gsoc_org_entity # append the adjusted ranker gsoc_rankers.append(ranker) # store all the new GSoCOrganizations db.put(gsoc_orgs) # store all the new rankers db.put(gsoc_rankers) # task completed, return return
def update_org_txn(): org = GSoCOrganization.get_by_key_name(key_name) if not org: logging.warning("Invalid org_key '%s'" % key_name) return if 'note' in properties: org.note = note if 'slots' in properties: org.slots = slots org.put()
def assignSlots(request, *args, **kwargs): """Sets the slots attribute for each organization entity POST Args: slots: an org_key:num_slots JSON dictionary """ # Setup an artifical request deadline timelimit = int(request.REQUEST.get("timelimit", 20000)) timekeeper = Timekeeper(timelimit) program_key = request.REQUEST.get("programkey") last_key = request.REQUEST.get("lastkey", "") program = GSoCProgram.get_by_key_name(program_key) # Copy for modification below params = request.POST.copy() params["timelimit"] = timelimit # Parse the JSON org:slots dictionary slots = simplejson.loads(program.slots_allocation) org_keys = [i for i in sorted(slots.keys()) if i > last_key] logging.info(org_keys) # Assign slots for each organization try: for clock, org_key in timekeeper.iterate(org_keys): logging.info("%s %s %s", request.path, clock, org_key) org_slots = slots[org_key] # Get the organization entity org_key = '/'.join([program_key, org_key]) org = GSoCOrganization.get_by_key_name(org_key) if not org: logging.error("no such org '%s'/'%s'" % (program_key, org_key)) continue # Count proposals and mentors org.slots = int(org_slots['slots']) org.nr_applications, org.nr_mentors = countProposals(org) # Update the organization entity org.put() # Mark the organization as done last_key = org_key # Requeue this task for continuation except DeadlineExceededError: params["lastkey"] = last_key taskqueue.add(url=request.path, params=params) # Exit this task successfully return responses.terminateTask()
def getListData(self): idx = lists.getListIndex(self.request) if idx != 0: return None q = GSoCOrganization.all().filter('scope', self.data.program) starter = lists.keyStarter response_builder = lists.RawQueryContentResponseBuilder( self.request, self._list_config, q, starter) return response_builder.build()
def clear(*args, **kwargs): """Removes all entities from the datastore. """ # there no explicit ranker model anywhere, so make one for # our own convenience to delete all rankers class ranker(db.Model): """ranker model used with ranklist module. """ pass # TODO(dbentley): If there are more than 1000 instances of any model, # this method will not clear all instances. Instead, it should continually # call .all(), delete all those, and loop until .all() is empty. entities = itertools.chain(*[ Notification.all(), GSoCMentor.all(), GHOPMentor.all(), GSoCStudent.all(), GHOPStudent.all(), Survey.all(), SurveyContent.all(), SurveyRecord.all(), GSoCOrgAdmin.all(), GHOPOrgAdmin.all(), ranker.all(), RankerRoot.all(), StudentProposal.all(), GSoCOrganization.all(), GHOPOrganization.all(), OrgApplication.all(), GSoCTimeline.all(), GHOPTimeline.all(), GSoCProgram.all(), GHOPProgram.all(), Host.all(), Sponsor.all(), User.all(), Site.all(), Document.all(), ]) try: for entity in entities: entity.delete() except db.Timeout: return http.HttpResponseRedirect('#') # pylint: disable-msg=E1101 memcache.flush_all() return http.HttpResponse('Done')
def getListData(self): idx = lists.getListIndex(self.request) if idx == 0: q = GSoCOrganization.all() q.filter('scope', self.data.program) q.filter('status IN', ['new', 'active']) starter = lists.keyStarter response_builder = lists.RawQueryContentResponseBuilder( self.request, self._list_config, q, starter) return response_builder.build() else: return None
def clear(*args, **kwargs): """Removes all entities from the datastore. """ # there no explicit ranker model anywhere, so make one for # our own convenience to delete all rankers class ranker(db.Model): """ranker model used with ranklist module. """ pass # TODO(dbentley): If there are more than 1000 instances of any model, # this method will not clear all instances. Instead, it should continually # call .all(), delete all those, and loop until .all() is empty. entities = itertools.chain(*[ Notification.all(), GSoCMentor.all(), GCIMentor.all(), GSoCStudent.all(), GCIStudent.all(), Survey.all(), SurveyContent.all(), SurveyRecord.all(), GSoCOrgAdmin.all(), GCIOrgAdmin.all(), ranker.all(), RankerRoot.all(), StudentProposal.all(), GSoCOrganization.all(), GCIOrganization.all(), GSoCTimeline.all(), GCITimeline.all(), GSoCProgram.all(), GCIProgram.all(), Host.all(), Sponsor.all(), User.all(), Site.all(), Document.all(), ]) try: for entity in entities: entity.delete() except db.Timeout: return http.HttpResponseRedirect('#') # pylint: disable=E1101 memcache.flush_all() return http.HttpResponse('Done')
def seed_student_proposal(request, i): """Returns the properties of a new student proposal. """ ensureUser() org = GSoCOrganization.get_by_key_name('google/gsoc2009/org_%d' % i) mentor = GSoCMentor.get_by_key_name('google/gsoc2009/org_%d/mentor' % i) user = User.get_by_key_name('user_%d' % i) student = GSoCStudent.get_by_key_name('google/gsoc2009/student_%d' % i) if not user: raise Error('Run seed_many for at least %d users first.' % i) if not student: raise Error('Run seed_many for at least %d students first.' % i) if not org: raise Error('Run seed_many for at least %d orgs first.' % i) if not mentor: raise Error('Run seed_many for at least %d mentors first.' % i) all_properties = [] # pylint: disable=E1103 for i in range(random.randint(5, 20)): link_id = 'proposal_%s_%d' % (org.link_id, i) scope_path = 'google/gsoc2009/' + user.link_id properties = { 'link_id': link_id, 'scope_path': scope_path, 'scope': student, 'key_name': '%s/%s' % (scope_path, link_id), 'title': 'The Awesome Proposal %s %d' % (user.link_id, i), 'abstract': 'This is an Awesome Proposal, look at its awesomeness!', 'content': 'Sorry, too Awesome for you to read!', 'additional_info': 'http://www.zipit.com', 'mentor': mentor, 'status': 'pending', 'org': org, 'program': org.scope, } all_properties.append(properties) return all_properties
def checkAccess(self): self.check.isLoggedIn() self.check.isProgramActive() if 'organization' in self.data.kwargs: self.check.isProfileActive() key_name = '%s/%s/%s' % (self.data.kwargs['sponsor'], self.data.kwargs['program'], self.data.kwargs['organization']) self.data.org = GSoCOrganization.get_by_key_name(key_name) if not self.data.org: NotFound('Organization does not exist.') self.check.isOrgAdminForOrganization(self.data.org) #probably check if the org is active else: self.data.org = None self.check.fail("Org creation is not supported at this time")
def checkAccess(self): self.check.isLoggedIn() self.check.isProgramActive() if 'organization' in self.data.kwargs: self.check.isProfileActive() key_name = '%s/%s/%s' % ( self.data.kwargs['sponsor'], self.data.kwargs['program'], self.data.kwargs['organization'] ) self.data.org = GSoCOrganization.get_by_key_name(key_name) if not self.data.org: NotFound('Organization does not exist.') self.check.isOrgAdminForOrganization(self.data.org) #probably check if the org is active else: self.data.org = None self.check.fail("Org creation is not supported at this time")
def clear(*args, **kwargs): """Removes all entities from the datastore. """ # TODO(dbentley): If there are more than 1000 instances of any model, # this method will not clear all instances. Instead, it should continually # call .all(), delete all those, and loop until .all() is empty. entities = itertools.chain(*[ Notification.all(), GCIStudent.all(), Survey.all(), SurveyRecord.all(), StudentProposal.all(), GSoCOrganization.all(), GCIOrganization.all(), GSoCTimeline.all(), GCITimeline.all(), GSoCProgram.all(), GSoCProfile.all(), GCIProfile.all(), GSoCProposal.all(), GCIProgram.all(), GCIScore.all(), GSoCStudentInfo.all(), GCIStudentInfo.all(), GCITask.all(), Host.all(), Sponsor.all(), User.all(), Site.all(), Document.all(), ]) try: for entity in entities: entity.delete() except db.Timeout: return http.HttpResponseRedirect('#') # pylint: disable=E1101 memcache.flush_all() return http.HttpResponse('Done')
def organizationFromKwargs(self): # kwargs which defines an organization fields = ['sponsor', 'program', 'organization'] key_name = '/'.join(self.data.kwargs[field] for field in fields) self.data.organization = GSoCOrganization.get_by_key_name(key_name)
def populate(self, redirect, request, args, kwargs): """Populates the fields in the RequestData object. Args: request: Django HTTPRequest object. args & kwargs: The args and kwargs django sends along. """ super(RequestData, self).populate(redirect, request, args, kwargs) if kwargs.get('sponsor') and kwargs.get('program'): program_key_name = "%s/%s" % (kwargs['sponsor'], kwargs['program']) program_key = db.Key.from_path('GSoCProgram', program_key_name) else: from soc.models.site import Site program_key = Site.active_program.get_value_for_datastore(self.site) program_key_name = program_key.name() import logging logging.error("No program specified") timeline_key = db.Key.from_path('GSoCTimeline', program_key_name) org_app_key_name = 'gsoc_program/%s/orgapp' % program_key_name org_app_key = db.Key.from_path('OrgAppSurvey', org_app_key_name) keys = [program_key, timeline_key, org_app_key] self.program, self.program_timeline, self.org_app = db.get(keys) if not self.program: raise NotFound("There is no program for url '%s'" % program_key_name) self.timeline = TimelineHelper(self.program_timeline, self.org_app) if kwargs.get('organization'): fields = [self.program.key().id_or_name(), kwargs.get('organization')] org_key_name = '/'.join(fields) self.organization = GSoCOrganization.get_by_key_name(org_key_name) if not self.organization: raise NotFound("There is no organization for url '%s'" % org_key_name) if self.user: key_name = '%s/%s' % (self.program.key().name(), self.user.link_id) self.profile = GSoCProfile.get_by_key_name( key_name, parent=self.user) from soc.modules.gsoc.models.program import GSoCProgram host_key = GSoCProgram.scope.get_value_for_datastore(self.program) self.is_host = host_key in self.user.host_for if self.profile: org_keys = set(self.profile.mentor_for + self.profile.org_admin_for) prop = GSoCProfile.student_info student_info_key = prop.get_value_for_datastore(self.profile) if student_info_key: self.student_info = db.get(student_info_key) self.is_student = True else: orgs = db.get(org_keys) org_map = self.org_map = dict((i.key(), i) for i in orgs) self.mentor_for = org_map.values() self.org_admin_for = [org_map[i] for i in self.profile.org_admin_for] self.is_org_admin = self.is_host or bool(self.org_admin_for) self.is_mentor = self.is_org_admin or bool(self.mentor_for)
def seed(request, *args, **kwargs): """Seeds the datastore with some default values. """ site_properties = { 'key_name': 'site', 'link_id': 'site', } site = Site(**site_properties) site.put() account = accounts.getCurrentAccount() if not account: account = users.User(email='*****@*****.**') user_properties = { 'key_name': 'test', 'link_id': 'test', 'account': account, 'name': 'Test', } current_user = User(**user_properties) current_user.put() group_properties = { 'key_name': 'google', 'link_id': 'google', 'name': 'Google Inc.', 'short_name': 'Google', 'founder': current_user, 'home_page': 'http://www.google.com', 'email': '*****@*****.**', 'description': 'This is the profile for Google.', 'contact_street': 'Some Street', 'contact_city': 'Some City', 'contact_country': 'United States', 'contact_postalcode': '12345', 'phone': '1-555-BANANA', 'status': 'active', } google = Sponsor(**group_properties) google.put() role_properties = { 'key_name': 'google/test', 'link_id': 'test', 'public_name': 'test', 'scope': google, 'scope_path': 'google', 'user': current_user, 'given_name': 'Test', 'surname': 'Example', 'name_on_documents': 'Test Example', 'email': '*****@*****.**', 'res_street': 'Some Street', 'res_city': 'Some City', 'res_state': 'Some State', 'res_country': 'United States', 'res_postalcode': '12345', 'phone': '1-555-BANANA', 'birth_date': db.DateProperty.now(), 'agreed_to_tos': True, 'is_org_admin': True, 'is_mentor': True, } current_user.host_for = [google.key()] current_user.put() google_host = Host(**role_properties) google_host.put() from datetime import datetime from datetime import timedelta now = datetime.now() before = now - timedelta(365) after = now + timedelta(365) timeline_properties = { 'key_name': 'google/gsoc2009', 'link_id': 'gsoc2009', 'scope_path': 'google', 'scope': google, 'program_start': before, 'program_end': after, 'accepted_organization_announced_deadline': before, 'student_signup_start': before, 'student_signup_end': after, } gsoc2009_timeline = GSoCTimeline(**timeline_properties) gsoc2009_timeline.put() program_properties = { 'key_name': 'google/gsoc2009', 'link_id': 'gsoc2009', 'scope_path': 'google', 'scope': google, 'name': 'Google Summer of Code 2009', 'short_name': 'GSoC 2009', 'group_label': 'GSOC', 'description': 'This is the program for GSoC 2009.', 'apps_tasks_limit': 42, 'slots': 42, 'timeline': gsoc2009_timeline, 'status': 'visible', } gsoc2009 = GSoCProgram(**program_properties) gsoc2009.put() timeline_properties.update({ 'key_name': 'google/gsoc2010', 'link_id': 'gsoc2010', }) gsoc2010_timeline = GSoCTimeline(**timeline_properties) gsoc2010_timeline.put() program_properties.update({ 'key_name': 'google/gsoc2010', 'link_id': 'gsoc2010', 'name': 'Google Summer of Code 2010', 'description': 'This is the program for GSoC 2010.', 'short_name': 'GSoC 2010', 'timeline': gsoc2010_timeline, }) gsoc2010 = GSoCProgram(**program_properties) gsoc2010.put() timeline_properties = { 'key_name': 'google/gci2009', 'link_id': 'gci2009', 'scope_path': 'google', 'scope': google, 'program_start': before, 'program_end': after, 'accepted_organization_announced_deadline': before, 'student_signup_start': before, 'student_signup_end': after, 'tasks_publicly_visible': before, 'task_claim_deadline': after, 'stop_all_work_deadline': after, } gci2009_timeline = GCITimeline(**timeline_properties) gci2009_timeline.put() program_properties.update({ 'key_name': 'google/gci2009', 'link_id': 'gci2009', 'name': 'Google Code In Contest 2009', 'short_name': 'GCI 2009', 'group_label': 'GCI', 'description': 'This is the program for GCI 2009.', 'timeline': gci2009_timeline, }) gci2009 = GCIProgram(**program_properties) gci2009.put() site.active_program = gci2009 site.put() group_properties.update({ 'key_name': 'google/gci2009/melange', 'link_id': 'melange', 'name': 'Melange Development Team', 'short_name': 'Melange', 'scope_path': 'google/gci2009', 'scope': gci2009, 'home_page': 'http://code.google.com/p/soc', 'description': 'Melange, share the love!', 'license_name': 'Apache License', 'ideas': 'http://code.google.com/p/soc/issues', }) melange = GCIOrganization(**group_properties) melange.put() group_properties.update({ 'scope_path': 'google/gsoc2009', 'scope': gsoc2009, }) role_properties.update({ 'key_name': 'google/gsoc2009/test', 'link_id': 'test', 'scope_path': 'google/gsoc2009', 'scope': gsoc2009, 'program': gsoc2009, 'parent': current_user, }) profile = GSoCProfile(**role_properties) role_properties.pop('parent') orgs = [] for i in range(15): group_properties.update({ 'key_name': 'google/gsoc2009/org_%d' % i, 'link_id': 'org_%d' % i, 'name': 'Organization %d' % i, 'short_name': 'Org %d' % i, 'description': 'Organization %d!' % i, }) entity = GSoCOrganization(**group_properties) orgs.append(entity) entity.put() # Admin (and thus mentor) for the first org if i == 0: profile.org_admin_for.append(entity.key()) profile.mentor_for.append(entity.key()) profile.is_mentor = True profile.is_org_admin = True profile.put() # Mentor for the second org if i == 1: profile.mentor_for.append(entity.key()) profile.is_mentor = True profile.put() role_properties.update({ 'key_name': 'google/gci2009/test', 'link_id': 'test', 'scope_path': 'google/gci2009', 'scope': gci2009, 'program': gci2009, 'org_admin_for': [melange.key()], 'mentor_for': [melange.key()], 'parent': current_user, }) melange_admin = GCIProfile(**role_properties) # TODO: add GCI orgs melange_admin.put() task_properties = { 'status': 'Open', 'modified_by': melange_admin.key(), 'subscribers': [melange_admin.key()], 'title': 'Awesomeness', 'created_by': melange_admin.key(), 'created_on': now, 'program': gci2009, 'time_to_complete': 1337, 'modified_on': now, 'org': melange.key(), 'description': '<p>AWESOME</p>', 'difficulty_level': DifficultyLevel.MEDIUM, 'types': ['Code'] } gci_task = GCITask(**task_properties) gci_task.put() user_properties = { 'key_name': 'student', 'link_id': 'student', 'account': users.User(email='*****@*****.**'), 'name': 'Student', } student_user = User(**user_properties) student_user.put() student_id = 'student' student_properties = { 'key_name': gsoc2009.key().name() + "/" + student_id, 'link_id': student_id, 'scope_path': gsoc2009.key().name(), 'parent': student_user, 'scope': gsoc2009, 'program': gsoc2009, 'user': student_user, 'is_student': True, 'public_name': 'Student', 'given_name': 'Student', 'surname': 'Student', 'birth_date': db.DateProperty.now(), 'email': '*****@*****.**', 'im_handle': 'student_im_handle', 'major': 'test major', 'name_on_documents': 'Student', 'res_country': 'United States', 'res_city': 'city', 'res_street': 'test street', 'res_postalcode': '12345', 'publish_location': True, 'blog': 'http://www.blog.com/', 'home_page': 'http://www.homepage.com/', 'photo_url': 'http://www.photosite.com/thumbnail.png', 'ship_state': None, 'tshirt_size': 'XS', 'tshirt_style': 'male', 'degree': 'Undergraduate', 'phone': '1650253000', 'can_we_contact_you': True, 'program_knowledge': 'I heard about this program through a friend.' } melange_student = GSoCProfile(**student_properties) student_info_properties = { 'key_name': melange_student.key().name(), 'parent': melange_student, 'expected_graduation': 2009, 'program': gsoc2009, 'school_country': 'United States', 'school_name': 'Test School', 'school_home_page': 'http://www.example.com', 'program': gsoc2009, } student_info = GSoCStudentInfo(**student_info_properties) student_info.put() melange_student.student_info = student_info melange_student.put() user_properties = { 'key_name': 'student2', 'link_id': 'student2', 'account': users.User(email='*****@*****.**'), 'name': 'Student 2', } student_user2 = User(**user_properties) student_user2.put() student_id = 'student2' student_properties.update({ 'key_name': gsoc2009.key().name() + "/" + student_id, 'link_id': student_id, 'user': student_user2, 'parent': student_user2, }) melange_student2 = GSoCProfile(**student_properties) melange_student2.put() project_id = 'test_project' project_properties = { 'key_name': gsoc2009.key().name() + "/org_1/" + project_id, 'link_id': project_id, 'scope_path': gsoc2009.key().name() + "/org_1", 'scope': orgs[1].key(), 'title': 'test project', 'abstract': 'test abstract', 'status': 'accepted', 'student': melange_student, 'mentor': profile, 'program': gsoc2009 } melange_project = StudentProject(**project_properties) melange_project.put() student_info_properties.update({'number_of_projects': 1, 'project_for_orgs': [orgs[1].key()]}) student_info = GSoCStudentInfo(**student_info_properties) student_info.put() melange_student.student_info = student_info melange_student.put() project_id = 'test_project2' project_properties.update({ 'key_name': gsoc2009.key().name() + "/org_1/" + project_id, 'link_id': project_id, 'student': melange_student2, 'title': 'test project2' }) student_info_properties.update({ 'key_name': gsoc2009.key().name() + "/" + student_id, 'link_id': student_id, 'parent': melange_student2, }) student_info2 = GSoCStudentInfo(**student_info_properties) student_info2.put() melange_student2.student_info = student_info2 melange_student2.put() melange_project2 = StudentProject(**project_properties) melange_project2.put() student_id = 'student' student_properties.update({ 'key_name': gci2009.key().name() + '/' + student_id, 'parent': student_user, 'scope': gci2009, 'scope_path': gci2009.key().name(), }) gci_student = GCIProfile(**student_properties) gci_student.put() student_info_properties.update({ 'key_name': gci_student.key().name(), 'parent': gci_student, 'program': gci2009, }) student_info = GCIStudentInfo(**student_info_properties) student_info.put() gci_student.student_info = student_info gci_student.put() score_properties = { 'parent': gci_student, 'program': gci2009, 'points': 5, 'tasks': [gci_task.key()] } score = GCIScore(**score_properties) score.put() document_properties = { 'key_name': 'site/site/home', 'link_id': 'home', 'scope_path': 'site', 'scope': site, 'prefix': 'site', 'author': current_user, 'title': 'Home Page', 'short_name': 'Home', 'content': 'This is the Home Page', 'modified_by': current_user, } home_document = Document(**document_properties) home_document.put() document_properties = { 'key_name': 'user/test/notes', 'link_id': 'notes', 'scope_path': 'test', 'scope': current_user, 'prefix': 'user', 'author': current_user, 'title': 'My Notes', 'short_name': 'Notes', 'content': 'These are my notes', 'modified_by': current_user, } notes_document = Document(**document_properties) notes_document.put() site.home = home_document site.put() # pylint: disable=E1101 memcache.flush_all() return http.HttpResponse('Done')
def seed(request, *args, **kwargs): """Seeds the datastore with some default values. """ site_properties = { 'key_name': 'site', 'link_id': 'site', } site = Site(**site_properties) site.put() _, current_user = ensureUser() seeder = UserSeeder() for i in range(15): seeder.seed(i) group_properties = { 'key_name': 'google', 'link_id': 'google', 'name': 'Google Inc.', 'short_name': 'Google', 'founder': current_user, 'home_page': 'http://www.google.com', 'email': '*****@*****.**', 'description': 'This is the profile for Google.', 'contact_street': 'Some Street', 'contact_city': 'Some City', 'contact_country': 'United States', 'contact_postalcode': '12345', 'phone': '1-555-BANANA', 'status': 'active', } google = Sponsor(**group_properties) google.put() role_properties = { 'key_name': 'google/test', 'link_id': 'test', 'scope': google, 'scope_path': 'google', 'user': current_user, 'given_name': 'Test', 'surname': 'Example', 'name_on_documents': 'Test Example', 'email': '*****@*****.**', 'res_street': 'Some Street', 'res_city': 'Some City', 'res_state': 'Some State', 'res_country': 'United States', 'res_postalcode': '12345', 'phone': '1-555-BANANA', 'birth_date': db.DateProperty.now(), 'agreed_to_tos': True, } google_host = Host(**role_properties) google_host.put() timeline_properties = { 'key_name': 'google/gsoc2009', 'link_id': 'gsoc2009', 'scope_path': 'google', 'scope': google, } gsoc2009_timeline = GSoCTimeline(**timeline_properties) gsoc2009_timeline.put() program_properties = { 'key_name': 'google/gsoc2009', 'link_id': 'gsoc2009', 'scope_path': 'google', 'scope': google, 'name': 'Google Summer of Code 2009', 'short_name': 'GSoC 2009', 'group_label': 'GSOC', 'description': 'This is the program for GSoC 2009.', 'apps_tasks_limit': 42, 'slots': 42, 'timeline': gsoc2009_timeline, 'status': 'visible', } gsoc2009 = GSoCProgram(**program_properties) gsoc2009.put() # TODO: Use real GHOPProgram here timeline_properties = { 'key_name': 'google/ghop2009', 'link_id': 'ghop2009', 'scope_path': 'google', 'scope': google, } ghop2009_timeline = GHOPTimeline(**timeline_properties) ghop2009_timeline.put() program_properties.update({ 'key_name': 'google/ghop2009', 'link_id': 'ghop2009', 'name': 'Google Highly Open Participation Contest 2009', 'short_name': 'GHOP 2009', 'group_label': 'GHOP', 'description': 'This is the program for GHOP 2009.', 'timeline': ghop2009_timeline, }) ghop2009 = GHOPProgram(**program_properties) ghop2009.put() org_app_properties = { 'scope_path': 'google/gsoc2009', 'scope': gsoc2009, 'applicant': current_user, 'home_page': 'http://www.google.com', 'email': '*****@*****.**', 'irc_channel': '#care', 'pub_mailing_list': 'http://groups.google.com', 'dev_mailing_list': 'http://groups.google.com', 'description': 'This is an awesome org!', 'why_applying': 'Because we can', 'member_criteria': 'They need to be awesome', 'status': 'pre-accepted', 'license_name': 'Apache License, 2.0', 'ideas': 'http://code.google.com/p/soc/issues', 'contrib_disappears': 'We use google to find them', 'member_disappears': 'See above', 'encourage_contribs': 'We offer them cookies.', 'continued_contribs': 'We promise them a cake.', 'agreed_to_admin_agreement': True, } for i in range(10): org_app_properties['key_name'] = 'google/gsoc2009/org_%04d' % i org_app_properties['link_id'] = 'org_%04d' % i org_app_properties['name'] = 'Org App %04d' % i entity = OrgApplication(**org_app_properties) entity.put() org_app_properties['status'] = 'pre-rejected' for i in range(10, 20): org_app_properties['key_name'] = 'google/gsoc2009/loser_%d' % i org_app_properties['link_id'] = 'loser_%d' % i org_app_properties['name'] = 'Loser %d' % i entity = OrgApplication(**org_app_properties) entity.put() group_properties.update({ 'key_name': 'google/ghop2009/melange', 'link_id': 'melange', 'name': 'Melange Development Team', 'short_name': 'Melange', 'scope_path': 'google/ghop2009', 'scope': ghop2009, 'home_page': 'http://code.google.com/p/soc', 'description': 'Melange, share the love!', 'license_name': 'Apache License', 'ideas': 'http://code.google.com/p/soc/issues', }) melange = GHOPOrganization(**group_properties) melange.put() # create a new ranker ranker_root_logic.create(student_proposal.DEF_RANKER_NAME, melange, student_proposal.DEF_SCORE, 100) group_properties.update({ 'scope_path': 'google/gsoc2009', 'scope': gsoc2009, }) orgs = [] for i in range(15): group_properties.update({ 'key_name': 'google/gsoc2009/org_%d' % i, 'link_id': 'org_%d' % i, 'name': 'Organization %d' % i, 'short_name': 'Org %d' % i, 'description': 'Organization %d!' % i, }) entity = GSoCOrganization(**group_properties) orgs.append(entity) entity.put() # create a new ranker ranker_root_logic.create(student_proposal.DEF_RANKER_NAME, entity, student_proposal.DEF_SCORE, 100) if i < 2: role_properties.update({ 'key_name': 'google/gsoc2009/org_%d/test' % i, 'link_id': 'test', 'scope_path': 'google/gsoc2009/org_%d' % i, 'scope': entity, 'program': gsoc2009, }) # Admin for the first org if i == 0: org_1_admin = GSoCOrgAdmin(**role_properties) org_1_admin.put() # Only a mentor for the second org if i == 1: org_1_admin = GSoCOrgAdmin(**role_properties) org_1_admin.put() org_1_mentor = GSoCMentor(**role_properties) org_1_mentor.put() role_properties.update({ 'key_name': 'google/ghop2009/melange/test', 'link_id': 'test', 'scope_path': 'google/ghop2009/melange', 'scope': melange, 'program': ghop2009, }) melange_admin = GHOPOrgAdmin(**role_properties) melange_admin.put() melange_mentor = GHOPMentor(**role_properties) melange_mentor.put() student_id = 'test' student_properties = { 'key_name': gsoc2009.key().name() + "/" + student_id, 'link_id': student_id, 'scope_path': gsoc2009.key().name(), 'scope': gsoc2009, 'program': gsoc2009, 'user': current_user, 'given_name': 'test', 'surname': 'test', 'birth_date': db.DateProperty.now(), 'email': '*****@*****.**', 'im_handle': 'test_im_handle', 'major': 'test major', 'name_on_documents': 'test', 'res_country': 'United States', 'res_city': 'city', 'res_street': 'test street', 'res_postalcode': '12345', 'publish_location': True, 'blog': 'http://www.blog.com/', 'home_page': 'http://www.homepage.com/', 'photo_url': 'http://www.photosite.com/thumbnail.png', 'ship_state': None, 'expected_graduation': 2009, 'school_country': 'United States', 'school_name': 'Test School', 'tshirt_size': 'XS', 'tshirt_style': 'male', 'degree': 'Undergraduate', 'phone': '1650253000', 'can_we_contact_you': True, 'program_knowledge': 'I heard about this program through a friend.' } melange_student = GSoCStudent(**student_properties) melange_student.put() student_id = 'test2' student_properties.update({ 'key_name': gsoc2009.key().name() + "/" + student_id, 'link_id': student_id, 'user': current_user }) melange_student2 = GSoCStudent(**student_properties) melange_student2.put() project_id = 'test_project' project_properties = { 'key_name': gsoc2009.key().name() + "/org_1/" + project_id, 'link_id': project_id, 'scope_path': gsoc2009.key().name() + "/org_1", 'scope': orgs[1].key(), 'title': 'test project', 'abstract': 'test abstract', 'status': 'accepted', 'student': melange_student, 'mentor': org_1_mentor, 'program': gsoc2009 } melange_project = StudentProject(**project_properties) melange_project.put() project_id = 'test_project2' project_properties.update({ 'key_name': gsoc2009.key().name() + "/org_1/" + project_id, 'link_id': project_id, 'student': melange_student2, 'title': 'test project2' }) melange_project2 = StudentProject(**project_properties) melange_project2.put() document_properties = { 'key_name': 'site/site/home', 'link_id': 'home', 'scope_path': 'site', 'scope': site, 'prefix': 'site', 'author': current_user, 'title': 'Home Page', 'short_name': 'Home', 'content': 'This is the Home Page', 'modified_by': current_user, } home_document = Document(**document_properties) home_document.put() document_logic._onCreate(home_document) document_properties = { 'key_name': 'user/test/notes', 'link_id': 'notes', 'scope_path': 'test', 'scope': current_user, 'prefix': 'user', 'author': current_user, 'title': 'My Notes', 'short_name': 'Notes', 'content': 'These are my notes', 'modified_by': current_user, } notes_document = Document(**document_properties) notes_document.put() document_logic._onCreate(home_document) site.home = home_document site.put() # pylint: disable-msg=E1101 memcache.flush_all() return http.HttpResponse('Done')
def seed(request, *args, **kwargs): """Seeds the datastore with some default values. """ site_properties = { 'key_name': 'site', 'link_id': 'site', } site = Site(**site_properties) site.put() _, current_user = ensureUser() seeder = UserSeeder() for i in range(15): seeder.seed(i) group_properties = { 'key_name': 'google', 'link_id': 'google', 'name': 'Google Inc.', 'short_name': 'Google', 'founder': current_user, 'home_page': 'http://www.google.com', 'email': '*****@*****.**', 'description': 'This is the profile for Google.', 'contact_street': 'Some Street', 'contact_city': 'Some City', 'contact_country': 'United States', 'contact_postalcode': '12345', 'phone': '1-555-BANANA', 'status': 'active', } google = Sponsor(**group_properties) google.put() role_properties = { 'key_name': 'google/test', 'link_id': 'test', 'scope': google, 'scope_path': 'google', 'user': current_user, 'given_name': 'Test', 'surname': 'Example', 'name_on_documents': 'Test Example', 'email': '*****@*****.**', 'res_street': 'Some Street', 'res_city': 'Some City', 'res_state': 'Some State', 'res_country': 'United States', 'res_postalcode': '12345', 'phone': '1-555-BANANA', 'birth_date': db.DateProperty.now(), 'agreed_to_tos': True, } current_user.host_for = [google.key()] current_user.put() google_host = Host(**role_properties) google_host.put() from datetime import datetime from datetime import timedelta before = datetime.now() - timedelta(365) after = datetime.now() + timedelta(365) timeline_properties = { 'key_name': 'google/gsoc2009', 'link_id': 'gsoc2009', 'scope_path': 'google', 'scope': google, 'program_start': before, 'program_end': after, 'accepted_organization_announced_deadline': after, 'student_signup_start': before, 'student_signup_end': after, } gsoc2009_timeline = GSoCTimeline(**timeline_properties) gsoc2009_timeline.put() program_properties = { 'key_name': 'google/gsoc2009', 'link_id': 'gsoc2009', 'scope_path': 'google', 'scope': google, 'name': 'Google Summer of Code 2009', 'short_name': 'GSoC 2009', 'group_label': 'GSOC', 'description': 'This is the program for GSoC 2009.', 'apps_tasks_limit': 42, 'slots': 42, 'timeline': gsoc2009_timeline, 'status': 'visible', } gsoc2009 = GSoCProgram(**program_properties) gsoc2009.put() site.active_program = gsoc2009 site.put() # TODO: Use real GCIProgram here timeline_properties = { 'key_name': 'google/gci2009', 'link_id': 'gci2009', 'scope_path': 'google', 'scope': google, } gci2009_timeline = GCITimeline(**timeline_properties) #gci2009_timeline.put() program_properties.update({ 'key_name': 'google/gci2009', 'link_id': 'gci2009', 'name': 'Google Code In Contest 2009', 'short_name': 'GCI 2009', 'group_label': 'GCI', 'description': 'This is the program for GCI 2009.', 'timeline': gci2009_timeline, }) gci2009 = GCIProgram(**program_properties) #gci2009.put() group_properties.update({ 'key_name': 'google/gci2009/melange', 'link_id': 'melange', 'name': 'Melange Development Team', 'short_name': 'Melange', 'scope_path': 'google/gci2009', 'scope': gci2009, 'home_page': 'http://code.google.com/p/soc', 'description': 'Melange, share the love!', 'license_name': 'Apache License', 'ideas': 'http://code.google.com/p/soc/issues', }) melange = GCIOrganization(**group_properties) #melange.put() # create a new ranker #ranker_root_logic.create(student_proposal.DEF_RANKER_NAME, melange, # student_proposal.DEF_SCORE, 100) group_properties.update({ 'scope_path': 'google/gsoc2009', 'scope': gsoc2009, }) role_properties.update({ 'key_name': 'google/gsoc2009/test', 'link_id': 'test', 'scope_path': 'google/gsoc2009', 'scope': gsoc2009, 'program': gsoc2009, 'parent': current_user, }) profile = GSoCProfile(**role_properties) role_properties.pop('parent') orgs = [] for i in range(15): group_properties.update({ 'key_name': 'google/gsoc2009/org_%d' % i, 'link_id': 'org_%d' % i, 'name': 'Organization %d' % i, 'short_name': 'Org %d' % i, 'description': 'Organization %d!' % i, }) entity = GSoCOrganization(**group_properties) orgs.append(entity) entity.put() # create a new ranker ranker_root_logic.create(student_proposal.DEF_RANKER_NAME, entity, student_proposal.DEF_SCORE, 100) # Admin for the first org if i == 0: profile.org_admin_for.append(entity.key()) profile.put() # Mentor and admin for the second org if i == 1: profile.org_admin_for.append(entity.key()) profile.mentor_for.append(entity.key()) profile.put() role_properties.update({ 'key_name': 'google/gci2009/melange/test', 'link_id': 'test', 'scope_path': 'google/gci2009/melange', 'scope': melange, 'program': gci2009, }) melange_admin = GCIOrgAdmin(**role_properties) #melange_admin.put() melange_mentor = GCIMentor(**role_properties) #melange_mentor.put() student_id = 'test' student_properties = { 'key_name': gsoc2009.key().name() + "/" + student_id, 'link_id': student_id, 'scope_path': gsoc2009.key().name(), 'scope': gsoc2009, 'program': gsoc2009, 'user': current_user, 'given_name': 'test', 'surname': 'test', 'birth_date': db.DateProperty.now(), 'email': '*****@*****.**', 'im_handle': 'test_im_handle', 'major': 'test major', 'name_on_documents': 'test', 'res_country': 'United States', 'res_city': 'city', 'res_street': 'test street', 'res_postalcode': '12345', 'publish_location': True, 'blog': 'http://www.blog.com/', 'home_page': 'http://www.homepage.com/', 'photo_url': 'http://www.photosite.com/thumbnail.png', 'ship_state': None, 'expected_graduation': 2009, 'school_country': 'United States', 'school_name': 'Test School', 'tshirt_size': 'XS', 'tshirt_style': 'male', 'degree': 'Undergraduate', 'phone': '1650253000', 'can_we_contact_you': True, 'program_knowledge': 'I heard about this program through a friend.' } melange_student = GSoCStudent(**student_properties) melange_student.put() student_id = 'test2' student_properties.update({ 'key_name': gsoc2009.key().name() + "/" + student_id, 'link_id': student_id, 'user': current_user }) melange_student2 = GSoCStudent(**student_properties) melange_student2.put() project_id = 'test_project' project_properties = { 'key_name': gsoc2009.key().name() + "/org_1/" + project_id, 'link_id': project_id, 'scope_path': gsoc2009.key().name() + "/org_1", 'scope': orgs[1].key(), 'title': 'test project', 'abstract': 'test abstract', 'status': 'accepted', 'student': melange_student, 'mentor': profile, 'program': gsoc2009 } melange_project = StudentProject(**project_properties) melange_project.put() project_id = 'test_project2' project_properties.update({ 'key_name': gsoc2009.key().name() + "/org_1/" + project_id, 'link_id': project_id, 'student': melange_student2, 'title': 'test project2' }) melange_project2 = StudentProject(**project_properties) melange_project2.put() document_properties = { 'key_name': 'site/site/home', 'link_id': 'home', 'scope_path': 'site', 'scope': site, 'prefix': 'site', 'author': current_user, 'title': 'Home Page', 'short_name': 'Home', 'content': 'This is the Home Page', 'modified_by': current_user, } home_document = Document(**document_properties) home_document.put() document_logic._onCreate(home_document) document_properties = { 'key_name': 'user/test/notes', 'link_id': 'notes', 'scope_path': 'test', 'scope': current_user, 'prefix': 'user', 'author': current_user, 'title': 'My Notes', 'short_name': 'Notes', 'content': 'These are my notes', 'modified_by': current_user, } notes_document = Document(**document_properties) notes_document.put() document_logic._onCreate(home_document) site.home = home_document site.put() # pylint: disable=E1101 memcache.flush_all() return http.HttpResponse('Done')
def calculate(self, request, *args, **kwargs): """Calculates the duplicate proposals in a given program for a student on a per Organization basis. Expects the following to be present in the POST dict: program_key: Specifies the program key name for which to find the duplicate proposals org_cursor: Specifies the organization datastore cursor from which to start the processing of finding the duplicate proposals Args: request: Django Request object """ post_dict = request.POST program_key = post_dict.get('program_key') if not program_key: # invalid task data, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid program key: %s' % post_dict) program_entity = GSoCProgram.get_by_key_name(program_key) if not program_entity: # invalid program specified, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid program specified: %s' % program_key) # get the organization and update the cursor if possible q = GSoCOrganization.all() q.filter('status', 'active') q.filter('scope', program_entity) q.filter('slots >', 0) # retrieve the org_cursor from POST data org_cursor = post_dict.get('org_cursor') if org_cursor: org_cursor = str(org_cursor) q.with_cursor(org_cursor) org_entity = q.get() # update the cursor org_cursor = q.cursor() if org_entity: # get all the proposals likely to be accepted in the program accepted_proposals = proposal_logic.getProposalsToBeAcceptedForOrg(org_entity) for ap in accepted_proposals: student_entity = ap.parent() q = GSoCProposalDuplicate.all() q.filter('student', student_entity) proposal_duplicate = q.get() if proposal_duplicate and ap.key() not in proposal_duplicate.duplicates: # non-counted (to-be) accepted proposal found proposal_duplicate.duplicates = proposal_duplicate.duplicates + \ [ap.key()] proposal_duplicate.is_duplicate = \ len(proposal_duplicate.duplicates) >= 2 if org_entity.key() not in proposal_duplicate.orgs: proposal_duplicate.orgs = proposal_duplicate.orgs + [org_entity.key()] else: pd_fields = { 'program': program_entity, 'student': student_entity, 'orgs':[org_entity.key()], 'duplicates': [ap.key()], 'is_duplicate': False } proposal_duplicate = GSoCProposalDuplicate(**pd_fields) proposal_duplicate.put() # Adds a new task that performs duplicate calculation for # the next organization. task_params = {'program_key': program_key, 'org_cursor': unicode(org_cursor)} task_url = '/tasks/gsoc/proposal_duplicates/calculate' new_task = taskqueue.Task(params=task_params, url=task_url) new_task.add() else: # There aren't any more organizations to process. So delete # all the proposals for which there are not more than one # proposal for duplicates property. duplicates_logic.deleteAllForProgram(program_entity, non_dupes_only=True) # update the proposal duplicate status and its timestamp pds_entity = duplicates_logic.getOrCreateStatusForProgram(program_entity) pds_entity.status = 'idle' pds_entity.calculated_on = datetime.datetime.now() pds_entity.put() # return OK return http.HttpResponse()