def test_save_timer(self): dao = TimerDAO() t1 = TimerEntity(notes="My Test LegacyTimer Running!", user=TestObjects().get_test_user(), running=True) dao.put(t1) assert (t1.id is not None)
def delete(self, id): api_v1_root = '/api/v1' dao = TimerDAO() count_deleted = dao.delete(id) if count_deleted == 1: return Response(status=204) else: return Response(status=404)
def get_many(self): args = self._get_args(request) # For now, just get everything for the current user: dao = TimerDAO() timers = dao.get_all_timers_for_user(current_user.id) formatter = TimerFormatter() timers_payload = [formatter.model_to_dict(timer) for timer in timers] return jsonify(dict(timers=timers_payload))
def post(self): api_v1_root = '/api/v1' timer = TimerFormatter().dict_to_model(TimerEntity, request.json) dao = TimerDAO() dao.put(timer) id = str(timer.id) resp = jsonify(dict(id=id)) resp.headers["Location"] = self.make_location(request.url, id) resp.status_code = http.client.CREATED return resp
def get_one(self, id): parser = RequestParser() # Look only in the querystring parser.add_argument('user', location='args', default=None) args = parser.parse_args(request) dao = TimerDAO() timer = dao.get(id) as_dict = TimerFormatter().model_to_dict(timer) resp = jsonify(as_dict) return resp
def index(): user = current_user dao = TimerDAO() timers = dao.get_all_timers_for_user(current_user.id) formatter = TimerFormatter() timers_payload = [formatter.model_to_dict(timer) for timer in timers] #timers = render_template("timer/user_timer.html", userId=user.id, userEmail=user.email, authToken=user.get_auth_token()) # timers_json = dumps(timers) return render_template("timer/user_timer.html", userId=user.id, userEmail=user.email, authToken=user.get_auth_token(), timers=timers_payload)
def put(self, id): #api_v1_root = '/api/v1' timer_new = TimerFormatter().dict_to_model(TimerEntity, request.json) dao = TimerDAO() timer = dao.get(id) if timer is not None: timer.update_attributes(timer_new) dao.put(timer) id = str(timer.id) resp = jsonify(dict(id=id)) #resp.headers["Location"] = api_v1_root + self.root + "/" + id resp.headers["Location"] = self.make_location(request.url, id) resp.status_code = http.client.OK return resp
def project_hours(): timerDao = TimerDAO() account = Account.objects(name="Goalboost").first() users = [user.id for user in account.get_users()] timer_stats = timerDao.get_weekly_timer_statistics(users, ["Goalboost"]) return render_template("timer/project_hours.html", stats = timer_stats)
def test_save_timer(self): dao = TimerDAO() t1 = Timer(notes="My Test LegacyTimer Running!", user=TestObjects().get_test_user(), running=True) dao.put(t1) assert(t1.id is not None)