How to set the __acl__ property of Sqlalchemy domain class?
zhangqiang99 opened this issue · 1 comments
I am a novice.
I tried to learn the pyramid authen demo like this way, but the code does not work.....
class Article(Base):
tablename = 'articles'
id = Column(Integer, primary_key=True)
title = Column(String(255), nullable=False)
content = Column(Text)
created_at = Column(DateTime, nullable=False, default=datetime.now())
edited_at = Column(DateTime, nullable=False, default=datetime.now())
user_id = Column(Integer, ForeignKey('tg_user.user_id'))
author = relationship('User', backref=backref("articles", lazy='dynamic'))
@Property
def acl(self):
return [
(Allow, self.author, 'edit'), # right? wrong?
]
def init(self, title, content, author):
self.title = title
self.content = content
self.author = author
@view_config(route_name="create_article", renderer="templates/create_article.jinja2",
permission="create")
def create_article(request):
logged_in = request.authenticated_userid
author = User.by_email_address(logged_in)
article = Article(title="", content="", author=author)
if 'form.submitted' in request.params:
title = request.params['title']
content = request.params['content']
article = Article(title=title, content=content, author=author)
DBSession.add(article)
DBSession.flush()
return HTTPFound(location=request.route_url('show_article', article_id=article.id))
return dict(
article=article,
save_url = request.route_url('create_article'),
logged_in = request.authenticated_userid
)
Is there anything wrong with what I'm doing?
PyramidAuthDemo http://michael.merickel.org/projects/pyramid_auth_demo/
The __acl__
property looks good!