コード例 #1
0
ファイル: post.py プロジェクト: cheesun/shuttlebugs
    def post(self,key):
        user = get_current_user_name()
        
        title = self.request.get('title')
        content = self.request.get('content')

        # get the existing post
        post = Post.get(key)

        errors = []
        if not is_current_user_admin():
            errors.append('Only admins can edit')
        if not user:
            errors.append('You need to be logged in to edit')
        if not title or not content:
            errors.append('Please fill out all fields') 
        if errors:
            session = sessions.Session()
            session['flash'] = errors
            data = {
                'title'     : title,
                'content'   : content,
                'session'   : session,
                'type'      : post.type,
                'key'       : key,
                'pages'     : Post.get_pages(),
                }
            return self.response.out.write(template.render('post/edit.html',data))

        post.title = title
        post.content = content
        post.put()
        
        return self.redirect('/news')
コード例 #2
0
ファイル: post.py プロジェクト: dburburan/shuttlebugs
    def post(self, key):
        user = get_current_user_name()

        title = self.request.get('title')
        content = self.request.get('content')

        # get the existing post
        post = Post.get(key)

        errors = []
        if not is_current_user_admin():
            errors.append('Only admins can edit')
        if not user:
            errors.append('You need to be logged in to edit')
        if not title or not content:
            errors.append('Please fill out all fields')
        if errors:
            session = sessions.Session()
            session['flash'] = errors
            data = {
                'title': title,
                'content': content,
                'session': session,
                'type': post.type,
                'key': key,
                'pages': Post.get_pages(),
            }
            return self.response.out.write(
                unicode(template.render('post/edit.html', data)))

        post.title = title
        post.content = content
        post.put()

        return self.redirect('/news')
コード例 #3
0
 def get(self,key):
     user = get_current_user_name()
     if not user:
         return self.redirect(create_login_url(self.request.uri))
     if not is_current_user_admin():
         sessions.Session()['flash'] = ['You must be an admin to delete pages.']
         return self.redirect('/')
        
     # delete the post
     Post.get(db.Key(key)).delete()
     
     sessions.Session()['flash'] = ['News item deleted succesfully.']
     return self.redirect('/news')
コード例 #4
0
    def post(self):        
        title = self.request.get('title')
        type = self.request.get('type')
        content = self.request.get('content')
        
        
        # if it's a page, check that the title/slug has not already been used
        existing = False
        if type == 'page':
            existing = Post.all().filter('type =', 'page').filter('slug =', slugify(title)).fetch(1)

        errors = []
        if not is_current_user_admin():
            errors.append('Only admins can post')
        if not get_current_user_name():
            errors.append('You need to be logged in to post')
        if not title or not type or not content:
            errors.append('Please fill out all fields')
        if existing:
            errors.append('A page with this title already exists')
        if type not in ['news','announcement','page','pdf']:
            errors.append('Invalid page type')            
        if errors:
            session = sessions.Session()
            session['flash'] = errors
            data = {
                'title'     : title,
                'type'      : type,
                'content'   : content,
                'session'   : session,
                'pages'     : Post.get_pages(),
                }
            return self.response.out.write(template.render('post/post.html',data))

        fixed_type = type
        if fixed_type == 'pdf':
            fixed_type = 'page'

        new_post = Post(
            title = title,
            type = fixed_type,
            content = content
        )
        if fixed_type == 'page':
            new_post.hidden = True
        new_post.put()
        
        if fixed_type == 'page':
            return self.redirect('/%s.html' % new_post.slug)
        else:
            return self.redirect('/')
