def comments(self): """Returns the GCIComments that have the given task as parent. The results are sorted by the date on which they have been created. """ q = GCIComment.all() q.ancestor(self) q.order('created_on') return q.fetch(1000)
def task_delete_txn(task): """Performs all necessary operations in a single transaction when a task is deleted. """ to_delete = [] to_delete += GCIComment.all(keys_only=True).ancestor(task) to_delete += GCIWorkSubmission.all(keys_only=True).ancestor(task) to_delete += [task.key()] db.delete(to_delete)
def turnaroundTime(task): from soc.modules.gci.logic import task as task_logic from soc.modules.gci.models.comment import GCIComment q = GCIComment.all() q.ancestor(task) q.filter('modified_by', None) q.filter('title', task_logic.DEF_ASSIGNED_TITLE) comments = sorted(q, key=lambda x: x.created_on) started = comments[-1] q = GCIComment.all() q.ancestor(task) q.filter('modified_by', None) q.filter('title', task_logic.DEF_SEND_FOR_REVIEW_TITLE) comments = sorted(q, key=lambda x: x.created_on) finished = comments[-1] q = GCIComment.all() q.ancestor(task) q.filter('modified_by', None) q.filter('title', task_logic.DEF_CLOSED_TITLE) approved = q.get() # there can only be one implementation = finished.created_on - started.created_on turnaround = approved.created_on - finished.created_on url = "http://www.google-melange.com/gci/task/view/google/gci2011/%d" return (url % task.key().id(), str(started.created_on), str(finished.created_on), str(approved.created_on), str(implementation), str(turnaround), task.difficulty_level, finished.created_by.name, approved.created_by.name, )
def process_task(task): """Conversion to make GCI Tasks ID based and getting rid of unnecessary properties. """ if task.key().name(): # Get the values for all the properties in the GCITask model from the # old entity to create the new entity. new_task_properties = {} for prop in TASK_PROPERTIES: new_task_properties[prop] = getattr(task, prop) new_task_properties['org'] = task.scope new_task = GCITask(**new_task_properties) new_task_key = new_task.put() if new_task_key: # Update all the comments with the new task as the parent comments = GCIComment.all().ancestor(task).fetch(1000) for c in comments: new_comm_properties = {} for c_prop in COMMENT_PROPERTIES: new_comm_properties[c_prop] = getattr(c, c_prop) new_comment = GCIComment(parent=new_task_key, **new_comm_properties) # set these fields to behave like last_modified_on/by new_comment.modified_on = new_comment.created_on new_comment.modified_by = new_comment.created_by yield operation.db.Put(new_comment) yield operation.counters.Increment("comment_updated") # Update all the work submission entities with the new task as the parent work_submissions = GCIWorkSubmission.all().ancestor(task).fetch(1000) for ws in work_submissions: new_ws_properties = {} for ws_prop in WORK_SUBMISSION_PROPERTIES: new_ws_properties[ws_prop] = getattr(ws, ws_prop) new_ws = GCIWorkSubmission(parent=new_task_key, **new_ws_properties) yield operation.db.Put(new_ws) yield operation.counters.Increment("work_submission_updated") yield operation.counters.Increment("task_updated")