Esempio n. 1
0
File: forms.py Progetto: DaC24/taskr
    def post(self, task_id):

        # get task from datastore
        task_key = ndb.Key(urlsafe=task_id)
        task = task_key.get()

        # check if user is authed to reassign task
        if not authed_for_task(task, self.user_entity):
            return self.abort(401)

        # build form with POST data
        form = reassign_task_form(task, self.request.POST, with_default=False)

        # check if form validates
        if form.validate():

            # coerce form data into valid datastore data
            if form.assigned_to.data == 'None':
                data = None
            else:
                data = ndb.Key(urlsafe=form.assigned_to.data)

            # construct history record
            if task.assigned_to is None:
                from_user = '******'
            else:
                from_user = task.assigned_to.get().given_name
            if data is None:
                to_user = '******'
            else:
                to_user = data.get().given_name
            history_text = 'Task reassigned from %s to %s' % (from_user, to_user)

            # reassign task
            task.assigned_to = data
            # store task
            task.put()

            # add history record and add flash msg
            add_to_history(task, self.user_entity, history_text)
            self.session.add_flash(history_text)

        else:

            # if form doesn't validate then add a flash message before redirecting
            flash_msg = form.errors
            self.session.add_flash(flash_msg)

        # build url of task and redirect to it
        redirect_url = self.uri_for('task-view', task_id=task.key.urlsafe())
        return self.redirect(redirect_url)
Esempio n. 2
0
File: task.py Progetto: DaC24/taskr
    def get(self, task_id, comment_cursor=None):

        # get task from datastore using ID passed in URL
        task_key = ndb.Key(urlsafe=task_id)
        task = task_key.get()
        # throw 404 if task not found
        if task_key is None or task is None:
            return self.abort(404, detail='Task not found: %s' % task_id)

        # check if user is authed to view task
        if not authed_for_task(task, self.user_entity):
            return self.abort(401, detail="Unauthorised for task")

        # get subtasks from datastore
        subtasks = ndb.get_multi_async(task.subtasks)
        # get list of users from datastore
        task_users = ndb.get_multi_async(task.users)
        # get page of comments
        if comment_cursor is not None:
            comment_cursor = Cursor(urlsafe=comment_cursor)
        comments = task.comments().fetch_page_async(5, start_cursor=comment_cursor)
        # form to allow altering of completion status
        completion_form = completion_task_form(task, self.request.POST)
        # form to allow adding comments
        comment_form = CommentForm()
        # for to allow reassigning of task
        reassign_form = reassign_task_form(task, self.request.POST)
        # form to allow adding users to projects
        add_user_form = add_user_to_task_form(task, self.request.POST)
        # add all required objects to context dict
        context = {
            'task': task,
            'subtasks': subtasks,
            'comment_form': comment_form,
            'reassign_form': reassign_form,
            'task_users': task_users,
            'completion_form': completion_form,
            'comments': comments,
            'comment_cursor': comment_cursor,
            'add_user_form': add_user_form,
        }
        # render template and return
        return self.render_response('task.html', context)