Exemplo n.º 1
0
 def post(self, request):
     if request.user.is_authenticated:
         database = Database(request.user.id)
         get_count_top_x_hashtag = database.get_count_top_x_hashtag(12)
         return JsonResponse({'result': get_count_top_x_hashtag})
     else:
         return redirect('home:login')
Exemplo n.º 2
0
 def post(self, request):
     if request.user.is_authenticated:
         database = Database(request.user.id)
         get_post_index = database.json_post(database.get_post_index())
         return JsonResponse({'result': get_post_index})
     else:
         return redirect('home:home')
Exemplo n.º 3
0
 def post(self, request):
     if request.user.is_authenticated:
         database = Database()
         profile_watching = database.get_watching(request.user.username)
         return JsonResponse({'result': profile_watching})
     else:
         return JsonResponse({'result': []})
Exemplo n.º 4
0
 def post(self, request):
     if request.user.is_authenticated:
         data = json.loads(request.body.decode('utf-8'))
         user_2_id = str(data['user_2_id'])
         database = Database()
         username = MyUser.objects.get(id=user_2_id)
         get_profile = database.get_profile(username)
         id_room = database.check_box_chat(request.user.id, user_2_id)
         data = Message.objects.filter(conversation=id_room)
         mess_content = []
         for i in data:
             d = model_to_dict(i)
             d["created_at"] = i.created_at.strftime(
                 "%H:%M:%S ngày %m/%d/%Y")
             mess_content.append(d)
         if not id_room:
             try:
                 Conv = Conversation()
                 Conv.user_1 = request.user
                 Conv.user_2 = MyUser.objects.get(id=user_2_id)
                 Conv.save()
             except:
                 pass
         get_profile[0]['count_mess'] = len(
             list(Message.objects.filter(conversation=id_room)))
         return JsonResponse(
             {
                 'result': get_profile,
                 'mess_content': mess_content
             },
             safe=False)
Exemplo n.º 5
0
 def get(self, request, username):
     database = Database(request.user.id)
     context = {
         'profile': database.lay_thong_tin_voi_username(username),
         'da_tung_chat': database.da_tung_chat(),
     }
     return render(request, 'home/profile.html', context)
Exemplo n.º 6
0
    def post(self, request):
        gender = request.POST.get('gender')
        tuoi_tu = request.POST.get('tuoi_tu')
        tuoi_den = request.POST.get('tuoi_den')
        diachi = request.POST.get('diachi')
        # sothich = request.POST.get('sothich')
        if tuoi_tu != '':
            today = date.today()
            x = today.year - int(tuoi_tu)
            y = today.year - int(tuoi_den)
            if x < y:
                sql_year = "AND DATE(namSinh) BETWEEN '" + str(
                    x) + "' AND '" + str(y) + "'"
            else:
                sql_year = "AND DATE(namSinh) BETWEEN '" + str(
                    y) + "' AND '" + str(x) + "'"
        else:
            sql_year = ""

        if diachi != '':
            sqldc = "AND diaChi like  '%" + str(diachi) + "%' "
        else:
            sqldc = ''

        sql = "SELECT * FROM home_myuser WHERE gioiTinh like '%" + str(
            gender) + "%'" + sql_year + sqldc
        results = MyUser.objects.raw(sql)
        database = Database(request.user.id)
        context = {
            'profile': results,
            'da_tung_chat': database.da_tung_chat(),
        }
        return render(request, 'home/return_user.html', context)
Exemplo n.º 7
0
 def post(self, request, hashtag):
     if request.user.is_authenticated:
         database = Database(request.user.id)
         get_post_hashtag = database.get_post_hashtag(hashtag.upper())
         posts = database.json_post(get_post_hashtag)
         return JsonResponse({'result': posts})
     else:
         return redirect('home:login')
Exemplo n.º 8
0
 def post(self, request, post_id):
     if request.user.is_authenticated:
         database = Database(request.user.id)
         get_post_id = database.get_post_id(post_id)
         posts = database.json_post(get_post_id)
         return JsonResponse({'result': posts})
     else:
         return redirect('home:login')
