Example #1
0
    def get(self, type):
        if type == "activity":
            ac = Activity.query.all()
        elif type == "article":
            ac = Article.query.all()
        data = []
        if len(ac) < 20:
            for i in range(len(ac)):
                x = Activity.get_activities(ac[i])
                data.append(x)
        else:
            ten_ac = random.sample(ac, 20)
            for i in range(len(ten_ac)):
                x = Activity.get_activities(ten_ac[i])
                data.append(x)

        return jsonify(true_data_Return(data, "", "获取数据成功"))
Example #2
0
def activities(request, game_id, round_id, thread_id):
    thread = Thread.get_by_uid(thread_id)
    if thread is None:
        raise Http404

    if not thread.profile_can_view(request.profile):
        return HttpResponse('Unauthorized', status=401)

    if request.method == 'GET':
        return json(list(Activity.get_activities(request.user, thread)))

    # no POSTs here, return 404
    raise Http404
Example #3
0
def stream(request, game_id, round_id, thread_id, message_id):
    thread = Thread.get_by_uid(thread_id)
    since = Activity.get_by_uid(message_id)

    if thread is None:
        raise Http404

    if not thread.profile_can_view(request.profile):
        return HttpResponse('Unauthorized', status=401)

    if request.method != 'GET':
        return HttpResponse('Method Not Allowed', status=405)

    activities = Activity.get_activities(request.user,
                                         thread,
                                         since=since)
    return json(list(activities.run()))