Пример #1
0
	def post(self):
		if users.get_current_user():
			admin =  methods.isAdmin(users.get_current_user().nickname())
			if (admin):

				User = methods.getUserById(methods.getIdUser(self.request.get('login')))
		
				if User:
					User.position = "admin"
					User.put()
					self.redirect('/user?id=%s' % methods.getIdUser(self.request.get('login'))) 
		 		
				else:
					User = methods.getUserById(methods.getIdUserForum(self.request.get('login')))
					User.position = "admin"
					User.put()
					self.redirect('/user?id=%s' % methods.getIdUserForum(self.request.get('login')))
			else:
				self.redirect('/error')
		else:
			self.redirect('/')
Пример #2
0
	def get(self):
		if users.get_current_user():
			greetings = methods.autorization("/topic?idTopic=1&topicPage=1")

			if (self.request.get('idTopic') and self.request.get('topicPage')):

				idTopic = self.request.get('idTopic')
				topicPagePost = True

				try:				
					topicPage = int(self.request.get('topicPage'))
					topicQuery = db.GqlQuery("SELECT * FROM Topic WHERE idTopic = %s" % idTopic)
				except:
					topicPagePost = False
				
				if topicPagePost:

					topic = topicQuery.get()	
			    		
					user = methods.getUserById(topic.idAuthor)
					if (user.loginForum):
						topic.author = user.loginForum
						topic.put()

					messagesQuery = db.GqlQuery("SELECT * FROM Message WHERE idTopic = %s ORDER BY idMessage" % idTopic)
					if (messagesQuery.count() != 0):

						for message in messagesQuery:
							user = methods.getUserById(message.idAuthor)
							if (user.loginForum):
								message.author = user.loginForum
								message.put()
							if(methods.isUser(users.get_current_user().nickname(), message.idAuthor)):
								message.isAuthor = True
								message.put()
							else:
								message.isAuthor = False
								message.put()
				
					else:
						countPages = 1;

					messagesOnPage = []
					startMessage = topicPage * 20 - 19
					endMessage = startMessage + 19
					count = 1
					for message in messagesQuery:
						if (count >= startMessage and count <= endMessage):
							messagesOnPage.append(message)
						count += 1
			
					countPages = int(messagesQuery.count() / 20)
					if (messagesQuery.count() % 20):
						countPages += 1
		

					visibleAllPages = []
					visibleStartPages = []
					visibleMiddlePages = []
					visibleEndPages = []

					if countPages < 10:
						for count in range(countPages):
							visibleAllPages.append(count + 1)
						visibleStartSeparator = False
						visibleEndSeparator = False
					elif (topicPage < 6):
						if (topicPage < 3):
							for page in range(3):
								visibleStartPages.append(page + 1)
						else:
							for page in range(topicPage + 1):
								visibleStartPages.append(page + 1)
						visibleStartSeparator = False
						visibleEndSeparator = True
						visibleEndPages.append(countPages - 2)
						visibleEndPages.append(countPages - 1)
						visibleEndPages.append(countPages)
			
					elif (topicPage > countPages - 5):
						visibleStartPages.append(1)
						visibleStartPages.append(2)
						visibleStartPages.append(3)
						visibleStartSeparator = True
						visibleEndSeparator = False
						if (topicPage > countPages - 2):
							visibleEndPages.append(countPages - 2)
							visibleEndPages.append(countPages - 1)
							visibleEndPages.appealend(countPages)
						else:
							visibleEndPages.append(topicPage - 1)
							visibleEndPages.append(topicPage)
							count = topicPage + 1
							while count <= countPages:
								visibleEndPages.append(count)
								count += 1
					else:	
						visibleStartPages.append(1)
						visibleStartPages.append(2)
						visibleStartPages.append(3)
						visibleStartSeparator = True
						visibleMiddlePages.append(topicPage - 1)
						visibleMiddlePages.append(topicPage)
						visibleMiddlePages.append(topicPage + 1)
						visibleEndSeparator = True
						visibleEndPages.append(countPages - 2)
						visibleEndPages.append(countPages - 1)
						visibleEndPages.append(countPages)

					admin = methods.isAdmin(users.get_current_user().nickname())
					template_values = {
								'greetings' : greetings,
								'admin' : admin,
			      					'messages': messagesOnPage,
								'topic': topic,
								'visibleAllPages' : visibleAllPages,
								'visibleStartPages' : visibleStartPages,
								'visibleStartSeparator' : visibleStartSeparator,
								'visibleMiddlePages' : visibleMiddlePages,
								'visibleEndPages' : visibleEndPages,
								'visibleEndSeparator' : visibleEndSeparator
							  }

					path = os.path.join(os.path.join(os.path.dirname(__file__), 'templates/forum'), 'topic.html')
					self.response.out.write(template.render(path, template_values))

				else:
					self.redirect('/forum?page=1')
			else:
				self.redirect('/forum?page=1')
		else:
			self.redirect('/forum?page=1')
