예제 #1
0
def get_grouped_tasks():
    now = dt.datetime.now().replace(second=0, microsecond=0)

    interval = request.args.get('interval')
    dateFrom = now
    dateTo = now + dt.timedelta(days=1)

    if interval != None:
        interval = interval.split('-')
        if len(interval) == 2:
            dateFrom = dt.datetime.strptime(interval[0], "%d.%m.%Y")
            dateTo = dt.datetime.strptime(interval[1],
                                          "%d.%m.%Y") + dt.timedelta(days=1)
        else:
            dateFrom = dt.datetime.strptime(interval[0], "%d.%m.%Y")
            dateTo = dateFrom + dt.timedelta(days=1)

    if app.config.get('SQLITE'):
        storage = Storage()
        tasks = storage.get_facts_by_dates(dateFrom, dateTo)
        # jsonify always encode unicode
        return app.response_class(json.dumps({"tasks": tasks},
                                             ensure_ascii=False),
                                  mimetype='application/json')

    api = ApiController()
    return api.get_grouped_tasks(dateFrom, dateTo)
예제 #2
0
def complete_task():
    if app.config.get('SQLITE'):
        storage = Storage()
        return jsonify({"values": storage.get_suggestions()})

    text = request.values.get('text')
    api = ApiController()
    return api.get_autocomlete(text)
예제 #3
0
def add_entry():
    if app.config.get('SQLITE'):
        storage = Storage()
        id = storage.add_fact(request.values['name'])
        return jsonify({"status": True, "id": id})

    name = request.values.get('name').strip()
    api = ApiController()
    return api.add_activity(name)
예제 #4
0
def link_project():
    project_id = int(request.values['projectId'])
    tracker_id = int(request.values['trackerId'])
    tracker_project_id = int(request.values['trackerProjectId'])
    tracker_project_title = request.values['trackerProjectTitle'].strip()

    api = ApiController()
    return api.link_project(project_id, tracker_id, tracker_project_id,
                            tracker_project_title)
예제 #5
0
def resume_task():
    id = int(request.values['id'])
    if app.config.get('SQLITE'):
        storage = Storage()
        result = storage.resume_fact(id)
        return jsonify(result)

    api = ApiController()
    return api.resume_task(id)
예제 #6
0
def save_tracker():
    # todo: валидация
    id = request.values.get('id')
    type = request.values.get('type')
    title = request.values.get('title').strip()
    api_url = request.values.get('api_url').strip()

    api = ApiController()
    return api.save_tracker(id, type, title, api_url)
예제 #7
0
def save_settings():
    data = {
        'evo_in_name': request.values['evo_in_name'],
        'evo_in_comment': request.values['evo_in_comment'],
        'evo_out_name': request.values['evo_out_name'],
        'evo_out_comment': request.values['evo_out_comment'],
    }

    api = ApiController()
    return api.save_settings(data)
예제 #8
0
def get_current():
    if app.config.get('SQLITE'):
        dateFrom = dt.datetime.now().replace(second=0, microsecond=0)

        storage = Storage()
        last_entries = storage.get_formated_facts(dateFrom)

        for k, item in enumerate(last_entries):
            if item['end_time'] is '':
                item['status'] = True
                return jsonify(item)

        return jsonify({"status": False})

    api = ApiController()
    return api.get_current()
예제 #9
0
def auth():
    error = None

    def get(field):
        global error
        value = request.values.get(field)
        if value is None:
            error = 'введите' + field
        if field not in ('password', 'token'):
            return value.lower()
        return value

    login, password = get('login'), get('password')

    if error is not None:
        return jsonify({'message': error})

    api = ApiController()
    return api.get_user_by_redmine(login, password)
예제 #10
0
def export_task():
    external_id = request.values['external_id']
    if external_id == '':
        external_id = 0
    else:
        external_id = int(external_id)

    api = ApiController()
    return api.export(
        request.values['tracker_id'], {
            'date': dt.datetime.strptime(request.values['date'],
                                         "%d.%m.%Y").date(),
            'hours': float(request.values['hours']),
            'comment': request.values['comment'],
            'name': request.values['name'],
            'external_id': external_id,
            'project_id': int(request.values['project_id']),
            'external_name': request.values['external_name']
        })
