app/soc/models/seed_db.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Fri, 18 Sep 2009 20:06:28 +0200
changeset 2957 f6515daaf000
parent 2813 6f7af233b5b0
child 2972 1e1b8f22e153
permissions -rw-r--r--
Enable document system for GHOP As can be seen from the changes outside app/soc/modules, there is still some work to be done to make the modules fully restricted to configuration changes and code in app/soc/modules. Reviewed-by: Sverre Rabbelier
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1335
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
     1
#!/usr/bin/python2.5
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
     2
#
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
     3
# Copyright 2008 the Melange authors.
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
     4
#
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
     6
# you may not use this file except in compliance with the License.
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
     7
# You may obtain a copy of the License at
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
     8
#
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
    10
#
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
    14
# See the License for the specific language governing permissions and
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
    15
# limitations under the License.
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
    16
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
    17
"""Seeds or clears the datastore.
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
    18
"""
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
    19
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
    20
__authors__ = [
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
    21
    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
2669
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
    22
    'JamesLevy" <jamesalexanderlevy@gmail.com>',
1335
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
    23
  ]
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
    24
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
    25
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
import itertools
2048
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
    27
import logging
1905
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
    28
import random
2669
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
    29
import datetime
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
1348
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
    31
from google.appengine.api import users
1453
378c844bf52c Flush cache after seeding or clearing the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1434
diff changeset
    32
from google.appengine.api import memcache
1348
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
    33
from google.appengine.ext import db
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
1789
6f112b2ebd1f Return a HttpResponse in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1623
diff changeset
    35
from django import http
6f112b2ebd1f Return a HttpResponse in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1623
diff changeset
    36
2669
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
    37
from soc.logic.models.document import logic as document_logic
1623
8b70d6bb3f8f Renamed rankerroot to ranker_root and made some changes due to comments.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1609
diff changeset
    38
from soc.logic.models.ranker_root import logic as ranker_root_logic
2669
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
    39
from soc.logic.models.survey import logic as survey_logic
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
    40
from soc.logic.models.user import logic as user_logic
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
    41
1798
ba4c00bc0c39 Use accounts.getCurrentAccount instead of users.get_current_user
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1794
diff changeset
    42
from soc.logic import accounts
1900
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    43
from soc.logic import dicts
1609
cd285bc524f1 Create a new Ranker for each organization that is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1602
diff changeset
    44
from soc.models import student_proposal
1355
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
    45
from soc.models.document import Document
1348
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
    46
from soc.models.host import Host
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
    47
from soc.models.mentor import Mentor
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
from soc.models.notification import Notification
1355
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
    49
from soc.models.org_admin import OrgAdmin
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
    50
from soc.models.organization import Organization
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
    51
from soc.models.org_app import OrgApplication
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
    52
from soc.models.program import Program
1794
6ffd25bedef9 Also clear RankerRoot and ranker from datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1793
diff changeset
    53
from soc.models.ranker_root import RankerRoot
1355
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
    54
from soc.models.site import Site
2200
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
    55
from soc.models.student import Student
2669
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
    56
from soc.models.student_project import StudentProject
1905
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
    57
from soc.models.student_proposal import StudentProposal
2669
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
    58
from soc.models.survey import Survey, SurveyContent
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
    59
from soc.models.survey_record import SurveyRecord
1355
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
    60
from soc.models.sponsor import Sponsor
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
    61
from soc.models.timeline import Timeline
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
    62
from soc.models.user import User
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    63
1900
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    64
class Error(Exception):
2074
5c75312566d5 Fix too long lines, style and remove unused imports in soc.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2048
diff changeset
    65
  """Base class for all exceptions raised by this module.
5c75312566d5 Fix too long lines, style and remove unused imports in soc.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2048
diff changeset
    66
  """
2167
91e622242f2d Respond to comments on r2769.
Daniel Bentley <dbentley@google.com>
parents: 2160
diff changeset
    67
1900
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    68
  pass
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    69
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    70
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    71
def ensureUser():
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    72
  """Returns the current user account and associated user object.
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    73
  """
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    74
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    75
  account = accounts.getCurrentAccount()
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    76
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    77
  if not account:
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    78
    account = users.User(email='test@example.com')
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    79
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    80
  user_properties = {
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    81
      'key_name': 'test',
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    82
      'link_id': 'test',
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    83
      'account': account,
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    84
      'name': 'Test',
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    85
      }
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    86
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    87
  current_user = User(**user_properties)
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    88
  current_user.put()
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    89
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    90
  return account, current_user
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    91
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
    92
2184
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
    93
class Seeder(object):
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
    94
  """A Seeder can seed Melange types.
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
    95
  """
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
    96
  def type(self):
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
    97
    """Returns the type to be seeded."""
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
    98
    raise NotImplementedError
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
    99
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   100
  def seed(self, i, entities=None, **kwargs):
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   101
    """Seed the ith instance of this type.
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   102
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   103
    Args:
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   104
      i, int: which to seed
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   105
      entities, list of type()'s: if None, persist at the end of this call.
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   106
        if non-None, append the created entity to entities instead of
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   107
        persisting.
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   108
      kwargs: the dictionary returned by commonSeedArgs
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   109
    """
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   110
    raise NotImplementedError
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   111
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   112
  def commonSeedArgs(self, request):
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   113
    """Find common information for seeding that's common across entities
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   114
    seeded in one request.
2048
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   115
2184
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   116
    Returns:
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   117
      dictionary of str->value; passed to each call of seed() for this
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   118
      request
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   119
    """
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   120
    raise NotImplementedError
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   121
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   122
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   123
class UserSeeder(Seeder):
2367
19ca23d78701 Add some missing docstrings to Seeder classes in seed_db.py
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2366
diff changeset
   124
  """A Seeder for Melange User model.
19ca23d78701 Add some missing docstrings to Seeder classes in seed_db.py
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2366
diff changeset
   125
  """
2184
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   126
  def type(self):
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   127
    return User
2366
1a954e80d444 Style fixes and pylint: disable-msg comments in different modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2361
diff changeset
   128
  
1a954e80d444 Style fixes and pylint: disable-msg comments in different modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2361
diff changeset
   129
  # pylint: disable-msg=W0221
2184
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   130
  def seed(self, i, entities=None):
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   131
    user_properties = {
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   132
        'key_name': 'user_%04d' % i,
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   133
        'link_id': 'user_%04d' % i,
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   134
        'account': users.User(email='user_%04d@example.com' % i),
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   135
        'name': 'User %04d' % i,
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   136
        }
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   137
    entity = User(**user_properties)
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   138
    if entities is None:
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   139
      entity.put()
2669
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   140
      user_logic._onCreate(entity)
2184
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   141
    else:
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   142
      entities.append(entity)
2048
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   143
2184
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   144
  def commonSeedArgs(self, request):
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   145
    return {}
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   146
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   147
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   148
class OrganizationSeeder(Seeder):
2367
19ca23d78701 Add some missing docstrings to Seeder classes in seed_db.py
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2366
diff changeset
   149
  """A Seeder for Melange Organization model.
19ca23d78701 Add some missing docstrings to Seeder classes in seed_db.py
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2366
diff changeset
   150
  """
2184
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   151
  def type(self):
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   152
    return Organization
2366
1a954e80d444 Style fixes and pylint: disable-msg comments in different modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2361
diff changeset
   153
  
1a954e80d444 Style fixes and pylint: disable-msg comments in different modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2361
diff changeset
   154
  # pylint: disable-msg=W0221