Exemplo n.º 9
0
def index(request):
    if request.user.is_authenticated:
        database = Database(request.user.id)
        context = {
            'profile': database.lay_thong_tin_all_user(),
            'da_tung_chat': database.da_tung_chat(),
        }
        return render(request, 'home/base.html', context)
    else:
        return render(request, 'home/login.html')
Exemplo n.º 10
0
    def get(self, request):
        if request.user.is_authenticated:
            database = Database(request.user.id)
            kt = database.get_watching(request.user.username)
            if kt:
                return render(request, 'home/home.html', {'page': 'Trang chủ Shili'})
            else:
                return render(request, 'user/all_user.html', {'page': 'all_user'})

        else:
            return render(request, 'home/index.html')
Exemplo n.º 11
0
    def post(self, request):
        if request.user.is_authenticated:
            data = json.loads(request.body.decode('utf-8'))
            database = Database()

            profile_watching = database.get_watching(data['username'])
            profile_followed = database.get_followed(data['username'])
            return JsonResponse({
                'dangtheodoi': profile_watching,
                'duoctheodoi': profile_followed
            })
        else:
            return redirect('home:home')
Exemplo n.º 12
0
 def get(self, request):
     if request.user.is_authenticated:
         database = Database()
         x = list(Post.objects.all().values('hashtag').annotate(
             soluot=Count('hashtag')).order_by('-soluot'))[:3]
         list_ht = [i["hashtag"] for i in x]
         posts = Post.objects.filter(
             hashtag__in=list_ht).order_by('-created_at')
         result = database.convert_post(posts)
         return render(request, 'home/home.html', {
             'posts': result,
             'page': 'Các bài viết nổi bật trong tuần'
         })
     else:
         return redirect('home:home')
Exemplo n.º 13
0
 def post(self, request):
     data = json.loads(request.body.decode('utf-8'))
     try:
         if data['content_input']:
             new_cm = Comment()
             new_cm.content = data['content_input']
             new_cm.user_id = request.user.id
             new_cm.post_id = data['post_id']
             new_cm.save()
             return HttpResponse(
                 'bình luận thành công, hãy tiếp tục tương tác nhé')
     except:
         pass
     database = Database(request.user.id)
     get_comment_post_id = database.get_comment_post_id(data['post_id'])
     return JsonResponse({'result': get_comment_post_id})
Exemplo n.º 14
0
 def get(self, request, post_id):
     if request.user.is_authenticated:
         x = Post.objects.filter(post=post_id)
         post = Database().convert_post(x)
         return render(request, 'home/home.html', {'posts': post})
     else:
         return redirect('home:home')
Exemplo n.º 15
0
 def post(self, request):
     if request.user.is_authenticated:
         data = json.loads(request.body.decode('utf-8'))
         user_2_id = str(data['user_2_id'])
         database = Database()
         id_room = database.check_box_chat(request.user.id, user_2_id)
         # lưu tin nhắn
         if data['content'] != '':
             Mess = Message()
             Mess.from_user = MyUser.objects.get(id=request.user.id)
             Mess.conversation = Conversation.objects.get(c_id=id_room)
             Mess.content = data['content']
             Mess.save()
         return HttpResponse('Gửi thành công rồi nhé Lalal')
     else:
         return redirect('home:home')
Exemplo n.º 16
0
    def get(self, request):
        if request.user.is_authenticated:
            database = Database()
            profile = database.get_profile(request.user.username)[0]
            posts = database.get_profile_posts(request.user.username,
                                               request.user.username)

            return render(
                request, 'user/profile.html', {
                    'posts': posts,
                    'profile': profile,
                    'username': request.user.username,
                    'page': 'profile'
                })
        else:
            return redirect('home:home')
Exemplo n.º 17
0
 def get(self, request, hashtag):
     if request.user.is_authenticated:
         posts = Post.objects.filter(
             hashtag=hashtag.upper()).order_by('-created_at')
         result = Database().convert_post(posts)
         return render(request, 'home/home.html', {'posts': result})
     else:
         return redirect('home:home')
