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)
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')
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])
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)
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 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'))
def Settings(Request, Section='Picture'): if not GF.SESSION(Request): return StatusPages.UnAuthurithedUserPage(Request, 'Settings') if Request.method == 'POST' and URL.REFERER_is_Set(Request): if URL.GetURL(Request) == init.Settings: return Settings_PictureResponse(Request) elif URL.GetURL(Request) == init.Settings+'/Name': return Settings_NameResponse(Request) elif URL.GetURL(Request) == init.Settings+'/Password': return Settings_PasswordResponse(Request) elif URL.GetURL(Request) == init.Settings+'/DeActivate': if 'DeactivateSubmit' in Request.POST: return Settings_Account(Request, 1) return Settings_Account(Request, 0) return Settings_Render(Request, Section, Request.GET["Result"] if 'Result' in Request.GET else '')
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'])