2184
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   155
  def seed(self, i, entities=None, current_user=None, gsoc2009=None):
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   156
    properties = {
2352
33ff03da52b6 Link id and key name fixes for Organization And OrgApplication in seed_db.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2351
diff changeset
   157
        'key_name': 'google/gsoc2009/org_%04d' % i,
2184
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   158
        'link_id': 'org_%04d' % i,
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   159
        'name': 'Organization %04d' % i,
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   160
        'short_name': 'Org %04d' % i,
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   161
        'founder': current_user,
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   162
        'scope_path': 'google/gsoc2009',
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   163
        'scope': gsoc2009,
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   164
        'status': 'active',
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   165
        'email': 'org_%04d@example.com' % i,
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   166
        'home_page': 'http://code.google.com/p/soc',
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   167
        'description': 'Melange, share the love!',
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   168
        'license_name': 'Apache License',
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   169
        'contact_street': 'Some Street',
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   170
        'contact_city': 'Some City',
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   171
        'contact_country': 'United States',
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   172
        'contact_postalcode': '12345',
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   173
        'phone': '1-555-BANANA',
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   174
        'ideas': 'http://code.google.com/p/soc/issues',
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   175
        }
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   176
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   177
    org = Organization(**properties)
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   178
    if entities is None:
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   179
      org.put()
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   180
    else:
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   181
      entities.append(org)
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   182
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   183
  def commonSeedArgs(self, request):
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   184
    _, current_user = ensureUser()
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   185
    gsoc2009 = Program.get_by_key_name('google/gsoc2009')
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   186
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   187
    if not gsoc2009:
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   188
      raise Error('Run seed_db first')
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   189
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   190
    return dict(current_user=current_user,
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   191
                gsoc2009=gsoc2009)
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   192
2048
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   193
2351
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   194
class OrgApplicationSeeder(Seeder):
2367
19ca23d78701 Add some missing docstrings to Seeder classes in seed_db.py
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2366
diff changeset
   195
  """A Seeder for Melange OrgApplication model.
19ca23d78701 Add some missing docstrings to Seeder classes in seed_db.py
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2366
diff changeset
   196
  """
2351
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   197
  def type(self):
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   198
    return OrgApplication
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   199
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   200
  def commonSeedArgs(self, request):
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   201
    _, current_user = ensureUser()
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   202
    gsoc2009 = Program.get_by_key_name('google/gsoc2009')
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   203
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   204
    if not gsoc2009:
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   205
      raise Error('Run seed_db first')
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   206
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   207
    status = request.GET.get('status', 'pre-accepted')
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   208
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   209
    return dict(current_user=current_user,
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   210
                gsoc2009=gsoc2009,
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   211
                status=status)
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   212
2366
1a954e80d444 Style fixes and pylint: disable-msg comments in different modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2361
diff changeset
   213
  # pylint: disable-msg=W0221
2351
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   214
  def seed(self, i, entities=None, current_user=None, gsoc2009=None,
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   215
           status=None):
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   216
    properties = {
2352
33ff03da52b6 Link id and key name fixes for Organization And OrgApplication in seed_db.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2351
diff changeset
   217
        'key_name': 'google/gsoc2009/org_%04d' % i,
33ff03da52b6 Link id and key name fixes for Organization And OrgApplication in seed_db.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2351
diff changeset
   218
        'link_id': 'org_%04d' % i,
2351
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   219
        'name': 'Org App %04d' % i,
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   220
        'scope_path': 'google/gsoc2009',
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   221
        'scope': gsoc2009,
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   222
        'status': status,
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   223
        'applicant': current_user,
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   224
        'home_page': 'http://www.google.com',
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   225
        'email': 'org@example.com',
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   226
        'irc_channel': '#care',
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   227
        'pub_mailing_list': 'http://groups.google.com',
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   228
        'dev_mailing_list': 'http://groups.google.com',
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   229
        'description': 'This is an awesome org!',
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   230
        'why_applying': 'Because we can',
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   231
        'member_criteria': 'They need to be awesome',
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   232
        'license_name': 'Apache License, 2.0',
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   233
        'ideas': 'http://code.google.com/p/soc/issues',
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   234
        'contrib_disappears': 'We use google to find them',
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   235
        'member_disappears': 'See above',
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   236
        'encourage_contribs': 'We offer them cookies.',
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   237
        'continued_contribs': 'We promise them a cake.',
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   238
        'agreed_to_admin_agreement': True,
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   239
        }
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   240
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   241
    org_application = OrgApplication(**properties)
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   242
    if entities is None:
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   243
      org_application.put()
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   244
    else:
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   245
      entities.append(org_application)
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   246
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   247
2669
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   248
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   249
1791
26fa036d68a0 Make it possible to add more users and orgs with GET args
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1789
diff changeset
   250
def seed(request, *args, **kwargs):
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   251
  """Seeds the datastore with some default values.
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   252
  """
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   253
1355
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   254
  site_properties = {
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   255
      'key_name': 'site',
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   256
      'link_id': 'site',
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   257
      }
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   258
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   259
  site = Site(**site_properties)
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   260
  site.put()
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   261
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   262
2074
5c75312566d5 Fix too long lines, style and remove unused imports in soc.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2048
diff changeset
   263
  _, current_user = ensureUser()
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   264
1348
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   265
2200
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   266
  seeder = UserSeeder()
1900
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
   267
  for i in range(15):
2200
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   268
    seeder.seed(i)
1602
723739837649 Seed some users as well
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1562
diff changeset
   269
1348
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   270
  group_properties = {
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   271
       'key_name': 'google',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   272
       'link_id': 'google',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   273
       'name': 'Google Inc.',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   274
       'short_name': 'Google',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   275
       'founder': current_user,
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   276
       'home_page': 'http://www.google.com',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   277
       'email': 'ospo@google.com',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   278
       'description': 'This is the profile for Google.',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   279
       'contact_street': 'Some Street',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   280
       'contact_city': 'Some City',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   281
       'contact_country': 'United States',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   282
       'contact_postalcode': '12345',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   283
       'phone': '1-555-BANANA',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   284
       'status': 'active',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   285
       }
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   286
1348
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   287
  google = Sponsor(**group_properties)
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   288
  google.put()
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   289
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   290
1348
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   291
  role_properties = {
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   292
      'key_name': 'google/test',
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   293
      'link_id': 'test',
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   294
      'scope': google,
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   295
      'scope_path': 'google',
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   296
      'user': current_user,
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   297
      'given_name': 'Test',
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   298
      'surname': 'Example',
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   299
      'name_on_documents': 'Test Example',
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   300
      'email': 'test@example.com',
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   301
      'res_street': 'Some Street',
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   302
      'res_city': 'Some City',
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   303
      'res_state': 'Some State',
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   304
      'res_country': 'United States',
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   305
      'res_postalcode': '12345',
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   306
      'phone': '1-555-BANANA',
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   307
      'birth_date': db.DateProperty.now(),
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   308
      'agreed_to_tos': True,
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   309
      }
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   310
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   311
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   312
  google_host = Host(**role_properties)
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   313
  google_host.put()
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   314
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   315
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   316
  timeline_properties = {
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   317
        'key_name': 'google/gsoc2009',
1475
22b63ab59b27 Make timeline a Linkable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1453
diff changeset
   318
        'link_id': 'gsoc2009',
22b63ab59b27 Make timeline a Linkable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1453
diff changeset
   319
        'scope_path': 'google',
22b63ab59b27 Make timeline a Linkable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1453
diff changeset
   320
        'scope': google,
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   321
        }
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   322
1348
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   323
  gsoc2009_timeline = Timeline(**timeline_properties)
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   324
  gsoc2009_timeline.put()
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   325
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   326
1348
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   327
  program_properties = {
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   328
      'key_name': 'google/gsoc2009',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   329
      'link_id': 'gsoc2009',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   330
      'scope_path': 'google',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   331
      'scope': google,
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   332
      'name': 'Google Summer of Code 2009',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   333
      'short_name': 'GSoC 2009',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   334
      'group_label': 'GSOC',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   335
      'description': 'This is the program for GSoC 2009.',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   336
      'apps_tasks_limit': 42,
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   337
      'slots': 42,
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   338
      'timeline': gsoc2009_timeline,
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   339
      'status': 'visible',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   340
      }
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   341
1348
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   342
  gsoc2009 = Program(**program_properties)
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   343
  gsoc2009.put()
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   344
2813
6f7af233b5b0 Removed workflow property from Program model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2669
diff changeset
   345
  # TODO: Use real GHOPProgram here
