Пример #1
0
 def init_tasks(self):
     r = self.init_researcher()
     t1 = Task.create(name='t1', url='http://www.a.com')
     t2 = Task.create(name='t2', url='https://www.b.com/c?d=f&#g')
     # get a fresh copy of the researcher
     r = Researcher.get_current()
     return r, t1, t2
Пример #2
0
 def test_set_tasks(self):
     r, t1, t2 = self.init_tasks()
     t3 = Task(url='blah', owner=r)
     t3.put()
     tasks = [t1, t2, t3]
     r.tasks(tasks)
     self.assertEqual(r.tasks(), tasks)
Пример #3
0
def task(task_id: int):
    if request.method == 'PATCH':
        if 'user_id' in session:
            user_id = session['user_id']
            user = Storage.get_user_by_id(user_id)
            dataObj = request.json

            error = None
            if not dataObj['title-input']:
                error = 'Необходимо ввести заголовок задачи'
            if error:
                return render_template('pages/new_task.html',
                                       page_title='Обновить задачу',
                                       error=error,
                                       user=user)
            Storage.update_task(
                Task(dataObj['id'], dataObj['title-input'],
                     dataObj['description-input'], dataObj['status-input'],
                     None))
            return 'ok'
        else:
            redirect(url_for('home'))
    elif (request.method == 'DELETE'):
        if 'user_id' in session:
            user_id = session['user_id']
            Storage.delete_task(
                Task(int(request.json['id']), None, None, None, None))
            return 'ok'
        else:
            return redirect('/login')
Пример #4
0
 def init_response_sets(self):
     r, t1, t2 = self.init_tasks()
     rs11 = ResponseSet.create(name='rs11', task=t1)
     rs12 = ResponseSet.create(name='rs12', task=t1)
     rs21 = ResponseSet.create(name='rs21', task=t2)
     rs22 = ResponseSet.create(name='rs22', task=t2)
     # get a fresh copy of researcher and tasks
     r = Researcher.get_current()
     t1 = Task.get_by_key_name('t1')
     t2 = Task.get_by_key_name('t2')
     return r, t1, t2, rs11, rs12, rs21, rs22
Пример #5
0
def get_tasks():
    user_id = session['user_id']
    task = Storage.get_task_by_id(user_id)
    taskList = []
    for t in task:
        taskList.append(Task(t[0], t[1], t[2], t[3]).serialize())
    return json.dumps(taskList)
Пример #6
0
def home_action():
    lenlist = 0
    user_id = session['user_id']
    user = Storage.get_user_by_id(user_id)
    # AJAX Delete
    if request.method == 'DELETE':
        search = request.get_json()
        Storage.del_task(user_id, search['task_id'])
        return jsonify(search)
    # AJAX Update
    if request.method == 'PATCH':
        search = request.get_json()
        Storage.update_task_status(search['task_id'], search['action'])
        return jsonify(search)
    task = Storage.get_task_by_id(user_id)
    if task:
        lenlist = len(task)
    if not request.form['task_name']:
        return render_template('pages/index.html', user=user, task=task, len=lenlist,
                               error="Введите название для задачи")
    if not request.form['task_desc']:
        return render_template('pages/index.html', user=user, task=task, len=lenlist,
                               error="Введите описание для задачи")
    Storage.add_task(Task(None, request.form['task_name'], request.form['task_desc'], None), user_id)
    return redirect(url_for('home'))
Пример #7
0
 def get_tasks(user_id: int) -> list:
     request = db.execute('SELECT * FROM tasks WHERE id_user = ?', (user_id,));
     tasks = request.fetchall();
     tasksList = [];
     for task in tasks:
         tasksList.append(Task(task[0], task[1], task[2], task[3], task[4]));
     return tasksList;
Пример #8
0
def filter():
    search = request.get_json()
    tasks = Storage.filter(search['state'], search['title'],
                           session['user_id'])
    taskList = []
    for t in tasks:
        taskList.append(Task(t[0], t[1], t[2], t[3]).serialize())
    return json.dumps(taskList)
Пример #9
0
 def get_task_status(task_id):
     """"добавить задачу в класс"""
     task_status = db.execute('SELECT * FROM tasks WHERE id = ?',
                              (task_id, )).fetchone()
     if task_status:
         return Task(task_status[0], task_status[1], task_status[2],
                     task_status[3])
     else:
         return None