コード例 #5
0
    def post(self):
        user = get_current_user_name()
        if not user:
            return self.redirect(create_login_url(self.request.uri))

        slug = self.request.get('slug')
        action = self.request.get('action')

        messages = []
        if not is_current_user_admin():
            messages.append('Only admins can manage pages')
        if not user:
            messages.append('You need to be logged in to manage pages')
        if not slug:
            messages.append('Please specify which page you would like to change')
        if not action:
            messages.append('Please specify what you would like to do')
        if messages:
            return self.__compose(messages)
            
        # get the existing post
        post = db.GqlQuery('''
            SELECT * FROM Post
            WHERE slug = '%s'
            AND type = 'page'
            LIMIT 1
            ''' % slug)[0]
        if action == 'delete':  
            post.active = False
            messages.append('%s deleted' % slug)
        elif action == 'undelete':
            post.active = True
            messages.append('%s undeleted' % slug)
        elif action == 'hide':
            post.hidden = True
            messages.append('%s hidden' % slug)
        elif action == 'unhide':
            post.hidden = False
            messages.append('%s unhidden' % slug)
        elif action == 'edit':
            return self.redirect('/page/edit/%s' % slug)
        # save the changes
        post.put()
            
        return self.redirect(self.request.uri)        
        
        
            
        
コード例 #6
0
ファイル: post.py プロジェクト: dburburan/shuttlebugs
    def post(self, slug):
        user = get_current_user_name()

        title = self.request.get('title')
        content = self.request.get('content')

        # get the existing post
        post = db.GqlQuery('''
            SELECT * FROM Post
            WHERE slug = '%s'
            AND type = 'page'
            LIMIT 1
            ''' % slug)[0]

        # if it's a page, and you've changed the title
        # check that the new title/slug has not already been used
        existing = False
        if post.type == 'page' and title != post.title:
            existing = Post.all().filter('type =', 'page').filter(
                'slug =', unicode(slugify(title))).fetch(1)

        errors = []
        if not is_current_user_admin():
            errors.append('Only admins can edit')
        if not user:
            errors.append('You need to be logged in to edit')
        if not title or not content:
            errors.append('Please fill out all fields')
        if existing:
            errors.append('A page with this title already exists')
        if errors:
            session = sessions.Session()
            session['flash'] = errors
            data = {
                'title': title,
                'content': content,
                'session': session,
                'type': post.type,
                'pages': Post.get_pages(),
            }
            return self.response.out.write(
                unicode(template.render('post/edit.html', data)))

        post.title = title
        post.content = content
        post.put()

        return self.redirect('/page/%s' % unicode(slugify(title)))
コード例 #7
0
ファイル: post.py プロジェクト: cheesun/shuttlebugs
    def post(self,slug):
        user = get_current_user_name()
        
        title = self.request.get('title')
        content = self.request.get('content')

        # get the existing post
        post = db.GqlQuery('''
            SELECT * FROM Post
            WHERE slug = '%s'
            AND type = 'page'
            LIMIT 1
            ''' % slug)[0]

        # if it's a page, and you've changed the title
        # check that the new title/slug has not already been used
        existing = False
        if post.type == 'page' and title != post.title:
            existing = Post.all().filter('type =', 'page').filter('slug =', slugify(title)).fetch(1)

        errors = []
        if not is_current_user_admin():
            errors.append('Only admins can edit')
        if not user:
            errors.append('You need to be logged in to edit')
        if not title or not content:
            errors.append('Please fill out all fields')
        if existing:
            errors.append('A page with this title already exists')            
        if errors:
            session = sessions.Session()
            session['flash'] = errors
            data = {
                'title'     : title,
                'content'   : content,
                'session'   : session,
                'type'      : post.type,
                'pages'     : Post.get_pages(),
                }
            return self.response.out.write(template.render('post/edit.html',data))

        post.title = title
        post.content = content
        post.put()

        return self.redirect('/page/%s' % slugify(title))
コード例 #8
0
 def get(self,slug):
     user = get_current_user_name()
     if not user:
         return self.redirect(create_login_url(self.request.uri))
     if not is_current_user_admin():
         sessions.Session()['flash'] = ['You must be an admin to delete pages.']
         return self.redirect('/')
        
     # get the existing post
     post = db.GqlQuery('''
         SELECT * FROM Post
         WHERE slug = '%s'
         AND type = 'page'
         LIMIT 1
         ''' % slug)[0]
         
     post.active = False
     post.put()
     sessions.Session()['flash'] = ['Page deleted succesfully.']
     return self.redirect('/')