def Filter_Comment(Comment): Result = Hashing.GetAllFromHashing([{ 'Type': 'Comments', 'Data': Comment.User_Email, 'Key': 'Email' }, { 'Type': 'Comments', 'Data': Comment.Comment, 'Key': 'Comment' }, { 'Type': 'Date', 'Data': Comment.Date, 'Key': 'Date' }, { 'Type': '', 'Data': Comment.id, 'Key': 'ID' }]) if Result['Result'] == -1: return Returns(-1, 'Searching For User', Result['Error']) User = Users.objects.filter(Email=Hashing.Hash_Users( Result['Data']['Email']), Deleted='0', Activate='1') if not User.exists(): return Returns(0, 'Not Found') Filtered_Comment = Result['Data'] Result = Hashing.GetAllFromHashing([{ 'Type': 'Users', 'Data': User[0].Name, 'Key': 'Name' }, { 'Type': 'Users', 'Data': User[0].Picture, 'Key': 'Picture' }, { 'Type': '', 'Data': User[0].id, 'Key': 'id' }]) if Result['Result'] == -1: return Returns(-1, 'Getting User Name From Hashing') Filtered_Comment['Name'] = Result['Data']['Name'] Filtered_Comment['Picture'] = Result['Data']['Picture'] Filtered_Comment['id'] = Result['Data']['id'] return Returns(1, Filtered_Comment)
def GetUserName(User): Result = Hashing.GetAllFromHashing([{ 'Type': 'Users', 'Data': User.Name, 'Key': 'Name' }]) return 'UnKnown' if Result['Result'] == -1 else Result['Data']['Name']
def GetPost(Article, args='0'): Result = CheckUser(Article.User_Email) if Result['Result'] != 1: return '' Result = Hashing.GetAllFromHashing([{ 'Type': 'Articles', 'Data': Article.ArticleTitle, 'Key': 'Title' }, { 'Type': 'Articles', 'Data': Article.Article, 'Key': 'Article' }, { 'Type': 'Articles', 'Data': Article.Tags, 'Key': 'Tags' }, { 'Type': 'Date', 'Data': Article.Date, 'Key': 'Date' }, { 'Type': '', 'Data': Result['Data']['Name'], 'Key': 'Name' }, { 'Type': '', 'Data': Result['Data']['Picture'], 'Key': 'Picture' }, { 'Type': '', 'Data': Result['Data']['ID'], 'Key': 'ID' }]) if Result['Result'] == -1: return '' Likes = LikesDisLikes.objects.filter(Post_id=Article.id, Status=0).count() DisLikes = LikesDisLikes.objects.filter(Post_id=Article.id, Status=1).count() CommentsCount = Comments.objects.filter(Post_id=Article.id).count() return Div( Div( Div( A(init.User + str(Result['Data']['ID']), InputImage(init.OnlineUser))) + Div( P(Strong('By ') + ' : ' + Result['Data']['Name']) + P(Strong('Date ') + ' : ' + Result['Data']['Date'])) + GetOptions(str(Article.id), args), 'Article_Header') + P(Strong('Title : ') + Result['Data']['Title'], 'Article_Title') + P( Strong('Tags : ') + GetArticleTags(Result['Data']['Tags']), 'Article_Tags') + Div(P(GetText(Result['Data']['Article'], 2))) + Div(A(init.Article + str(Article.id), 'The Link To Full Article'), 'Article_Link') + Div( P(Span('Likes ') + str(Likes)) + P(Span('DisLikes ') + str(DisLikes)) + P(Span('Comments ') + str(CommentsCount)), 'Article_Statics'), 'Article', 'Post' + str(Article.id))
def GetPostTitle(Article): Result = Hashing.GetAllFromHashing([{ 'Type': 'Articles', 'Data': Article.ArticleTitle, 'Key': 'Title' }]) return 'UnKnown' if Result['Result'] == -1 else Result['Data']['Title']
def GetUserPicture(User): Result = Hashing.GetAllFromHashing([{ 'Type': 'Users', 'Data': User.Picture, 'Key': 'Picture' }]) return OnlineUser if Result['Result'] == -1 else Result['Data']['Picture']
def GetArticlePost(Article): Result = Hashing.GetAllFromHashing([{ 'Type': 'Articles', 'Data': Article.Article, 'Key': 'Article' }]) return P('Error in Getting Post') if Result['Result'] == -1 else GetText( Result['Data']['Article'])
def GetArticleTags(Article): Result = Hashing.GetAllFromHashing([{ 'Type': 'Articles', 'Data': Article.Tags, 'Key': 'Tags' }]) return Span('No Tags') if Result['Result'] == -1 else GetTags( Result['Data']['Tags'])
def GetUserComments(User): Result = Hashing.GetAllFromHashing([{ 'Type': 'Users', 'Data': User.Email, 'Key': 'Email' }]) if Result['Result'] == -1: return '0' return Comments.objects.filter( User_Email=Hashing.Hash_Comments(Result['Data']['Email'])).count()
def GetUserDisLikes(User): Result = Hashing.GetAllFromHashing([{ 'Type': 'Users', 'Data': User.Email, 'Key': 'Email' }]) if Result['Result'] == -1: return '0' return LikesDisLikes.objects.filter(User_Email=Hashing.Hash_LikeDisLike( Result['Data']['Email']), Status=1).count()
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()
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)
def GetNotification(Notification): Result = Hashing.GetAllFromHashing([{ 'Type': 'Notifications', 'Data': Notification.User_Email, 'Key': 'Email' }, { 'Type': '', 'Data': Notification.Type, 'Key': 'Type' }, { 'Type': 'Notifications', 'Data': Notification.Message, 'Key': 'Message' }]) if Result['Result'] == -1: return '' Data = json.loads(Result['Data']['Message']) User = Users.objects.filter(Email=Hashing.Hash_Users(Data['Email']), Deleted=0) if not User.exists(): User = '' else: Hash = Hashing.Get_Hashed_Users(User[0].Name) if Hash['Result'] == -1: User = '' else: User = Hash['Data'] Post = Posts.objects.filter(id=Data['PostID'], Deleted=0) if not Post.exists(): Title = '' else: Hash = Hashing.Get_Hashed_Articles(Post[0].ArticleTitle) if Hash['Result'] == -1: Title = '' else: Title = Hash['Data'] User = Span(User, 'Green') Title = Span(Title, 'Green') if Result['Data']['Type'] == 1: Message = 'User : '******' Liked Your Post : ' + Title elif Result['Data']['Type'] == 2: Message = 'User : '******' DisLiked Your Post : ' + Title elif Result['Data']['Type'] == 3: Message = 'User : '******' Commented in Your Post : ' + Title else: Message = 'User : '******' Added New Tag in Your Post : ' + Title return Div(P(Message))
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)
def CheckUser(Email): Result = Hashing.GetAllFromHashing([{ 'Type': 'Articles', 'Data': Email, 'Key': 'Email' }]) if Result['Result'] == -1: return Returns(-1, 'Searching For User', Result['Error']) User = Users.objects.filter(Email=Hashing.Hash_Users( Result['Data']['Email']), Deleted='0', Activate='1') if not User.exists(): return Returns(0, 'Not Found') Result = Hashing.GetAllFromHashing([{ 'Type': 'Users', 'Data': User[0].Name, 'Key': 'Name' }, { 'Type': 'Users', 'Data': User[0].Picture, 'Key': 'Picture' }, { 'Type': '', 'Data': User[0].id, 'Key': 'ID' }, { 'Type': '', 'Data': Result['Data']['Email'], 'Key': 'Email' }]) if Result['Result'] == -1: return Returns(-1, 'Searching For User', Result['Error']) return Returns(1, Result['Data'])
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'])
def CheckPost(Request, Form): if not Form.isValid() or not GF.SESSION(Request) or not URL.REFERER_is_Set(Request): return GF.Returns(-1, 'Not Valid') if not URL.GetREFERER(Request) == init.Article + str(Form.GetID()): return GF.Returns(-1, 'Not Valid') Post = Posts.objects.filter(Deleted='0', id=Form.GetID()) if not Post.exists(): return GF.Returns(0, 'Post Not Found') if ASF.CheckUser(Post[0].User_Email)['Result'] != 1: return GF.Returns(0, 'Post Not Found') Result = Hashing.GetAllFromHashing([{'Type': 'Articles', 'Data': Post[0].User_Email, 'Key': 'Email'}]) if Result['Result'] == -1: return GF.Returns(-1, 'Searching For User', Result['Error']) return GF.Returns(1, Result['Data'])
def GetTheWholeNotification(Notification): Result = Hashing.GetAllFromHashing([{ 'Type': 'Notifications', 'Data': Notification.User_Email, 'Key': 'Email' }, { 'Type': '', 'Data': Notification.Type, 'Key': 'Type' }, { 'Type': 'Notifications', 'Data': Notification.Message, 'Key': 'Message' }, { 'Type': 'Date', 'Data': Notification.Date, 'Key': 'Date' }]) if Result['Result'] == -1: return '' Data = json.loads(Result['Data']['Message']) Comment = Data['Comment'] if 'Comment' in Data else '' User = Users.objects.filter(Email=Hashing.Hash_Users(Data['Email']), Deleted=0, Activate=1) if not User.exists(): UserName = '' UserPicture = init.OfflineUser UserID = '' else: Hash = Hashing.GetAllFromHashing([{ 'Type': 'Users', 'Data': User[0].Name, 'Key': 'Name' }, { 'Type': '', 'Data': User[0].id, 'Key': 'ID' }, { 'Type': 'Users', 'Data': User[0].Picture, 'Key': 'Picture' }]) if Hash['Result'] == -1: UserName = '' UserPicture = init.OfflineUser UserID = '' else: UserName = Hash['Data']['Name'] UserPicture = Hash['Data']['Picture'] UserID = Hash['Data']['ID'] Post = Posts.objects.filter(id=Data['PostID'], Deleted=0) if not Post.exists(): Title = '' else: Hash = Hashing.Get_Hashed_Articles(Post[0].ArticleTitle) if Hash['Result'] == -1: Title = '' else: Title = Hash['Data'] if Notification.See == 0: Class = 'Notification DidNotSeeNotification' else: Class = 'Notification' from Register.models import Notifications Notifications.objects.filter(id=Notification.id).update(See=1) Title = Strong(Title) if Result['Data']['Type'] == 1: Message = 'This User Liked Your Post : ' + Title elif Result['Data']['Type'] == 2: Message = 'This User DisLiked Your Post : ' + Title elif Result['Data']['Type'] == 3: Message = 'This User Commented in Your Post : ' + Title else: Message = 'This User Added New Tag To Your Post : ' + Title return Div( Div( A(init.User + str(UserID), InputImage(UserPicture)) + Div( P(Strong('By : ') + UserName) + P(Strong('Date : ') + Result['Data']['Date']))) + Div( P(Message) + A(GetLink(Data['PostID'], Result['Data']['Type'], Comment), 'The Link For Article')), Class)