Example #1
0
 def test_create_tip_with_two_tags(self):
     t = Tip()
     t.author = self.user
     t.title = 'Share files using samba3'
     t.body = 'Using samba you will can be share files on network.'
     t.tags = 'samba linux'
     t.save()
     self.assertEquals('samba linux', t.tags)
Example #2
0
def add_tips(tweets):
    tweets = tweets if isinstance(tweets, list) else tweets.items()
    for tw in tweets:
        session.add(
            Tip(tweetid=tw.id,
                text=tw.text,
                created=tw.created_at,
                likes=tw.favorite_count,
                retweets=tw.retweet_count))
    session.commit()
Example #3
0
def send_tip(request):
	# save tip
	# notify receiver
	data = {}

	if request.method=='POST':		
		logger.debug(str(request.POST))

		mobile=request.POST.get('mobile')
		friend=request.POST.get('friend_mobile')
		try:
			client = User.objects.get(username=mobile)
			to_friend = User.objects.get(username=friend)
			to_friend_info = UserInfo.objects.get(user=to_friend)
		except ObjectDoesNotExist:
			logger.debug("user or friend do not exist!")
			data['status']=28
			data['error']='user have not register'
			return HttpResponse(json.dumps(data,ensure_ascii=False),content_type='application/json')

		
		content=request.POST.get('message')
		create_time=request.POST.get('create_time')
		audio_url=request.POST.get('audio_url')
		photo_url=request.POST.get('photo_url')

		tip = Tip(user=client)
		tip.receiver = friend
		tip.message = content
		tip.create_time = create_time
		if 'photo_file' in request.FILES:
			photo_name = request.FILES['photo_file']._get_name()
			tip.photo.save(photo_name, request.FILES['photo_file'])
		if 'audio_file' in request.FILES:
			audio_name = request.FILES['audio_file']._get_name()
			tip.audio.save(audio_name, request.FILES['audio_file'])
		tip.save()
		# retrieve tip id for next to get
		cacheID = tip.id
 	
		push_target = to_friend_info.imsi

		_jpush = jpush.JPush(app_key, master_secret)
		push = _jpush.create_push()
		push.audience = jpush.audience(
			jpush.tag(push_target)
		)
		push_data = {}
		push_data['from'] = mobile
		push_data['id'] = cacheID
		push.message = jpush.message(msg_content=302, extras=json.dumps(push_data,ensure_ascii=False))
		push.platform = jpush.all_
		push.send()

		data['status']=0
		return HttpResponse(json.dumps(data,ensure_ascii=False),content_type='application/json')
Example #4
0
 def test_create_unique_slug_for_each_tip(self):
     t = Tip()
     t.author = self.user
     t.title = 'Solução para Desligamento Rápido'
     t.body = '# halt'
     t.save()
     self.assertEquals('solucao-para-desligamento-rapido', t.slug_title)
     
     t = Tip()
     t.author = self.user
     t.title = 'Solução para Desligamento Rápido'
     t.body = 'Digite halt no terminal'
     t.save()
     self.assertEquals('solucao-para-desligamento-rapido-1', t.slug_title)