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})
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})
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})
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})
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})
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 })
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})
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}, )
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})
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 })