예제 #1
0
    def test_deps_text(self):
        text = ''
        task1 = Task(chat=1,
                     name='{}'.format(text),
                     status='TODO',
                     dependencies='',
                     parents='',
                     priority='')
        task2 = Task(chat=1,
                     name='{}'.format(text),
                     status='TODO',
                     dependencies='1,2,',
                     parents='',
                     priority='')
        task3 = Task(chat=1,
                     name='{}'.format(text),
                     status='TODO',
                     dependencies='2,',
                     parents='',
                     priority='')

        db.session.add(task1)
        db.session.add(task2)
        db.session.add(task3)
        db.session.commit()

        chat = 1
        preceed = ''

        assert text == Services().deps_text(task1, chat, preceed)
예제 #2
0
파일: db_test.py 프로젝트: firerml/Tasker
 def setUp(self):
     with patch('db.datetime') as mock_datetime:
         mock_datetime.now.return_value = default_timestamp
         self.DB = Database(TEST_DB_URL)
         session = self.DB.sessionmaker()
         session.add(
             Task(assigner_id=user1,
                  assignee_id=user2,
                  description='order lunch'))
         session.add(
             Task(assigner_id=user1,
                  assignee_id=user2,
                  description='eat lunch'))
         session.commit()
예제 #3
0
def new_task(msg, chat):
    task = Task(chat=chat, name=msg, status='TODO',
                dependencies='', parents='', priority='')
    db.session.add(task)
    db.session.commit()
    send_message("New task *TODO* [[{}]] {}".format(task.id, task.name), chat)
    create_issue(task.name, 'Task ID: [{}]\n\ Task Name: {}'.format(task.id, task.name))
예제 #4
0
파일: main.py 프로젝트: hojovi/shanbei
def todayWord():
    if current_user.task is None:
        current_user.task=Task(user=current_user,wordNumPerDay=0)
        session.commit()
    if session.query(HistoryTask).filter(HistoryTask.user==current_user,HistoryTask.taskTime==date.today()).count()==0:
        history=HistoryTask(userId=current_user.id,taskTime=date.today(),plan=current_user.task.wordNumPerDay,complete=0)
        session.add(history)
        session.commit()
    else:
        history=session.query(HistoryTask).filter(HistoryTask.user==current_user,HistoryTask.taskTime==date.today()).first()
    need=history.plan-history.complete
    # print(need)
    count=session.query(Word).filter(Word.progresses.any(and_(Progress.progress<5,Progress.userId==current_user.id))).count()
    # print(count)
    try:
        if count<need:
            extendProgressCount=extendProgress(current_user, 1000)
            if count==0 and extendProgressCount.rowcount==0:
                return error({'message':'您已背完所有单词!'})
        if need<=0:
            return success({'words':[]})
        progresses=session.query(Progress).filter(Progress.userId==current_user.id,Progress.progress<5).order_by(Progress.progress).limit(need).all()
        # print(progresses)
        words=[progress.word.asDict() for progress in progresses]
        return success({'words':words})
    except Exception as e:
        print(e)
        import traceback
        traceback.print_exc()
        session.rollback()
        return error({'message':"抱歉出现错误,请发送详细内容到[email protected]"})
예제 #5
0
 def setUp(self):
     self.task = Task(chat=1,
                      name="teste",
                      status='TODO',
                      dependencies='',
                      parents='2, 3',
                      priority='')
    def duplicate(self, bot, update, args):
        if args[0].isdigit():
            task_id = int(args[0])
            query = db.session.query(Task).filter_by(
                id=task_id, chat=update.message.chat_id)
            try:
                task = query.one()
            except sqlalchemy.orm.exc.NoResultFound:
                self.services.not_found_message(bot, update, task_id)
                return

            dtask = Task(chat=task.chat, name=task.name, status=task.status,
                         dependencies=task.dependencies, parents=task.parents,
                         priority=task.priority, duedate=task.duedate)
            db.session.add(dtask)

            for each_task in task.dependencies.split(',')[:-1]:
                each_query = db.session.query(Task).filter_by(
                    id=int(each_task), chat=update.message.chat_id)
                each_task = each_query.one()
                each_task.parents += '{},'.format(dtask.id)

            db.session.commit()
            bot.send_message(chat_id=update.message.chat_id,
                             text="New task *TODO* [[{}]] {}"
                             .format(dtask.id, dtask.name))
        else:
            bot.send_message(chat_id=update.message.chat_id,
                             text="You must inform the task id")