Exemplo n.º 18
0
    def post(self, request, user_2_id):
        if request.user.is_authenticated:
            database = Database(request.user.id)
            id_room = database.id_room(request.user.id, user_2_id)
            # lưu tin nhắn
            if request.POST.get('content') != '':
                Mess = Message()
                Mess.from_user = MyUser.objects.get(id=request.user.id)
                Mess.conversation = Conversation.objects.get(c_id=id_room)
                Mess.content = request.POST.get('content')
                Mess.save()
            # in ra kết quả
            ketqua = database.context_room_chat(id_room)
            profile = database.lay_thong_tin_voi_username(user_2_id)
            context = {'ketqua': ketqua, 'profile': profile}
            return render(request, 'home/return_chat.html', context)

        else:
            return redirect('home:login')
Exemplo n.º 19
0
 def get(self, request):
     if request.user.is_authenticated:
         database = Database()
         kt = database.get_watching(request.user.username)
         if kt:
             a = Follower.objects.filter(
                 main_user=int(request.user.id)).values('followres')
             x = [i["followres"] for i in a] + [request.user.id]
             x = Post.objects.filter(user__id__in=x).exclude(
                 public="Chỉ Mình Tôi").order_by('-created_at')
             out = Database().convert_post(x)
             # return JsonResponse(out, safe=False)
             return render(request, 'home/home.html', {
                 'posts': out,
                 'page': 'Trang chủ Shili'
             })
         else:
             return render(request, 'user/all_user.html',
                           {'page': 'all_user'})
     else:
         return render(request, 'home/index.html')
Exemplo n.º 20
0
    def get(self, request, user_2_id):
        if request.user.is_authenticated:
            database = Database(request.user.id)
            id_room = database.id_room(request.user.id, user_2_id)
            if not id_room:
                try:
                    Conv = Conversation()
                    Conv.user_1 = MyUser.objects.get(id=request.user.id)
                    Conv.user_2 = MyUser.objects.get(id=user_2_id)
                    Conv.save()
                except:
                    return redirect('home:login')
            ketqua = database.context_room_chat(id_room)
            profile = database.lay_thong_tin_voi_username(user_2_id)
            context = {
                'ketqua': ketqua,
                'profile': profile,
            }
            return render(request, 'home/return_chat.html', context)

        else:
            return redirect('home:login')
Exemplo n.º 21
0
 def post(self, request):
     if request.user.is_authenticated:
         content = request.POST.get('content')
         hashtag = request.POST.get('hashtag').upper().replace(" ", "")
         feeling = request.POST.get('feeling')
         tag_friends = request.POST.get('tag_friends')
         public = request.POST.get('public')
         photo = ''
         try:
             photo = request.FILES['photo']
         except:
             pass
         new_post = Post()
         new_post.content = content
         new_post.photo = photo
         new_post.hashtag = hashtag
         new_post.feeling = feeling
         new_post.tag_friends = tag_friends
         new_post.public = public
         new_post.user = request.user
         new_post.save()
         database = Database(request.user.id)
         post_id = database.get_id_new_post()
         return redirect('post:ShowPost', post_id)
Exemplo n.º 22
0
 def post(self, request):
     if request.user.is_authenticated:
         data = json.loads(request.body.decode('utf-8'))
         user_2_id = str(data['user_2_id'])
         database = Database(request.user.id)
         username = database.id_convert_username(user_2_id)
         get_profile = database.get_profile(username)
         id_room = database.check_box_chat(request.user.id, user_2_id)
         mess_content = database.get_context_box_chat(id_room)
         if not id_room:
             try:
                 Conv = Conversation()
                 Conv.user_1 = MyUser.objects.get(id=request.user.id)
                 Conv.user_2 = MyUser.objects.get(id=user_2_id)
                 Conv.save()
             except:
                 pass
         get_profile[0]['count_mess'] = database.count_mess(id_room)
         return JsonResponse({
             'result': get_profile,
             'mess_content': mess_content
         })