def seed_org(unused_request, i): """Returns the properties for a new org entity. """ _, current_user = ensureUser() gsoc2009 = Program.get_by_key_name('google/gsoc2009') if not gsoc2009: raise Error('Run seed_db first') properties = { 'key_name': 'google/gsoc2009/org_%d' % i, 'link_id': 'org_%d' % i, 'name': 'Organization %d' % i, 'short_name': 'Org %d' % 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', } return properties
def getProjects(self, survey, user): """Get projects linking user to a program. Serves as access handler (since no projects == no access). And retrieves projects to choose from (if mentors have >1 projects). params: survey = survey entity user = survey taking user """ this_program = survey.scope or Program.get_by_key_name(survey.scope_path) if 'mentor' in survey.taking_access: these_projects = self.getMentorProjects(user, this_program) elif 'student' in survey.taking_access: these_projects = self.getStudentProjects(user, this_program) logging.info(these_projects) if len(these_projects) == 0: return False return these_projects
def commonSeedArgs(self, request): _, current_user = ensureUser() gsoc2009 = Program.get_by_key_name('google/gsoc2009') if not gsoc2009: raise Error('Run seed_db first') return dict(current_user=current_user, gsoc2009=gsoc2009)
def commonSeedArgs(self, request): _, current_user = ensureUser() gsoc2009 = Program.get_by_key_name('google/gsoc2009') if not gsoc2009: raise Error('Run seed_db first') status = request.GET.get('status', 'pre-accepted') return dict(current_user=current_user, gsoc2009=gsoc2009, status=status)
def activateGrades(self, survey): """Activates the grades on a Grading Survey. TODO(James) Fix this Docstring params: survey = survey entity """ if survey.taking_access != "mentor evaluation": logging.error("Cannot grade survey %s with taking access %s" % (survey.key().name(), survey.taking_access)) return False program = survey.scope or Program.get_by_key_name(survey.scope_path) for project in program.student_projects.fetch(1000): this_record_group = SurveyRecordGroup.all().filter( "project = ", project).filter( "initial_status = ", project.status).get() if not this_record_group: logging.warning('neither mentor nor student has \ taken the survey for project %s' % project.key().name() ) continue if not this_record_group.mentor_record: # student has taken survey, but not mentor logging.warning('not continuing without mentor record...') continue status_options = PROJECT_STATUSES.get(project.status) if not status_options: logging.warning('unable to find status options for project \ status %s' % project.status) continue new_project_grade = this_record_group.mentor_record.grade new_project_status = status_options.get(new_project_grade) if getattr(this_record_group, 'final_status'): logging.warning('project %s record group should not \ yet have a final status %s' % ( project.key().name(), this_record_group.final_status ) ) continue # assign the new status to the project and surveyrecordgroup project.status = new_project_status this_record_group.final_status = new_project_status
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(), Mentor.all(), Student.all(), OrgAdmin.all(), ranker.all(), RankerRoot.all(), StudentProposal.all(), Organization.all(), OrgApplication.all(), Timeline.all(), Program.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 seed_student(request, i): """Returns the properties for a new student entity. """ gsoc2009 = Program.get_by_key_name('google/gsoc2009') user = User.get_by_key_name('user_%d' % i) if not gsoc2009: raise Error('Run seed_db first') if not user: raise Error('Run seed_many for at least %d users first.' % i) properties = { 'key_name':'google/gsoc2009/student_%d' % i, 'link_id': 'student_%d' % i, 'scope_path': 'google/gsoc2009', 'scope': gsoc2009, 'user' : user, 'given_name': 'Student %d' % i, 'surname': 'Last Name', '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, 'school_name': 'School %d' % i, 'school_country': 'United States', 'major': 'Computer Science', 'degree': 'Undergraduate', 'expected_graduation': 2012, 'program_knowledge': 'Knowledge %d' % i, 'school': None, 'can_we_contact_you': True, } return properties
def seed_org_app(request, i): """Returns the properties for a new org proposal, """ _, current_user = ensureUser() status = request.GET.get('status', 'pre-accepted') gsoc2009 = Program.get_by_key_name('google/gsoc2009') if not gsoc2009: raise Error('Run seed_db first') properties = { 'key_name': 'google/gsoc2009/org_%d' % i, 'link_id': 'org_%d' % i, 'name': 'Org App %d' % i, 'scope_path': 'google/gsoc2009', 'scope': gsoc2009, 'status': status, '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', '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, } return properties
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 = Timeline(**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, 'workflow': 'gsoc', 'timeline': gsoc2009_timeline, 'status': 'visible', } gsoc2009 = Program(**program_properties) gsoc2009.put() timeline_properties = { 'key_name': 'google/ghop2009', 'link_id': 'ghop2009', 'scope_path': 'google', 'scope': google, } ghop2009_timeline = Timeline(**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.', 'workflow': 'ghop', 'timeline': ghop2009_timeline, }) ghop2009 = Program(**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 = Organization(**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, }) 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 = Organization(**group_properties) 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 = OrgAdmin(**role_properties) org_1_admin.put() # Only a mentor for the second org if i == 1: org_1_mentor = Mentor(**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 = OrgAdmin(**role_properties) melange_admin.put() melange_mentor = Mentor(**role_properties) melange_mentor.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-msg=E1101 memcache.flush_all() return http.HttpResponse('Done')