예제 #7
0
def create_task():
    post_body = json.loads(request.data)
    task = Task(description=post_body.get('description'),
                done=bool(post_body.get('done')))
    db.session.add(task)
    db.session.commit()
    return json.dumps({'success': True, 'data': task.serialize()}), 201
예제 #8
0
    def startGeneratingTasks(self, message):
        _log.debug("sleeping some time")
        some_locations = [[2, 9], [3, 10], [3, 9], [3, 11], [4, 4], [4, 1.5],
                          [2.5, 9], [4, 10], [4, 11]]
        number_of_locations = randint(1, 4)
        locations_to_visit = []
        for _ in range(number_of_locations):
            loc = randint(0, len(some_locations) - 1)
            locations_to_visit.append(some_locations[loc])
        locations = locations_to_visit

        user = "******"
        status = 'pending'
        locations = [Point(l) for l in locations]
        new_task = Task(username=user, locations=locations, status=status)
        try:
            self.session.add(new_task)
            self.session.commit()
            entry_id = new_task.id
            _log.debug("-------------------------sending new request")
            self.send_message(to=settings.SCHEDULER, directive="request",\
                                           body = {'locations':locations, 'request_id':entry_id})
            yield from asyncio.sleep(30)
            self.send_message(to="generator", directive="start")

        except Exception as e:
            self.session.rollback()
            self.set_status(400)
예제 #9
0
 def duplicate_assigment(msg, chat):
     if not msg.isdigit():
         self.u.send_message("You must inform the task id", chat)
     else:
         task_id = int(msg)
         query = db.session.query(Task).filter_by(id=task_id, chat=chat)
         try:
             task = query.one()
         except sqlalchemy.orm.exc.NoResultFound:
             self.u.send_message(
                 "_404_ Task {} not found x.x".format(task_id), chat)
             return
         dtask = Task(chat=task.chat,
                      name=task.name,
                      status=task.status,
                      dependencies=task.dependencies,
                      parents=task.parents,
                      priority=task.priority,
                      duedate=task.duedate)
         db.session.add(dtask)
         for t in task.dependencies.split(',')[:-1]:
             qy = db.session.query(Task).filter_by(id=int(t), chat=chat)
             t = qy.one()
             t.parents += '{},'.format(dtask.id)
         db.session.commit()
         self.u.send_message(
             "New task *TODO* [[{}]] {}".format(dtask.id, dtask.name),
             chat)
