def forCurrentAccount(): """Retrieves the user entity for the currently logged in account. Also Updates the user entity's unique identifier. getCurrentUser() should be favored over this method. If there is no user logged in, or they have no valid associated User entity, None is returned. """ account = accounts.getCurrentAccount() if not account: return None user_ent = forAccount(account) if user_ent and not user_ent.user_id and account.user_id(): # update the user id that was added to GAE after Melange was launched try: user_ent.user_id = account.user_id() user_ent.put() except apiproxy_errors.CapabilityDisabledError: # readonly mode, that's fine pass return user_ent
def forCurrentUserId(): """Retrieves the user entity for the currently logged in user id. If there is no user logged in, or they have no valid associated User entity, None is returned. """ user_id = accounts.getCurrentUserId() if not user_id: return None user_ent = forUserId(user_id) current_account = accounts.getCurrentAccount() if user_ent and (str(user_ent.account) != str(current_account)): # The account of the user has changed, we use this account to send system # emails to. try: user_ent.account = current_account user_ent.put() except apiproxy_errors.CapabilityDisabledError: # readonly mode, that's fine pass return user_ent
def _checkHasStatisticAccess(self, statistic, params=None): """Checks that the user has access to the specified statistic. """ logic = params['logic'] id = accounts.getCurrentAccount() user = None if id: user = user_logic.getForAccount(id) checker = access.Checker(None) checker.setCurrentUser(id, user) access_type = statistic.read_access has_access = False minimal_rights = logic.ACCESS_TYPES.index(access_type) for item in logic.ACCESS_TYPES[minimal_rights:]: ref_logic = logic.helper.LOGICS_DICT[item] try: checker.checkHasActiveRole({}, ref_logic.logic) has_access = True break except Exception: pass return has_access
def listPublic(self, request, access_type, page_name=None, params=None, filter=None, **kwargs): """See base.View.list. """ account = accounts.getCurrentAccount() user = user_logic.logic.getForAccount(account) if account else None try: rights = self._params['rights'] rights.setCurrentUser(account, user) rights.checkIsHost() is_host = True except out_of_band.Error: is_host = False params = params.copy() if is_host: params['list_action'] = (redirects.getAdminRedirect, params) else: params['list_action'] = (redirects.getPublicRedirect, params) new_filter = {} new_filter['scope_path'] = kwargs['scope_path'] new_filter['status'] = 'active' filter = dicts.merge(filter, new_filter) content = lists.getListContent(request, params, filter) contents = [content] return self._list(request, params, contents, page_name)
def listPublic(self, request, access_type, page_name=None, params=None, filter=None, **kwargs): """See base.View.list. """ account = accounts.getCurrentAccount() user = user_logic.logic.getForAccount(account) if account else None try: rights = self._params['rights'] rights.setCurrentUser(account, user) rights.checkIsHost() is_host = True except out_of_band.Error: is_host = False params = params.copy() if is_host: params['public_row_extra'] = lambda entity: { 'link': redirects.getAdminRedirect(entity, params) } else: params['public_row_extra'] = lambda entity: { 'link': redirects.getPublicRedirect(entity, params) } new_filter = {} new_filter['scope_path'] = kwargs['scope_path'] new_filter['status'] = 'active' filter = dicts.merge(filter, new_filter) return self.list(request, 'allow', page_name=page_name, params=params, filter=filter)
def getUniversalContext(request): """Constructs a template context dict will many common variables defined. Args: request: the Django HTTP request object Returns: a new context dict containing: { 'request': the Django HTTP request object passed in by the caller 'account': the logged-in Google Account if there is one 'user': the User entity corresponding to the Google Account in context['account'] 'is_admin': True if users.is_current_user_admin() is True 'is_debug': True if system.isDebug() is True 'sign_in': a Google Account login URL 'sign_out': a Google Account logout URL 'sidebar_menu_html': an HTML string that renders the sidebar menu } """ account = accounts.getCurrentAccount() user = None is_admin = False context = {} context['request'] = request if account: user = user_logic.getForAccount(account) is_admin = user_logic.isDeveloper(account=account, user=user) context['account'] = account context['user'] = user context['is_admin'] = is_admin context['is_local'] = system.isLocal() context['is_debug'] = system.isDebug() context['sign_in'] = users.create_login_url(request.path) context['sign_out'] = users.create_logout_url(request.path) context['sidebar_menu_items'] = callback.getCore().getSidebar(account, user) context['gae_version'] = system.getAppVersion() context['soc_release'] = system.getMelangeVersion() settings = site.logic.getSingleton() context['ga_tracking_num'] = settings.ga_tracking_num context['gmaps_api_key'] = settings.gmaps_api_key context['site_name'] = settings.site_name context['site_notice'] = settings.site_notice context['tos_link'] = redirects.getToSRedirect(settings) context['in_maintenance'] = timeline.isActivePeriod(site, 'maintenance') return context
def get(entity, *args, **kwargs): """Retrieves the news_feed for the specified entity from the memcache. """ # only cache the page for non-logged-in users if accounts.getCurrentAccount(normalize=False): return (None, None) if not entity: return (None, None) memcache_key = key(entity) return memcache.get(memcache_key), memcache_key
def testGetCurrentAccount(self): """Tests that current account is returned. """ expected_account = accounts.normalizeAccount(self.account) self.assertEqual(accounts.getCurrentAccount(), expected_account) expected_account = self.account self.assertEqual(accounts.getCurrentAccount(False), expected_account) default_account_setting = os.environ.get('USER_EMAIL', None) try: os.environ['USER_EMAIL'] = self.non_normal_email expected_account = users.get_current_user() self.assertEqual(accounts.getCurrentAccount(False), expected_account) self.assertEqual(accounts.getCurrentAccount(True), accounts.normalizeAccount(expected_account)) finally: if default_account_setting is None: del os.environ['USER_EMAIL'] else: os.environ['USER_EMAIL'] = default_account_setting
def getForCurrentAccount(self): """Retrieves the user entity for the currently logged in account. If there is no user logged in, or they have no valid associated User entity, None is returned. """ account = accounts.getCurrentAccount() if not account: return None return self.getForAccount(account)
def put(result, memcache_key, *args, **kwargs): """Sets the news_feed for the specified user in the memcache. Args: news_feed: the news_feed to be cached """ # no sense in storing anything if we won't query it later on # also, no need to normalize as we don't use it anyway if accounts.getCurrentAccount(normalize=False): return # Store news_feed for just ten minutes to force a refresh every so often retention = 10*60 memcache.add(memcache_key, result, retention)
def request_account_deletion(user): """Requests deletion of user's account from application administrators by sending them an email. This is a temporary method, until we have an automated solution. """ account = accounts.getCurrentAccount(normalize=False) sender = system.getApplicationNoReplyEmail() subject = ADMIN_REQUEST_EMAIL_SUBJEST % {'url_id': user.url_id} body = ADMIN_REQUEST_EMAIL_BODY % { 'name': user.name, 'email': account.email(), 'url_id': user.url_id, } mail.send_mail_to_admins(sender, subject, body)
def put(result, memcache_key, *args, **kwargs): """Sets the homepage for the specified entity in the memcache. Args: result: the homepage to be cached """ # no sense in storing anything if we won't query it later on # also, no need to normalize as we don't use it anyway if accounts.getCurrentAccount(normalize=False): return # Store homepage for just ten minutes to force a refresh every so often retention = 10 * 60 logging.info("Setting %s" % memcache_key) # pylint: disable=E1101 memcache.add(memcache_key, result, retention)
def put(result, memcache_key, *args, **kwargs): """Sets the homepage for the specified entity in the memcache. Args: result: the homepage to be cached """ # no sense in storing anything if we won't query it later on # also, no need to normalize as we don't use it anyway if accounts.getCurrentAccount(normalize=False): return # Store homepage for just ten minutes to force a refresh every so often retention = 10*60 logging.info("Setting %s" % memcache_key) # pylint: disable=E1101 memcache.add(memcache_key, result, retention)
def request_account_deletion(user): """Requests deletion of user's account from application administrators by sending them an email. This is a temporary method, until we have an automated solution. """ account = accounts.getCurrentAccount(normalize=False) sender = system.getApplicationNoReplyEmail() subject = ADMIN_REQUEST_EMAIL_SUBJEST % { 'url_id': user.url_id } body = ADMIN_REQUEST_EMAIL_BODY % { 'name': user.name, 'email': account.email(), 'url_id': user.url_id, } mail.send_mail_to_admins(sender, subject, body)
def get(self, *args, **kwargs): """Retrieves the sidebar for the specified user from the memcache. """ # only cache the page for non-logged-in users # TODO: figure out how to cache everything but the sidebar # also, no need to normalize as we don't use it anyway if accounts.getCurrentAccount(normalize=False): return (None, None) entity = self._logic.getFromKeyFields(kwargs) # if we can't retrieve the entity, leave it to the actual method if not entity: return (None, None) memcache_key = key(entity) logging.info("Retrieving %s" % memcache_key) return memcache.get(memcache_key), memcache_key
def listPublic(self, request, access_type, page_name=None, params=None, filter=None, **kwargs): """See base.View.list. """ account = accounts.getCurrentAccount() user = user_logic.logic.getForAccount(account) if account else None try: rights = self._params['rights'] rights.setCurrentUser(account, user) rights.checkIsHost() is_host = True except out_of_band.Error: is_host = False params = params.copy() if is_host: params['public_row_extra'] = lambda entity: { 'link': redirects.getAdminRedirect(entity, params) } else: params['public_row_extra'] = lambda entity: { 'link': redirects.getPublicRedirect(entity, params) } new_filter = {} new_filter['scope_path'] = kwargs['scope_path'] new_filter['status'] = 'active' filter = dicts.merge(filter, new_filter) return self.list(request, 'any_access', page_name=page_name, params=params, filter=filter)
def ensureUser(): """Returns the current user account and associated user object. """ 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() return account, current_user
def get(self, *args, **kwargs): """Retrieves the homepage for the specified entity from the memcache. """ # only cache the page for non-logged-in users # TODO: figure out how to cache everything but the sidebar # also, no need to normalize as we don't use it anyway if accounts.getCurrentAccount(normalize=False): return (None, None) entity = self._logic.getFromKeyFields(kwargs) # if we can't retrieve the entity, leave it to the actual method if not entity: return (None, None) memcache_key = key(entity) logging.info("Retrieving %s" % memcache_key) # pylint: disable=E1101 return memcache.get(memcache_key), memcache_key
def _getForCurrentUserId(self): """Retrieves the user entity for the currently logged in user id. If there is no user logged in, or they have no valid associated User entity, None is returned. """ user_id = accounts.getCurrentUserId() if not user_id: return None user = self.getForUserId(user_id) current_account = accounts.getCurrentAccount() if user and (str(user.account) != str(current_account)): # The account of the user has changed, we use this account to send system # emails to. self.updateEntityProperties(user, {'account': current_account}) return user
def _getForCurrentAccount(self): """Retrieves the user entity for the currently logged in account. Also Updates the user entity's unique identifier. getCurrentUser() should be favored over this method. If there is no user logged in, or they have no valid associated User entity, None is returned. """ account = accounts.getCurrentAccount() if not account: return None user = self.getForAccount(account) if user and not user.user_id: # update the user id that was added to GAE after Melange was launched self.updateEntityProperties(user, {'user_id': account.user_id()}) return user
def getDefaultMailSender(): """Returns the sender that currently can be used to send emails. Returns: - A tuple containing (sender_name, sender_address) Consisting of: - If available the site name and noreply address from the site singleton - Or the (public) name and email address of the current logged in User - None if there is no address to return """ import logging from soc.logic import accounts from soc.logic.models import user as user_logic from soc.logic.models import site as site_logic # check if there is a noreply email address set site_entity = site_logic.logic.getSingleton() if site_entity.noreply_email: return (site_entity.site_name, site_entity.noreply_email) # use the email address of the current logged in user account = accounts.getCurrentAccount(normalize=False) if not account: logging.warning('Non-Authenticated user triggered getDefaultMailSender ' 'please set a no-reply address in Site settings') return None # we need to retrieve account separately, as user_logic normalizes it # and the GAE admin API is case sensitive user_entity = user_logic.logic.getForAccount(account) # pylint: disable-msg=E1103 name = user_entity.name if user_entity else account.nickname() return (name, account.email())
def isDeveloper(account=None, user=None): """Returns true iff the specified user is a Developer. Args: account: if not supplied, defaults to the current account user: if not specified, defaults to the current user """ current = accounts.getCurrentAccount() if not account: # default account to the current logged in account account = current if account and (not user): # default user to the current logged in user user = forAccount(account) if user and user.is_developer: return True if account and (account == current): return users.is_current_user_admin()
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', 'latest_gsoc': 'google/gsoc2014', 'latest_gci': 'google/gci2013', } site = Site(**site_properties) site.put() account = accounts.getCurrentAccount() if not account: account = users.User(email='*****@*****.**') user_properties = { 'id': 'test', 'account_id': account.user_id(), 'account': account, } current_user = user.User(**user_properties) current_user.put() group_properties = { 'key_name': 'google', 'link_id': 'google', 'name': 'Google Inc.', 'short_name': 'Google', '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': '15551110000', 'status': 'active', } google = Sponsor(**group_properties) google.put() now = datetime.datetime.now() before = now - datetime.timedelta(365) after = now + datetime.timedelta(365) past_before = before - datetime.timedelta(2 * 365) past_after = after - datetime.timedelta(2 * 365) timeline_properties = { 'key_name': 'google/gsoc2014', 'link_id': 'gsoc2014', 'scope': google, 'program_start': before, 'program_end': after, 'accepted_organization_announced_deadline': before, 'accepted_students_announced_deadline': after, 'student_signup_start': before, 'student_signup_end': after, 'application_review_deadline': after, 'student_application_matched_deadline': after, 'accepted_students_announced_deadline': after, 'form_submission_start': before, } gsoc2014_timeline = GSoCTimeline(**timeline_properties) gsoc2014_timeline.put() program_properties = { 'key_name': 'google/gsoc2014', 'link_id': 'gsoc2014', 'program_id': 'gsoc2014', 'sponsor': google, 'scope': google, 'name': 'Google Summer of Code 2014', 'short_name': 'GSoC 2014', 'description': 'This is the program for GSoC 2014.', 'apps_tasks_limit': 42, 'slots': 42, 'timeline': gsoc2014_timeline, 'status': program_model.STATUS_VISIBLE, } gsoc2014 = GSoCProgram(**program_properties) gsoc2014.put() timeline_properties.update({ 'key_name': 'google/gsoc2010', 'link_id': 'gsoc2010', 'program_start': past_before, 'program_end': past_after, 'accepted_organization_announced_deadline': past_before, 'accepted_students_announced_deadline': past_after, 'student_signup_start': past_before, 'student_signup_end': past_after, 'application_review_deadline': past_after, 'student_application_matched_deadline': past_after, 'accepted_students_announced_deadline': past_after, 'form_submission_start': past_before, }) gsoc2010_timeline = GSoCTimeline(**timeline_properties) gsoc2010_timeline.put() program_properties.update({ 'key_name': 'google/gsoc2010', 'link_id': 'gsoc2010', 'program_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() # TODO(drew): Replace gsoc2014.prefix with whatever its replacement becomes # once prefix is removed from program and no longer used in the query for # OrgAppSurvey in soc.views.helper.RequestData._getProgramWideFields(). org_app_survey_properties = { 'key_name': '%s/%s/orgapp' % (gsoc2014.prefix, gsoc2014.key().name()), 'program': gsoc2014, 'title': 'Org App Survey', 'content': 'Here is some content.', 'modified_by': current_user.key.to_old_key(), 'survey_start': before, 'survey_end': after } org_app_survey_model.OrgAppSurvey(**org_app_survey_properties).put() org_app_survey_properties['key_name'] = ( '%s/%s/orgapp' % (gsoc2010.prefix, gsoc2010.key().name())) org_app_survey_properties['program'] = gsoc2010 org_app_survey_properties['survey_start'] = past_before org_app_survey_properties['survey_end'] = past_after org_app_survey_model.OrgAppSurvey(**org_app_survey_properties).put() timeline_properties = { 'key_name': 'google/gci2013', 'link_id': 'gci2013', '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, } gci2013_timeline = GCITimeline(**timeline_properties) gci2013_timeline.put() program_properties.update({ 'key_name': 'google/gci2013', 'link_id': 'gci2013', 'program_id': 'gci2013', 'name': 'Google Code In Contest 2013', 'short_name': 'GCI 2009', 'description': 'This is the program for GCI 2013.', 'timeline': gci2013_timeline, }) gci2013 = GCIProgram(**program_properties) gci2013.put() site.active_program = gci2013 site.put() current_user.host_for = [ ndb.Key.from_old_key(gsoc2010.key()), ndb.Key.from_old_key(gsoc2014.key()), ndb.Key.from_old_key(gci2013.key()) ] current_user.put() group_properties.update({ 'key_name': 'google/gci2013/melange', 'link_id': 'melange', 'name': 'Melange Development Team', 'short_name': 'Melange', 'scope': gci2013, 'program': gci2013, 'sponsor': google, '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': gsoc2014, 'program': gsoc2014, }) address_properties = address.Address(street='1 Test St.', city='Some City', country='United States', postal_code='12345') address_properties.put() contact_info = contact.Contact(email='*****@*****.**') contact_info.put() gsoc_delta = datetime.timedelta(days=(365 * 18)) profile_properties = { 'id': gsoc2014.key().name() + '/' + current_user.key.id(), 'parent': current_user.key, 'public_name': 'test', 'program': ndb.Key.from_old_key(gsoc2014.key()), 'first_name': 'Test', 'last_name': 'Example', 'contact': contact_info, 'residential_address': address_properties, 'shipping_address': address_properties, 'birth_date': datetime.date.today() - gsoc_delta, 'program_knowledge': 'Friend referral', } profile = profile_model.Profile(**profile_properties) ndb_orgs = [] for i in range(15): group_properties.update({ 'key_name': 'google/gsoc2014/org_%d' % i, 'link_id': 'org_%d' % i, 'name': 'Organization %d' % i, 'short_name': 'Org %d' % i, 'description': 'Organization %d!' % i, }) org_properties = { 'name': 'Organization %d' % i, 'org_id': 'org_%d' % i, 'program': ndb.Key.from_old_key(gsoc2014.key()), 'description': 'Organization %d!' % i, } org = soc_org_model.SOCOrganization(id='google/gsoc2014/org_%d' % i, **org_properties) org.put() ndb_orgs.append(org) # Admin (and thus mentor) for the first org if i == 0: profile.admin_for.append(org.key) profile.mentor_for.append(org.key) profile.put() # Mentor for the second org if i == 1: profile.mentor_for.append(org.key) profile.put() profile_properties.update({ 'id': gci2013.key().name() + '/' + current_user.key.id(), 'parent': current_user.key, 'program': ndb.Key.from_old_key(gci2013.key()), 'admin_for': [ndb.Key.from_old_key(melange.key())], 'mentor_for': [ndb.Key.from_old_key(melange.key())], }) melange_admin = profile_model.Profile(**profile_properties) # TODO: add GCI orgs melange_admin.put() task_properties = { 'status': 'Open', 'modified_by': melange_admin.key.to_old_key(), 'subscribers': [melange_admin.key.to_old_key()], 'title': 'Awesomeness', 'created_by': melange_admin.key.to_old_key(), 'created_on': now, 'program': gci2013, '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 = { 'id': 'student', 'account_id': '12345', 'account': users.User(email='*****@*****.**'), } student_user = user.User(**user_properties) student_user.put() gci_delta = datetime.timedelta(days=(365 * 14)) contact_properties = contact.Contact(email='*****@*****.**', web_page='http://www.homepage.com/', blog='http://www.blog.com/', phone='1650253000') contact_properties.put() graduation_year = datetime.date.today() + datetime.timedelta(days=365) student_data = soc_profile.SOCStudentData(education=education.Education( school_id="123", school_country="United States", expected_graduation=int(graduation_year.strftime('%Y')), major='Some Major', degree=education.Degree.UNDERGRADUATE)) student_data.put() student_id = 'student' student_properties = { 'id': gsoc2014.key().name() + "/" + student_id, 'parent': student_user.key, 'program': ndb.Key.from_old_key(gsoc2014.key()), 'public_name': 'Student', 'first_name': 'Student', 'last_name': 'Student', 'contact': contact_properties, 'residential_address': address_properties, 'shipping_address': address_properties, 'birth_date': datetime.date.today() - gci_delta, 'tee_size': profile_model.TeeSize.L, 'tee_style': profile_model.TeeStyle.MALE, 'gender': profile_model.Gender.MALE, 'program_knowledge': 'Friend referral.', 'student_data': student_data, } melange_student = profile_model.Profile(**student_properties) melange_student.put() student_id = 'student2' user_properties = { 'id': student_id, 'account_id': 'student2', 'account': users.User(email='*****@*****.**'), } student_user2 = user.User(**user_properties) student_user2.put() student_properties.update({ 'id': gsoc2014.key().name() + "/" + student_id, 'parent': student_user2.key, 'first_name': 'Student 2', 'last_name': 'Example' }) melange_student2 = profile_model.Profile(**student_properties) melange_student2.put() proposal_properties = { 'parent': melange_student.key.to_old_key(), 'program': gsoc2014, 'title': 'test proposal', 'abstract': 'test abstract', 'content': 'test content', 'mentor': profile.key.to_old_key(), 'status': 'accepted', 'has_mentor': True, 'org': ndb_orgs[0].key.to_old_key(), 'possible_mentors': [profile.key.to_old_key()] } melange_proposal = GSoCProposal(**proposal_properties) melange_proposal.put() project_properties = { 'title': 'test project', 'abstract': 'test abstract', 'status': 'accepted', 'parent': melange_student.key.to_old_key(), 'mentors': [profile.key.to_old_key()], 'program': gsoc2014, 'org': ndb_orgs[0].key.to_old_key(), 'proposal': melange_proposal.key(), } melange_project = GSoCProject(**project_properties) melange_project.put() ndb_orgs[1].slot_allocation = 1 ndb_orgs[1].put() student_data.number_of_projects = 1 student_data.number_of_proposals = 1 student_data.project_for_orgs = [ndb_orgs[1].key] melange_student.put() melange_student2.put() project_properties.update({ 'student': melange_student2, 'title': 'test project2' }) melange_project2 = GSoCProject(**project_properties) melange_project2.put() ndb_orgs[1].slot_allocation += 1 ndb_orgs[1].put() student_id = 'student' student_properties.update({ 'id': gci2013.key().name() + '/' + student_id, 'parent': student_user.key, 'program': ndb.Key.from_old_key(gci2013.key()), }) gci_student = profile_model.Profile(**student_properties) gci_student.put() score_properties = { 'parent': gci_student.key.to_old_key(), 'program': gci2013, 'points': 5, 'tasks': [gci_task.key()] } score = GCIScore(**score_properties) score.put() document_properties = { 'key_name': 'site/site/home', 'link_id': 'home', 'scope': site, 'prefix': 'site', 'author': current_user.key.to_old_key(), 'title': 'Home Page', 'content': 'This is the Home Page', 'modified_by': current_user.key.to_old_key(), } home_document = Document(**document_properties) home_document.put() document_properties = { 'key_name': 'user/test/notes', 'link_id': 'notes', 'scope': current_user.key.to_old_key(), 'prefix': 'user', 'author': current_user.key.to_old_key(), 'title': 'My Notes', 'content': 'These are my notes', 'modified_by': current_user.key.to_old_key(), } notes_document = Document(**document_properties) notes_document.put() site.home = home_document site.put() memcache.flush_all() return http.HttpResponse('Done')
def seed(request, *args, **kwargs): """Seeds the datastore with some default values. """ site_properties = { 'key_name': 'site', 'latest_gsoc': 'numenta/son2014', # 'latest_gci': 'numenta/gci2013', } site = Site(**site_properties) site.put() account = accounts.getCurrentAccount() if not account: account = users.User(email='*****@*****.**') user_properties = { 'id': 'matt', 'account_id': account.user_id(), 'account': account, } current_user = user.User(**user_properties) current_user.put() group_properties = { 'key_name': 'numenta', 'link_id': 'numenta', 'name': 'Numenta Inc.', 'short_name': 'Numenta', 'home_page': 'http://numenta.org', 'email': '*****@*****.**', 'description': 'This is the profile for Numenta.', 'contact_street': '811 Hamilton St', 'contact_city': 'Redwood City, CA', 'contact_country': 'United States', 'contact_postalcode': '94063', 'phone': '6503698282', 'status': 'active', } numenta = Sponsor(**group_properties) numenta.put() now = datetime.datetime.now() # before = now - datetime.timedelta(365) # after = now + datetime.timedelta(365) # past_before = before - datetime.timedelta(2 * 365) # past_after = after - datetime.timedelta(2 * 365) # first_day = datetime.datetime(2014, 5, 1) # last_day = datetime.datetime(2014, 9, 1) # signup_deadline = first_day + datetime.timedelta(30) # signup_start = first_day # students_announced = signup_deadline + datetime.timedelta(15) program_start = datetime.datetime(2014, 3, 5) program_end = datetime.datetime(2014, 9, 1) timeline_properties = { 'key_name': 'numenta/son2014', 'link_id': 'son2014', 'scope': numenta, 'program_start': program_start, 'program_end': program_end, 'accepted_organization_announced_deadline': datetime.datetime(2014, 3, 1), 'accepted_students_announced_deadline' : datetime.datetime(2014, 4, 15), 'student_signup_start': datetime.datetime(2014, 3, 5), 'student_signup_end': datetime.datetime(2014, 4, 1), 'application_review_deadline': datetime.datetime(2014, 4, 10), 'form_submission_start': datetime.datetime(2014, 3, 5), 'student_application_matched_deadline': datetime.datetime(2014, 4, 12), 'bonding_start': datetime.datetime(2014, 4, 15), 'bonding_end': datetime.datetime(2014, 5, 1), 'coding_start': datetime.datetime(2014, 5, 1), 'coding_end': datetime.datetime(2014, 8, 1), } son2014_timeline = GSoCTimeline(**timeline_properties) son2014_timeline.put() program_properties = { 'key_name': 'numenta/son2014', 'link_id': 'son2014', 'program_id': 'son2014', 'sponsor': numenta, 'scope': numenta, 'name': 'Numenta Season of NuPIC 2014', 'short_name': 'SoN 2014', 'description': 'This is the program for SoN 2014.', 'apps_tasks_limit': 42, 'slots': 42, 'timeline': son2014_timeline, 'status': program_model.STATUS_VISIBLE, } son2014 = GSoCProgram(**program_properties) son2014.put() # timeline_properties.update({ # 'key_name': 'numenta/gsoc2010', # 'link_id': 'gsoc2010', # 'program_start': past_before, # 'program_end': past_after, # 'accepted_organization_announced_deadline': past_before, # 'accepted_students_announced_deadline' : past_after, # 'student_signup_start': past_before, # 'student_signup_end': past_after, # 'application_review_deadline': past_after, # 'student_application_matched_deadline': past_after, # 'accepted_students_announced_deadline': past_after, # 'form_submission_start': past_before, # }) # gsoc2010_timeline = GSoCTimeline(**timeline_properties) # gsoc2010_timeline.put() # program_properties.update({ # 'key_name': 'numenta/gsoc2010', # 'link_id': 'gsoc2010', # 'program_id': 'gsoc2010', # 'name': 'Numenta Season of NuPIC 2010', # 'description': 'This is the program for GSoC 2010.', # 'short_name': 'GSoC 2010', # 'timeline': gsoc2010_timeline, # }) # gsoc2010 = GSoCProgram(**program_properties) # gsoc2010.put() # TODO(drew): Replace son2014.prefix with whatever its replacement becomes # once prefix is removed from program and no longer used in the query for # OrgAppSurvey in soc.views.helper.RequestData._getProgramWideFields(). org_app_survey_properties = { 'key_name' : '%s/%s/orgapp' % (son2014.prefix, son2014.key().name()), 'program' : son2014, 'title' : 'Org App Survey', 'content' : 'Here is some content.', 'modified_by' : current_user.key.to_old_key(), 'survey_start' : program_start, 'survey_end' : program_end } org_app_survey_model.OrgAppSurvey(**org_app_survey_properties).put() org_app_survey_properties['key_name'] = ('%s/%s/orgapp' % ( son2014.prefix, son2014.key().name())) org_app_survey_properties['program'] = son2014 org_app_survey_properties['survey_start'] = program_start org_app_survey_properties['survey_end'] = program_end org_app_survey_model.OrgAppSurvey(**org_app_survey_properties).put() # timeline_properties = { # 'key_name': 'numenta/gci2013', # 'link_id': 'gci2013', # 'scope': numenta, # '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, # } # gci2013_timeline = GCITimeline(**timeline_properties) # gci2013_timeline.put() # program_properties.update({ # 'key_name': 'numenta/gci2013', # 'link_id': 'gci2013', # 'program_id': 'gci2013', # 'name': 'Numenta Code In Contest 2013', # 'short_name': 'GCI 2009', # 'description': 'This is the program for GCI 2013.', # 'timeline': gci2013_timeline, # }) # gci2013 = GCIProgram(**program_properties) # gci2013.put() # site.active_program = gci2013 site.active_program = son2014 site.put() current_user.host_for = [ # ndb.Key.from_old_key(gsoc2010.key()), ndb.Key.from_old_key(son2014.key()), # ndb.Key.from_old_key(gci2013.key()) ] current_user.put() # group_properties.update({ # 'key_name': 'numenta/gci2013/melange', # 'link_id': 'melange', # 'name': 'Melange Development Team', # 'short_name': 'Melange', # 'scope': gci2013, # 'program': gci2013, # 'sponsor': numenta, # 'home_page': 'http://code.numenta.com/p/soc', # 'description': 'Melange, share the love!', # 'license_name': 'Apache License', # 'ideas': 'http://code.numenta.com/p/soc/issues', # }) # melange = GCIOrganization(**group_properties) # melange.put() group_properties.update({ 'scope': son2014, 'program': son2014, }) address_properties = address.Address( street='942 Brookgrove Ln', city='Cupertino, CA', country='United States', postal_code='95014') address_properties.put() contact_info = contact.Contact(email='*****@*****.**') contact_info.put() gsoc_delta = datetime.timedelta(days=(365 * 18)) profile_properties = { 'id': son2014.key().name() + '/' + current_user.key.id(), 'parent': current_user.key, 'public_name': 'Matt Taylor', 'program': ndb.Key.from_old_key(son2014.key()), 'first_name': 'Matthew', 'last_name': 'Taylor', 'contact' : contact_info, 'residential_address' : address_properties, 'shipping_address' : address_properties, 'birth_date' : datetime.datetime(1978, 7, 11), 'program_knowledge' : 'Creator', } profile = profile_model.Profile(**profile_properties) # ndb_orgs = [] # for i in range(2): group_properties.update({ 'key_name': 'numenta/son2014/numenta_org', 'link_id': 'numenta_org', 'name': 'Numenta Inc.', 'short_name': 'Numenta', 'description': 'This is the organization for Numenta, Inc.', }) org_properties = { 'name': 'Numenta Inc.', 'org_id': 'numenta_org', 'program': ndb.Key.from_old_key(son2014.key()), 'description': 'This is the organization for Numenta, Inc.', } org = soc_org_model.SOCOrganization( id='numenta/son2014/numenta_org', **org_properties) org.put() profile.admin_for.append(org.key) profile.mentor_for.append(org.key) profile.put() # profile_properties.update({ # 'id': son2014.key().name() + '/' + current_user.key.id(), # 'parent': current_user.key, # 'program': ndb.Key.from_old_key(son2014.key()), # 'admin_for': [ndb.Key.from_old_key(son2014.key())], # 'mentor_for': [ndb.Key.from_old_key(son2014.key())], # }) # numenta_admin = profile_model.Profile(**profile_properties) # # TODO: add GCI orgs # numenta_admin.put() # task_properties = { # 'status': 'Open', # 'modified_by': numenta_admin.key.to_old_key(), # 'subscribers': [numenta_admin.key.to_old_key()], # 'title': 'Awesomeness (test task)', # 'created_by': numenta_admin.key.to_old_key(), # 'created_on': now, # 'program': son2014, # 'time_to_complete': 1337, # 'modified_on': now, # 'org': org.key, # 'description': '<p>AWESOME</p>', # 'difficulty_level': DifficultyLevel.MEDIUM, # 'types': ['Code'] # } # gci_task = GCITask(**task_properties) # gci_task.put() user_properties = { 'id': 'student', 'account_id': '12345', 'account': users.User(email='*****@*****.**'), } student_user = user.User(**user_properties) student_user.put() gci_delta = datetime.timedelta(days=(365 * 14)) contact_properties = contact.Contact( email='*****@*****.**', web_page='http://www.homepage.com/', blog='http://www.blog.com/', phone='1650253000') contact_properties.put() graduation_year = datetime.date.today() + datetime.timedelta(days=365) student_data = soc_profile.SOCStudentData( education=education.Education( school_id="123", school_country="United States", expected_graduation=int(graduation_year.strftime('%Y')), major='Some Major', degree=education.Degree.UNDERGRADUATE) ) student_data.put() student_id = 'student' student_properties = { 'id': son2014.key().name() + "/" + student_id, 'parent': student_user.key, 'program': ndb.Key.from_old_key(son2014.key()), 'public_name': 'Student', 'first_name': 'Student', 'last_name': 'Student', 'contact' : contact_properties, 'residential_address' : address_properties, 'shipping_address' : address_properties, 'birth_date': datetime.date.today() - gci_delta, 'tee_size': profile_model.TeeSize.L, 'tee_style': profile_model.TeeStyle.MALE, 'gender' : profile_model.Gender.MALE, 'program_knowledge': 'Friend referral.', 'student_data' : student_data, } nupic_student = profile_model.Profile(**student_properties) nupic_student.put() student_id = 'student2' user_properties = { 'id': student_id, 'account_id': 'student2', 'account': users.User(email='*****@*****.**'), } student_user2 = user.User(**user_properties) student_user2.put() student_properties.update({ 'id': son2014.key().name() + "/" + student_id, 'parent': student_user2.key, 'first_name' : 'Student 2', 'last_name' : 'Example' }) nupic_student2 = profile_model.Profile(**student_properties) nupic_student2.put() proposal_properties = { 'parent': nupic_student.key.to_old_key(), 'program': son2014, 'title': 'test proposal', 'abstract': 'test abstract', 'content': 'test content', 'mentor': profile.key.to_old_key(), 'status': 'accepted', 'has_mentor': True, 'org': org.key.to_old_key(), 'possible_mentors': [profile.key.to_old_key()] } nupic_proposal = GSoCProposal(**proposal_properties) nupic_proposal.put() project_properties = { 'title': 'NuPIC test project 1', 'abstract': 'test abstract', 'status': 'accepted', 'parent': nupic_student.key.to_old_key(), 'mentors': [profile.key.to_old_key()], 'program': son2014, 'org': org.key.to_old_key(), 'proposal' : nupic_proposal.key(), } nupic_project = GSoCProject(**project_properties) nupic_project.put() org.slot_allocation = 1 org.put() student_data.number_of_projects = 1 student_data.number_of_proposals = 1 student_data.project_for_orgs = [org.key] nupic_student.put() nupic_student2.put() project_properties.update({ 'student': nupic_student2, 'title': 'NuPIC test project 2' }) nupic_project2 = GSoCProject(**project_properties) nupic_project2.put() org.slot_allocation += 1 org.put() # student_id = 'student' # student_properties.update({ # 'id': son2014.key().name() + '/' + student_id, # 'parent': student_user.key, # 'program': ndb.Key.from_old_key(son2014.key()), # }) # gci_student = profile_model.Profile(**student_properties) # gci_student.put() # score_properties = { # 'parent': gci_student.key.to_old_key(), # 'program': gci2013, # 'points': 5, # 'tasks': [gci_task.key()] # } # score = GCIScore(**score_properties) # score.put() document_properties = { 'key_name': 'site/site/home', 'link_id': 'home', 'scope': site, 'prefix': 'site', 'author': current_user.key.to_old_key(), 'title': 'Home Page', 'content': 'This is the Home Page', 'modified_by': current_user.key.to_old_key(), } home_document = Document(**document_properties) home_document.put() document_properties = { 'key_name': 'user/test/notes', 'link_id': 'notes', 'scope': current_user.key.to_old_key(), 'prefix': 'user', 'author': current_user.key.to_old_key(), 'title': 'My Notes', 'content': 'These are my notes', 'modified_by': current_user.key.to_old_key(), } notes_document = Document(**document_properties) notes_document.put() site.home = home_document site.put() memcache.flush_all() return http.HttpResponse('Done')
def getUniversalContext(request): """Constructs a template context dict will many common variables defined. Args: request: the Django HTTP request object Returns: a new context dict containing: { 'request': the Django HTTP request object passed in by the caller 'account': the logged-in Google Account if there is one 'user': the User entity corresponding to the Google Account in context['account'] 'is_admin': True if users.is_current_user_admin() is True 'is_debug': True if system.isDebug() is True 'sign_in': a Google Account login URL 'sign_out': a Google Account logout URL 'sidebar_menu_html': an HTML string that renders the sidebar menu } """ core = callback.getCore() context = core.getRequestValue('context', {}) if context: return context account = accounts.getCurrentAccount() user = None is_admin = False context['request'] = request if account: user = user_logic.getForAccount(account) is_admin = user_logic.isDeveloper(account=account, user=user) context['account'] = account context['user'] = user context['is_admin'] = is_admin context['is_local'] = system.isLocal() context['is_debug'] = system.isDebug() context['sign_in'] = users.create_login_url(request.path) context['sign_out'] = users.create_logout_url(request.path) context['sidebar_menu_items'] = core.getSidebar(account, user) context['gae_version'] = system.getAppVersion() context['soc_release'] = system.getMelangeVersion() settings = site.logic.getSingleton() context['ga_tracking_num'] = settings.ga_tracking_num context['gmaps_api_key'] = settings.gmaps_api_key context['site_name'] = settings.site_name context['site_notice'] = settings.site_notice context['tos_link'] = redirects.getToSRedirect(settings) context['in_maintenance'] = timeline.isActivePeriod( settings, 'maintenance') # Only one xsrf_token is generated per request. xsrf_secret_key = site.logic.getXsrfSecretKey(settings) context['xsrf_token'] = xsrfutil.getGeneratedTokenForCurrentUser( xsrf_secret_key) core.setRequestValue('context', context) return context
def seed(request, *args, **kwargs): """Seeds the datastore with some default values. """ site_properties = { 'key_name': 'site', 'latest_gsoc': 'google/gsoc2014', 'latest_gci': 'google/gci2013', } site = Site(**site_properties) site.put() account = accounts.getCurrentAccount() if not account: account = users.User(email='*****@*****.**') user_properties = { 'id': 'test', 'account_id': account.user_id(), 'account': account, } current_user = user.User(**user_properties) current_user.put() group_properties = { 'key_name': 'google', 'link_id': 'google', 'name': 'Google Inc.', 'short_name': 'Google', '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': '15551110000', 'status': 'active', } google = Sponsor(**group_properties) google.put() now = datetime.datetime.now() before = now - datetime.timedelta(365) after = now + datetime.timedelta(365) past_before = before - datetime.timedelta(2 * 365) past_after = after - datetime.timedelta(2 * 365) timeline_properties = { 'key_name': 'google/gsoc2014', 'link_id': 'gsoc2014', 'scope': google, 'program_start': before, 'program_end': after, 'accepted_organization_announced_deadline': before, 'accepted_students_announced_deadline' : after, 'student_signup_start': before, 'student_signup_end': after, 'application_review_deadline': after, 'student_application_matched_deadline': after, 'accepted_students_announced_deadline': after, 'form_submission_start': before, } gsoc2014_timeline = GSoCTimeline(**timeline_properties) gsoc2014_timeline.put() program_properties = { 'key_name': 'google/gsoc2014', 'link_id': 'gsoc2014', 'program_id': 'gsoc2014', 'sponsor': google, 'scope': google, 'name': 'Google Summer of Code 2014', 'short_name': 'GSoC 2014', 'description': 'This is the program for GSoC 2014.', 'apps_tasks_limit': 42, 'slots': 42, 'timeline': gsoc2014_timeline, 'status': program_model.STATUS_VISIBLE, } gsoc2014 = GSoCProgram(**program_properties) gsoc2014.put() timeline_properties.update({ 'key_name': 'google/gsoc2010', 'link_id': 'gsoc2010', 'program_start': past_before, 'program_end': past_after, 'accepted_organization_announced_deadline': past_before, 'accepted_students_announced_deadline' : past_after, 'student_signup_start': past_before, 'student_signup_end': past_after, 'application_review_deadline': past_after, 'student_application_matched_deadline': past_after, 'accepted_students_announced_deadline': past_after, 'form_submission_start': past_before, }) gsoc2010_timeline = GSoCTimeline(**timeline_properties) gsoc2010_timeline.put() program_properties.update({ 'key_name': 'google/gsoc2010', 'link_id': 'gsoc2010', 'program_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() # TODO(drew): Replace gsoc2014.prefix with whatever its replacement becomes # once prefix is removed from program and no longer used in the query for # OrgAppSurvey in soc.views.helper.RequestData._getProgramWideFields(). org_app_survey_properties = { 'key_name' : '%s/%s/orgapp' % (gsoc2014.prefix, gsoc2014.key().name()), 'program' : gsoc2014, 'title' : 'Org App Survey', 'content' : 'Here is some content.', 'modified_by' : current_user.key.to_old_key(), 'survey_start' : before, 'survey_end' : after } org_app_survey_model.OrgAppSurvey(**org_app_survey_properties).put() org_app_survey_properties['key_name'] = ('%s/%s/orgapp' % ( gsoc2010.prefix, gsoc2010.key().name())) org_app_survey_properties['program'] = gsoc2010 org_app_survey_properties['survey_start'] = past_before org_app_survey_properties['survey_end'] = past_after org_app_survey_model.OrgAppSurvey(**org_app_survey_properties).put() timeline_properties = { 'key_name': 'google/gci2013', 'link_id': 'gci2013', '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, } gci2013_timeline = GCITimeline(**timeline_properties) gci2013_timeline.put() program_properties.update({ 'key_name': 'google/gci2013', 'link_id': 'gci2013', 'program_id': 'gci2013', 'name': 'Google Code In Contest 2013', 'short_name': 'GCI 2009', 'description': 'This is the program for GCI 2013.', 'timeline': gci2013_timeline, }) gci2013 = GCIProgram(**program_properties) gci2013.put() site.active_program = gci2013 site.put() current_user.host_for = [ ndb.Key.from_old_key(gsoc2010.key()), ndb.Key.from_old_key(gsoc2014.key()), ndb.Key.from_old_key(gci2013.key())] current_user.put() group_properties.update({ 'key_name': 'google/gci2013/melange', 'link_id': 'melange', 'name': 'Melange Development Team', 'short_name': 'Melange', 'scope': gci2013, 'program': gci2013, 'sponsor': google, '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': gsoc2014, 'program': gsoc2014, }) address_properties = address.Address( street='1 Test St.', city='Some City', country='United States', postal_code='12345') address_properties.put() contact_info = contact.Contact(email='*****@*****.**') contact_info.put() gsoc_delta = datetime.timedelta(days=(365 * 18)) profile_properties = { 'id': gsoc2014.key().name() + '/' + current_user.key.id(), 'parent': current_user.key, 'public_name': 'test', 'program': ndb.Key.from_old_key(gsoc2014.key()), 'first_name': 'Test', 'last_name': 'Example', 'contact' : contact_info, 'residential_address' : address_properties, 'shipping_address' : address_properties, 'birth_date' : datetime.date.today() - gsoc_delta, 'program_knowledge' : 'Friend referral', } profile = profile_model.Profile(**profile_properties) ndb_orgs = [] for i in range(15): group_properties.update({ 'key_name': 'google/gsoc2014/org_%d' % i, 'link_id': 'org_%d' % i, 'name': 'Organization %d' % i, 'short_name': 'Org %d' % i, 'description': 'Organization %d!' % i, }) org_properties = { 'name': 'Organization %d' % i, 'org_id': 'org_%d' % i, 'program': ndb.Key.from_old_key(gsoc2014.key()), 'description': 'Organization %d!' % i, } org = soc_org_model.SOCOrganization( id='google/gsoc2014/org_%d' % i, **org_properties) org.put() ndb_orgs.append(org) # Admin (and thus mentor) for the first org if i == 0: profile.admin_for.append(org.key) profile.mentor_for.append(org.key) profile.put() # Mentor for the second org if i == 1: profile.mentor_for.append(org.key) profile.put() profile_properties.update({ 'id': gci2013.key().name() + '/' + current_user.key.id(), 'parent': current_user.key, 'program': ndb.Key.from_old_key(gci2013.key()), 'admin_for': [ndb.Key.from_old_key(melange.key())], 'mentor_for': [ndb.Key.from_old_key(melange.key())], }) melange_admin = profile_model.Profile(**profile_properties) # TODO: add GCI orgs melange_admin.put() task_properties = { 'status': 'Open', 'modified_by': melange_admin.key.to_old_key(), 'subscribers': [melange_admin.key.to_old_key()], 'title': 'Awesomeness', 'created_by': melange_admin.key.to_old_key(), 'created_on': now, 'program': gci2013, '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 = { 'id': 'student', 'account_id': '12345', 'account': users.User(email='*****@*****.**'), } student_user = user.User(**user_properties) student_user.put() gci_delta = datetime.timedelta(days=(365 * 14)) contact_properties = contact.Contact( email='*****@*****.**', web_page='http://www.homepage.com/', blog='http://www.blog.com/', phone='1650253000') contact_properties.put() graduation_year = datetime.date.today() + datetime.timedelta(days=365) student_data = soc_profile.SOCStudentData( education=education.Education( school_id="123", school_country="United States", expected_graduation=int(graduation_year.strftime('%Y')), major='Some Major', degree=education.Degree.UNDERGRADUATE) ) student_data.put() student_id = 'student' student_properties = { 'id': gsoc2014.key().name() + "/" + student_id, 'parent': student_user.key, 'program': ndb.Key.from_old_key(gsoc2014.key()), 'public_name': 'Student', 'first_name': 'Student', 'last_name': 'Student', 'contact' : contact_properties, 'residential_address' : address_properties, 'shipping_address' : address_properties, 'birth_date': datetime.date.today() - gci_delta, 'tee_size': profile_model.TeeSize.L, 'tee_style': profile_model.TeeStyle.MALE, 'gender' : profile_model.Gender.MALE, 'program_knowledge': 'Friend referral.', 'student_data' : student_data, } melange_student = profile_model.Profile(**student_properties) melange_student.put() student_id = 'student2' user_properties = { 'id': student_id, 'account_id': 'student2', 'account': users.User(email='*****@*****.**'), } student_user2 = user.User(**user_properties) student_user2.put() student_properties.update({ 'id': gsoc2014.key().name() + "/" + student_id, 'parent': student_user2.key, 'first_name' : 'Student 2', 'last_name' : 'Example' }) melange_student2 = profile_model.Profile(**student_properties) melange_student2.put() proposal_properties = { 'parent': melange_student.key.to_old_key(), 'program': gsoc2014, 'title': 'test proposal', 'abstract': 'test abstract', 'content': 'test content', 'mentor': profile.key.to_old_key(), 'status': 'accepted', 'has_mentor': True, 'org': ndb_orgs[0].key.to_old_key(), 'possible_mentors': [profile.key.to_old_key()] } melange_proposal = GSoCProposal(**proposal_properties) melange_proposal.put() project_properties = { 'title': 'test project', 'abstract': 'test abstract', 'status': 'accepted', 'parent': melange_student.key.to_old_key(), 'mentors': [profile.key.to_old_key()], 'program': gsoc2014, 'org': ndb_orgs[0].key.to_old_key(), 'proposal' : melange_proposal.key(), } melange_project = GSoCProject(**project_properties) melange_project.put() ndb_orgs[1].slot_allocation = 1 ndb_orgs[1].put() student_data.number_of_projects = 1 student_data.number_of_proposals = 1 student_data.project_for_orgs = [ndb_orgs[1].key] melange_student.put() melange_student2.put() project_properties.update({ 'student': melange_student2, 'title': 'test project2' }) melange_project2 = GSoCProject(**project_properties) melange_project2.put() ndb_orgs[1].slot_allocation += 1 ndb_orgs[1].put() student_id = 'student' student_properties.update({ 'id': gci2013.key().name() + '/' + student_id, 'parent': student_user.key, 'program': ndb.Key.from_old_key(gci2013.key()), }) gci_student = profile_model.Profile(**student_properties) gci_student.put() score_properties = { 'parent': gci_student.key.to_old_key(), 'program': gci2013, 'points': 5, 'tasks': [gci_task.key()] } score = GCIScore(**score_properties) score.put() document_properties = { 'key_name': 'site/site/home', 'link_id': 'home', 'scope': site, 'prefix': 'site', 'author': current_user.key.to_old_key(), 'title': 'Home Page', 'content': 'This is the Home Page', 'modified_by': current_user.key.to_old_key(), } home_document = Document(**document_properties) home_document.put() document_properties = { 'key_name': 'user/test/notes', 'link_id': 'notes', 'scope': current_user.key.to_old_key(), 'prefix': 'user', 'author': current_user.key.to_old_key(), 'title': 'My Notes', 'content': 'These are my notes', 'modified_by': current_user.key.to_old_key(), } notes_document = Document(**document_properties) notes_document.put() site.home = home_document site.put() memcache.flush_all() return http.HttpResponse('Done')