1363
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   346
  timeline_properties = {
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   347
        'key_name': 'google/ghop2009',
1475
22b63ab59b27 Make timeline a Linkable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1453
diff changeset
   348
        'link_id': 'ghop2009',
22b63ab59b27 Make timeline a Linkable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1453
diff changeset
   349
        'scope_path': 'google',
22b63ab59b27 Make timeline a Linkable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1453
diff changeset
   350
        'scope': google,
1363
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   351
        }
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   352
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   353
  ghop2009_timeline = Timeline(**timeline_properties)
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   354
  ghop2009_timeline.put()
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   355
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   356
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   357
  program_properties.update({
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   358
      'key_name': 'google/ghop2009',
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   359
      'link_id': 'ghop2009',
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   360
      'name': 'Google Highly Open Participation Contest 2009',
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   361
      'short_name': 'GHOP 2009',
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   362
      'group_label': 'GHOP',
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   363
      'description': 'This is the program for GHOP 2009.',
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   364
      'timeline': ghop2009_timeline,
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   365
      })
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   366
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   367
  ghop2009 = Program(**program_properties)
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   368
  ghop2009.put()
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   369
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   370
1348
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   371
  org_app_properties = {
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   372
    'scope_path': 'google/gsoc2009',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   373
    'scope': gsoc2009,
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   374
    'applicant': current_user,
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   375
    'home_page': 'http://www.google.com',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   376
    'email': 'org@example.com',
1562
0e1a93e0c54d Made mailing lists and IRC channel required for group/org applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1475
diff changeset
   377
    'irc_channel': '#care',
0e1a93e0c54d Made mailing lists and IRC channel required for group/org applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1475
diff changeset
   378
    'pub_mailing_list': 'http://groups.google.com',
0e1a93e0c54d Made mailing lists and IRC channel required for group/org applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1475
diff changeset
   379
    'dev_mailing_list': 'http://groups.google.com',
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   380
    'description': 'This is an awesome org!',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   381
    'why_applying': 'Because we can',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   382
    'member_criteria': 'They need to be awesome',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   383
    'status': 'pre-accepted',
1429
cfa0c3f2dc19 Update seed_db as WTFPL is no longer an allowed license
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1415
diff changeset
   384
    'license_name': 'Apache License, 2.0',
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   385
    'ideas': 'http://code.google.com/p/soc/issues',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   386
    'contrib_disappears': 'We use google to find them',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   387
    'member_disappears': 'See above',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   388
    'encourage_contribs': 'We offer them cookies.',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   389
    'continued_contribs': 'We promise them a cake.',
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   390
    'agreed_to_admin_agreement': True,
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   391
    }
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   392
1900
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
   393
  for i in range(10):
2352
33ff03da52b6 Link id and key name fixes for Organization And OrgApplication in seed_db.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2351
diff changeset
   394
    org_app_properties['key_name'] = 'google/gsoc2009/org_%04d' % i
33ff03da52b6 Link id and key name fixes for Organization And OrgApplication in seed_db.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2351
diff changeset
   395
    org_app_properties['link_id'] = 'org_%04d' % i
2351
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   396
    org_app_properties['name'] = 'Org App %04d' % i
1348
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   397
    entity = OrgApplication(**org_app_properties)
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   398
    entity.put()
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   399
1348
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   400
1791
26fa036d68a0 Make it possible to add more users and orgs with GET args
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1789
diff changeset
   401
  org_app_properties['status'] = 'pre-rejected'
26fa036d68a0 Make it possible to add more users and orgs with GET args
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1789
diff changeset
   402
1900
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
   403
  for i in range(10, 20):
1791
26fa036d68a0 Make it possible to add more users and orgs with GET args
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1789
diff changeset
   404
    org_app_properties['key_name'] = 'google/gsoc2009/loser_%d' % i
26fa036d68a0 Make it possible to add more users and orgs with GET args
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1789
diff changeset
   405
    org_app_properties['link_id'] = 'loser_%d' % i
26fa036d68a0 Make it possible to add more users and orgs with GET args
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1789
diff changeset
   406
    org_app_properties['name'] = 'Loser %d' % i
26fa036d68a0 Make it possible to add more users and orgs with GET args
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1789
diff changeset
   407
    entity = OrgApplication(**org_app_properties)
26fa036d68a0 Make it possible to add more users and orgs with GET args
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1789
diff changeset
   408
    entity.put()
26fa036d68a0 Make it possible to add more users and orgs with GET args
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1789
diff changeset
   409
26fa036d68a0 Make it possible to add more users and orgs with GET args
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1789
diff changeset
   410
1348
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   411
  group_properties.update({
1363
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   412
    'key_name': 'google/ghop2009/melange',
1335
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
   413
    'link_id': 'melange',
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
   414
    'name': 'Melange Development Team',
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
   415
    'short_name': 'Melange',
1363
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   416
    'scope_path': 'google/ghop2009',
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   417
    'scope': ghop2009,
1335
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
   418
    'home_page': 'http://code.google.com/p/soc',
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
   419
    'description': 'Melange, share the love!',
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
   420
    'license_name': 'Apache License',
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
   421
    'ideas': 'http://code.google.com/p/soc/issues',
1348
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   422
    })
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   423
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   424
  melange = Organization(**group_properties)
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   425
  melange.put()
1609
cd285bc524f1 Create a new Ranker for each organization that is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1602
diff changeset
   426
  # create a new ranker
1623
8b70d6bb3f8f Renamed rankerroot to ranker_root and made some changes due to comments.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1609
diff changeset
   427
  ranker_root_logic.create(student_proposal.DEF_RANKER_NAME, melange,
1609
cd285bc524f1 Create a new Ranker for each organization that is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1602
diff changeset
   428
      student_proposal.DEF_SCORE, 100)
1335
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
   429
1791
26fa036d68a0 Make it possible to add more users and orgs with GET args
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1789
diff changeset
   430
1363
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   431
  group_properties.update({
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   432
    'scope_path': 'google/gsoc2009',
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   433
    'scope': gsoc2009,
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   434
    })
5667c29be1a3 Add GHOP as program and put 'Melange' under it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1362
diff changeset
   435
2669
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   436
  orgs = []
1900
a2966f072219 Factor out ensureUser and add Error class in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1799
diff changeset
   437
  for i in range(15):
1362
31b2cb6b75d8 Seed in some orgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1355
diff changeset
   438
    group_properties.update({
31b2cb6b75d8 Seed in some orgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1355
diff changeset
   439
        'key_name': 'google/gsoc2009/org_%d' % i,
31b2cb6b75d8 Seed in some orgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1355
diff changeset
   440
        'link_id': 'org_%d' % i,
31b2cb6b75d8 Seed in some orgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1355
diff changeset
   441
        'name': 'Organization %d' % i,
31b2cb6b75d8 Seed in some orgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1355
diff changeset
   442
        'short_name': 'Org %d' % i,
31b2cb6b75d8 Seed in some orgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1355
diff changeset
   443
        'description': 'Organization %d!' % i,
31b2cb6b75d8 Seed in some orgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1355
diff changeset
   444
        })
31b2cb6b75d8 Seed in some orgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1355
diff changeset
   445
31b2cb6b75d8 Seed in some orgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1355
diff changeset
   446
    entity = Organization(**group_properties)
2669
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   447
    orgs.append(entity)
1362
31b2cb6b75d8 Seed in some orgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1355
diff changeset
   448
    entity.put()
1609
cd285bc524f1 Create a new Ranker for each organization that is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1602
diff changeset
   449
    # create a new ranker