예제 #10
0
    def duplicate_task(cls, msg, chat):
        """This function duplicates the task."""
        if not msg.isdigit():
            return "You must inform the task id"
        else:
            task_id = int(msg)
            query = db.session.query(Task).filter_by(id=task_id, chat=chat)
            try:
                task = query.one()
            except sqlalchemy.orm.exc.NoResultFound:
                return "_404_ Task {} not found x.x".format(task_id)

            dtask = Task(chat=task.chat,
                         name=task.name,
                         status=task.status,
                         dependencies=task.dependencies,
                         parents=task.parents,
                         priority=task.priority,
                         overdue=task.overdue,
                         duedate=task.duedate)
            db.session.add(dtask)

            for dependency in task.dependencies.split(',')[:-1]:
                query = db.session.query(Task).filter_by(id=int(dependency),
                                                         chat=chat)
                dependency = query.one()
                dependency.parents += '{},'.format(dtask.id)

            db.session.commit()
            return "New task *TODO* [[{}]] {}".format(dtask.id, dtask.name)
    def duplicate(self, command, msg, chat):
        '''
        Duplica uma task
        '''
        msg = self.strip_message(msg)
        for i in range(len(msg)):
            if self.check_msg_not_exists(msg[i]):
                self.msg_no_task(chat)
            else:
                task_id = int(msg[i])

                try:
                    task = self.query_one(task_id, chat)
                except sqlalchemy.orm.exc.NoResultFound:
                    self.task_not_found_msg(task_id, chat)
                    continue
                dep_task = Task(chat=task.chat, name=task.name,
                                status=task.status,
                                dependencies=task.dependencies,
                                parents=task.parents,
                                priority=task.priority, duedate=task.duedate)
                db.session.add(dep_task)
                for t in task.dependencies.split(',')[:-1]:
                    query_dep = db.session.query(Task).\
                                                filter_by(id=int(t),
                                                          chat=chat)
                    t = query_dep.one()
                    t.parents += '{},'.format(dep_task.id)
                db.session.commit()
                text_message = 'New task *TODO* [[{}]] {}'
                self.send_message(text_message.format(dep_task.id,
                                                      dep_task.name),
                                  chat)
예제 #12
0
    def duplicate(self, message, chat, apiBot):
        """ Function description.
            :type message: string
            :type chat: int
        """
        if message.isdigit():
            task_id = int(message)
            try:
                task = self.find_task(task_id, chat)
            except sqlalchemy.orm.exc.NoResultFound:
                self.id_error_message(message, chat, apiBot)
                return

            duplicated_task = Task(chat=task.chat,
                                   name=task.name,
                                   status=task.status,
                                   dependencies=task.dependencies,
                                   parents=task.parents,
                                   priority=task.priority,
                                   duedate=task.duedate)
            db.session.add(duplicated_task)

            for dependent_task_id in task.dependencies.split(',')[:-1]:
                dependent_task = self.find_task(dependent_task_id, chat)
                dependent_task.parents += '{},'.format(duplicated_task.id)

            issue = repository.create_issue(duplicated_task.name)
            duplicated_task.issue_number = issue.number
            db.session.commit()
            apiBot.send_message(
                "New task *TODO* [[{}]] {}".format(duplicated_task.id,
                                                   duplicated_task.name), chat)
        else:
            self.id_error_message(message, chat, apiBot)
예제 #13
0
파일: app.py 프로젝트: cesard90/optix-demo
def save_task(task_request, job_id):
    task = Task()
    task.name = task_request['name']
    task.sequence = task_request['sequence']
    task.job_id = job_id
    session.add(task)
    session.commit()
    save_taskqueue(task_request, task.id)
    return 'ok'
예제 #14
0
    def newTask(self, msg, chat):
        text, msg = self.checkMsg(msg)

        if text == '':
            task = Task(chat=chat,
                        name=msg,
                        status='TODO',
                        dependencies='',
                        parents='',
                        priority='')
            db.session.add(task)
            db.session.commit()
            self.send_message(
                "New task *TODO* [[{}]] {}".format(task.id, task.name), chat)
            self.upload_github_issue(
                task.name, 'ID : [{}]\n\
                                                Name : [{}]\n\
                                                Priority : [None]\n\
                                                Issue created from and with 404tasknotfoundbot tasks'
                .format(task.id, task.name))
        else:
            if text.lower() not in ['high', 'medium', 'low']:
                self.send_message(
                    "The priority *must be* one of the following: high, medium, low",
                    chat)
            else:
                priority = text.lower()
                task = Task(chat=chat,
                            name=msg,
                            status='TODO',
                            dependencies='',
                            parents='',
                            priority=priority)
                db.session.add(task)
                db.session.commit()
                self.send_message(
                    "New task *TODO* [[{}]] {} with priority {}".format(
                        task.id, task.name, task.priority), chat)
                self.upload_github_issue(
                    task.name, 'ID : [{}]\n\
                                                     Name : [{}]\n\
                                                     Priority : [{}]\n\
                                                     Issue created from and with 404tasknotfoundbot tasks'
                    .format(task.id, task.name, task.priority))
