blob: fa4210765d13b5f7e480d6b788e483a6470b2c92 [file] [log] [blame]
# Copyright 2010 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.
"""Utils for manipulating Code-in task data."""
import datetime
from google.appengine.ext import db
from soc.modules.gci.models import task as task_model
from soc.modules.gci.models import work_submission
from soc.modules.seeder.logic.seeder import logic as seeder_logic
def seedTask(program, org, mentors, student=None, **kwargs):
"""Seeds a new task.
Args:
program: Program to which the task belongs.
org: Organization to which the task belongs.
mentors: List of mentor profile keys assigned to the task.
student: Profile entity of the student assigned to the task.
Returns:
A newly seeded task entity.
"""
# TODO(daniel): remove support for old models when all tests are updated
org_key = org.key() if isinstance(org, db.Model) else org.key.to_old_key()
if not student:
student_key = None
user_key = None
elif isinstance(student, db.Model):
student_key = student.key()
user_key = student.parent_key()
else:
student_key = student.key.to_old_key()
user_key = student.key.parent().to_old_key()
properties = {
'program': program,
'org': org_key,
'status': task_model.OPEN,
'task_type': program.task_types[0],
'mentors': mentors,
'student': student_key,
'user': user_key,
'created_by': mentors[0] if mentors else None,
'modified_by': mentors[0] if mentors else None,
'created_on': datetime.datetime.now() - datetime.timedelta(20),
'modified_on': datetime.datetime.now() - datetime.timedelta(10),
'time_to_complete': 24,
}
properties.update(**kwargs)
return seeder_logic.seed(task_model.GCITask, properties,
auto_seed_optional_properties=False)
def seedWorkSubmission(task, url_to_work=None):
"""Seeds a work submission for the specified task.
Args:
task: task entity.
url_to_work: optional URL at which work submission is
available for download.
Returns:
A newly seeded work submission entity.
"""
url_to_work = url_to_work or 'http://www.example.com/'
student_key = (
task_model.GCITask.student.get_value_for_datastore(task).parent())
work = work_submission.GCIWorkSubmission(
parent=task,
program=task.program,
org=task_model.GCITask.org.get_value_for_datastore(task),
user=student_key,
url_to_work=url_to_work)
work.put()
return work