app/soc/models/seed_db.py
changeset 1901 5a98e8a8efb5
parent 1900 a2966f072219
child 1902 be3dbaa17114
equal deleted inserted replaced
1900:a2966f072219 1901:5a98e8a8efb5
   359   memcache.flush_all()
   359   memcache.flush_all()
   360 
   360 
   361   return http.HttpResponse('Done')
   361   return http.HttpResponse('Done')
   362 
   362 
   363 
   363 
       
   364 def seed_many(request, *args, **kwargs):
       
   365   """Seeds many instances of the specified type.
       
   366   """
       
   367 
       
   368   get_args = request.GET
       
   369 
       
   370   if not dicts.containsAll(get_args, ['goal', 'start', 'end', 'seed_type']):
       
   371     return http.HttpResponse('Missing get args.')
       
   372 
       
   373   seed_types = {
       
   374     }
       
   375 
       
   376   goal = int(get_args['goal'])
       
   377   start = int(get_args['start'])
       
   378   end = int(get_args['end'])
       
   379   step = int(get_args.get('step', '15'))
       
   380   seed_type = get_args['seed_type']
       
   381 
       
   382   if not seed_type in seed_types:
       
   383     return http.HttpResponse('Unknown seed_type: "%s".' % seed_type)
       
   384 
       
   385   action, model = seed_types[seed_type]
       
   386 
       
   387   for i in range(start, end):
       
   388     try:
       
   389       props = action(request, i)
       
   390     except Error, error:
       
   391       return http.HttpResponse(error.message)
       
   392 
       
   393     for properties in props if isinstance(props, list) else [props]:
       
   394       entity = model(**properties)
       
   395       entity.put()
       
   396 
       
   397   if end < goal:
       
   398     info = {
       
   399         'start': start + step,
       
   400         'end': end + step,
       
   401         'goal': goal,
       
   402         'step': step,
       
   403         'seed_type': seed_type,
       
   404         }
       
   405 
       
   406     args = ["%s=%s" % (k, v) for k, v in info.iteritems()]
       
   407     url = '/seed_many?' + '&'.join(args)
       
   408     return http.HttpResponseRedirect(url)
       
   409 
       
   410   return http.HttpResponse('Done.')
       
   411 
       
   412 
   364 def clear(*args, **kwargs):
   413 def clear(*args, **kwargs):
   365   """Removes all entities from the datastore.
   414   """Removes all entities from the datastore.
   366   """
   415   """
   367 
   416 
   368   # there no explicit ranker model anywhere, so make one for
   417   # there no explicit ranker model anywhere, so make one for