当前位置: 首页>>代码示例>>Python>>正文


Python Feed.user_feed方法代码示例

本文整理汇总了Python中models.Feed.user_feed方法的典型用法代码示例。如果您正苦于以下问题:Python Feed.user_feed方法的具体用法?Python Feed.user_feed怎么用?Python Feed.user_feed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Feed的用法示例。


在下文中一共展示了Feed.user_feed方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: api_user_login

# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import user_feed [as 别名]
def api_user_login(request):

    api_result = {"api": "login"}

    username = request.POST["username"]
    password = request.POST["password"]

    print username, password
    user = authenticate(username=username, password=password)
    print user.pk
    if user is not None:
        if user.is_active:
            login(request, user)
            api_result["status"] = "success"
        else:
            # Return a 'disabled account' error message
            api_result["status"] = "failure"
    else:
        # Return an 'invalid login' error message.
        api_result["status"] = "failure"

    print request.user.is_authenticated()

    # if no polls in feed, initiate new user protocol
    polls = Feed.user_feed(user, 1, 10)

    if len(polls) == 0:
        create_feed_new_user(user)

    return JsonResponse(api_result)
开发者ID:krdeepak,项目名称:djmysite,代码行数:32,代码来源:views.py

示例2: feed_ajax

# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import user_feed [as 别名]
def feed_ajax(request):
    try:
        page = int(request.GET["page"])
        if page <= 0:
            page = 1
    except:
        page = 1
    new_questions = Feed.user_feed(request.user, page)

    context = {"nav": "home", "questions": new_questions}

    if new_questions:
        return render(request, "polls/v1_feed_ajax.html", context)
    else:
        return HttpResponse("no more polls")
开发者ID:krdeepak,项目名称:djmysite,代码行数:17,代码来源:views.py

示例3: api_feed

# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import user_feed [as 别名]
def api_feed(request):
    api_result = {"api": "feed", "status": "success"}

    try:
        token = request.GET["token"]
        user = get_user_from_token(token)
        group_id = 0
        try:
            group_id = request.GET["group_id"]
        except:
            pass

        page = 1
        try:
            page = int(request.GET["page"])
        except:
            pass

        page_size = 10
        try:
            page_size = int(request.GET["page_size"])
        except:
            pass

        if not user:
            api_result["status"] = "failure"
            api_result["error"] = "user not found"
        else:
            if group_id == 0:
                polls = Feed.user_feed(user, page, page_size)
            else:
                polls = Feed.group_feed(user, group_id, page, page_size)

            if page == 1 and not polls:
                # create_feed_new_user(user)
                # polls = Feed.user_feed(user, page, page_size)
                pass

            if polls:
                api_result["polls"] = json_polls(polls)
            else:
                api_result["polls"] = "None"
    except Exception as e:
        api_result["status"] = "failure"
        api_result["error"] = e.message
        pass

    return JsonResponse(api_result)
开发者ID:krdeepak,项目名称:djmysite,代码行数:50,代码来源:views.py

示例4: home

# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import user_feed [as 别名]
def home(request):
    if request.user.is_authenticated():

        """
        answered = [vote.question.id for vote in Vote.objects.filter(user=request.user)]
        ignored = [ig.question.id for ig in Ignored.objects.filter(user=request.user)]
        unanswered = Question.objects.exclude(id__in=answered).exclude(id__in=ignored)
        new_questions = random.sample(unanswered,min(len(unanswered),10))
        """
        new_questions = Feed.user_feed(request.user)

        for q in new_questions:
            try:
                suser = UserSocialAuth.objects.get(user_id=q.user.id)
                image_url = "http://graph.facebook.com/{0}/picture".format(suser.uid)
            except:
                image_url = "/static/polls/images/user.png"

            q.user.image_url = image_url

        context = {"nav": "home", "questions": new_questions}
        return render(request, "polls/v1_feed.html", context)
    else:
        if request.method == "POST":
            form = LoginForm(request.POST)
            if form.is_valid():
                username = form.cleaned_data["username"]
                password = form.cleaned_data["password"]

                print username, password
                user = authenticate(username=username, password=password)
                if user is not None:
                    if user.is_active:
                        login(request, user)
                        status = "success"
                    else:
                        # Return a 'disabled account' error message
                        status = "failure"
                else:
                    # Return an 'invalid login' error message.
                    status = "failure"

                print request.user.is_authenticated()

                """
                url = HttpRequest.build_absolute_uri(request, '/polls/api/login/')
                print(url)
                values = {
                    'username': username,
                    'password': password
                }
                data = urllib.urlencode(values)
                req = urllib2.Request(url, data)
                response = urllib2.urlopen(req)
                res = response.read()
                res_json = json.loads(res)
                """

                if status == "success":
                    return HttpResponseRedirect("/")
                else:
                    form._errors["username"] = ErrorList(["invalid username/password"])
        else:
            form = LoginForm()

        # recently finished polls
        questions = Question.objects.all().order_by("-id")[:10]

        for q in questions:
            choices = []
            for choice in q.choice_set.all():
                choices.append({"cid": choice.id, "ctext": choice.choice_text, "cvotes": choice.votes})

            choices = sorted(choices, key=lambda k: k["cvotes"], reverse=True)
            q.choices = json.dumps(choices)

        context = {"form": form, "nav": "home", "questions": questions}

        return render(request, "polls/v1_login.html", context)
开发者ID:krdeepak,项目名称:djmysite,代码行数:81,代码来源:views.py


注:本文中的models.Feed.user_feed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。