1623
8b70d6bb3f8f Renamed rankerroot to ranker_root and made some changes due to comments.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1609
diff changeset
   450
    ranker_root_logic.create(student_proposal.DEF_RANKER_NAME, entity,
1609
cd285bc524f1 Create a new Ranker for each organization that is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1602
diff changeset
   451
        student_proposal.DEF_SCORE, 100)
1362
31b2cb6b75d8 Seed in some orgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1355
diff changeset
   452
2027
199bcab679df Make test@example.com a mentor for one gsoc org and an admin (for a different) gsoc org.
Tim Ansell <mithro@gmail.com>
parents: 1945
diff changeset
   453
    if i < 2:
199bcab679df Make test@example.com a mentor for one gsoc org and an admin (for a different) gsoc org.
Tim Ansell <mithro@gmail.com>
parents: 1945
diff changeset
   454
      role_properties.update({
199bcab679df Make test@example.com a mentor for one gsoc org and an admin (for a different) gsoc org.
Tim Ansell <mithro@gmail.com>
parents: 1945
diff changeset
   455
          'key_name': 'google/gsoc2009/org_%d/test' % i,
199bcab679df Make test@example.com a mentor for one gsoc org and an admin (for a different) gsoc org.
Tim Ansell <mithro@gmail.com>
parents: 1945
diff changeset
   456
          'link_id': 'test',
199bcab679df Make test@example.com a mentor for one gsoc org and an admin (for a different) gsoc org.
Tim Ansell <mithro@gmail.com>
parents: 1945
diff changeset
   457
          'scope_path': 'google/gsoc2009/org_%d' % i,
199bcab679df Make test@example.com a mentor for one gsoc org and an admin (for a different) gsoc org.
Tim Ansell <mithro@gmail.com>
parents: 1945
diff changeset
   458
          'scope': entity,
199bcab679df Make test@example.com a mentor for one gsoc org and an admin (for a different) gsoc org.
Tim Ansell <mithro@gmail.com>
parents: 1945
diff changeset
   459
          'program': gsoc2009,
199bcab679df Make test@example.com a mentor for one gsoc org and an admin (for a different) gsoc org.
Tim Ansell <mithro@gmail.com>
parents: 1945
diff changeset
   460
          })
2048
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   461
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   462
      # Admin for the first org
2027
199bcab679df Make test@example.com a mentor for one gsoc org and an admin (for a different) gsoc org.
Tim Ansell <mithro@gmail.com>
parents: 1945
diff changeset
   463
      if i == 0:
199bcab679df Make test@example.com a mentor for one gsoc org and an admin (for a different) gsoc org.
Tim Ansell <mithro@gmail.com>
parents: 1945
diff changeset
   464
        org_1_admin = OrgAdmin(**role_properties)
199bcab679df Make test@example.com a mentor for one gsoc org and an admin (for a different) gsoc org.
Tim Ansell <mithro@gmail.com>
parents: 1945
diff changeset
   465
        org_1_admin.put()
199bcab679df Make test@example.com a mentor for one gsoc org and an admin (for a different) gsoc org.
Tim Ansell <mithro@gmail.com>
parents: 1945
diff changeset
   466
199bcab679df Make test@example.com a mentor for one gsoc org and an admin (for a different) gsoc org.
Tim Ansell <mithro@gmail.com>
parents: 1945
diff changeset
   467
      # Only a mentor for the second org
199bcab679df Make test@example.com a mentor for one gsoc org and an admin (for a different) gsoc org.
Tim Ansell <mithro@gmail.com>
parents: 1945
diff changeset
   468
      if i == 1:
2669
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   469
        org_1_admin = OrgAdmin(**role_properties)
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   470
        org_1_admin.put()
2027
199bcab679df Make test@example.com a mentor for one gsoc org and an admin (for a different) gsoc org.
Tim Ansell <mithro@gmail.com>
parents: 1945
diff changeset
   471
        org_1_mentor = Mentor(**role_properties)
199bcab679df Make test@example.com a mentor for one gsoc org and an admin (for a different) gsoc org.
Tim Ansell <mithro@gmail.com>
parents: 1945
diff changeset
   472
        org_1_mentor.put()
1362
31b2cb6b75d8 Seed in some orgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1355
diff changeset
   473
1348
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   474
  role_properties.update({
1434
441a2b39f88b Fixed a bug in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1429
diff changeset
   475
      'key_name': 'google/ghop2009/melange/test',
1348
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   476
      'link_id': 'test',
1434
441a2b39f88b Fixed a bug in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1429
diff changeset
   477
      'scope_path': 'google/ghop2009/melange',
1348
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   478
      'scope': melange,
1434
441a2b39f88b Fixed a bug in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1429
diff changeset
   479
      'program': ghop2009,
1348
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   480
      })
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   481
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   482
  melange_admin = OrgAdmin(**role_properties)
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   483
  melange_admin.put()
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   484
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   485
  melange_mentor = Mentor(**role_properties)
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
   486
  melange_mentor.put()
1335
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
   487
2669
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   488
  student_id = 'test'
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   489
  student_properties = {
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   490
      'key_name': gsoc2009.key().name() + "/" + student_id,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   491
      'link_id': student_id, 
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   492
      'scope_path': gsoc2009.key().name(),
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   493
      'scope': gsoc2009,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   494
      'program': gsoc2009,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   495
      'user': current_user,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   496
      'given_name': 'test',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   497
      'surname': 'test',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   498
      'birth_date': db.DateProperty.now(),
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   499
      'email': 'test@email.com',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   500
      'im_handle': 'test_im_handle',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   501
      'major': 'test major',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   502
      'name_on_documents': 'test',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   503
      'res_country': 'United States',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   504
      'res_city': 'city',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   505
      'res_street': 'test street',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   506
      'res_postalcode': '12345',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   507
      'publish_location': True,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   508
      'blog': 'http://www.blog.com/',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   509
      'home_page': 'http://www.homepage.com/',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   510
      'photo_url': 'http://www.photosite.com/thumbnail.png',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   511
      'ship_state': None,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   512
      'expected_graduation': 2009,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   513
      'school_country': 'United States',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   514
      'school_name': 'Test School', 
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   515
      'tshirt_size': 'XS',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   516
      'tshirt_style': 'male',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   517
      'degree': 'Undergraduate',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   518
      'phone': '1650253000',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   519
      'can_we_contact_you': True, 
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   520
      'program_knowledge': 'I heard about this program through a friend.'
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   521
      }
1355
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   522
2669
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   523
  melange_student = Student(**student_properties)
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   524
  melange_student.put()
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   525
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   526
  student_id = 'test2'
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   527
  student_properties.update({
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   528
      'key_name': gsoc2009.key().name() + "/" + student_id,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   529
      'link_id': student_id,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   530
      'user': current_user 
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   531
      })
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   532
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   533
  melange_student2 = Student(**student_properties)
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   534
  melange_student2.put()
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   535
                                       
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   536
  project_id = 'test_project'
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   537
  project_properties = {
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   538
      'key_name':  gsoc2009.key().name() + "/org_1/" + project_id,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   539
      'link_id': project_id, 
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   540
      'scope_path': gsoc2009.key().name() + "/org_1",
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   541
      'scope': orgs[1].key(),
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   542
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   543
      'title': 'test project',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   544
      'abstract': 'test abstract',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   545
      'status': 'accepted',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   546
      'student': melange_student,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   547
      'mentor': org_1_mentor,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   548
      'program':  gsoc2009
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   549
       }
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   550
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   551
  melange_project = StudentProject(**project_properties)
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   552
  melange_project.put()
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   553
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   554
  project_id = 'test_project2'
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   555
  project_properties.update({
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   556
      'key_name':  gsoc2009.key().name() + "/org_1/" + project_id,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   557
      'link_id': project_id,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   558
      'student': melange_student2,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   559
      'title': 'test project2'
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   560
      })
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   561
      
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   562
  melange_project2 = StudentProject(**project_properties)
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   563
  melange_project2.put()
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   564
    
