Example #1
0
def Like_DisLikePost(Request):
    Form = LikeDisLikeForm(Request.POST)
    Result = CheckPost(Request, Form)

    if Result['Result'] != 1:
        if Result['Data'] == 'Not Valid':
            return StatusPages.UnAuthurithedUserPage(Request, 'Un Authorized User')
        return JsonResponse(Result)

    Post_Like_DisLike = LikesDisLikes.objects.filter(Post_id=Form.GetID(),
                                                     User_Email=Hashing.Hash_LikeDisLike(
                                                         Request.session["Email"]))
    if Post_Like_DisLike.exists():
        return JsonResponse(GF.Returns(0, 'You Already ' +
                                       ('Liked' if Post_Like_DisLike[0].Status == 0 else 'DisLiked')))

    LikeOrDisLike = LikesDisLikes(Post_id=Form.GetID(),
                                  User_Email=Hashing.Hash_LikeDisLike(Request.session["Email"]),
                                  Status=Form.GetType())
    LikeOrDisLike.save()

    if Request.session["Email"] != Result['Data']['Email']:
        Notification = Notifications(Type=(Form.GetType()+1),
                                     User_Email=Hashing.Hash_Notifications(
                                         Result['Data']['Email']),
                                     Message=Hashing.Hash_Notifications(
                                         json.dumps({
                                             'Email': Request.session["Email"],
                                             'PostID': Form.GetID()
                                         })
                                     ))
        Notification.save()
    return JsonResponse(GF.Returns(1, 'Done'))
Example #2
0
def GetMoreNotifications(Request):
    if not GF.SESSION(Request) or not URL.REFERER_is_Set(Request):
        return StatusPages.UnAuthurithedUserPage(Request, 'Un Authorized User')

    if URL.GetREFERER(Request) != init.Notifications:
        return StatusPages.UnAuthurithedUserPage(Request, 'Un Authorized User')

    Form = CheckPostsNumberForm(Request.POST)
    if not Form.isValid():
        return JsonResponse(GF.Returns(-1, 'Not Valid Number'))

    index = int(Form.GetNumber())
    Slice = slice(index, index + 7)
    The_Notifications = Notifications.objects.filter(User_Email=Hashing.Hash_Notifications(
        Request.session["Email"])).order_by('-id')[Slice]

    if not len(The_Notifications):
        return JsonResponse(GF.Returns(0, 'No Data'))

    Result = GF.Returns(1, {
        'Notifications': {},
        'Count': 0
    })
    Count = 0

    for Notification in The_Notifications:
        Text = GetTheWholeNotification(Notification)
        if Text != '':
            Count += 1
            Result['Data']['Notifications'][str(Count)] = Text

    Result['Data']['Count'] = Count
    return JsonResponse(Result)
Example #3
0
def MyNotifications(Request):
    if not GF.SESSION(Request):
        return StatusPages.UnAuthurithedUserPage(Request, 'My Notifications')

    UserNotifications = Notifications.objects.filter(User_Email=Hashing.Hash_Notifications(
        Request.session["Email"]
    )).order_by('-id')[:7]
    return MyNotifications_Render(Request, UserNotifications)
Example #4
0
def MakeComment(Request):
    Form = MakeCommentForm(Request.POST)
    Result = CheckPost(Request, Form)

    if Result['Result'] != 1:
        if Result['Data'] == 'Not Valid':
            return StatusPages.UnAuthurithedUserPage(Request, 'Un Authorized User')
        return JsonResponse(Result)

    Comment = Comments(Post_id=Form.GetID(),
                       User_Email=Hashing.Hash_Comments(Request.session["Email"]),
                       Comment=Hashing.Hash_Comments(Form.GetComment()))
    Comment.save()
    Comment = Comments.objects.filter().order_by('-id')[:1]
    if not Comment.exists():
        Comment = ''
    else:
        Comment = Comment[0].id

    if Request.session["Email"] != Result['Data']['Email']:
        Notification = Notifications(Type=3,
                                     User_Email=Hashing.Hash_Notifications(
                                         Result['Data']['Email']),
                                     Message=Hashing.Hash_Notifications(
                                         json.dumps({
                                             'Email': Request.session["Email"],
                                             'PostID': Form.GetID(),
                                             'Comment': Comment
                                         })
                                     ))
        Notification.save()

    return JsonResponse(GF.Returns(1, Div(
        Div(A(init.User+str(Request.session["ID"]), InputImage(Request.session["Picture"])) +
            Div(P('By : '+Request.session["Name"]) +
                P('Date : '+str(datetime.datetime.now())))) +
        Div(P(GetText(Form.GetComment())), 'Comment_Text')
        , 'Comments')))
Example #5
0
def GetNotifications(Request):
    if not SESSION(Request):
        return ''
    return Notifications.objects.filter(User_Email=Hashing.Hash_Notifications(
        Request.session["Email"]
    )).order_by('-id')[:3]