def post(self): if users.get_current_user(): idTopic = self.request.get('idTopic') queryLastMessage = db.Query(Message) queryLastMessage.order("-idMessage") lastMessage = queryLastMessage.get() messagesQuery = db.GqlQuery("SELECT * FROM Message WHERE idTopic=%s" % idTopic) if(messagesQuery.count() != 0): topicPage = int(messagesQuery.count() / 20) if (messagesQuery.count() % 20): topicPage += 1 messageFromPost = re.sub('<[^>]*>', '', self.request.get('message')).replace('\n','<br />') if(messageFromPost): message = Message() message.idMessage = lastMessage.idMessage + 1 if(lastMessage.Row == 1): message.Row = 2 else: message.Row = 1 message.idTopic = int(idTopic) message.author = users.get_current_user().nickname() message.idAuthor = methods.getIdUser(users.get_current_user().nickname()) message.message = messageFromPost message.dateMessage = datetime.now().strftime('%d.%m.%y %H:%M') message.put() self.redirect('/topic?idTopic=%s&topicPage=%s' % (idTopic, topicPage)) else: self.redirect('/errorAddMessage?idTopic=%s&topicPage=%s' % (idTopic, topicPage)) else: messageFromPost = re.sub('<[^>]*>', '', self.request.get('message')).replace('\n','<br />') if(messageFromPost): message = Message() message.idMessage = 1 message.Row = 1 message.idTopic = int(idTopic) message.author = users.get_current_user().nickname() message.idAuthor = methods.getIdUser(users.get_current_user().nickname()) message.message = messageFromPost message.dateMessage = datetime.now().strftime('%d.%m.%y %H:%M') message.put() self.redirect('/topic?idTopic=%s&topicPage=1' % idTopic) else: self.redirect('/errorAddMessage?idTopic=%s&topicPage=%s' % (idTopic, topicPage)) else: self.redirect('/error')
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('/')
def post(self): if users.get_current_user(): queryLastTopic = db.Query(Topic) queryLastTopic.order("-idTopic") lastTopic = queryLastTopic.get() nameTopicFromPost = re.sub('<[^>]*>', '', self.request.get('nameTopic')) if (nameTopicFromPost): topic = Topic() if lastTopic: topic.idTopic = lastTopic.idTopic + 1 else: topic.idTopic = 1 topic.author = users.get_current_user().nickname() topic.idAuthor = methods.getIdUser(users.get_current_user().nickname()) topic.nameTopic = nameTopicFromPost topic.dateTopic = datetime.now().strftime('%d.%m.%y %H:%M') messageFromPost = re.sub('<[^>]*>', '', self.request.get('message')).replace('\n','<br />') if (messageFromPost): message = Message() message.idMessage = 1 message.Row = 1 message.idTopic = topic.idTopic message.author = users.get_current_user().nickname() message.idAuthor = methods.getIdUser(users.get_current_user().nickname()) message.message = messageFromPost message.dateMessage = datetime.now().strftime('%d.%m.%y %H:%M') message.put() topic.put() self.redirect('/topic?idTopic=%s&topicPage=1' % topic.idTopic) else: self.redirect('/errorCreateTopic') else: self.redirect('/errorCreateTopic') else: self.redirect('/forum?page=1')
def post(self): if users.get_current_user(): isUser = methods.isUser(users.get_current_user().nickname(), methods.getIdUser(self.request.get('loginGoogle'))) loginExist = True if (isUser): queryLoginExist = db.GqlQuery("SELECT * FROM UserForum ") for userForum in queryLoginExist: if (userForum.loginForum == self.request.get('login')): loginExist = False if loginExist: query = db.GqlQuery("SELECT * FROM UserForum WHERE idUser = %s" % methods.getIdUser(self.request.get('loginGoogle'))) for userForum in query: idUser = userForum.idUser if self.request.get('login'): userForum.loginForum = re.sub('<[^>]*>', '',self.request.get('login')) else: userForum.loginForum = None if self.request.get('name'): userForum.name = re.sub('<[^>]*>', '',self.request.get('name')) else: userForum.name = None if self.request.get('lastName'): userForum.lastName = re.sub('<[^>]*>', '',self.request.get('lastName')) else: userForum.lastName = None userForum.put() self.redirect('/user?id=%s' % idUser) else: self.redirect('/errorLoginExist') else: self.redirect('/')
def get(self): idTopic = self.request.get('idTopic') idMessage = self.request.get('idMessage') if(idTopic and idMessage): messageQuery = db.GqlQuery("SELECT * FROM Message WHERE idTopic=%s AND idMessage=%s" % (idTopic, idMessage)) for message in messageQuery: if(methods.getIdUser(users.get_current_user().nickname()) == message.idAuthor): message.delete() self.redirect('/successDeleteMessage?idTopic=%s' % idTopic) else: self.redirect('/error') else: self.redirect('/error')
def post(self): idTopic = self.request.get('idTopic') idMessage = self.request.get('idMessage') messageText = self.request.get('message').replace('\n','</br>') if(idTopic and idMessage and messageText): messageQuery = db.GqlQuery("SELECT * FROM Message WHERE idTopic=%s AND idMessage=%s" % (idTopic, idMessage)) for message in messageQuery: if(methods.getIdUser(users.get_current_user().nickname()) == message.idAuthor): message.message = messageText message.put() self.redirect('/successEditMessage?idTopic=%s' % idTopic) else: self.redirect('/error') else: self.redirect('/successEditMessage?idTopic=%s' % idTopic)
def get(self): greetings = methods.autorization("/editMessage") idTopic = self.request.get('idTopic') idMessage = self.request.get('idMessage') if(idTopic and idMessage): messageQuery = db.GqlQuery("SELECT * FROM Message WHERE idTopic=%s AND idMessage=%s" % (idTopic, idMessage)) for message in messageQuery: if(methods.getIdUser(users.get_current_user().nickname()) == message.idAuthor): messageText = message.message.replace('<br />','\n') template_values = { 'messageText': messageText, 'idTopic': idTopic, 'idMessage': idMessage, 'greetings': greetings } path = os.path.join(os.path.join(os.path.dirname(__file__), 'templates/forum'), 'editMessage.html') self.response.out.write(template.render(path, template_values)) else: self.redirect('/error')