1355
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   565
  document_properties = {
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   566
      'key_name': 'site/site/home',
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   567
      'link_id': 'home',
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   568
      'scope_path': 'site',
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   569
      'scope': site,
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   570
      'prefix': 'site',
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   571
      'author': current_user,
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   572
      'title': 'Home Page',
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   573
      'short_name': 'Home',
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   574
      'content': 'This is the Home Page',
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   575
      'modified_by': current_user,
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   576
      }
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   577
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   578
  home_document = Document(**document_properties)
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   579
  home_document.put()
2669
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   580
  document_logic._onCreate(home_document) 
1355
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   581
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   582
1415
d34768bf62d8 Added a document in the test user's user space
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1390
diff changeset
   583
  document_properties = {
d34768bf62d8 Added a document in the test user's user space
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1390
diff changeset
   584
      'key_name': 'user/test/notes',
d34768bf62d8 Added a document in the test user's user space
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1390
diff changeset
   585
      'link_id': 'notes',
d34768bf62d8 Added a document in the test user's user space
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1390
diff changeset
   586
      'scope_path': 'test',
d34768bf62d8 Added a document in the test user's user space
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1390
diff changeset
   587
      'scope': current_user,
d34768bf62d8 Added a document in the test user's user space
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1390
diff changeset
   588
      'prefix': 'user',
d34768bf62d8 Added a document in the test user's user space
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1390
diff changeset
   589
      'author': current_user,
d34768bf62d8 Added a document in the test user's user space
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1390
diff changeset
   590
      'title': 'My Notes',
d34768bf62d8 Added a document in the test user's user space
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1390
diff changeset
   591
      'short_name': 'Notes',
d34768bf62d8 Added a document in the test user's user space
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1390
diff changeset
   592
      'content': 'These are my notes',
d34768bf62d8 Added a document in the test user's user space
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1390
diff changeset
   593
      'modified_by': current_user,
d34768bf62d8 Added a document in the test user's user space
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1390
diff changeset
   594
      }
d34768bf62d8 Added a document in the test user's user space
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1390
diff changeset
   595
d34768bf62d8 Added a document in the test user's user space
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1390
diff changeset
   596
  notes_document = Document(**document_properties)
d34768bf62d8 Added a document in the test user's user space
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1390
diff changeset
   597
  notes_document.put()
2669
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   598
  document_logic._onCreate(home_document) 
1415
d34768bf62d8 Added a document in the test user's user space
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1390
diff changeset
   599
1355
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   600
  site.home = home_document
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
   601
  site.put()
2361
40b0c25a5793 Some more pylint fixes in different Melange modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2352
diff changeset
   602
  # pylint: disable-msg=E1101
1453
378c844bf52c Flush cache after seeding or clearing the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1434
diff changeset
   603
  memcache.flush_all()
378c844bf52c Flush cache after seeding or clearing the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1434
diff changeset
   604
1789
6f112b2ebd1f Return a HttpResponse in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1623
diff changeset
   605
  return http.HttpResponse('Done')
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   606
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   607
2048
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   608
def seed_user(unused_request, i):
1902
be3dbaa17114 Added seed user to seed many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1901
diff changeset
   609
  """Returns the properties for a new user entity.
be3dbaa17114 Added seed user to seed many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1901
diff changeset
   610
  """
be3dbaa17114 Added seed user to seed many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1901
diff changeset
   611
  properties = {
2175
8dd78e7015f9 Fix a bug in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2167
diff changeset
   612
      'key_name': 'user_%d' % i,
8dd78e7015f9 Fix a bug in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2167
diff changeset
   613
      'link_id': 'user_%d' % i,
8dd78e7015f9 Fix a bug in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2167
diff changeset
   614
      'account': users.User(email='user_%d@example.com' % i),
8dd78e7015f9 Fix a bug in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2167
diff changeset
   615
      'name': 'User %d' % i,
1902
be3dbaa17114 Added seed user to seed many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1901
diff changeset
   616
      }
be3dbaa17114 Added seed user to seed many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1901
diff changeset
   617
be3dbaa17114 Added seed user to seed many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1901
diff changeset
   618
  return properties
be3dbaa17114 Added seed user to seed many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1901
diff changeset
   619
be3dbaa17114 Added seed user to seed many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1901
diff changeset
   620
1907
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   621
def seed_org_app(request, i):
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   622
  """Returns the properties for a new org proposal,
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   623
  """
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   624
2074
5c75312566d5 Fix too long lines, style and remove unused imports in soc.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2048
diff changeset
   625
  _, current_user = ensureUser()
1907
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   626
  status = request.GET.get('status', 'pre-accepted')
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   627
  gsoc2009 = Program.get_by_key_name('google/gsoc2009')
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   628
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   629
  if not gsoc2009:
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   630
    raise Error('Run seed_db first')
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   631
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   632
  properties = {
2352
33ff03da52b6 Link id and key name fixes for Organization And OrgApplication in seed_db.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2351
diff changeset
   633
      'key_name': 'google/gsoc2009/org_%d' % i,
33ff03da52b6 Link id and key name fixes for Organization And OrgApplication in seed_db.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2351
diff changeset
   634
      'link_id': 'org_%d' % i,
1907
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   635
      'name': 'Org App %d' % i,
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   636
      'scope_path': 'google/gsoc2009',
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   637
      'scope': gsoc2009,
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   638
      'status': status,
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   639
      'applicant': current_user,
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   640
      'home_page': 'http://www.google.com',
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   641
      'email': 'org@example.com',
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   642
      'irc_channel': '#care',
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   643
      'pub_mailing_list': 'http://groups.google.com',
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   644
      'dev_mailing_list': 'http://groups.google.com',
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   645
      'description': 'This is an awesome org!',
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   646
      'why_applying': 'Because we can',
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   647
      'member_criteria': 'They need to be awesome',
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   648
      'license_name': 'Apache License, 2.0',
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   649
      'ideas': 'http://code.google.com/p/soc/issues',
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   650
      'contrib_disappears': 'We use google to find them',
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   651
      'member_disappears': 'See above',
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   652
      'encourage_contribs': 'We offer them cookies.',
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   653
      'continued_contribs': 'We promise them a cake.',
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   654
      'agreed_to_admin_agreement': True,
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   655
      }
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   656
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   657
  return properties
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   658
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
   659
2184
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   660
def seed_org(unused_request, i):
1903
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   661
  """Returns the properties for a new org entity.
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   662
  """
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   663
2074
5c75312566d5 Fix too long lines, style and remove unused imports in soc.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2048
diff changeset
   664
  _, current_user = ensureUser()
