Beispiel #1
0
def following(request):
    timestamp = get_request_timestamp(request)

    if timestamp == 0:
        stream = Stream.objects.filter(user=request.user)\
            .order_by('-date')[:20]
    else:
        stream = Stream.objects.filter(user=request.user)\
            .extra(where=['date<%s'], params=[timestamp])\
            .order_by('-date')[:20]

    idis = []
    for p in stream:
        idis.append(int(p.post_id))

    latest_items = Post.objects.filter(id__in=idis, status=1)\
        .all().order_by('-id')

    sorted_objects = latest_items

    if request.is_ajax():
        if latest_items.exists():
            return render(request, 'pin/_items.html',
                          {'latest_items': sorted_objects})
        else:
            return HttpResponse(0)
    else:
        return render(request, 'pin/home.html',
                      {'latest_items': sorted_objects})
Beispiel #2
0
def following(request):
    timestamp = get_request_timestamp(request)

    if timestamp == 0:
        stream = Stream.objects.filter(user=request.user)\
            .order_by('-date')[:20]
    else:
        stream = Stream.objects.filter(user=request.user)\
            .extra(where=['date<%s'], params=[timestamp])\
            .order_by('-date')[:20]

    idis = []
    for p in stream:
        idis.append(int(p.post_id))

    latest_items = Post.objects.filter(id__in=idis, status=1)\
        .all().order_by('-id')

    sorted_objects = latest_items

    if request.is_ajax():
        if latest_items.exists():
            return render(request,
                          'pin/_items.html',
                          {'latest_items': sorted_objects})
        else:
            return HttpResponse(0)
    else:
        return render(request,
                      'pin/home.html',
                      {'latest_items': sorted_objects})
Beispiel #3
0
def latest(request):
    timestamp = get_request_timestamp(request)

    if timestamp == 0:
        latest_items = Post.accepted.order_by("-is_ads", "-timestamp")[:20]
    else:
        latest_items = Post.accepted.extra(where=["timestamp<%s"], params=[timestamp]).order_by("-timestamp")[:20]

    if request.is_ajax():
        if latest_items.exists():
            return render(request, "pin/_items.html", {"latest_items": latest_items})
        else:
            return HttpResponse(0)
    else:
        return render(request, "pin/home.html", {"latest_items": latest_items})
Beispiel #4
0
def notif_user(request):
    timestamp = get_request_timestamp(request)
    if timestamp:
        date = datetime.datetime.fromtimestamp(timestamp)
        notif = Notif.objects.filter(user_id=request.user.id, date__lt=date)\
            .order_by('-date')[:20]
    else:
        notif = Notif.objects.filter(user_id=request.user.id)\
            .order_by('-date')[:20]

    for n in notif:
        n.actors = Notif_actors.objects.filter(notif=n).order_by('-id')[:20]

    if request.is_ajax():
        return render(request, 'pin/_notif.html', {'notif': notif})
    else:
        return render(request, 'pin/notif_user.html', {'notif': notif})
Beispiel #5
0
def notif_user(request):
    timestamp = get_request_timestamp(request)
    if timestamp:
        date = datetime.datetime.fromtimestamp(timestamp)
        notif = Notif.objects.filter(user_id=request.user.id, date__lt=date)\
            .order_by('-date')[:20]
    else:
        notif = Notif.objects.filter(user_id=request.user.id)\
            .order_by('-date')[:20]

    for n in notif:
        n.actors = Notif_actors.objects.filter(notif=n).order_by('-id')[:20]

    if request.is_ajax():
        return render(request, 'pin/_notif.html', {'notif': notif})
    else:
        return render(request, 'pin/notif_user.html', {'notif': notif})
Beispiel #6
0
def user(request, user_id, user_name=None):
    user = get_object_or_404(User, pk=user_id)

    profile, created = Profile.objects.get_or_create(user=user)
    if not profile.count_flag:
        profile.user_statics()

    timestamp = get_request_timestamp(request)

    if request.user == user:
        if timestamp == 0:
            latest_items = Post.objects.filter(user=user_id)\
                .order_by('-timestamp')[:20]
        else:
            latest_items = Post.objects.filter(user=user_id)\
                .extra(where=['timestamp<%s'], params=[timestamp])\
                .order_by('-timestamp')[:20]

    else:
        if timestamp == 0:
            latest_items = Post.objects.filter(status=1, user=user_id)\
                .order_by('-timestamp')[:20]
        else:
            latest_items = Post.objects.filter(user=user_id, status=1)\
                .extra(where=['timestamp<%s'], params=[timestamp])\
                .order_by('-timestamp')[:20]

    if request.is_ajax():
        if latest_items.exists():
            return render(request, 'pin/_items.html',
                          {'latest_items': latest_items})
        else:
            return HttpResponse(0)
    else:

        follow_status = Follow.objects\
            .filter(follower=request.user.id, following=user.id).count()

        return render(
            request, 'pin/user.html', {
                'latest_items': latest_items,
                'follow_status': follow_status,
                'profile': profile,
                'cur_user': user
            })
