| # Copyright 2014 the Melange authors. |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| """Seeder functions for user model.""" |
| |
| from google.appengine.ext import ndb |
| |
| from melange.models import user as user_model |
| |
| from soc.modules.seeder.logic.providers import string as string_provider |
| |
| |
| def seedUser(user_id=None, host_for=None, **kwargs): |
| """Seeds a new user. |
| |
| Args: |
| user_id: Identifier of the new user. |
| host_for: List of program entities for which the seeded user is a host. |
| |
| Returns: |
| Newly seeded user_model.User entity. |
| """ |
| user_id = user_id or string_provider.UniqueIDProvider().getValue() |
| |
| host_for = host_for or [] |
| host_for = [ndb.Key.from_old_key(program.key()) for program in host_for] |
| |
| properties = { |
| 'account_id': string_provider.UniqueIDProvider().getValue(), |
| 'host_for': host_for, |
| } |
| properties.update(**kwargs) |
| |
| user = user_model.User(id=user_id, **properties) |
| user.put() |
| |
| return user |