1903
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   665
  gsoc2009 = Program.get_by_key_name('google/gsoc2009')
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   666
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   667
  if not gsoc2009:
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   668
    raise Error('Run seed_db first')
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   669
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   670
  properties = {
2200
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   671
      'key_name': 'google/gsoc2009/org_%d' % i,
1903
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   672
      'link_id': 'org_%d' % i,
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   673
      'name': 'Organization %d' % i,
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   674
      'short_name': 'Org %d' % i,
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   675
      'founder': current_user,
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   676
      'scope_path': 'google/gsoc2009',
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   677
      'scope': gsoc2009,
1929
1ce28a2dd71f Added missing status to seeded orgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1907
diff changeset
   678
      'status': 'active',
1903
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   679
      'email': 'org_%i@example.com' % i,
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   680
      'home_page': 'http://code.google.com/p/soc',
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   681
      'description': 'Melange, share the love!',
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   682
      'license_name': 'Apache License',
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   683
      'contact_street': 'Some Street',
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   684
      'contact_city': 'Some City',
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   685
      'contact_country': 'United States',
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   686
      'contact_postalcode': '12345',
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   687
      'phone': '1-555-BANANA',
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   688
      'ideas': 'http://code.google.com/p/soc/issues',
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   689
      }
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   690
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   691
  return properties
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   692
2669
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   693
DEADLINE = datetime.datetime.now() + datetime.timedelta(10)
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   694
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   695
def seed_survey(request, i):
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   696
  """Returns the properties for a new survey.
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   697
  """
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   698
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   699
  _, current_user = ensureUser()
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   700
  gsoc2009 = Program.get_by_key_name('google/gsoc2009')
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   701
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   702
  if not gsoc2009:
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   703
    raise Error('Run seed_db first')
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   704
  link_id = 'survey_%d' % i
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   705
  fields = {'SelectionQ': [u'SelectionQ Option 2 for %s' % link_id,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   706
                           u'SelectionQ Option 1 for %s'  % link_id
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   707
                           ],
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   708
            'PickMultipleQ': ['PickMultipleQ Checkbox 1 for %s' % link_id,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   709
                              'PickMultipleQ Checkbox 2 for %s' % link_id,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   710
                              ],
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   711
            'LongQ': 'LongQ Custom Prompt for %s' % link_id,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   712
            'ShortQ': 'ShortQ Custom Prompt for %s' % link_id,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   713
            }
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   714
  schema = {u'PickMultipleQ': {'index': 5, 'type': 'pick_multi',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   715
                               'render': 'multi_checkbox'},
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   716
            u'LongQ': {'index': 2, 'type': 'long_answer'},
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   717
            u'ShortQ': {'index': 3, 'type': 'short_answer'},
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   718
            u'SelectionQ': {'index': 4, 'type': 'selection',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   719
                            'render': 'single_select'}
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   720
            }
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   721
  properties = {
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   722
      'key_name': 'program/google/gsoc2009/%s' % link_id,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   723
      'link_id': link_id,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   724
      'scope_path': 'google/gsoc2009',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   725
      'scope': None,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   726
      'prefix': 'program',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   727
      'author': current_user,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   728
      'title': 'My Survey %d' % i,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   729
      'short_name': 'Survey %d' % i,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   730
      'modified_by': current_user,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   731
      'is_featured': True,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   732
      'fields': fields,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   733
      'schema': schema,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   734
      'deadline': DEADLINE,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   735
      'taking_access': 'everyone',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   736
      }
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   737
  return properties
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   738
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   739
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   740
def seed_survey_answer(request, i):
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   741
  """Returns the properties of a student's survey answers.
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   742
  """
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   743
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   744
  ensureUser()
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   745
  survey = Survey.get_by_key_name('program/google/gsoc2009/survey_%d' % i)
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   746
  user = User.get_by_key_name('user_%d' % i)
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   747
  #student = Student.get_by_key_name('google/gsoc2009/student_%d' % i)
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   748
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   749
  if not user:
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   750
    raise Error('Run seed_many for at least %d users first.' % i)
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   751
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   752
  if not survey:
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   753
    raise Error('Run seed_many for at least %d surveys first.' % i)
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   754
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   755
  all_properties = []
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   756
  scope_path = 'google/gsoc2009/'
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   757
  checkbox = 'PickMultipleQ Checkbox 2 for survey_%d' % i
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   758
  # pylint: disable-msg=E1103
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   759
  for i in range(5):
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   760
    #student = Student.get_by_key_name('google/gsoc2009/student_%d' % i)
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   761
    user = User.get_by_key_name('user_%d' % i)
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   762
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   763
    properties = {
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   764
        'scope_path': scope_path,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   765
        'user': user,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   766
        'project': None,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   767
        '_survey': survey,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   768
        '_fields': {'ShortQ':'Test', 'SelectionQ': u'SelectionQ Option 2',
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   769
                   'LongQ': 'Long answer... \n' * 10,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   770
                   'PickMultipleQ': checkbox,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   771
                   }
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   772
        }
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   773
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   774
    all_properties.append(properties)
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   775
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   776
  return all_properties
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
   777
1903
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
   778
1904
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   779
def seed_mentor(request, i):
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   780
  """Returns the properties of a new student proposal.
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   781
  """
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   782
2074
5c75312566d5 Fix too long lines, style and remove unused imports in soc.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2048
diff changeset
   783
  _, current_user = ensureUser()
2200
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   784
  org = Organization.get_by_key_name('google/gsoc2009/org_%d' % i)
1904
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   785
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   786
  if not org:
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   787
    raise Error('Run seed_many for at least %d orgs first.' % i)
2361
40b0c25a5793 Some more pylint fixes in different Melange modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2352
diff changeset
   788
  
40b0c25a5793 Some more pylint fixes in different Melange modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2352
diff changeset
   789
  # pylint: disable-msg=E1103
1904
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   790
  properties = {
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   791
      'key_name': 'google/gsoc2009/org_%d/mentor' % i,
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   792
      'link_id': 'mentor',
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   793
      'scope': org,
2160
3f9dd37d98a8 Use key().id_or_name() instead of key().name()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2074
diff changeset
   794
      'scope_path': org.key().id_or_name(),
1904
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   795
      'user': current_user,
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   796
      'given_name': 'Mentor',
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   797
      'surname': 'Man',
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   798
      'name_on_documents': 'Mentor Man',
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   799
      'email': 'mentor@example.com',
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   800
      'res_street': 'Some Street',
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   801
      'res_city': 'Some City',
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   802
      'res_state': 'Some State',
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   803
      'res_country': 'United States',
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   804
      'res_postalcode': '12345',
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   805
      'phone': '1-555-BANANA',
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   806
      'birth_date': db.DateProperty.now(),
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   807
      'agreed_to_tos': True,
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   808
      'program': org.scope,
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   809
      }
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   810
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   811
  return properties
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   812
2200
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   813
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   814
def seed_student(request, i):
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   815
  """Returns the properties for a new student entity.
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   816
  """
2351
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   817
2200
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   818
  gsoc2009 = Program.get_by_key_name('google/gsoc2009')
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   819
  user = User.get_by_key_name('user_%d' % i)
2351
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   820
2200
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   821
  if not gsoc2009:
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   822
    raise Error('Run seed_db first')
2351
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   823
2200
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   824
  if not user:
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   825
    raise Error('Run seed_many for at least %d users first.' % i)
2351
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   826
2200
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   827
  properties = {
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   828
      'key_name':'google/gsoc2009/student_%d' % i,
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   829
      'link_id': 'student_%d' % i,
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   830
      'scope_path': 'google/gsoc2009',
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   831
      'scope': gsoc2009,
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   832
      'user' : user,
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   833
      'given_name': 'Student %d' % i,
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   834
      'surname': 'Last Name',
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   835
      'name_on_documents': 'Test Example',
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   836
      'email': 'test@example.com',
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   837
      'res_street': 'Some Street',
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   838
      'res_city': 'Some City',
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   839
      'res_state': 'Some State',
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   840
      'res_country': 'United States',
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   841
      'res_postalcode': '12345',
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   842
      'phone': '1-555-BANANA',
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   843
      'birth_date': db.DateProperty.now(),
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   844
      'agreed_to_tos': True,
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   845
      'school_name': 'School %d' % i,
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   846
      'school_country': 'United States',
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   847
      'major': 'Computer Science',
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   848
      'degree': 'Undergraduate',
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   849
      'expected_graduation': 2012,
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   850
      'program_knowledge': 'Knowledge %d' % i,
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   851
      'school': None,
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   852
      'can_we_contact_you': True,
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   853
  }
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   854
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   855
  return properties
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   856
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   857
1905
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   858
def seed_student_proposal(request, i):
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   859
  """Returns the properties of a new student proposal.
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   860
  """
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   861
2200
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   862
  ensureUser()
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   863
  org = Organization.get_by_key_name('google/gsoc2009/org_%d' % i)
1905
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   864
  mentor = Mentor.get_by_key_name('google/gsoc2009/org_%d/mentor' % i)
2200
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   865
  user = User.get_by_key_name('user_%d' % i)
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   866
  student = Student.get_by_key_name('google/gsoc2009/student_%d' % i)
2351
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   867
2200
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   868
  if not user:
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   869
    raise Error('Run seed_many for at least %d users first.' % i)
