Permalink
Browse files

some modify

  • Loading branch information...
1 parent 10889ee commit a9f29361411d8384cafbb4c6ba64bd41e54d2f59 @klb3713 committed Jun 5, 2012
@@ -72,9 +72,5 @@ def save(self, size=(100,100), *args, **kwargs):
return super(UserProfile, self).save(*args, **kwargs)
-class FollowRelation(models.Model):
- user = models.ForeignKey(User)
- follower = models.ForeignKey(User, related_name='+')
-
@@ -0,0 +1,8 @@
+#!/usr/bin/env python
+#-*- coding:utf-8 -*-
+
+__author__ = 'klb3713'
+
+def getUserStatus(uid, cat):
+ if cat.startswith("signup"):
+ return False
View
@@ -5,8 +5,6 @@
from django.template import RequestContext
from django.http import HttpResponseRedirect, HttpResponse
from django.contrib.auth.decorators import login_required
-from django.utils.translation import ugettext_lazy as _
-from django.conf import settings
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from data.dao.douban_dao import *
@@ -35,3 +35,10 @@ def getBookRecommend(uid):
return bids
else:
return []
+
+def getUserContacts(uid):
+ query = UserRelated.objects(uid=uid)
+ if query:
+ return query[0].contacts
+ else:
+ return []
@@ -1,8 +1,8 @@
#!/usr/bin/env python
#-*- coding:utf-8 -*-
-from usermining import UserMining
-from bookmining import BookMining
+from data.mining.usermining import UserMining
+from data.mining.bookmining import BookMining
class InitData(object):
"""
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+#-*- coding:utf-8 -*-
+from unittest import TestCase
+from data.mining.usermining import UserMining
+
+__author__ = 'klb3713'
+
+class TestUserMining(TestCase):
+ def test_initUserCircle(self):
+ self.fail()
+
+ def test_getUserValue(self):
+ self.fail()
+
+ def test_run(self):
+ usermini = UserMining("klb-3713")
+ usermini.run()
+ #self.fail()
+
+ def test_followPeople(self):
+ self.fail()
+
+ def test_unfollowPeople(self):
+ self.fail()
@@ -5,6 +5,7 @@
import threading
from data.model.douban import UserRelated
from data.mongodb import MongoDB
+from data.signal import SInitUserData
class UserMining(threading.Thread):
"""
@@ -20,18 +21,18 @@ def __init__(self, uid):
self.mining_db = MongoDB.getConnection('mining')
self.recommend_db = MongoDB.getConnection('recommend')
- def initUserRecommend(self):
+ def initUserCircle(self):
peoples = []
- trial = 0
- while(trial < 7):
+ trial = 7
+ while trial:
query = UserRelated.objects(uid=self.uid)
if query:
contacts = query[0].contacts
break;
else:
time.sleep(3)
- trial += 1
- if trial == 7:
+ trial -= 1
+ if not trial:
return False
circle = {}
@@ -55,7 +56,8 @@ def getUserValue(cls):
def run(self):
#TODO add log record
- return self.initUserRecommend()
+ self.initUserCircle()
+
@classmethod
def followPeople(cls, sour, dest):
View
@@ -1,3 +1,9 @@
+#!/usr/bin/env python
+#-*- coding:utf-8 -*-
+
from django.db import models
+from django.contrib.auth.models import User
-# Create your models here.
+class FollowRelation(models.Model):
+ user = models.ForeignKey(User)
+ follower = models.ForeignKey(User, related_name='+')
View
@@ -6,38 +6,25 @@
from django.http import HttpResponseRedirect, HttpResponse
from django.contrib.auth.decorators import login_required
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
-from accounts.models import FollowRelation, UserProfile
+from accounts.models import UserProfile
+from accounts.status import getUserStatus
+from people.models import FollowRelation
from stage.signal import follow_signal, unfollow_signal
from data.model.douban import User as DUser, UserRelated, Api
-
from data.crawl.api import ApiOperation
from data.crawl.user import UserProcessor
+from data.dao.douban_dao import getUserContacts
import logging
logger = logging.getLogger('django')
@login_required
def follow(request):
#TODO 修改为 显示关注的人中的已注册用户
- profile = request.user.get_profile()
- did = profile.did
- query = UserRelated.objects(uid=did)
- contacts = []
- if query:
- contacts = query[0].contacts
- else:
- #return HttpResponseRedirect("/")
- #TODO remove
- url = ApiOperation.apiGenerator('USER_CONTACTS', did)
- api = Api(url=url, api_type='USER_CONTACTS', api_id=did)
- processor = UserProcessor(api)
- result = processor.getUserContacts()
- if result:
- contacts = result
- else:
- return HttpResponseRedirect("/")
- #TODO end
-
+ uid = request.user.get_profile().did
+ if not uid:
+ return HttpResponseRedirect("/")
+ contacts = getUserContacts(uid)
for user in contacts:
user.image_link = user.image_link.replace('icon/u', 'icon/ul')
@@ -118,8 +105,6 @@ def action(request):
return HttpResponse('fail')
if act.startswith('follow'):
return follow_action(request)
- elif act.startswith('like'):
- return like_action(request)
else:
return HttpResponse('fail')
View
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+#-*- coding:utf-8 -*-
+
+__author__ = 'klb3713'
+
+from django.dispatch import receiver
+#from data.signal import SInitUserData
+from data.dao.douban_dao import getUserContacts
+from people.models import FollowRelation
+from accounts.models import UserProfile
+
+#@receiver(SInitUserData)
+def getUserFollow(sender, **kwargs):
+ if sender:
+ contacts = getUserContacts(sender)
+ for people in contacts:
+ try:
+ me = UserProfile.objects.get(did=sender).user
+ follow = UserProfile.objects.get(did=people.uid).user
+ follow_ship = FollowRelation(user=me, follower=follow)
+ follow_ship.save()
+ except:
+ continue

0 comments on commit a9f2936

Please sign in to comment.