Exemplo n.º 1
0
    def post(self):
        json_data = request.get_json()
        result = TaskCreateSchema().load(json_data)

        if result.errors:
            return jsonify(result.errors), 403

        project = Project.query.get(result.data['project_id'])
        if project is None:
            return jsonify({'error': 'Project not found.'}), 404

        if not self.is_project_member(project):
            return jsonify({'error': 'Project not found.'}), 404

        task = Task()
        parse_json_to_object(task, result.data)
        task.creator = current_identity

        db.session.add(task)
        db.session.flush()

        tasks_order = list(project.tasks_order)
        tasks_order.insert(0, task.id)
        parse_json_to_object(project, {'tasks_order': tasks_order})

        db.session.add(project)
        db.session.commit()

        data = TaskSchema().dump(task).data
        return jsonify(data)
Exemplo n.º 2
0
 def get(self):
     tasks = list(Task.gql('where is_completed = False and is_deleted = False'))
     tasks.sort(key=lambda t: (t.category.name, datetime.datetime.now() - t.create_time))
     values = { 'tasks': tasks }
     path = os.path.join(os.path.dirname(__file__), '../../templates/tasks', 'home.html')
     html = template.render(path, values)
     self.response.out.write(html)
Exemplo n.º 3
0
 def update_action(self):
     id = int(self.request.get('id'))
     name = self.request.get('name')
     task = Task.get_by_id(id)
     task.set_origin_name(name)
     task.put()
     output = simplejson.dumps(task.to_dict())
     self.response.out.write(output)
Exemplo n.º 4
0
    def _getTasks(cls, fetch=20):
#        tasks = memcache.get('tasks')

#        if tasks:
#            return get_entity_from_protobuf(tasks)

        tasks = Task.all().order('-updated_on').fetch(fetch)
 #       memcache.set('tasks', get_protobuf_from_entity(tasks), 10 * 60)
        return tasks
Exemplo n.º 5
0
    def post(self, **kwargs):
        if not self.form.validate():
            # Since the form didn't validate, render it again using self.get().
            return self.get(**kwargs)

        author = self.auth_current_user
        if author != None:
            author = author.username

        # Form is valid. Use the form data and redirect the user to the
        # final destination.
        name = self.form.name.data
        assignee = self.form.assignee.data
        description = self.form.description.data
        task = Task(name=name, assignee=assignee, description=description, created_by=author, updated_by=author, author=author)

        task.put()
        memcache.delete('tasks')

        return redirect_to('tasks-index')
Exemplo n.º 6
0
 def get(self):
     today = datetime.date.today()
     delta = datetime.timedelta(days=today.weekday() + 2)
     last_saturday = today - delta
     last_saturday = 'Date(%d, %d, %d)' % (last_saturday.year, last_saturday.month, last_saturday.day)
     tasks = list(Task.gql('''where is_completed = True and is_deleted = False
         and complete_time >= %s order by complete_time desc''' % last_saturday))
     values = { 'tasks': tasks }
     path = os.path.join(os.path.dirname(__file__), '../../templates/tasks', 'review.html')
     html = template.render(path, values)
     self.response.out.write(html)
Exemplo n.º 7
0
 def add_action(self):
     name = self.request.get('name')
     task = Task()
     task.set_origin_name(name)
     task.put()
     output = simplejson.dumps(task.to_dict())
     self.response.out.write(output)
Exemplo n.º 8
0
 def post(self, request, pk, **kwargs):
     form = TaskForm(request.POST)
     if form.is_valid():
         object = Task(
             name=form.cleaned_data.get('name'),
             description=form.cleaned_data.get('description'),
         )
         object.save()
         object.subject.add(Subject.objects.get(pk=pk))
         return HttpResponse(
             json.dumps({
                 'success': 1
             }),
             content_type="application/json"
         )
     else:
         return HttpResponse(
             json.dumps({
                 'success': 0,
                 'errors': dict(form.errors.items()),
             }),
             content_type="application/json"
         )
Exemplo n.º 9
0
def generate_fake():
    """
        generate fake users with projects & tasks
    """
    with application.app_context():
        from apps.users.models import User
        from apps.projects.models import Project
        from apps.tasks.models import Task

        fake = Faker()

        users = []
        for _ in range(5):
            user = User(
                name=fake.name(),
                email=fake.email(),
                password=generate_password_hash('123456')
            )
            db.session.add(user)
            db.session.flush()

            users.append(user)

        # save users
        db.session.commit()

        projects = []
        for user in users:
            for _ in range(random.randint(3, 5)):
                is_shared = fake.boolean(chance_of_getting_true=60)
                project = Project(
                    owner_id=user.id,
                    is_shared=is_shared,
                    name=fake.word()
                )
                db.session.add(project)
                db.session.flush()

                if is_shared:
                    rand_count = random.randint(1, 2)
                    rand_collabs = random.sample(users, k=rand_count)
                    while user.id in [x.id for x in rand_collabs]:
                        rand_collabs = random.sample(users, k=rand_count)

                    for collab in rand_collabs:
                        project.collaborators.append(collab)
                        db.session.add(project)
                        db.session.flush()

                projects.append(project)

        # save projects
        db.session.commit()

        for project in projects:
            tasks = []
            all_collabs = [x for x in project.collaborators.all()]
            all_collabs.append(project.owner)
            for _ in range(random.randint(4, 6)):
                creator = random.choice(all_collabs)
                notify_date = fake.date_time_this_month(before_now=False, after_now=True)
                task = Task(
                    creator_id=creator.id,
                    project_id=project.id,
                    text=' '.join(fake.words(nb=random.randint(1, 2))),
                    note=fake.sentence(),
                    notification_date=notify_date,
                    completion_date=notify_date
                )

                if project.is_shared:
                    is_assigned = fake.boolean(chance_of_getting_true=70)
                    if is_assigned:
                        assigned_to_user = random.choice(all_collabs)
                        task.assigned_to_user_id = assigned_to_user.id

                db.session.add(task)
                db.session.flush()
                tasks.append(task)

            for _ in range(random.randint(1, 2)):
                task = random.choice(tasks)
                task.is_completed = True
                task.completed_at = task.completion_date
                task.completed_by_user_id = task.assigned_to_user_id or task.creator_id

                db.session.add(task)
                db.session.flush()

            project.tasks_order = list([x.id for x in tasks])
            db.session.add(project)
            db.session.flush()

        # save tasks
        db.session.commit()
Exemplo n.º 10
0
def new_task(user, data: []):
    """
    Create a new task and save it.
    """
    Task(user=user, description=data[0], due_time=data[1]).save()
Exemplo n.º 11
0
 def migrate_20110124(self):
     for task in Task.all():
         task.set_origin_name(task.origin_name)
         task.put()
Exemplo n.º 12
0
 def complete_action(self):
     id = int(self.request.get('id'))
     task = Task.get_by_id(id)
     task.is_completed = True;
     task.complete_time = datetime.datetime.now()
     task.put()