| # 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 document model.""" |
| |
| from seeder import utils as seeder_utils |
| from seeder import user as user_seeder |
| |
| from soc.models import document as document_model |
| from soc.modules.seeder.logic.providers import string as string_provider |
| |
| |
| TEST_DOCUMENT_PREFIX = 'program' |
| TEST_DOCUMENT_TITLE = 'Test Document' |
| |
| def seedDocument(program, document_id=None, prefix=None, author=None, **kwargs): |
| """Seeds a new document entity for the specified program. |
| |
| Args: |
| program: Program entity. |
| document_id: Optional identifier of the document. |
| prefix: Optional prefix for the document. |
| author: Optional user_model.User entity with the author of the document. |
| |
| Returns: |
| The newly seeded document entity. |
| """ |
| document_id = document_id or string_provider.UniqueIDProvider().getValue() |
| prefix = prefix or TEST_DOCUMENT_PREFIX |
| author = author or user_seeder.seedUser(host_for=[program]) |
| |
| properties = { |
| 'scope': program, |
| 'read_access': 'public', |
| 'key_name': '%s/%s/%s' % (prefix, program.key().name(), document_id), |
| 'link_id': document_id, |
| 'modified_by': author.key.to_old_key(), |
| 'author': author.key.to_old_key(), |
| 'home_for': None, |
| 'title': TEST_DOCUMENT_TITLE, |
| 'prefix': prefix, |
| 'content': document_id + '---' + seeder_utils.LOREM_IPSUM, |
| } |
| properties.update(kwargs) |
| document = document_model.Document(**properties) |
| document.put() |
| |
| return document |