Ejemplo n.º 1
0
def MakeArticle_POSTResponse(Request, Form):
    Post = Posts(User_Email=Hashing.Hash_Articles(Request.session["Email"]),
                 ArticleTitle=Hashing.Hash_Articles(Form.GetTitle()),
                 Article=Hashing.Hash_Articles(Form.GetArticle()),
                 Deleted=0,
                 Tags=Hashing.Hash_Articles(Form.GetTags()))
    Post.save()
    Request.session["Articles_Number"] += 1
    return HttpResponseRedirect(init.MakeArticle + '?Done')
Ejemplo n.º 2
0
def GetPosts(Request):
    Form = CheckPostsNumberForm(Request.POST)
    if not Form.isValid():
        return JsonResponse(GF.Returns(-1, 'Not Valid Number'))

    Options = '0'
    Articles = ''
    index = int(Form.GetNumber())
    Slice = slice(index, index + 5)

    if URL.REFERER_is_Set(Request):

        if URL.GetREFERER(Request) == init.Articles+ '/':
            Options = '0'
            Articles = Posts.objects.filter(Deleted=0)[Slice]

        elif URL.GetREFERER(Request) == init.MyProfile:
            Options = '1'
            Articles = Posts.objects.filter(User_Email=Hashing.Hash_Articles(
                Request.session["Email"]), Deleted=0)[Slice]
        else:
            Match = re.search(r'' + init.User + '(\d)+', URL.GetREFERER(Request))
            if not Match:
                return StatusPages.UnAuthurithedUserPage(Request, 'Un Authorized User')
            User = Users.objects.filter(id=Match.group(1))
            if not User.exists():
                return StatusPages.UnAuthurithedUserPage(Request, 'Un Authorized User')
            Result = Hashing.GetAllFromHashing([{
                'Type': 'Users', 'Data': User[0].Email, 'Key': 'Email'}])
            if Result['Result'] == -1:
                return GF.Returns(-1, 'Getting Data From Hashing', Result['Result']['Error'])

            Articles = Posts.objects.filter(User_Email=Hashing.Hash_Articles(
                Result['Data']['Email']), Deleted=0)[Slice]
            Options = '2'

    if not Articles.exists():
        return JsonResponse(GF.Returns(0, 'No Data'))

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

    for Article in Articles:
        Text = ASF.GetPost(Article, Options)
        if Text != '':
            Count += 1
            Result['Data']['Posts'][str(Count)] = Text

    Result['Data']['Count'] = Count
    return JsonResponse(Result)
Ejemplo n.º 3
0
def MakeArticle(Request):
    if not GF.SESSION(Request):
        return StatusPages.UnAuthurithedUserPage(Request, 'Make Article')

    if Request.method == 'POST' and URL.REFERER_is_Set(Request):
        Form = MakeArticleForm(Request.POST)
        if Form.isValid() and URL.GetREFERER(Request) == init.MakeArticle:
            return MakeArticle_POSTResponse(Request, Form)

    Post = Posts.objects.filter(User_Email=Hashing.Hash_Articles(
        Request.session["Email"]),
                                Deleted=0).order_by('-id')[:1]
    if not Post.exists():
        Article_id = ''
    else:
        Article_id = Post[0].id

    if 'Done' in Request.GET:
        Result = {
            'id': Article_id,
            'GetButtonValue': 'Make New Article',
            'GetResult': 'Done',
            'GetPage': ''
        }
        return Render.MakeOrEditSuccess_Render(Request, 'Make Article', Result)

    return Render.__Render(Request, init.MakeArticle_Template, 'Make Article')
Ejemplo n.º 4
0
def DeletePost(Request):
    Form = CheckPostsNumberForm(Request.POST)
    if not Form.isValid() or not URL.REFERER_is_Set(Request) or not GF.SESSION(Request):
        return StatusPages.UnAuthurithedUserPage(Request, 'Un Authorized User')

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

    if not Posts.objects.filter(User_Email=Hashing.Hash_Articles(Request.session["Email"]),
                                Deleted=0, id=Form.GetNumber()).exists():
        return JsonResponse(GF.Returns(0, 'Post Not Found'))

    Posts.objects.filter(User_Email=Hashing.Hash_Articles(Request.session["Email"]),
                         id=Form.GetNumber()).update(Deleted=1)

    Request.session["Articles_Number"] -= 1
    return JsonResponse(GF.Returns(1, 'Deleted'))
