本文整理汇总了Python中tagger.model.DBSession类的典型用法代码示例。如果您正苦于以下问题:Python DBSession类的具体用法?Python DBSession怎么用?Python DBSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBSession类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _fill_db
def _fill_db(self):
tadm = DBSession.query(User).filter_by(user_name=u'test_admin').one()
language = Language(u'xx', u'test language')
DBSession.add(language)
DBSession.flush()
languageid = language.id
return languageid, tadm
开发者ID:lento,项目名称:tagger,代码行数:7,代码来源:test_admin.py
示例2: test_comment
def test_comment(self):
"""controllers.admin.Controller.comment is working properly"""
languageid, tadm = self._fill_db()
comment = Comment(u'anonymous', u'[email protected]', u'test comment')
DBSession.add(comment)
DBSession.flush()
commentid = comment.id
transaction.commit()
environ = {'REMOTE_USER': 'test_admin'}
response = self.app.get('/admin/comment/', extra_environ=environ,
status=200)
tr = response.html.table('tr')[1]
# Date
eq_(str(tr('td')[1]), '<td>%s</td>' % commentid)
eq_(str(tr('td')[2]), '<td></td>')
eq_(str(tr('td')[3]), '<td>anonymous</td>')
eq_(str(tr('td')[4]), '<td>[email protected]</td>')
eq_(str(tr('td')[5]), '<td>test comment</td>')
# Status
actions = tr('td')[7]
eq_(str(actions('a')[0]['class']), 'icon edit overlay')
eq_(str(actions('a')[1]['class']), 'icon delete overlay')
eq_(str(actions('a')[2]['class']), 'icon approve')
eq_(str(actions('a')[3]['class']), 'icon spam')
开发者ID:lento,项目名称:tagger,代码行数:26,代码来源:test_admin.py
示例3: edit
def edit(self, articleid, pagestringid, **kwargs):
"""Display a EDIT form."""
tmpl_context.form = f_edit
article = DBSession.query(Article).get(articleid.decode())
page = article.pages[pagestringid]
fargs = dict(pageid=page.id, id_=page.id,
languageid=page.language_id,
version=page.version,
modified=page.data[0].modified,
name=page.name[''],
text=page.text[''],
)
languages = [(l.id, l.name) for l in DBSession.query(Language)]
data = page.data[0]
DataHistory = data.__history_mapper__.class_
query = DBSession.query(DataHistory).filter_by(id=data.id)
versions = range(query.count(), 0, -1)
versions.insert(0, int(data.version))
fcargs = dict(
languageid=dict(options=languages),
version=dict(options=versions),
)
return dict(title='%s %s' % (_('Edit page:'), page.string_id),
args=fargs, child_args=fcargs)
开发者ID:lento,项目名称:tagger,代码行数:28,代码来源:page.py
示例4: settings
def settings(self):
"""Return a form to edit settings"""
tmpl_context.f_settings = f_settings
lang = tmpl_context.lang
query = DBSession.query(Setting)
settings = dict([('v_%s' % s.id, s.value) for s in query])
fargs = settings
querymedia = DBSession.query(Media).filter_by(type=u'image')
media_list = [('', '')]
media_list.extend([(m.id, m.name[lang]) for m in querymedia])
link_list = [('', '')]
link_list.extend([(l.id, l.name[lang]) for l in DBSession.query(Link)])
cc_list = [
('', ''),
('cc by', 'CC Attribution'),
('cc by-sa', 'CC Attribution Share Alike'),
('cc by-nd', 'CC Attribution No Derivatives'),
('cc by-nc', 'CC Attribution Non-Commercial'),
('cc by-nc-sa', 'CC Attribution Non-Commercial Share Alike'),
('cc by-nc-nd', 'CC Attribution Non-Commercial No Derivatives'),
]
fcargs = dict(v_logo_media=dict(options=media_list),
v_banner_media=dict(options=media_list),
v_banner_link=dict(options=link_list),
v_theme = dict(options=G.themes),
v_cc = dict(options=cc_list),
)
return dict(args=fargs, child_args=fcargs, path=('admin', 'settings'))
开发者ID:lento,项目名称:tagger,代码行数:30,代码来源:admin.py
示例5: post
def post(self, name, languageid):
"""create a new Tag"""
user = tmpl_context.user
tag = Tag(name, languageid)
DBSession.add(tag)
flash('%s %s' % (_('Created Tag:'), tag.id), 'ok')
return dict(redirect_to=url('/admin/tag/'))
开发者ID:lento,项目名称:tagger,代码行数:7,代码来源:tag.py
示例6: post_delete
def post_delete(self, languageid):
"""Delete a Language"""
language = DBSession.query(Language).get(languageid.decode())
DBSession.delete(language)
flash('%s %s' % (_('Deleted Language:'), language.id), 'ok')
return dict(redirect_to=url('/admin/language/'))
开发者ID:lento,项目名称:tagger,代码行数:7,代码来源:language.py
示例7: edit
def edit(self, linkid, **kwargs):
"""Display a EDIT form."""
tmpl_context.form = f_edit
lang = tmpl_context.lang
link = DBSession.query(Link).get(linkid.decode())
tags = ', '.join([t.name[lang] for t in link.tags])
fargs = dict(linkid=link.id, id_=link.id,
uri=link.uri,
languageid=link.language_id,
version=link.version,
modified=link.data[0].modified,
name=link.name[''],
description=link.description[''],
tagids=tags,
)
languages = [(l.id, l.name) for l in DBSession.query(Language)]
data = link.data[0]
DataHistory = data.__history_mapper__.class_
query = DBSession.query(DataHistory).filter_by(id=data.id)
versions = range(query.count(), 0, -1)
versions.insert(0, int(data.version))
fcargs = dict(
languageid=dict(options=languages),
version=dict(options=versions),
)
return dict(title='%s %s' % (_('Edit link:'), link.id),
args=fargs, child_args=fcargs)
开发者ID:lento,项目名称:tagger,代码行数:31,代码来源:link.py
示例8: get_all
def get_all(self, tag=[], max_results=None, mode='all'):
"""Return a list of links"""
settings = dict([(s.id, s.value) for s in DBSession.query(Setting)])
if max_results is None:
max_results = int(settings.get('max_results', 0))
else:
max_results = int(max_results)
tmpl_context.w_object_title = w_object_title
tmpl_context.w_link = w_link
query = DBSession.query(Link)
query = query.join(Link.associable).filter_by(published=True)
query = query.order_by(desc(Link.created))
tot_results = query.count()
if max_results:
links = query[0:max_results]
more_results = max(tot_results - max_results, 0)
else:
links = query.all()
more_results = False
if tag:
tagids = isinstance(tag, list) and tag or [tag]
tagstring = ', '.join(tagids)
tags = set(tags_from_string(tagstring, create=False))
if mode == 'all':
links = [obj for obj in links if set(obj.tags) >= (tags)]
elif mode == 'any':
links = [obj for obj in links if set(obj.tags) & (tags)]
return dict(links=links, recent=find_recent(), path=('links', ''),
more_results=more_results)
开发者ID:lento,项目名称:tagger,代码行数:33,代码来源:link.py
示例9: put
def put(self, linkid, name, uri, languageid, description=None, tagids=None,
version=None, modified=None):
"""Edit a link"""
lang = tmpl_context.lang or DBSession.query(Language).first().id
link = DBSession.query(Link).get(linkid.decode())
modified = False
if link.uri != uri:
link.uri = uri
modified = True
if link.name[languageid] != name:
link.name[languageid] = name
modified = True
if link.description[languageid] != description:
link.description[languageid] = description
modified = True
tags = tags_from_string(tagids, lang=lang)
if link.tags != tags:
link.tags[:] = tags
modified = True
if modified:
link.data[languageid].modified = datetime.datetime.now()
flash('%s %s' % (_('Updated Link:'), link.id), 'ok')
else:
flash('%s %s' % (_('Link is unchanged:'), link.id), 'info')
return dict(redirect_to=url('/admin/link/'))
开发者ID:lento,项目名称:tagger,代码行数:30,代码来源:link.py
示例10: post_delete
def post_delete(self, commentid):
"""Delete a Comment"""
comment = DBSession.query(Comment).get(commentid)
DBSession.delete(comment)
flash('%s %s' % (_('Deleted Comment:'), comment.id), 'ok')
return dict(redirect_to=url('/admin/comment/'))
开发者ID:lento,项目名称:tagger,代码行数:7,代码来源:comment.py
示例11: _fill_db
def _fill_db(self):
language = Language(u'xx', u'test language')
DBSession.add(language)
DBSession.flush()
languageid = language.id
transaction.commit()
return languageid.encode()
开发者ID:lento,项目名称:tagger,代码行数:7,代码来源:test_language.py
示例12: post_delete
def post_delete(self, pageid):
"""Delete a Page"""
page = DBSession.query(Page).get(pageid)
for pagedata in page.data:
DBSession.delete(pagedata)
DBSession.delete(page)
flash('%s %s' % (_('Deleted Page:'), page.string_id), 'ok')
return dict(redirect_to=url('/article/%s/edit' % page.article.id))
开发者ID:lento,项目名称:tagger,代码行数:9,代码来源:page.py
示例13: post_delete
def post_delete(self, tagid):
"""Delete a Tag"""
tag = DBSession.query(Tag).get(tagid.decode())
for tagdata in tag.data:
DBSession.delete(tagdata)
DBSession.delete(tag)
flash('%s %s' % (_('Deleted Tag:'), tag.id), 'ok')
return dict(redirect_to=url('/admin/tag/'))
开发者ID:lento,项目名称:tagger,代码行数:9,代码来源:tag.py
示例14: new
def new(self, articleid, **kwargs):
"""Display a NEW form."""
tmpl_context.form = f_new
article = DBSession.query(Article).get(articleid.decode())
fargs = dict(articleid=article.id)
lang_list = [(l.id, l.name) for l in DBSession.query(Language)]
fcargs = dict(languageid=dict(options=lang_list))
return dict(title=_('Create a new Page'), args=fargs, child_args=fcargs)
开发者ID:lento,项目名称:tagger,代码行数:9,代码来源:page.py
示例15: post_delete
def post_delete(self, categoryid):
"""Delete a Category"""
category = DBSession.query(Category).get(categoryid.decode())
for categorydata in category.data:
DBSession.delete(categorydata)
DBSession.delete(category)
flash('%s %s' % (_('Deleted Category:'), category.id), 'ok')
return dict(redirect_to=url('/admin/category/'))
开发者ID:lento,项目名称:tagger,代码行数:9,代码来源:category.py
示例16: post
def post(self, articleid, name, languageid, text=None):
"""create a new Page"""
user = tmpl_context.user
article = DBSession.query(Article).get(articleid.decode())
page = Page(name, languageid, user, text)
article.pages.append(page)
DBSession.flush()
flash('%s %s' % (_('Created Page:'), page.string_id), 'ok')
return dict(redirect_to=url('/article/%s/edit' % article.id))
开发者ID:lento,项目名称:tagger,代码行数:10,代码来源:page.py
示例17: edit
def edit(self, tagid, **kwargs):
"""Display a EDIT form."""
tmpl_context.form = f_edit
tag = DBSession.query(Tag).get(tagid.decode())
fargs = dict(tagid=tag.id, id_=tag.id,
languageid=tag.language_id,
name=tag.name[''],
)
languages = [(l.id, l.name) for l in DBSession.query(Language)]
fcargs = dict(languageid=dict(options=languages))
return dict(title='%s %s' % (_('Edit tag:'), tag.id),
args=fargs, child_args=fcargs)
开发者ID:lento,项目名称:tagger,代码行数:12,代码来源:tag.py
示例18: post
def post(self, name, uri, languageid, description=None, tagids=None):
"""create a new Link"""
user = tmpl_context.user
lang = tmpl_context.lang or DBSession.query(Language).first().id
link = Link(name, uri, user, languageid, description)
DBSession.add(link)
tags = tags_from_string(tagids, lang=lang)
link.tags[:] = tags
flash('%s %s' % (_('Created Link:'), link.id), 'ok')
return dict(redirect_to=url('/admin/link/'))
开发者ID:lento,项目名称:tagger,代码行数:12,代码来源:link.py
示例19: post
def post(self, title, categoryid, languageid, text=None, tagids=None):
"""create a new Article"""
user = tmpl_context.user
lang = tmpl_context.lang or DBSession.query(Language).first().id
category = DBSession.query(Category).get(categoryid)
article = Article(title, category, languageid, user, text)
DBSession.add(article)
tags = tags_from_string(tagids, lang=lang)
article.tags[:] = tags
flash('%s %s' % (_('Created Article:'), article.id), 'ok')
return dict(redirect_to=url('/admin/article/'))
开发者ID:lento,项目名称:tagger,代码行数:13,代码来源:article.py
示例20: edit
def edit(self, categoryid, **kwargs):
"""Display a EDIT form."""
tmpl_context.form = f_edit
lang = tmpl_context.lang
category = DBSession.query(Category).get(categoryid.decode())
fargs = dict(categoryid=category.id, id_=category.id,
languageid=category.language_id,
name=category.name[lang],
description=category.description[lang])
languages = [(l.id, l.name) for l in DBSession.query(Language)]
fcargs = dict(languageid=dict(options=languages))
return dict(title='%s %s' % (_('Edit Category:'), category.id),
args=fargs, child_args=fcargs)
开发者ID:lento,项目名称:tagger,代码行数:13,代码来源:category.py
注:本文中的tagger.model.DBSession类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论