예제 #11
0
def get_tasks():
    now = dt.datetime.now().replace(second=0, microsecond=0)

    interval = request.args.get('interval')
    dateFrom = now - dt.timedelta(days=1)
    dateTo = now

    if interval is not None:
        interval = interval.split('-')
        if len(interval) == 2:
            dateFrom = dt.datetime.strptime(interval[0], "%d.%m.%Y")
            dateTo = dt.datetime.strptime(interval[1], "%d.%m.%Y")
        else:
            dateFrom = dt.datetime.strptime(interval[0], "%d.%m.%Y")
            dateTo = dateFrom

    if app.config.get('SQLITE'):
        storage = Storage()
        last_entries = storage.get_formated_facts(dateFrom, dateTo)
        return jsonify({"tasks": last_entries})

    api = ApiController()
    return api.get_tasks(dateFrom, dateTo)
예제 #12
0
def tracker_task():
    tracker_id = int(request.values['trackerId'])
    task_id = int(request.values['taskId'])

    api = ApiController()
    return api.get_tracker_task(tracker_id, task_id)
예제 #13
0
def get_user_tags():
    api = ApiController()
    return api.get_user_tags()
예제 #14
0
def get_user_projects():
    api = ApiController()
    return api.get_user_projects()
예제 #15
0
def get_tracker_projects():
    id = request.args.get('id')

    api = ApiController()
    return api.get_tracker_projects(id)
예제 #16
0
def get_settings():
    api = ApiController()
    return api.get_settings()
예제 #17
0
def get_token():
    tracker_id = request.values.get('id')
    login = request.values.get('login').strip()
    password = request.values.get('password')
    api = ApiController()
    return api.get_token(tracker_id, login, password)
예제 #18
0
def edit_task():
    description = request.values['description']
    if description == 'null':
        description = ''

    fact = {
        'id': request.values['id'],
        'name': request.values['name'],
        'category': request.values['category'],
        'date': request.values['date'],
        'start_time': request.values['start_time'],
        'end_time': request.values['end_time'],
        'description': description,
        'tags': [tag.strip() for tag in request.values['tags'].split(',')]
    }

    try:
        start_dt = dt.datetime.strptime(
            fact['date'] + ' ' + fact['start_time'], "%d.%m.%Y %H:%M")
    except ValueError:
        return jsonify({
            "status": False,
            "message": "Дата и время начала введены некорректно"
        })

    if len(fact['end_time']) < 5 or fact['end_time'] == '__:__':
        end_dt = None
    else:
        try:
            end_dt = dt.datetime.strptime(
                fact['date'] + ' ' + fact['end_time'], "%d.%m.%Y %H:%M")
        except ValueError:
            return jsonify({
                "status": False,
                "message": "Время окончания заполнено некорректно"
            })

    if app.config.get('SQLITE'):
        storage = Storage()
        db_fact = storage.get_fact(request.values['id'])
        for k, v in fact.items():
            db_fact[k] = v
        fact = db_fact
        # todo: сделать инициализацию факта по id
        factNew = Fact(id=fact['id'],
                       activity=fact['name'],
                       category=fact['category'],
                       start_time=fact['start_time'],
                       end_time=fact['end_time'],
                       description=fact['description'],
                       tags=fact['tags'])
        result = storage.update_fact(fact['id'], factNew.serialized_name(),
                                     start_dt, end_dt)
        return jsonify({"status": True, "id": result})

    api = ApiController()
    return api.edit_task(
        fact['id'],
        Fact2(activity=fact['name'],
              category=fact['category'],
              description=fact['description'],
              start_time=start_dt,
              end_time=end_dt,
              tags=fact['tags']))
예제 #19
0
def delete_tracker():
    # todo: валидация
    id = request.values.get('id')

    api = ApiController()
    return api.delete_tracker(id)
예제 #20
0
def save_evo_user():
    id = request.values.get('id')

    api = ApiController()
    return api.save_evo_user(id)
예제 #21
0
def get_trackers():
    api = ApiController()
    return api.get_trackers()
예제 #22
0
def get_evo_users():
    api = ApiController()
    return api.get_evo_users()
예제 #23
0
def get_projects():
    project_ids = request.args.getlist('projects[]')
    project_ids = list(map(int, project_ids))

    api = ApiController()
    return api.get_projects(project_ids)