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)
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)
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)
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)
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()
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)
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']))