Пример #3
0
	def get(self):
		if (self.request.get('page')):
			pagePost = True

			try:
				page = int(self.request.get('page'))
			except:
				pagePost = False
			if (pagePost):
				greetings = methods.autorization("/forum?page=1")
		
				if users.get_current_user():
					isLogin = True
				else:
					isLogin = False
			
				topicsQuery = db.GqlQuery("SELECT * FROM Topic ORDER BY dateTopic DESC")
				for topic in topicsQuery:
					user = methods.getUserById(topic.idAuthor)
					if (user.loginForum):
						topic.author = user.loginForum
						topic.put()

		
	
				countPages = int(topicsQuery.count()/20)
				if (topicsQuery.count()%20):
					countPages += 1
		
				topicsOnPage = []
				startTopic = page * 20 - 19
				endTopic = startTopic + 19
				count = 1
				for topic in topicsQuery:
					if (count >= startTopic and count <= endTopic):
						topicsOnPage.append(topic)
					count += 1
			
				countPages = int(topicsQuery.count() / 20)
				if (topicsQuery.count() % 20):
					countPages += 1

				visibleAllPages = []
				visibleStartPages = []
				visibleMiddlePages = []
				visibleEndPages = []

				if countPages < 10:
					for count in range(countPages):
						visibleAllPages.append(count + 1)
					visibleStartSeparator = False
					visibleEndSeparator = False

				elif (page < 6):
					if (page < 3):
						for pageForum in range(3):
							visibleStartPages.append(pageForum + 1)
					else:
						for pageForum in range(page + 1):
							visibleStartPages.append(pageForum + 1)
					visibleStartSeparator = False
					visibleEndSeparator = True
					visibleEndPages.append(countPages - 2)
					visibleEndPages.append(countPages - 1)
					visibleEndPages.append(countPages)
			
				elif (page > countPages - 5):
					visibleStartPages.append(1)
					visibleStartPages.append(2)
					visibleStartPages.append(3)
					visibleStartSeparator = True
					visibleEndSeparator = False
					if (page > countPages - 2):
						visibleEndPages.append(countPages - 2)
						visibleEndPages.append(countPages - 1)
						visibleEndPages.append(countPages)
					else:
						visibleEndPages.append(page - 1)
						visibleEndPages.append(page)
						count = page + 1
						while count <= countPages:
							visibleEndPages.append(count)
							count += 1
				else:	
					visibleStartPages.append(1)
					visibleStartPages.append(2)
					visibleStartPages.append(3)
					visibleStartSeparator = True
					visibleMiddlePages.append(page - 1)
					visibleMiddlePages.append(page)
					visibleMiddlePages.append(page + 1)
					visibleEndSeparator = True
					visibleEndPages.append(countPages - 2)
					visibleEndPages.append(countPages - 1)
					visibleEndPages.append(countPages)

				template_values = {
							'isLogin' : isLogin,
		      					'greetings': greetings,
							'topics': topicsOnPage,
							'countPages' : countPages, 
							'visibleAllPages' : visibleAllPages,
							'visibleStartPages' : visibleStartPages,
							'visibleStartSeparator' : visibleStartSeparator,
							'visibleMiddlePages' : visibleMiddlePages,
							'visibleEndPages' : visibleEndPages,
							'visibleEndSeparator' : visibleEndSeparator
		      				   }
		
				path = os.path.join(os.path.join(os.path.dirname(__file__), 'templates/forum'), 'forum.html')
				self.response.out.write(template.render(path, template_values))
			else:
				self.redirect('/forum?page=1')
		else:
			self.redirect('/forum?page=1')