1905
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   870
2200
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   871
  if not student:
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   872
    raise Error('Run seed_many for at least %d students first.' % i)
2351
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   873
1905
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   874
  if not org:
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   875
    raise Error('Run seed_many for at least %d orgs first.' % i)
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   876
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   877
  if not mentor:
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   878
    raise Error('Run seed_many for at least %d mentors first.' % i)
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   879
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   880
  all_properties = []
2361
40b0c25a5793 Some more pylint fixes in different Melange modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2352
diff changeset
   881
  
40b0c25a5793 Some more pylint fixes in different Melange modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2352
diff changeset
   882
  # pylint: disable-msg=E1103
1905
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   883
  for i in range(random.randint(5, 20)):
2200
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   884
    link_id = 'proposal_%s_%d' % (org.link_id, i)
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   885
    scope_path = 'google/gsoc2009/' + user.link_id
1905
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   886
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   887
    properties = {
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   888
        'link_id': link_id,
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   889
        'scope_path': scope_path,
2200
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   890
        'scope': student,
1905
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   891
        'key_name': '%s/%s' % (scope_path, link_id),
2200
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
   892
        'title': 'The Awesome Proposal %s %d' % (user.link_id, i),
1905
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   893
        'abstract': 'This is an Awesome Proposal, look at its awesomeness!',
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   894
        'content': 'Sorry, too Awesome for you to read!',
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   895
        'additional_info': 'http://www.zipit.com',
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   896
        'mentor': mentor,
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   897
        'status': 'pending',
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   898
        'org': org,
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   899
        'program': org.scope,
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   900
        }
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   901
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   902
    all_properties.append(properties)
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   903
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
   904
  return all_properties
1904
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
   905
2048
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   906
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   907
SEEDABLE_MODEL_TYPES = {
2184
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   908
    'user' : UserSeeder(),
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   909
    'organization' : OrganizationSeeder(),
2351
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   910
    'org_application' : OrgApplicationSeeder(),
2048
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   911
    }
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   912
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   913
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   914
def new_seed_many(request, *args, **kwargs):
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   915
  """Seeds many instances of the specified type.
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   916
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   917
  Takes as URL parameters:
2167
91e622242f2d Respond to comments on r2769.
Daniel Bentley <dbentley@google.com>
parents: 2160
diff changeset
   918
    seed_type: the type of entity to seed; should be a key in
91e622242f2d Respond to comments on r2769.
Daniel Bentley <dbentley@google.com>
parents: 2160
diff changeset
   919
               SEEDABLE_MODEL_TYPES
91e622242f2d Respond to comments on r2769.
Daniel Bentley <dbentley@google.com>
parents: 2160
diff changeset
   920
    goal: the total number of entities desired
2048
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   921
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   922
  This differs from seed_many. Instead of having to specify many parameters
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   923
    that are the state of an in-flight process, simply say how many you want
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   924
    to have (at least) at the end.  This will make progress towards that goal.
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   925
    In my test run, even adding 1001 users completed in far less than the
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   926
    limit for one request, so pagination was unnecessary.
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   927
  """
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   928
  # First, figure out which model we're interested in.
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   929
  if ('seed_type' not in request.GET or
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   930
      request.GET['seed_type'] not in SEEDABLE_MODEL_TYPES):
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   931
    return http.HttpResponse(
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   932
        ('Missing or invalid required argument "seed_type" (which model'
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   933
        ' type to populate). '
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   934
        'Valid values are: %s') % SEEDABLE_MODEL_TYPES.keys())
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   935
2184
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   936
  seeder = SEEDABLE_MODEL_TYPES[request.GET['seed_type']]
2048
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   937
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   938
  if 'goal' not in request.GET:
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   939
    return http.HttpResponse(
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   940
        'Missing required argument "goal" (how many entities of '
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   941
        'this type you want to have in the datastore).'
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   942
        )
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   943
  goal = int(request.GET['goal'])
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   944
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   945
  # Get the highest instance of this model so that we know
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   946
  # where to start seeding new ones.
2184
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   947
  query = db.Query(seeder.type())
2048
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   948
  query.order('-link_id')
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   949
  # TODO(dbentley): filter for ones < user_9999
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   950
  highest_instance = query.get()
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   951
  if not highest_instance:
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   952
    start_index = 0
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   953
  else:
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   954
    # We know that seeded entities have link_id's of the form foo_%04d
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   955
    # so, we look for what's after the _ and turn it into an int.
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   956
    link_id = highest_instance.link_id
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   957
    if '_' in link_id:
2351
73448b71aa07 Add Organization Application seeding.
Dan Bentley <dbentley@google.com>
parents: 2200
diff changeset
   958
      start_index = int(link_id.split('_')[-1]) + 1
2048
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   959
    else:
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   960
      # couldn't find seeded_entities; guessing there are none
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   961
      start_index = 0
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   962
2184
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   963
  common_args = seeder.commonSeedArgs(request)
2048
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   964
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   965
  # Insert from start_index to goal
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   966
  logging.info("To insert: %d to %d" % (start_index, goal))
2184
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   967
  seeded_entities = []
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   968
  total = 0
2048
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   969
  for i in xrange(start_index, goal):
2167
91e622242f2d Respond to comments on r2769.
Daniel Bentley <dbentley@google.com>
parents: 2160
diff changeset
   970
    if i % 20 == 0:
91e622242f2d Respond to comments on r2769.
Daniel Bentley <dbentley@google.com>
parents: 2160
diff changeset
   971
      logging.info("Inserting: %d of %d" % (i+1, goal))
2184
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   972
    if len(seeded_entities) % 100 == 0:
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   973
      db.put(seeded_entities)
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   974
      total += len(seeded_entities)
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   975
      seeded_entities = []
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   976
    seeder.seed(i, entities=seeded_entities, **common_args)
2048
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   977
2184
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   978
  db.put(seeded_entities)
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   979
  total += len(seeded_entities)
a1bda9afa5d0 Step 2 of moving to new seeding model.
Daniel Bentley <dbentley@google.com>
parents: 2175
diff changeset
   980
  return http.HttpResponse('Seeded %d entities.' % total)
2048
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   981
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
   982
1901
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
   983
def seed_many(request, *args, **kwargs):
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
   984
  """Seeds many instances of the specified type.
1945
ad3e6c4bb604 Moved and updated seed_many documentation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1929
diff changeset
   985
ad3e6c4bb604 Moved and updated seed_many documentation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1929
diff changeset
   986
    Understands the following GET args:
ad3e6c4bb604 Moved and updated seed_many documentation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1929
diff changeset
   987
    start: where to start adding new users at
ad3e6c4bb604 Moved and updated seed_many documentation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1929
diff changeset
   988
    end: where to stop adding new users at
ad3e6c4bb604 Moved and updated seed_many documentation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1929
diff changeset
   989
    goal: how many users to add in total, implies user_only
ad3e6c4bb604 Moved and updated seed_many documentation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1929
diff changeset
   990
    step: how many users to add per request, defaults to 15
ad3e6c4bb604 Moved and updated seed_many documentation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1929
diff changeset
   991
    seed_type: the type of entity to seed, should be one of:
ad3e6c4bb604 Moved and updated seed_many documentation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1929
diff changeset
   992
      user, org, org_app, mentor, student_proposal
ad3e6c4bb604 Moved and updated seed_many documentation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1929
diff changeset
   993
ad3e6c4bb604 Moved and updated seed_many documentation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1929
diff changeset
   994
    Redirects if end < goal, incrementing both start and end with step.
ad3e6c4bb604 Moved and updated seed_many documentation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1929
diff changeset
   995
1901
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
   996
  """
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
   997
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
   998
  get_args = request.GET
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
   999
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1000
  if not dicts.containsAll(get_args, ['goal', 'start', 'end', 'seed_type']):
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1001
    return http.HttpResponse('Missing get args.')
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1002
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1003
  seed_types = {
1902
be3dbaa17114 Added seed user to seed many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1901
diff changeset
  1004
    'user': (seed_user, User),
1903
9d95d3e20773 Added seed org support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1902
diff changeset
  1005
    'org': (seed_org, Organization),
1907
8e1ea5609325 Added org app seeding to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1906
diff changeset
  1006
    'org_app': (seed_org_app, OrgApplication),
1904
63b026919efd Add seed mentor support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1903
diff changeset
  1007
    'mentor': (seed_mentor, Mentor),
2200
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
  1008
    'student': (seed_student, Student),
1905
8065fd1f3e4c Added seed student proposal support to seed_many
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1904
diff changeset
  1009
    'student_proposal': (seed_student_proposal, StudentProposal),
2669
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
  1010
    'survey': (seed_survey, Survey),
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
  1011
    'survey_answer': (seed_survey_answer, SurveyRecord),
1901
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1012
    }
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1013
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1014
  goal = int(get_args['goal'])
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1015
  start = int(get_args['start'])
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1016
  end = int(get_args['end'])
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1017
  step = int(get_args.get('step', '15'))
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1018
  seed_type = get_args['seed_type']
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1019
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1020
  if not seed_type in seed_types:
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1021
    return http.HttpResponse('Unknown seed_type: "%s".' % seed_type)
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1022
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1023
  action, model = seed_types[seed_type]
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1024
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1025
  for i in range(start, end):
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1026
    try:
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1027
      props = action(request, i)
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1028
    except Error, error:
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1029
      return http.HttpResponse(error.message)
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1030
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1031
    for properties in props if isinstance(props, list) else [props]:
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1032
      entity = model(**properties)
