Beispiel #1
0
def attach_friends(report):
	friends = report.friends
	user = report.user
	oldf = user.friends.filter(q_inner(report.start_date), unfollow = False).order_by('friend')
	newf = user.friends.filter(q_inner(report.end_date), unfollow = False).order_by('friend')

	m = Marge(oldf, newf, lambda a,b: cmp(a.friend_id, b.friend_id))

	m.full(left = lambda l: friends.create(user = l.friend, remove = True),
			right = lambda r: friends.create(user = r.friend, remove = False))

	return friends
Beispiel #2
0
def attach_icon(report):
	user = report.user
	try:
		newi = user.icons.get(q_inner(report.end_date))
	except UserIcon.DoesNotExist:
		newi = None
		 
	try:
		oldi = user.icons.get(q_inner(report.start_date))
	except UserIcon.DoesNotExist:
		oldi = None

	if newi == None: icons = DiffIcon(report = report, diff_type = 'N')
	elif oldi == None: icons = DiffIcon(report = report, new = newi, diff_type = 'E')
	elif oldi.digest == newi.digest:
		icons = DiffIcon(report = report, old = oldi, new = newi, diff_type = 'E')
	else:
		icons = DiffIcon(report = report, old = oldi, new = newi, diff_type = 'C')
	
	icons.save()
	report.icons = icons

	return icons
Beispiel #3
0
def attach_screen_name(report):
	user = report.user
	try:
		new = user.screen_names.get(q_inner(report.end_date))
	except UserScreenName.DoesNotExist:
		new = None

	try:
		old = user.screen_names.get(q_inner(report.start_date))
	except UserScreenName.DoesNotExist:
		old = None

	if new == None: names = DiffScreenName(report = report, diff_type = 'N')
	elif old == None: names = DiffScreenName(report = report, new = new, diff_type = 'E')
	elif old.screen_name == new.screen_name:
		names = DiffScreenName(report = report, old = old, new = new, diff_type = 'E')
	else:
		names = DiffScreenName(report = report, old = old, new = new, diff_type = 'C')

	names.save()
	report.screen_names = names

	return names
Beispiel #4
0
	def test_update_screen_names(self):
		from twirem.main.models import UserScreenName, q_inner
		names = ([
			{"id":1, "screen_name":"test1"},
			{"id":2, "screen_name":"test2"},
			{"id":3, "screen_name":"test3mod"},
			])
		db_update.update_screen_names(names)

		inner = q_inner()
		
		self.assertEquals(
				UserScreenName.objects.get(inner, user__user_id = 1).screen_name, 'test1')
		self.assertEquals(
				UserScreenName.objects.get(inner, user__user_id = 2).screen_name, 'test2')
		self.assertEquals(
				UserScreenName.objects.get(inner, user__user_id = 3).screen_name, 'test3mod')