def get(self, group_id): tasks = _all( db.session.query(Task.name, Task.value, Task.group, Task.frequency).filter_by(group=group_id)) last = _all( db.session.query( Journal.id, Task.name, Task.frequency, func.max(Journal.date).label('date')).join(Task).filter_by( group=group_id).group_by(Task.name).order_by( Journal.date.desc())) todo = copy.deepcopy(tasks) for t in tasks: if t['value'] < 0: todo.remove(t) elif t['frequency'] < 0: todo.remove(t) else: try: res = next( (item for item in last if item['name'] == t['name'])) d = dt.datetime.strptime(res['date'], "%Y-%m-%d").date() if (dt.date.today() - d).days < res['frequency']: todo.remove(t) except: pass return todo
def get(self, group_id): parser = reqparse.RequestParser() parser.add_argument('offset') parser.add_argument('count') args = parser.parse_args() try: offset = int(args['offset']) except: offset = 0 try: count = int(args['count']) except: count = 10 activities = (db.session.query( Journal.id, Journal.date, Journal.description, User.name.label('user'), Task.name.label('task'), ).join(Task).join(User).filter_by(group=group_id).order_by( Journal.date.desc()).offset(offset).limit(count)) count = (db.session.query(func.count( Journal.id).label('number')).join(User).filter_by( group=group_id)).first()[0] return {'activities': _all(activities), 'count': count}
def get(self, group_id, user_id): journal = (db.session.query(Journal.date, func.sum(Task.value).label('points')) .join(Task) .join(User) .filter_by(id=user_id) .group_by(Journal.date) .order_by(Journal.date)) return {'user': user_id,'gist': _all(journal)}
def get(self, group_id): tasks = (db.session.query( Journal.id, Task.name.label('task'), User.name.label('user'), Journal.description, func.max( Journal.date).label('date')).join(User).join(Task).group_by( Task.name).order_by(Journal.date.desc())) return _all(tasks)
def get(self, group_id): group = Group.query.filter_by(id=group_id).first() if group is None: return {'message': 'No such group'} members = (db.session.query( User.name, User.id, func.sum(Task.value).label('points'), User.password, User.balance).filter_by( group=group_id).outerjoin(Journal).outerjoin(Task).group_by( User.id).order_by(func.sum(Task.value).desc())) group.members = _all(members) return group.toJSON()
def get(self, group_id, user_id): activities = _all(db.session.query(Journal.id, Journal.date, User.name.label('user'), Task.name.label('task'), Journal.description ) .join(Task) .join(User) .filter_by(group=group_id) .filter_by(id=user_id)) return activities
def post(self, group_id): group = get_group().get(group_id=group_id) Group.query.filter_by(id=group_id).delete() # cascade users = _all(db.session.query(User.id).filter_by(group=group_id)) ul = User.query.filter_by(group=group_id).delete() t = Task.query.filter_by(group=group_id).delete() for u in users: print(u) f = Finance.query.filter_by(user=u['id']).delete() j = Journal.query.filter_by(user=u['id']).delete() db.session.commit() return group
def get(self, group_id): parser = reqparse.RequestParser() parser.add_argument('offset') parser.add_argument('count') args = parser.parse_args() try: offset = int(args['offset']) except: offset = 0 try: count = int(args['count']) except: count = 10 movements = (db.session.query( Finance.amount, Finance.date, Finance.description, User.name.label('user')).order_by( Finance.date.desc()).join(User).filter_by( group=group_id).offset(offset).limit(count)) count = (db.session.query(func.count( Finance.id).label('number')).join(User).filter_by( group=group_id)).first()[0] return {'movements': _all(movements), 'count': count}