2669
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
  1033
      if seed_type == 'survey':
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
  1034
        survey_content = survey_logic.createSurvey(properties['fields'],
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
  1035
                                                    properties['schema'],
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
  1036
                                                    this_survey=None
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
  1037
                                                    )
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
  1038
        entity.this_survey = survey_content
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
  1039
      elif seed_type == 'survey_answer':
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
  1040
        record = SurveyRecord.gql("WHERE user = :1 AND this_survey = :2",
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
  1041
                                  properties['user'], properties['_survey']
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
  1042
                                  ).get()
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
  1043
        entity = survey_logic.updateSurveyRecord(properties['user'],
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
  1044
                                                   properties['_survey'],
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
  1045
                                                   record,
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
  1046
                                                   properties['_fields']
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
  1047
                                                   )
1901
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1048
      entity.put()
2669
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
  1049
      if seed_type == 'survey': survey_logic._onCreate(entity) 
1901
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1050
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1051
  if end < goal:
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1052
    info = {
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1053
        'start': start + step,
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1054
        'end': end + step,
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1055
        'goal': goal,
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1056
        'step': step,
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1057
        'seed_type': seed_type,
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1058
        }
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1059
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1060
    args = ["%s=%s" % (k, v) for k, v in info.iteritems()]
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1061
    url = '/seed_many?' + '&'.join(args)
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1062
    return http.HttpResponseRedirect(url)
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1063
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1064
  return http.HttpResponse('Done.')
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1065
5a98e8a8efb5 Added a seed_many url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1900
diff changeset
  1066
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
  1067
def clear(*args, **kwargs):
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
  1068
  """Removes all entities from the datastore.
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
  1069
  """
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
  1070
1794
6ffd25bedef9 Also clear RankerRoot and ranker from datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1793
diff changeset
  1071
  # there no explicit ranker model anywhere, so make one for
6ffd25bedef9 Also clear RankerRoot and ranker from datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1793
diff changeset
  1072
  # our own convenience to delete all rankers
6ffd25bedef9 Also clear RankerRoot and ranker from datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1793
diff changeset
  1073
  class ranker(db.Model):
2074
5c75312566d5 Fix too long lines, style and remove unused imports in soc.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2048
diff changeset
  1074
    """ranker model used with ranklist module.
5c75312566d5 Fix too long lines, style and remove unused imports in soc.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2048
diff changeset
  1075
    """
1794
6ffd25bedef9 Also clear RankerRoot and ranker from datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1793
diff changeset
  1076
    pass
6ffd25bedef9 Also clear RankerRoot and ranker from datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1793
diff changeset
  1077
2048
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
  1078
  # TODO(dbentley): If there are more than 1000 instances of any model,
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
  1079
  # this method will not clear all instances.  Instead, it should continually
236f37777764 A new model for seeding the database that makes it easier to seed many entities.
Daniel Bentley <dbentley@google.com>
parents: 2027
diff changeset
  1080
  # call .all(), delete all those, and loop until .all() is empty.
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
  1081
  entities = itertools.chain(*[
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
  1082
      Notification.all(),
1348
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
  1083
      Mentor.all(),
2200
a1a7c262235d Add proper generation of Student entities and StudentProposal entities to seed_db module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2184
diff changeset
  1084
      Student.all(),
2669
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
  1085
      Survey.all(),
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
  1086
      SurveyContent.all(),
c28e2dc4cd51 seed_db now creates fixture student project entities, and corresponding project surveys and grading surveys for debugging purposes.
JamesLevy <jamesalexanderlevy@gmail.com>
parents: 2367
diff changeset
  1087
      SurveyRecord.all(),
1348
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
  1088
      OrgAdmin.all(),
1794
6ffd25bedef9 Also clear RankerRoot and ranker from datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1793
diff changeset
  1089
      ranker.all(),
6ffd25bedef9 Also clear RankerRoot and ranker from datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1793
diff changeset
  1090
      RankerRoot.all(),
1906
224f597846b5 Added StudentProposal to clean_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1905
diff changeset
  1091
      StudentProposal.all(),
1335
a8c5b1e200bd Added melange as org.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1332
diff changeset
  1092
      Organization.all(),
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
  1093
      OrgApplication.all(),
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
  1094
      Timeline.all(),
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
  1095
      Program.all(),
1348
8e3bd495729f Seed more roles and factor out common properties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1335
diff changeset
  1096
      Host.all(),
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
  1097
      Sponsor.all(),
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
  1098
      User.all(),
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
  1099
      Site.all(),
1355
7a00bcfa0371 Add a Home document to the seeded entities
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1348
diff changeset
  1100
      Document.all(),
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
  1101
      ])
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
  1102
1799
53d15b129a3b Redirect to current page if the current request times out
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1798
diff changeset
  1103
  try:
53d15b129a3b Redirect to current page if the current request times out
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1798
diff changeset
  1104
    for entity in entities:
53d15b129a3b Redirect to current page if the current request times out
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1798
diff changeset
  1105
      entity.delete()
53d15b129a3b Redirect to current page if the current request times out
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1798
diff changeset
  1106
  except db.Timeout:
53d15b129a3b Redirect to current page if the current request times out
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1798
diff changeset
  1107
    return http.HttpResponseRedirect('#')
2361
40b0c25a5793 Some more pylint fixes in different Melange modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2352
diff changeset
  1108
  # pylint: disable-msg=E1101
1453
378c844bf52c Flush cache after seeding or clearing the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1434
diff changeset
  1109
  memcache.flush_all()
378c844bf52c Flush cache after seeding or clearing the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1434
diff changeset
  1110
1789
6f112b2ebd1f Return a HttpResponse in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1623
diff changeset
  1111
  return http.HttpResponse('Done')
6f112b2ebd1f Return a HttpResponse in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1623
diff changeset
  1112
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
  1113
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
  1114
def reseed(*args, **kwargs):
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
  1115
  """Clears and seeds the datastore.
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
  1116
  """
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
  1117
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
  1118
  clear(*args, **kwargs)
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
  1119
  seed(*args, **kwargs)
1789
6f112b2ebd1f Return a HttpResponse in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1623
diff changeset
  1120
6f112b2ebd1f Return a HttpResponse in seed_db
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1623
diff changeset
  1121
  return http.HttpResponse('Done')