예제 #15
0
def new(chat, msg):
    task = Task(chat=chat,
                name=msg,
                status='TODO',
                dependencies='',
                parents='',
                priority='')
    db.session.add(task)
    db.session.commit()
    send_message("New task *TODO* [[{}]] {}".format(task.id, task.name), chat)
def create(parsed_message):
    task = Task(**parsed_message['parsed']['task'])
    task.raw_text = parsed_message['text']
    task.team_id = parsed_message['team']
    task.channel_id = parsed_message['channel']
    task.user_id = parsed_message['user']
    task.created_ts = parsed_message['ts']
    session.add(task)
    session.commit()
    return "New task : {task}".format(task=str(task)), task
예제 #17
0
def create_task(name, description, date, budget, event_id):
    new_task = Task(
        name=name,
        description=description,
        date=date,
        budget=budget,
        event_id=event_id
    )
    db.session.add(new_task)
    db.session.commit()
    return new_task.serialize()
예제 #18
0
 def new_task(cls, msg, chat):
     """This function creates the new tasks."""
     task = Task(chat=chat,
                 name=msg,
                 status='TODO',
                 dependencies='',
                 parents='',
                 priority='')
     db.session.add(task)
     db.session.commit()
     return "New task *TODO* [[{}]] {}".format(task.id, task.name)
def new_task(chat_id, name):
    """
    This method will create a new task.
    :param chat_id: specify the current chat.
    :param name: the name of the new task.
    """
    task = Task(chat=chat_id, name=name, status='TODO', dependencies='', parents='', priority='', duedate = None)
    if(name != ''):
        db.session.add(task)
        db.session.commit()
        send_message("New task *TODO* [[{}]] {}".format(task.id, task.name), chat_id)
 def new(cls, bot, update, args):
     text = ''
     for each_word in args:
         text += each_word + ' '
     task = Task(chat=update.message.chat_id, name='{}'.format(text),
                 status='TODO', dependencies='', parents='', priority='')
     db.session.add(task)
     db.session.commit()
     bot.send_message(chat_id=update.message.chat_id,
                      text="New task *TODO* [[{}]] {}"
                      .format(task.id, task.name))
예제 #21
0
def create_task():
    body = json.loads(request.data)

    new_task = Task(description=body['description'],
                    done=body.get('done', False)
                    # 無法取得數值時,給予初始值避免出錯
                    )

    db.session.add(new_task)
    db.session.commit()
    return success_response(new_task.serialize(), 201)
 def new_task(self, command, msg, chat):
     '''
     Retorna uma nova task e abre uma nova issue no repositório
     '''
     msg = self.strip_message(msg)
     for i in range(len(msg)):
         task = Task(chat=chat, name=''.join(msg[i]), status='TODO',
                     dependencies='', parents='', priority='')
         print('\ntask', task)
         db.session.add(task)
         db.session.commit()
         text_message = 'New task *TODO* [[{}]] {}'
         self.send_message(text_message.format(task.id, task.name), chat)
예제 #23
0
def new_task(chat, msg):
    task = Task(chat=chat,
                name=msg,
                status='TODO',
                dependencies='',
                parents='',
                priority='',
                duedate=None)
    db.session.add(task)
    db.session.commit()
    make_github_issue(title=msg,
                      body="New task *TODO* [{}] {}".format(
                          task.id, task.name))
    send_message("New task *TODO* [[{}]] {}".format(task.id, task.name), chat)
