def post(self): forum = Forum.from_url(self.request.path_info) is_admin = users.is_current_user_admin() # Only admins can move topics if not forum or not is_admin: return self.redirect("/") try: forumto = Forum.from_url(self.request.get('forumto')) topic = db.get( db.Key.from_path( 'Topic', int(self.request.get('id')) ) ) except ValueError: return self.redirect(forum.root()) if topic and forumto: topic.forum = forumto topic.put() forum.num_topics -= 1 forum.num_posts -= topic.ncomments forum.put() forumto.num_topics += 1 forumto.num_posts += topic.ncomments forumto.put() return self.redirect(forum.root())
def get(self): forum = Forum.from_url(self.request.path_info) user = users.get_current_user() is_admin = users.is_current_user_admin() if not forum or (forum.is_disabled and not is_admin): return self.redirect("/") if not is_admin and not self.settings.check_ip(self.request.remote_addr): return self.response.out.write('Your IP address has been banned') if not is_admin and not self.settings.check_user( user ): return self.redirect( users.create_login_url("/") ) offset, topics = Topic.getlist(forum, is_admin=is_admin, offset=self.request.get("from") or None) for topic in topics: topic.excerpt = Post.gql("WHERE topic = :1 ORDER BY created_on", topic)[0].get_excerpt() tvals = { 'user': user, 'analytics_code': forum.analytics_code or "", 'siteurl': self.request.url, 'isadmin': is_admin, 'forum' : forum, 'forum_urls': [f.url for f in Forum.all()], 'topics': topics, 'offset': offset, 'login_url': users.create_login_url(forum.root()), 'logout_url': users.create_logout_url(forum.root()) } self.template_out("skins/default/topic_list.html", tvals)
def get(self): forum = Forum.from_url(self.request.path_info) is_admin = users.is_current_user_admin() # Only admins can delete or undelete posts if not forum or not is_admin: return self.redirect("/") try: topic = db.get( db.Key.from_path( 'Topic', int(self.request.get('id')) ) ) except ValueError: return self.redirect( forum.root() ) if topic: topic.is_locked = not topic.is_locked topic.put() return self.redirect( forum.root() )
def get(self): forum = Forum.from_url(self.request.path_info) is_admin = users.is_current_user_admin() user = users.get_current_user() if not forum or (forum.is_disabled and not is_admin): return self.redirect("/") if not is_admin and not self.settings.check_ip(self.request.remote_addr): return self.response.out.write('Your IP address has been banned') if not is_admin and not self.settings.check_user( user ): return self.redirect( users.create_login_url("/") ) try: topic_id = int( self.request.get('id') or 0 ) except ValueError: topic_id = 0 if not topic_id: return self.redirect(forum.root()) topic = db.get( db.Key.from_path('Topic', topic_id) ) if not topic or (topic.is_deleted and not is_admin): return self.redirect(forum.root()) # TODO: Make Pagination if is_admin: posts = Post.gql("WHERE topic = :1 ORDER BY created_on", topic) else: posts = Post.gql("WHERE topic = :1 AND is_deleted = False ORDER BY created_on", topic) tvals = { 'user': user, 'analytics_code' : forum.analytics_code or "", 'isadmin': is_admin, 'forum': forum, 'topic': topic, 'posts': posts, 'login_url' : users.create_login_url(self.request.url), 'logout_url' : users.create_logout_url(self.request.url) } self.template_out("skins/default/topic.html", tvals)
def get(self): forum = Forum.from_url(self.request.path_info) is_admin = users.is_current_user_admin() # Only admins can delete or undelete posts if not forum or not is_admin: return self.redirect("/") try: post = db.get( db.Key.from_path( 'Post', int( self.request.get('id') ) ) ) except ValueError: return self.redirect(forum.root()) topic = post.topic first = Post.gql("WHERE topic=:1 ORDER BY created_on", topic).get() if not post or topic.forum.key() != forum.key(): return self.redirect(forum.root()) if post.is_deleted: post.is_deleted = False if first.key() == post.key(): topic.is_deleted = False forum.num_topics += 1 forum.num_posts += topic.ncomments else: topic.ncomments += 1 if not topic.is_deleted: forum.num_posts += 1 else: post.is_deleted = True if first.key() == post.key(): topic.is_deleted = True forum.num_topics -= 1 forum.num_posts -= topic.ncomments else: topic.ncomments -= 1 forum.num_posts -= 1 post.put() topic.put() forum.put() return self.redirect( "%stopic?id=%s" % (forum.root(), topic.id) )
def get(self): is_admin = users.is_current_user_admin() forum = Forum.from_url(self.request.path_info) user = users.get_current_user() if not forum or (forum.is_disabled and not is_admin): return self.redirect("/") if not is_admin and not self.settings.check_ip(self.request.remote_addr): return self.response.out.write('Your IP address has been banned') if not is_admin and not self.settings.check_user( user ): return self.redirect( users.create_login_url("/") ) # Get user either by google user id or cookie if user: fuser = FofouUser.gql("WHERE user = :1", user).get() else: fuser = FofouUser.gql("WHERE cookie = :1", self.cookie ).get() tvals = { 'user': user, 'isadmin': is_admin, 'forum': forum, 'fuser': fuser or { 'email': user.email() if user else "", 'name': user.nickname() if user else "", 'remember_me': True }, 'post': { 'subject': '' }, 'login_url' : users.create_login_url(self.request.url), 'logout_url' : users.create_logout_url(self.request.url) } topic_id = self.request.get('id') if topic_id: tvals['topic'] = db.get(db.Key.from_path('Topic', int(topic_id))) if not tvals['topic']: return self.redirect( forum.root() ) self.template_out("skins/default/post.html", tvals)
def post(self): forum = Forum.from_url(self.request.path_info) is_admin = users.is_current_user_admin() user = users.get_current_user() if not forum or (forum.is_disabled and not is_admin): return self.redirect("/") if not is_admin and not self.settings.check_ip(self.request.remote_addr): return self.response.out.write('Your IP address has been banned') if not is_admin and not self.settings.check_user( user ): return self.redirect( users.create_login_url("/") ) name = self.request.get('name').strip() email = self.request.get('email').strip() subject = self.request.get('subject').strip() message = to_unicode( self.request.get('message') ).strip() homepage = self.request.get('homepage').strip() homepage = "" if homepage == "http://" else homepage remember = bool(self.request.get('remember')) try: topic_id = int( self.request.get('topic_id') or 0 ) if topic_id: topic = db.get(db.Key.from_path('Topic', topic_id)) else: topic = None except ValueError: topic = None if topic and topic.is_locked: return self.redirect( "%stopic?id=%s" % (forum.root(), topic.id) ) # Perform simple validation errors = { 'valid': True } # First post must have a subject if not topic and not subject: errors['valid'] = False errors['subject'] = "Subject required for new topic" if not message: errors['valid'] = False errors['message'] = "Message is required" # sha.new() doesn't accept Unicode strings, so convert to utf8 first sha1_digest = sha.new( message.encode('UTF-8') ).hexdigest() if Post.gql("WHERE sha1_digest = :1 AND topic = :2", sha1_digest, topic).get(): errors['valid'] = False errors['message'] = "This is a duplicate post" if not errors['valid']: return self.template_out("skins/default/post.html", { 'isadmin': is_admin, 'user': user, 'errors': errors, 'forum': forum, 'topic': topic and { 'id': topic_id, 'subject': topic.subject }, 'post': { 'message': message, 'subject': subject }, 'fuser': { 'name': name, 'email': email, 'homepage': homepage, 'remember_me': remember } }) # Get user either by google user id or cookie. Create user objects if don't already exist if user: fuser = FofouUser.gql("WHERE user = :1", user).get() else: fuser = FofouUser.gql("WHERE cookie = :1", self.cookie).get() if not fuser: fuser = FofouUser( user = user or users.User('*****@*****.**'), remember_me = remember, email = email or '*****@*****.**', name = name or 'Anonymous', homepage = homepage, cookie = self.cookie ) else: fuser.remember_me = remember fuser.email = email or '*****@*****.**' fuser.name = name or 'Anonymous' fuser.homepage = homepage if not topic: topic = Topic(forum=forum, subject=subject, created_by=fuser.name) forum.num_topics += 1 else: topic.ncomments += 1 forum.num_posts += 1 topic.put() fuser.put() post = Post( topic = topic, user = fuser, user_ip = self.request.remote_addr, message = message, sha1_digest = sha1_digest, user_name = fuser.name, user_email = fuser.email, user_homepage = homepage ) post.put() forum.put() self.redirect( "%stopic?id=%s" % (forum.root(), topic.id) )