def deadlines_for_user_for_group(self, user_id, group_id): deadline_list = [] with self._conn.cursor() as cursor: cursor.execute('SELECT `d`.`id`, `d`.`name`, `d`.`group_id`, `d`.`deadline`, `d`.`type`, `dm`.`user_id`, `dm`.`deadline_id`, `dm`.`notes`, `g`.`name` as `group` ' 'FROM `deadline` as `d` ' 'LEFT JOIN `deadline_metadata` as `dm` ' 'ON `dm`.`deadline_id` = `d`.`id`' 'JOIN `group` as `g` ' 'ON `g`.`id` = `d`.`group_id` ' 'JOIN `group_membership` as `gm` ' 'ON `gm`.`group_id` = `g`.`id` ' 'WHERE (`dm`.`user_id` =? ' ' OR (`gm`.`member_id` =? ' ' AND (`d`.`type` = \'END\' ' ' OR `d`.`type` = \'COM\'))) ' 'AND `d`.`group_id` =? ' 'GROUP BY `d`.`id` ' 'ORDER BY `d`.`deadline` ', (user_id, user_id, group_id)) for result in self._fetch_all_dict(cursor): deadline = self._create_entity(data=result) deadlineMeta = None if result['user_id'] == user_id: deadlineMeta = DeadlineMetadata() deadlineMeta.user_id = result['user_id'] deadlineMeta.deadline_id = result['id'] deadlineMeta.notes = result['notes'] deadline.meta = deadlineMeta deadline_list.append(deadline) print "Result: ", result print "List: ", deadline_list return deadline_list
def deadline_for_user(self, user_id, deadline_id): with self._conn.cursor() as cursor: cursor.execute('SELECT `d`.`id`, `d`.`name`, `d`.`group_id`, `d`.`deadline`, `d`.`type`, `dm`.`user_id`, `dm`.`deadline_id`, `dm`.`notes`, `g`.`name` as `group` ' 'FROM `deadline` AS `d` ' 'JOIN `deadline_metadata` as `dm` ' 'ON `dm`.`deadline_id` = `d`.`id` ' 'JOIN `group` as `g` ' 'ON `g`.`id` = `d`.`group_id` ' 'WHERE `d`.`id` =?', (deadline_id,)) result = self._fetch_dict(cursor) deadline = self._create_entity(data=result) deadlineMeta = None if result['deadline_id']: deadlineMeta = DeadlineMetadata() deadlineMeta.user_id = result['user_id'] deadlineMeta.deadline_id = result['id'] deadlineMeta.notes = result['notes'] deadline.meta = deadlineMeta return deadline
def deadlines_in_group_with_same_name(self, deadline): deadline_list = [] with self._conn.cursor() as cursor: cursor.execute('SELECT `d`.`id`, `d`.`name`, `d`.`group_id`, `d`.`deadline`, `d`.`type`, `dm`.`user_id`, `dm`.`deadline_id`, `dm`.`notes`, `g`.`name` as `group` ' 'FROM `deadline` AS `d` ' 'JOIN `group` as `g` ' 'ON `g`.`id` = `d`.`group_id` ' 'JOIN `deadline_metadata` as `dm` ' 'ON `dm`.`deadline_id` = `d`.`id` ' 'WHERE `d`.`name` =? ' 'and `g`.`id` =?', (deadline.name,deadline.group_id)) for result in self._fetch_all_dict(cursor): deadline = self._create_entity(data=result) deadlineMeta = None if result['user_id']: deadlineMeta = DeadlineMetadata() deadlineMeta.user_id = result['user_id'] deadlineMeta.deadline_id = result['id'] deadlineMeta.notes = result['notes'] deadline.meta = deadlineMeta deadline_list.append(deadline) return deadline_list