示例#1
0
    def post(self):
        user = get_current_user_name()
        type = self.request.get('type')
        action = self.request.get('action')

        if type == 'sessionnotice':
            if action == 'add':
                try:
                    date_string = self.request.get('date')
                    date_input = datetime.date(*strptime(date_string,'%d/%m/%Y')[:3])
                    SessionNotice(
                        date = date_input,
                        reason = self.request.get('reason'),
                        type = self.request.get('noticetype'),
                        author = user,
                    ).put()
                except (db.Error,ValueError), e:
                    messages = ['Error saving note: %s'%e]
                    cancel_data = {
                        'date'      : date_input,
                        'reason'    : self.request.get('reason'),
                        'type'      : self.request.get('noticetype'),
                        }
                    return self.__compose(messages,notice_data=notice_data)
            elif action == 'del':
                try:
                    key = db.Key(self.request.get('key'))
                    db.get(key).delete()
                except (db.Error,ValueError,AttributeError), e:
                    messages = ['Error removing note: %s'%e]
                    return self.__compose(messages)    
示例#2
0
    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')
示例#3
0
    def post(self):
        user = get_current_user_name()
        type = self.request.get('type')
        action = self.request.get('action')

        if type == 'sessionnotice':
            if action == 'add':
                try:
                    date_string = self.request.get('date')
                    date_input = datetime.date(
                        *strptime(date_string, '%d/%m/%Y')[:3])
                    SessionNotice(
                        date=date_input,
                        reason=self.request.get('reason'),
                        type=self.request.get('noticetype'),
                        author=user,
                    ).put()
                except (db.Error, ValueError), e:
                    messages = ['Error saving note: %s' % e]
                    cancel_data = {
                        'date': date_input,
                        'reason': self.request.get('reason'),
                        'type': self.request.get('noticetype'),
                    }
                    return self.__compose(messages, notice_data=notice_data)
            elif action == 'del':
                try:
                    key = db.Key(self.request.get('key'))
                    db.get(key).delete()
                except (db.Error, ValueError, AttributeError), e:
                    messages = ['Error removing note: %s' % e]
                    return self.__compose(messages)
示例#4
0
    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')
示例#5
0
 def new_funct(self, *args, **kw):
     user = get_current_user_name()
     if not user:
         sessions.Session()['flash'] = [
             'You must login to use this feature.'
         ]
         return self.redirect(create_login_url(self.request.uri))
     return funct(self, *args, **kw)
示例#6
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')
示例#7
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('/')
示例#8
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)        
        
        
            
        
示例#9
0
    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)))
示例#10
0
    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))
示例#11
0
 def get(self,key):
     user = get_current_user_name()
     if not user:
         return self.redirect(create_login_url(self.request.uri))
        
     # get the existing post
     post = Post.get(key)
     
     data = {
         'session'   : sessions.Session(),
         'pages'     : Post.get_pages(),
         'title'     : post.title,
         'type'      : post.type,
         'key'       : key,
         'content'   : post.content,
     }
     return self.response.out.write(template.render('post/edit.html',data))
示例#12
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('/')
示例#13
0
 def get(self,slug):
     user = get_current_user_name()
     if not user:
         return self.redirect(create_login_url(self.request.uri))
        
     # get the existing post
     post = db.GqlQuery('''
         SELECT * FROM Post
         WHERE slug = '%s'
         AND type = 'page'
         LIMIT 1
         ''' % (slug))[0]
         
     data = {
         'session'   : sessions.Session(),
         'pages'     : Post.get_pages(),
         'title'     : post.title,
         'type'      : post.type,
         'content'   : post.content,
     }
     return self.response.out.write(template.render('post/edit.html',data))
示例#14
0
 def new_funct(self,*args,**kw):
     user = get_current_user_name()
     if not user:
         sessions.Session()['flash'] = ['You must login to use this feature.']
         return self.redirect(create_login_url(self.request.uri))
     return funct(self,*args,**kw)