def createWorkSubmission(self, task, student, url='http://www.example.com/'): """Creates a GCIWorkSubmission. Args: task: The task to create a worksubmission for. student: The student whose work it is. url: The url to the work. """ work = GCIWorkSubmission( parent=task, program=task.program, org=task.org, user=student.user, url_to_work=url) work.put() return work
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 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 checkAccess(self): """Checks whether this task is visible to the public and any other checks if it is a POST request. """ self.mutator.taskFromKwargs(comments=True, work_submissions=True) self.data.is_visible = self.check.isTaskVisible() if task_logic.updateTaskStatus(self.data.task): # The task logic updated the status of the task since the deadline passed # and the GAE task was late to run. Reload the page. raise RedirectRequest('') if self.request.method == 'POST': # Access checks for the different forms on this page. Note that there # are no elif clauses because one could add multiple GET params :). self.check.isProfileActive() if 'reply' in self.data.GET: # checks for posting comments # valid tasks and profile are already checked. self.check.isBeforeAllWorkStopped() self.check.isCommentingAllowed() if 'submit_work' in self.data.GET: self.check.isBeforeAllWorkStopped() if not task_logic.canSubmitWork(self.data.task, self.data.profile): self.check.fail(DEF_NOT_ALLOWED_TO_UPLOAD_WORK) if 'button' in self.data.GET: # check for any of the buttons button_name = self._buttonName() buttons = {} TaskInformation(self.data).setButtonControls(buttons) if not buttons.get(button_name): self.check.fail(DEF_NOT_ALLOWED_TO_OPERATE_BUTTON % button_name) if 'send_for_review' in self.data.GET: self.check.isBeforeAllWorkStopped() if not task_logic.isOwnerOfTask(self.data.task, self.data.profile) or \ not self.data.work_submissions: self.check.fail(DEF_CANT_SEND_FOR_REVIEW) if 'delete_submission' in self.data.GET: self.check.isBeforeAllWorkStopped() id = self._submissionId() work = GCIWorkSubmission.get_by_id(id, parent=self.data.task) if not work: self.check.fail(DEF_NO_WORK_FOUND %id) time_expired = work.submitted_on - datetime.datetime.now() if work.user.key() != self.data.user.key() or \ time_expired > task_logic.DELETE_EXPIRATION: self.check.fail(DEF_NOT_ALLOWED_TO_DELETE)
def get(self): """Attempts to download the blob in the worksubmission that is specified in the GET argument. """ id_s = self.request.GET.get('id', '') id = int(id_s) if id_s.isdigit() else -1 work = GCIWorkSubmission.get_by_id(id, self.data.task) if not work or not work.upload_of_work: return self.error(400, DEF_NO_WORK_FOUND %id) upload = work.upload_of_work self.response = bs_helper.sendBlob(upload)
def _postDeleteSubmission(self): """POST handler to delete a GCIWorkSubmission. """ id = self._submissionId() work = GCIWorkSubmission.get_by_id(id, parent=self.data.task) if not work: return self.error(400, DEF_NO_WORK_FOUND %id) # Deletion of blobs always runs separately from transaction so it has no # added value to use it here. upload = work.upload_of_work work.delete() if upload: upload.delete() self.redirect.id().to('gci_view_task')
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")
from soc.modules.gci.models.mentor import GCIMentor from soc.modules.gci.models.org_admin import GCIOrgAdmin from soc.modules.gci.models.profile import GCIProfile from soc.modules.gci.models.student import GCIStudent from soc.modules.gci.models.task import GCITask from soc.modules.gci.models.task_subscription import GCITaskSubscription from soc.modules.gci.models.work_submission import GCIWorkSubmission TASK_PROPERTIES = GCITask.properties() # We do not want history property in the new entities in any more because # we are not using it TASK_PROPERTIES.pop('scope', 'history') COMMENT_PROPERTIES = GCIComment.properties() WORK_SUBMISSION_PROPERTIES = GCIWorkSubmission.properties() 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)
def workSubmissions(self): """Returns the GCIWorksubmissions that have the given task as parent.""" q = GCIWorkSubmission.all() q.ancestor(self) return q.fetch(1000)
def workSubmissions(self): """Returns the GCIWorksubmissions that have the given task as parent. """ q = GCIWorkSubmission.all() q.ancestor(self) return q.fetch(1000)