Ejemplo n.º 1
0
    def _decorator(request, user_id, *args, **kwargs):
        from www.timeline.interface import UserFollowBase
        from django.shortcuts import render_to_response
        from django.template import RequestContext

        ufb = UserFollowBase()
        ub = UserBase()
        if not user_id:
            user = request.user
        else:
            user = ub.get_user_by_id(user_id)
            if not user:
                err_msg = u'用户不存在'
                return render_to_response(
                    'error.html',
                    locals(),
                    context_instance=RequestContext(request))
        request.is_me = (request.user == user)
        if not request.is_me:
            request.is_follow = ufb.check_is_follow(request.user.id, user.id)

        user_count_info = UserCountBase().get_user_count_info(user_id)
        request.user_question_count = user_count_info['user_question_count']
        request.user_answer_count = user_count_info['user_answer_count']
        request.user_liked_count = user_count_info['user_liked_count']
        request.following_count = user_count_info['following_count']
        request.follower_count = user_count_info['follower_count']

        return func(request, user, *args, **kwargs)
Ejemplo n.º 2
0
    def _decorator(request, user_id, *args, **kwargs):
        from www.timeline.interface import UserFollowBase
        from django.shortcuts import render_to_response
        from django.template import RequestContext

        ufb = UserFollowBase()
        ub = UserBase()
        if not user_id:
            user = request.user
        else:
            user = ub.get_user_by_id(user_id)
            if not user:
                err_msg = u'用户不存在'
                return render_to_response('error.html', locals(), context_instance=RequestContext(request))
        request.is_me = (request.user == user)
        if not request.is_me:
            request.is_follow = ufb.check_is_follow(request.user.id, user.id)

        user_count_info = UserCountBase().get_user_count_info(user_id)
        request.user_journey_count = user_count_info['user_journey_count']
        request.user_answer_count = user_count_info['user_answer_count']
        request.user_liked_count = user_count_info['user_liked_count']
        request.following_count = user_count_info['following_count']
        request.follower_count = user_count_info['follower_count']

        return func(request, user, *args, **kwargs)
Ejemplo n.º 3
0
 def get_recommend_users(self, user_id, random=False):
     from www.timeline.interface import UserFollowBase
     exclude_user_ids = [
         f.to_user_id
         for f in UserFollowBase().get_following_by_user_id(user_id)
     ]
     exclude_user_ids.append(user_id)
     if not random:
         rusers = RecommendUser.objects.exclude(
             user_id__in=exclude_user_ids)
     else:
         rusers = RecommendUser.objects.exclude(
             user_id__in=exclude_user_ids).order_by('?')
     return rusers[:4]
Ejemplo n.º 4
0
def update_user_count():
    from www.account.models import UserCount, User
    from www.question.interface import QuestionBase, AnswerBase, LikeBase
    from www.timeline.interface import UserFollowBase

    for user in User.objects.all():
        user_id = user.id
        user_question_count = QuestionBase().get_user_question_count(user_id)
        user_answer_count = AnswerBase().get_user_sended_answers_count(user_id)
        user_liked_count = LikeBase().get_user_liked_count(user_id)
        following_count = UserFollowBase().get_following_count(user_id)
        follower_count = UserFollowBase().get_follower_count(user_id)

        if user_question_count or user_answer_count or user_liked_count or following_count or follower_count:
            user_count, created = UserCount.objects.get_or_create(
                user_id=user_id)
            user_count.user_question_count = user_question_count
            user_count.user_answer_count = user_answer_count
            user_count.user_liked_count = user_liked_count
            user_count.following_count = following_count
            user_count.follower_count = follower_count
            user_count.save()

    print 'ok'
Ejemplo n.º 5
0
    def regist_user(self,
                    email,
                    nick,
                    password,
                    ip,
                    mobilenumber=None,
                    username=None,
                    source=0,
                    gender=0,
                    invitation_code=None):
        '''
        @note: 注册
        '''
        try:
            from www.message.interface import UnreadCountBase

            if not (email and nick and password):
                transaction.rollback(using=ACCOUNT_DB)
                return 99800, dict_err.get(99800)

            errcode, errmsg = self.check_user_info(email, nick, password,
                                                   mobilenumber)
            if errcode != 0:
                transaction.rollback(using=ACCOUNT_DB)
                return errcode, errmsg

            id = utils.uuid_without_dash()
            now = datetime.datetime.now()

            user = User.objects.create(id=id,
                                       email=email,
                                       mobilenumber=mobilenumber,
                                       last_login=now,
                                       password=self.set_password(password))
            profile = Profile.objects.create(id=id,
                                             nick=nick,
                                             ip=ip,
                                             source=source,
                                             gender=gender)
            self.set_profile_login_att(profile, user)

            if invitation_code:
                invitation = InvitationBase().add_invitation_user(
                    invitation_code, profile.id)
                if invitation:
                    # 发送系统通知
                    content = u'成功邀请一个注册用户 <a href="%s">%s</a>' % (
                        profile.get_url(), profile.nick)
                    UnreadCountBase().add_system_message(
                        user_id=invitation.user_id, content=content)

                    # 自动关注邀请者
                    from www.timeline.interface import UserFollowBase
                    UserFollowBase().follow_people(profile.id,
                                                   invitation.user_id)

            # 初始化用户数据
            UserCount.objects.get_or_create(user_id=user.id)

            transaction.commit(using=ACCOUNT_DB)

            # todo发送验证邮件
            return 0, profile
        except Exception, e:
            debug.get_debug_detail(e)
            transaction.rollback(using=ACCOUNT_DB)
            return 99900, dict_err.get(99900)
Ejemplo n.º 6
0
from django.contrib import auth
from django.http import HttpResponse, HttpResponseRedirect
from django.template import RequestContext
from django.shortcuts import render_to_response

from common import utils, user_agent_parser, page
from www.misc import qiniu_client
from www.account import interface
from www.misc.decorators import member_required
from www.account.interface import user_profile_required
from www.timeline.interface import UserFollowBase
from www.tasks import async_clear_count_info_by_code

ub = interface.UserBase()
ib = interface.InvitationBase()
ufb = UserFollowBase()


def show_index(request):
    if request.user.is_authenticated():
        from www.timeline.views import show_user_timeline
        return show_user_timeline(request)
    else:
        from www.question.views import question_home
        return question_home(request)


def login(request, template_name='account/login_bg.html'):
    email = request.POST.get('email', '').strip()
    password = request.POST.get('password', '').strip()