Пример #10
0
 def test_delete(self):
     r1, t1, t2, rs11, rs12, rs21, rs22 = self.init_response_sets()
     # associate the task with another researcher to test removal process
     self.testbed.setup_env(
         USER_EMAIL='*****@*****.**',
         USER_ID='456',
         USER_IS_ADMIN='1',
         overwrite=True)
     r2 = Researcher.create(users.get_current_user())
     r2.add_task(t1)
     r2.put()
     # associate a contained response set with another researcher
     self.testbed.setup_env(
         USER_EMAIL='*****@*****.**',
         USER_ID='789',
         USER_IS_ADMIN='1',
         overwrite=True)
     r3 = Researcher.create(users.get_current_user())
     r3.add_response_set(rs11)
     r3.put()
     # "delete" the task
     Task.delete(t1)
     # refresh the objects
     r1, r2, r3, t1, rs11, rs12 = db.get(
         [r1.key(), r2.key(), r3.key(), t1.key(), rs11.key(), rs12.key()])
     # the task should be inactive
     self.assertFalse(t1.active)
     # the contained response sets should be inactive
     self.assertFalse(rs11.active)
     self.assertFalse(rs12.active)
     # the task should no longer show up when queried for either associated
     # researcher
     self.assertNotIn(t1, r1.tasks())
     self.assertNotIn(t1, r2.tasks())
     # the response sets should no longer show up when queried for any
     # associated researchers
     self.assertNotIn(rs11, r1.response_sets())
     self.assertNotIn(rs11, r2.response_sets())
     self.assertNotIn(rs11, r3.response_sets())
     self.assertNotIn(rs12, r1.response_sets())
     self.assertNotIn(rs12, r2.response_sets())
     self.assertNotIn(rs12, r3.response_sets())
Пример #11
0
 def do_POST(self):
     parsed_url = urlparse(self.path)
     parsed_query_params = parse_qs(parsed_url.query)
     concurrency = int(parsed_query_params['concurrency'][0])
     url = parsed_query_params['url'][0]
     task = Task(concurrency=concurrency, url=url)
     self.queue.put(task)
     logging.info('Put task to queue with id: {id}'.format(id=task.id))
     with self.lock:
         self.map_job_id_to_total_info[task.id] = {'state': Task.QUEUED}
     self.response(200, data=json.dumps({'job_id': task.id}))
Пример #12
0
 def find_task(task_id):
     """"найти задачу пальзователя"""
     change_task = db.execute('SELECT * FROM tasks WHERE id = ?',
                              (task_id, )).fetchone()
     if change_task:
         return Task(id=change_task[0],
                     name=change_task[1],
                     description=change_task[2],
                     status=change_task[3])
     else:
         return None
Пример #13
0
    def get(self):
        """Create a bunch of entities so we can practice quering."""
        self.write('hi')
        return
        # create a researcher out of the current user
        Researcher.create(users.get_current_user().user_id())

        # create some tasks for that researcher
        t1 = Task.create(name='t1', url_list=[
            'http://www.gentoo.org', 'http://www.xkcd.com'])
        t2 = Task.create(name='t2', url_list=[
            'http://www.abc.com', 'http://www.hampsterdance.com'])

        # create response sets in each task
        rs11 = ResponseSet.create(name='rs11', task=t1)
        rs12 = ResponseSet.create(name='rs12', task=t1)
        ResponseSet.create(name='rs21', task=t2)
        ResponseSet.create(name='rs22', task=t2)

        # create participants in one of the response sets
        Participant.create(response_set=rs11)
        Participant.create(response_set=rs12)
Пример #14
0
 def get(self):
     # does writing to the same entity many times break things?
     num = 50
     r = Researcher.get_current()
     t = Task(key_name='break_task2', url='0', owner=r)
     t.put()
     for x in range(1, num + 1):
         t.url = str(x)
         t.put()
     self.write("Handler complete.<br><br>")
     t = db.get(t.key())
     self.write("Final status of url: {} of {}.".format(t.url, num))
Пример #15
0
def load_tasks(file_path: str) -> [Task]:
    with open(file_path, "r") as file:
        lines = file.readlines()

    tasks = []

    # noinspection PyTypeChecker
    constructor_parameter_types = ((ResourceConstraints, ) * 3 + (str2bool, ))

    for line in lines[1:]:
        line = line.strip()
        split = list(zip(constructor_parameter_types, tuple(line.split(','))))
        split = list(map(lambda t: t[0](t[1]), split))
        tasks.append(Task(*split))

    return tasks
Пример #16
0
 def get_task_by_id(task_id: int) -> Task:
     """Найти задачу по id
     :param task_id:  идентификатор задачи
     :type task_id:   int
     :return:    задача
     :rtype:     Task"""
     task_data = db.execute('SELECT * FROM tasks WHERE tasks.id=?',
                            (task_id, )).fetchone()
     if task_data:
         user = Storage.get_user_by_id(task_data[4])
         return Task(id=task_data[0],
                     title=task_data[1],
                     description=task_data[2],
                     status=task_data[3],
                     user=user)
     else:
         return None
