def test_converts_datetime_without_timezone_to_utc(self): localnow = datetime.now() utcnow = datetime.utcnow() tz_offset = int((localnow - utcnow).total_seconds() / 60 / 60) m = message(id=None, type='my type', message='my message', createdDatetime=datetime(2011, 8, 22, 18, 16, 45) + timedelta(hours=tz_offset), userId=None, name=None, imageId=None) self.assertEqual(m['created'], '2011-08-22 18:16:45')
def getMessages(self, limit, offset): """ Returns a list of messages for this user. The results are paginated (i.e., this will return ``limit`` rows, starting at ``ofsset``-th row). """ messages = [] try: sql = """select p.project_id, p.title, m.project_message_id, m.message_type, m.message, m.created_datetime as created_datetime, mu.user_id, mu.first_name, mu.last_name, mu.affiliation, mu.group_membership_bitmask, mu.image_id, i.idea_id, i.description as idea_description, i.submission_type as idea_submission_type, i.created_datetime as idea_created_datetime from project_message m inner join project__user pu on pu.project_id = m.project_id and pu.user_id = $userId inner join project p on p.project_id = pu.project_id and p.is_active = 1 inner join user mu on mu.user_id = m.user_id left join idea i on i.idea_id = m.idea_id where m.is_active = 1 union select p.project_id, p.title, null as project_message_id, 'invite' as message_type, concat('You''ve been invited to the ', ucase(p.title), ' project!', coalesce(concat('<br/><br/>"', inv.message, '"'), '')) as message, inv.created_datetime as created_datetime, iu.user_id, iu.first_name, iu.last_name, iu.affiliation, iu.group_membership_bitmask, iu.image_id, i.idea_id, i.description as idea_description, i.submission_type as idea_submission_type, i.created_datetime as idea_created_datetime from project_invite inv inner join project p on p.project_id = inv.project_id and p.is_active = 1 inner join user iu on iu.user_id = inv.inviter_user_id inner join idea i on i.idea_id = inv.invitee_idea_id and i.user_id =$userId order by created_datetime desc limit $limit offset $offset""" data = list(self.db.query(sql, {'userId':self.id, 'limit':limit, 'offset':offset})) for item in data: messages.append(mProject.message(id=item.project_message_id, type=item.message_type, message=item.message, createdDatetime=item.created_datetime, userId=item.user_id, name=mProject.userNameDisplay(item.first_name, item.last_name, item.affiliation, mProject.isFullLastName(item.group_membership_bitmask)), imageId=item.image_id, ideaId=item.idea_id, idea=item.idea_description, ideaSubType=item.idea_submission_type, ideaCreatedDatetime=item.idea_created_datetime, projectId=item.project_id, projectTitle=item.title)) except Exception, e: log.info("*** couldn't get messages") log.error(e)
def getMessages(self, limit, offset): """ Returns a list of messages for this user. The results are paginated (i.e., this will return ``limit`` rows, starting at ``ofsset``-th row). """ messages = [] try: sql = """select p.project_id, p.title, m.project_message_id, m.message_type, m.message, m.created_datetime as created_datetime, mu.user_id, mu.first_name, mu.last_name, mu.affiliation, mu.group_membership_bitmask, mu.image_id, i.idea_id, i.description as idea_description, i.submission_type as idea_submission_type, i.created_datetime as idea_created_datetime from project_message m inner join project__user pu on pu.project_id = m.project_id and pu.user_id = $userId inner join project p on p.project_id = pu.project_id and p.is_active = 1 inner join user mu on mu.user_id = m.user_id left join idea i on i.idea_id = m.idea_id where m.is_active = 1 union select p.project_id, p.title, null as project_message_id, 'invite' as message_type, concat('You''ve been invited to the ', ucase(p.title), ' project!', coalesce(concat('<br/><br/>"', inv.message, '"'), '')) as message, inv.created_datetime as created_datetime, iu.user_id, iu.first_name, iu.last_name, iu.affiliation, iu.group_membership_bitmask, iu.image_id, i.idea_id, i.description as idea_description, i.submission_type as idea_submission_type, i.created_datetime as idea_created_datetime from project_invite inv inner join project p on p.project_id = inv.project_id and p.is_active = 1 inner join user iu on iu.user_id = inv.inviter_user_id inner join idea i on i.idea_id = inv.invitee_idea_id and i.user_id =$userId order by created_datetime desc limit $limit offset $offset""" data = list( self.db.query(sql, { 'userId': self.id, 'limit': limit, 'offset': offset })) for item in data: messages.append( mProject.message( id=item.project_message_id, type=item.message_type, message=item.message, createdDatetime=item.created_datetime, userId=item.user_id, name=mProject.userNameDisplay( item.first_name, item.last_name, item.affiliation, mProject.isFullLastName( item.group_membership_bitmask)), imageId=item.image_id, ideaId=item.idea_id, idea=item.idea_description, ideaSubType=item.idea_submission_type, ideaCreatedDatetime=item.idea_created_datetime, projectId=item.project_id, projectTitle=item.title)) except Exception, e: log.info("*** couldn't get messages") log.error(e)