Ejemplo n.º 5
0
def MyProfile(Request):
    if not GF.SESSION(Request):
        return StatusPages.UnAuthurithedUserPage(Request, 'My Profile')

    return __Render(Request, init.MyProfile_Template, 'My Profile',
                    A=Posts.objects.filter(User_Email=Hashing.Hash_Articles(
                        Request.session["Email"]),
                                    Deleted='0')[:5])
Ejemplo n.º 6
0
def GetUserArticlesNumber(User):
    Result = Hashing.GetAllFromHashing([{
        'Type': 'Users',
        'Data': User.Email,
        'Key': 'Email'
    }])
    if Result['Result'] == -1:
        return 'UnKnown'
    return Posts.objects.filter(User_Email=Hashing.Hash_Articles(
        Result['Data']['Email']),
                                Deleted=0).count()
Ejemplo n.º 7
0
def UserProfile(Request, User_id):
    User = Users.objects.filter(id=User_id, Activate=1, Deleted=0)
    if not User.exists():
        return StatusPages.NotFoundPage(Request, 'User')

    Result = Hashing.GetAllFromHashing([{'Type': 'Users', 'Data': User[0].Email, 'Key': 'Email'}])
    if Result['Result'] == -1:
        return StatusPages.ErrorPage(Request, 'User')

    Articles = Posts.objects.filter(User_Email=Hashing.Hash_Articles(Result['Data']['Email']),
                                    Deleted=0)[:5]

    return UserProfile_Render(Request, User[0], Articles)
Ejemplo n.º 8
0
def EditArticle(Request, Article_id):
    if not GF.SESSION(Request):
        return StatusPages.UnAuthurithedUserPage(Request, 'Edit Article')

    Post = Posts.objects.filter(User_Email=Hashing.Hash_Articles(
        Request.session["Email"]),
                                id=Article_id,
                                Deleted=0)
    if not Post.exists():
        return StatusPages.NotFoundPage(Request, 'Edit Article')

    if Request.method == 'POST' and URL.REFERER_is_Set(Request):
        Form = MakeArticleForm(Request.POST)
        if Form.isValid() and URL.GetREFERER(
                Request) == init.EditArticle + str(Post[0].id):
            return EditArticle_POSTResponse(Form, Article_id)

    Result = Hashing.GetAllFromHashing([{
        'Type': 'Articles',
        'Data': Post[0].Article,
        'Key': 'Post'
    }, {
        'Type': 'Articles',
        'Data': Post[0].ArticleTitle,
        'Key': 'Title'
    }, {
        'Type': 'Articles',
        'Data': Post[0].Tags,
        'Key': 'Tags'
    }])

    if Result['Result'] == -1:
        return StatusPages.ErrorPage(Request, 'Edit Article')

    if 'Edited' in Request.GET:
        Result = {
            'id': Article_id,
            'GetButtonValue': 'Edit This Article',
            'GetResult': 'Edited',
            'GetPage': ''
        }
        return Render.MakeOrEditSuccess_Render(Request, 'Edit Article', Result)

    return Render.EditArticle_Render(
        Request, 'Edited' if 'Edited' in Request.GET else '',
        Result['Data']['Title'], Result['Data']['Post'],
        Result['Data']['Tags'])
Ejemplo n.º 9
0
def EditArticle_POSTResponse(Form, Article_id):
    Posts.objects.filter(id=Article_id).update(
        Article=Hashing.Hash_Articles(Form.GetArticle()),
        ArticleTitle=Hashing.Hash_Articles(Form.GetTitle()),
        Tags=Hashing.Hash_Articles(Form.GetTags()))
    return HttpResponseRedirect(init.EditArticle + str(Article_id) + '?Edited')