예제 #24
0
파일: main.py 프로젝트: hojovi/shanbei
def updateTask():
    num=request.form['wordNumPerDay']
    try:
        if current_user.task is None:
            current_user.task=Task(wordNumPerDay=num)
        else:
            current_user.task.wordNumPerDay=num
        for history in session.query(HistoryTask).filter(HistoryTask.user==current_user,HistoryTask.taskTime>=date.today()).all():
            history.plan=num
        session.commit()
        return success({})
    except:
        session.rollback()
        return error({'message':"抱歉出现错误,请发送详细内容到[email protected]"})
예제 #25
0
def create_task(project_id):
    body = json.loads(request.data)
    if (body.get('title') == None or body.get('deadline') == None):
        return failure_response('One or more fields is missing.')
    else:
        selected_project = Project.query.filter_by(id=project_id).first()
        if selected_project == None:
            return failure_response("Project not found.")
        if body.get('body') == None:
            new_task = Task(title=body.get('title'),
                            body=body.get('body'),
                            deadline=body.get('deadline'),
                            project_id=project_id)
        else:
            new_task = Task(title=body.get('title'),
                            body=body.get('body'),
                            deadline=body.get('deadline'),
                            project_id=project_id)
        db.session.add(new_task)
        db.session.commit()
        formatted_task = new_task.serialize()
        #formatted_task['project'] = selected_project.serialize()
        #formatted_task['users'] = [u.serialize() for u in selected_task.users]
        return success_response(formatted_task, 201)
예제 #26
0
def new_task(chat, msg):

    from datetime import datetime
    task = Task(chat=chat,
                name=msg,
                status='TODO',
                description='No description.',
                priority='None',
                duedate='')

    task.duedate = datetime.strptime(task.duedate, '')
    db.session.add(task)
    db.session.commit()

    send_message("New task *TODO* [[{}]] {}".format(task.id, task.name), chat)
 def new_task(self, name, chat):
     """Create and returns a new task named by the user"""
     task = Task(chat=chat,
                 name=name,
                 status='TODO',
                 dependencies='',
                 parents='',
                 priority='2')
     db.SESSION.add(task)
     db.SESSION.commit()
     self.url_handler.send_message("Okay, I'll write this {}.\nThe ID is [[{}]]\n{}".format(constants.WRITING_EMOJI,
                                                                                    task.id,
                                                                                    task.name),
                                   chat)
     return task
예제 #28
0
 def new_assigment(msg, chat):
     duedate = msg.split(' ', 1)[1]
     msg = msg.split(' ', 1)[0]
     task = Task(chat=chat,
                 name=msg,
                 status='TODO',
                 dependencies='',
                 parents='',
                 priority='',
                 duedate=duedate)
     db.session.add(task)
     db.session.commit()
     make_github_issue(task.name, '')
     self.u.send_message(
         "New task *TODO* [[{}]] {} - {}".format(
             task.id, task.name, task.duedate), chat)
예제 #29
0
def get_or_create_task_for_user(user, date=None, ip=None):
    if not date:
        date = today()
    try:
        task_obj = Task.get(Task.user == user, Task.day == date)
        if task_obj.task not in get_tasks(user.level):
            task_obj.task = random_task_for_user(user)
            task_obj.save()
    except Task.DoesNotExist:
        if ip:
            task_name = random_task_for_ip(ip)
        else:
            task_name = random_task_for_user(user)
        task_obj = Task(user=user, day=date, task=task_name)
        task_obj.save()
    return task_obj
예제 #30
0
def creteNewTask(chat, msg):
    body = ''
    if msg != '':
        if len(msg.split(' ', 1)) > 1:
            body = msg.split(' ', 1)[1]
        title = msg.split(' ', 1)[0]

    task = Task(chat=chat,
                name=title,
                status='TODO',
                dependencies='',
                parents='',
                priority='')
    db.session.add(task)
    db.session.commit()
    sendMessage("New task *TODO* [[{}]] {}".format(task.id, task.name), chat)