Пример #17
0
def test_start_should_throw_error_for_task_we_are_already_tracking():
    task_id = "1000000"

    # create mocks
    task_tracker = Mock()
    local_storage = get_local_storage()()

    usecase = TimeTracking(task_tracker, local_storage)

    task = Task(task_id, datetime.now())

    # This is a testing only method.
    usecase.local_storage.DB.append(task_serializer.task_to_dict(task))

    # check that local storage is checked and causes an error
    with pytest.raises(TaskAlreadyExists):
        usecase.start_tracking(task_id)
Пример #18
0
    def get_tasks(self):
        cmd = 'cd {}; duoconnect -arc -relay phab.duosec.org arc tasks'.format(conf.REPO_DIR)
        # cmd = 'cat ~/src/tasks.txt'
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
        task_str, err = p.communicate()

        has_tasks = bool(util.regex_phab_id(task_str.decode()))
        if not has_tasks:
            return []

        tasks = []
        for line in task_str.decode().split('\n'):
            if line.strip() == "":
                break

            tasks.append(Task(line))

        return tasks
Пример #19
0
 def get_task_by_user(user_id: int):
     """Найти задачу по пользователю
     :param user_id:  идентификатор пользователя
     :type user_id:  int
     :return:    список задач
     :rtype:     Tasks[]"""
     tasks = db.execute(
         'SELECT tasks.id, tasks.title, tasks.description, tasks.status, tasks.user_id FROM tasks INNER JOIN users ON tasks.user_id = users.id WHERE tasks.user_id=?',
         (user_id, )).fetchall()
     tasks_list = []
     for task in tasks:
         tasks_list.append(
             Task(id=task[0],
                  title=task[1],
                  description=task[2],
                  status=task[3],
                  user=Storage.get_user_by_id(task[4])))
     return tasks_list
Пример #20
0
def create_task():
    if 'user_id' in session:
        user_id = session['user_id']
        user = Storage.get_user_by_id(user_id)

        status = "false"
        if 'status-input' in request.form:
            status = "true"

        error = None
        if not request.form['title-input']:
            error = 'Необходимо ввести заголовок!'
        if error:
            return render_template('pages/new_task.html', page_title='Добавить задачу', error=error, user=user)
        Storage.add_task(Task(None, request.form['title-input'], request.form['description-input'], status, user))
        return redirect(url_for('show_tasks'))
    else:
        redirect(url_for('home'))
Пример #21
0
 def init(self):
     # create a dummy user
     self.testbed.setup_env(
         USER_EMAIL = '*****@*****.**',
         USER_ID = '123',
         USER_IS_ADMIN = '1',
         overwrite = True)
     user = users.get_current_user()
     # create a researcher from that user
     r = Researcher.create(user)
     # create a task for the participant
     t = Task.create(name='t1', url='http://www.a.com')
     # create a response set for the participant
     rs = ResponseSet.create(name='rs', task=t)
     # create a participant
     p = Participant.create(response_set=rs)
     # and get the datastore's copy
     p = db.get(p.key())
     return r, t, rs, p
Пример #22
0
def add_task():
    if "user_id" not in session:
        return redirect('/login')

    user = Storage.get_user_by_id(session["user_id"])
    title = request.form['title']
    description = request.form['description']

    if not title:
        error = "Введите название задачи."
        tasks = Storage.get_tasks(user.id)
        return render_template('pages/tasks.html',
                               error=error,
                               user=user,
                               tasks=tasks)

    Storage.add_task(Task(None, title, description, user.id, 0))
    tasks = Storage.get_tasks(user.id)

    return render_template('pages/tasks.html', user=user, tasks=tasks)
Пример #23
0
def json_to_task(input_json: dict) -> Task:
    return Task(
        input_json[TASK_ID_COLUMN],
        datetime.strptime(input_json[TASK_CREATED_COLUMN], TASK_CREATED_FORMAT),
    )
Пример #24
0
 def test_add_task(self):
     r, t1, t2 = self.init_tasks()
     t3 = Task(url='blah', owner=r)
     t3.put()
     r.add_task(t3)
     self.assertEqual(r.tasks(), [t1, t2, t3])
Пример #25
0
 def get_task(taskId: int) -> Task:
     request = db.execute('SELECT * FROM tasks WHERE id = ?', (taskId,));
     task = request.fetchone();
     return Task(task[0], task[1], task[2], task[3], task[4]);