Beispiel #1
0
 def manage(self,type,id):
     if type == 'article':
         c.articles = Session.query(Article).order_by(desc(Article.pub_date)).all()
         return render('/admin/manage_news.html')
     elif type == 'comments':
         c.article = Session.query(Article).filter_by(id=id).order_by(desc(Article.pub_date)).one()
         return render('/admin/manage_comments.html')
Beispiel #2
0
 def __call__(self, environ, start_response):
     """Invoke the Controller"""
     # WSGIController.__call__ dispatches to the Controller method
     # the request is routed to. This routing information is
     # available in environ['pylons.routes_dict']
     try:
         return WSGIController.__call__(self, environ, start_response)
     finally:
         Session.remove()
Beispiel #3
0
 def __before__(self):
     c.comment_type = 'article'
     self.news_q = Session.query(Article).options(joinedload(Article.comments))
     if 'page' in request.params:
         c.page = request.params['page']
     else:
         c.page = 1
Beispiel #4
0
 def index(self):
     c.races = Session.query(Race).order_by(desc(Race.id)).all()
     tmp = {}
     for r in c.races:
         tmp[r.id] = r
     c.jsonrace = json.dumps(tmp, cls=raceEncode)
     return render('/resources/char_create_index.html');
Beispiel #5
0
 def __validate_article(self, type, id):
     query_obj = Session.query(Article)
     try:
         article = query_obj.filter_by(id = id).one()
         if request.params['type'] != type or \
            request.params['com_id'] != str(article.id) or \
            request.params['com_slug'] != article.slug:
                return "What we have here is a failure to communicate!"
         c.article = article
         c.comment_id = c.article.id
         c.comment_slug = c.article.slug
     except NoResultFound, error:
         return error
Beispiel #6
0
            c.articleModel = ModelTags(session.get('new_article'))
            del session['new_article']
            session.save()
        return render('/admin/post_news.html')

    def __new_article(self):
        schema = ArticleForm()
        try: 
            form_result = schema.to_python(request.params)
        except formencode.validators.Invalid, error:
            article = Article(title=error.value['title'],content=error.value['content'])
            d = {}
            for key,error in error.error_dict.items():
                d[key] = error.msg
            session['new_article'] = article
            session['form_errors'] = d
            session.save()
#           log.info(session)
            redirect(url(controller='admin',action='index'))
        else:
            article = Article(title=form_result['title'],content=form_result['content'],
                              author_id=User.getCurrent().id,slug=slugify(form_result['title']))
            Session.add(article)
            Session.commit()
            return "Article Posted!"

    @authenticate_form
    def add_new(self, type):
        if type == "article":
            return self.__new_article()
Beispiel #7
0
def init_model(engine):
    """Call me before using any of the tables or classes in the model"""
    Session.configure(bind=engine)
Beispiel #8
0
def setup_app(command, conf, vars):
    """Place any commands to setup lazydm here"""
    # Don't reload the app if it was loaded under the testing environment
    if not pylons.test.pylonsapp:
        load_environment(conf.global_conf, conf.local_conf)

    # Create the tables if they don't already exist
    log.info("Creating tables....")
    Base.metadata.create_all(bind=Session.bind)
    log.info("Success!!")

    log.info("Adding initial users, groups and permissions...")
    g = Group()
    g.name = u'admin'
    Session.add(g)

    p = Permission()
    p.name = u'admin'
    p.groups.append(g)
    Session.add(p)

    u = User()
    u.username = u'admin'
    u.fullname = u'admin'
    u._set_password('zero')
    u.email = u'*****@*****.**'
    u.groups.append(g)
    Session.add(u)

    u = User()
    u.username = u'test'
    u.fullname = u'Zero'
    u._set_password('test')
    u.email = u'*****@*****.**'
    Session.add(u)
    Session.commit()
    
    log.info("Adding Data...")
    con = u'<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumyeirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diamvoluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumyeirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diamvoluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumyeirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diamvoluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumyeirmod tempor invidunt ut labore et dolore magna</p>\n\n'
    con += u'<img src="/img/flower.png" />\n\n'
    con += u'<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumyeirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diamvoluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumyeirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diamvoluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumyeirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diamvoluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumyeirmod tempor invidunt ut labore et dolore magna</p>\n\n'
    con += u'<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumyeirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diamvoluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumyeirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diamvoluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumyeirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diamvoluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumyeirmod tempor invidunt ut labore et dolore magna</p>'

    Session.add(Article(author_id=u.id,title=u'Testing This Post',slug=u'testing-this-post',
                        content=con))

    content = u'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumyeirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diamvoluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumyeirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diamvoluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumyeirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diamvoluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumyeirmod tempor invidunt ut labore et dolore magna'
    Session.add(Comment(user=u'Benjamin Franklin', email=u'*****@*****.**', content=content, article_id=1,type='article',ip_addr='192.168.1.1'))
    Session.add(Comment(user=u'George Washington', email=u'*****@*****.**', content=content, article_id=1,type='article',ip_addr='192.168.1.1'))
    Session.commit()
    
    b = Book(title="Player's Handbook")
    Session.add(b)
    Session.commit()
    
    r = Race()
    r.name = 'Elf'
    r._dex = 2
    r._con = -2
    r.book = b
    r.male_ft = 4
    r.female_ft = 4
    r.male_in = 5
    r.female_in = 5
    r.male_lb = 85
    r.female_lb = 80
    r.height_mod = "2d6"
    r.weight_mod = "1d6"
    
    Session.add(r)
    Session.commit()
    
    log.info("Success!!")
Beispiel #9
0
                c.form_result = error.value
                c.form_errors = error.error_dict or {}
                c.modelcomment = ModelTags(com)
                return render('/comment-form.html')
            else:            
                d = {}
                for key,error in error.error_dict.items():
                    d[key] = error.msg
                session['com_object'] = com
                session['form_errors'] = d
                session.save()
#                log.info(session)
                redirect(self.__com_url(type, id, 'comment-form-section'))
        else:
            com = Comment(user=form_result['user'],email=form_result['email'],
                        website=form_result['website'],content=form_result['content'], 
                        type=type,ip_addr=request.environ.get('REMOTE_ADDR'))
            if type == 'article':
                com.article_id = id
            Session.add(com)
            Session.commit()
            
            anchor = 'comments'
            if 'partial' in request.params:
                c.link_url = self.__com_url(type, id, anchor)
                c.partial_url = self.__com_url(type, id, anchor, True)
                return render('/refresh_comments.html')
            else:
                redirect(self.__com_url(type, id, anchor))

Beispiel #10
0
 def get(user):
     return Session.query(User).filter_by(username=user).one()