Beispiel #7
0
def home(request):
    timestamp = get_request_timestamp(request)

    if timestamp == 0:
        latest_items = Post.accepted.filter(show_in_default=1)\
            .order_by('-is_ads', '-timestamp')[:20]
    else:
        latest_items = Post.accepted.filter(show_in_default=1)\
            .extra(where=['timestamp<%s'], params=[timestamp])\
            .order_by('-timestamp')[:20]

    if request.is_ajax():
        if latest_items.exists():
            return render(request, 'pin/_items.html',
                          {'latest_items': latest_items})
        else:
            return HttpResponse(0)
    else:
        return render(request, 'pin/home.html', {'latest_items': latest_items})
Beispiel #8
0
def user(request, user_id, user_name=None):
    user = get_object_or_404(User, pk=user_id)

    profile, created = Profile.objects.get_or_create(user=user)
    if not profile.count_flag:
        profile.user_statics()

    timestamp = get_request_timestamp(request)

    if request.user == user:
        if timestamp == 0:
            latest_items = Post.objects.filter(user=user_id).order_by("-timestamp")[:20]
        else:
            latest_items = (
                Post.objects.filter(user=user_id)
                .extra(where=["timestamp<%s"], params=[timestamp])
                .order_by("-timestamp")[:20]
            )

    else:
        if timestamp == 0:
            latest_items = Post.objects.filter(status=1, user=user_id).order_by("-timestamp")[:20]
        else:
            latest_items = (
                Post.objects.filter(user=user_id, status=1)
                .extra(where=["timestamp<%s"], params=[timestamp])
                .order_by("-timestamp")[:20]
            )

    if request.is_ajax():
        if latest_items.exists():
            return render(request, "pin/_items.html", {"latest_items": latest_items})
        else:
            return HttpResponse(0)
    else:

        follow_status = Follow.objects.filter(follower=request.user.id, following=user.id).count()

        return render(
            request,
            "pin/user.html",
            {"latest_items": latest_items, "follow_status": follow_status, "profile": profile, "cur_user": user},
        )
Beispiel #9
0
def category(request, cat_id):
    cat = get_object_or_404(Category, pk=cat_id)
    cat_id = cat.id
    timestamp = get_request_timestamp(request)

    if timestamp == 0:
        latest_items = Post.objects.filter(status=1, category=cat_id).order_by("-is_ads", "-timestamp")[:20]
    else:
        latest_items = (
            Post.objects.filter(status=1, category=cat_id)
            .extra(where=["timestamp<%s"], params=[timestamp])
            .order_by("-timestamp")[:20]
        )

    if request.is_ajax():
        if latest_items.exists():
            return render(request, "pin/_items.html", {"latest_items": latest_items})
        else:
            return HttpResponse(0)
    else:
        return render(request, "pin/category.html", {"latest_items": latest_items, "cur_cat": cat})
Beispiel #10
0
def category(request, cat_id):
    cat = get_object_or_404(Category, pk=cat_id)
    cat_id = cat.id
    timestamp = get_request_timestamp(request)

    if timestamp == 0:
        latest_items = Post.objects.filter(status=1, category=cat_id)\
            .order_by('-is_ads', '-timestamp')[:20]
    else:
        latest_items = Post.objects.filter(status=1, category=cat_id)\
            .extra(where=['timestamp<%s'], params=[timestamp])\
            .order_by('-timestamp')[:20]

    if request.is_ajax():
        if latest_items.exists():
            return render(request, 'pin/_items.html',
                          {'latest_items': latest_items})
        else:
            return HttpResponse(0)
    else:
        return render(request, 'pin/category.html', {
            'latest_items': latest_items,
            'cur_cat': cat
        })