本文整理汇总了Python中blog.models.Category.all方法的典型用法代码示例。如果您正苦于以下问题:Python Category.all方法的具体用法?Python Category.all怎么用?Python Category.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Category
的用法示例。
在下文中一共展示了Category.all方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: POST
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import all [as 别名]
def POST(self):
def check(cate):
parent=cate.parent_cat
skey=cate.key()
while parent:
if parent.key()==skey:
return False
parent=parent.parent_cat
return True
action=self.param("action")
name=self.param("name")
slug=self.param("slug")
parentkey=self.param('parentkey')
key=self.param('key')
vals={'action':action,'postback':True}
try:
if action=='add':
cat= Category(name=name,slug=slug)
if not (name and slug):
raise Exception(_('Please input name and slug.'))
if parentkey:
cat.parent_cat=Category.get(parentkey)
cat.put()
self.redirect('/admin/categories')
#vals.update({'result':True,'msg':_('Saved ok')})
#self.render2('views/admin/category.html',vals)
elif action=='edit':
cat=Category.get(key)
cat.name=name
cat.slug=slug
if not (name and slug):
raise Exception(_('Please input name and slug.'))
if parentkey:
cat.parent_cat=Category.get(parentkey)
if not check(cat):
raise Exception(_('A circle declaration found.'))
else:
cat.parent_cat=None
cat.put()
self.redirect('/admin/categories')
except Exception ,e :
if cat.is_saved():
cates=[c for c in Category.all() if c.key()!=cat.key()]
else:
cates= Category.all()
vals.update({'result':False,'msg':e.message,'category':cat,'key':key,'categories':cates})
self.render2('views/admin/category.html',vals)
示例2: GET
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import all [as 别名]
def GET(self,tags=None):
urls = []
def addurl(loc,lastmod=None,changefreq=None,priority=None):
url_info = {
'location': loc,
'lastmod': lastmod,
'changefreq': changefreq,
'priority': priority
}
urls.append(url_info)
addurl(self.blog.baseurl,changefreq='daily',priority=0.9 )
entries = Entry.all().filter(published = True).order_by('-date')[0:self.blog.sitemap_entries]#.fetch(self.blog.sitemap_entries)
for item in entries:
loc = "%s/%s" % (self.blog.baseurl, item.link)
addurl(loc,item.mod_date or item.date,'never',0.6)
if self.blog.sitemap_include_category:
cats=Category.all()
for cat in cats:
loc="%s/category/%s"%(self.blog.baseurl,cat.slug)
addurl(loc,None,'weekly',0.5)
if self.blog.sitemap_include_tag:
tags=Tag.all()
for tag in tags:
loc="%s/tag/%s"%(self.blog.baseurl, urlencode(tag.tag))
addurl(loc,None,'weekly',0.5)
## self.response.headers['Content-Type'] = 'application/atom+xml'
self.render('/admin/views/sitemap.xml', {'urlset':urls}, content_type='text/xml')#, content_type='application/xhtml+xml')
示例3: generate_sitemap
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import all [as 别名]
def generate_sitemap():
"""Deferred task to generate a Sitemap.xml for all published blog posts"""
root = etree.Element('urlset', { 'attr': 'http://www.sitemaps.org/schemas/sitemap/0.9' })
def add_url(location, last_modified=None, change_freq='always', priority=0.5):
e = etree.SubElement(root, 'url')
etree.SubElement(e, 'loc').text = location
if last_modified:
etree.SubElement(e, 'lastmod').text = last_modified.strftime('%Y-%m-%dT%H:%M:%S+00:00')
etree.SubElement(e, 'changefreq').text = change_freq
etree.SubElement(e, 'priority').text = str(priority)
for p in Post.objects_published().order('-created_at'):
add_url(p.absolute_url(external=True), p.updated_at)
for c in Category.all():
add_url(c.absolute_url(external=True))
add_url(url_for('blog.index', _external=True), priority=1.0)
add_url(url_for('blog.latest_posts', _external=True))
logging.info('Generated sitemap.xml with %d blog posts', len(root))
xml = etree.tostring(root, encoding='utf-8', pretty_print=True, xml_declaration=True)
cache.set('blog_sitemaps', xml)
return xml
示例4: admin_list_category
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import all [as 别名]
def admin_list_category(request):
if users.is_current_user_admin():
return object_list(request,
template_object_name='obj',
queryset=Category.all(),
allow_empty=True,
extra_context={'type': 'category'},
template_name='admin/list.html',
paginate_by=setting.ADMIN_LIST_PER_PAGE,
)
else:
return HttpResponseRedirect('/')
示例5: initialize
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import all [as 别名]
def initialize(self, request):
m_pages=Entry.all().filter('entrytype =','page')\
.filter('published =',True)\
.filter('entry_parent =',0)\
.order('menu_order')
blogroll=Link.all().filter('linktype =','blogroll')
archives=Archive.all().order('-year').order('-month').fetch(12)
alltags=Tag.all()
self.template_vals.update({
'menu_pages':m_pages,
'categories':Category.all(),
'blogroll':blogroll,
'archives':archives,
'alltags':alltags,
'recent_comments':Comment.all().order('-date').fetch(5)
})
示例6: wwb_list_category
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import all [as 别名]
def wwb_list_category():
html = ''
for category in Category.all()[:10]:
html += '<li><a href="%s">%s ( %d )</a></li>'%(category.get_absolute_url(), category.title.encode('utf-8'), category.posts.count())
return html
示例7: process_request
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import all [as 别名]
def process_request(self, request):
if not hasattr(request, 'categories'):
request.categories = Category.all().order('-post_count')
if not hasattr(request, 'most_read_posts'):
request.most_read_posts = Post.all().order('-read_count')[:10]
return None
示例8: GenericSitemap
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import all [as 别名]
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from django.conf.urls.defaults import *
from django.contrib.sitemaps import FlatPageSitemap, GenericSitemap
from blog.models import Post, Category, Tag
from feeds.models import LatestEntries, HottestEntries
feeds = {"latest": LatestEntries, "hottest": HottestEntries}
posts = {"queryset": Post.all().filter("is_published", True), "date_field": "create_time"}
tags = {"queryset": Tag.all().order("-post_count")}
categories = {"queryset": Category.all().order("-post_count")}
sitemaps = {
"flatpages": FlatPageSitemap,
"blog": GenericSitemap(posts, priority=0.6, changefreq="monthly"),
#'tag': GenericSitemap(tags, priority=0.5, changefreq='monthly'),
#'category': GenericSitemap(categories, priority=0.4, changefreq='yearly'),
}
urlpatterns = patterns(
"",
(r"^$", "blog.views.list_post"),
(r"update/$", "blog.views.update"),
(r"^about/$", "blog.views.about"),
(r"^download/$", "blog.views.download"),
(r"^account/setting/$", "account.views.setting"),
示例9: GenericSitemap
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import all [as 别名]
feeds = {
'latest': LatestEntries,
'hottest': HottestEntries,
}
posts = {
'queryset': Post.all().filter('is_published', True),
'date_field': 'create_time',
}
tags = {
'queryset': Tag.all().order('-post_count'),
}
categories = {
'queryset': Category.all().order('-post_count'),
}
sitemaps = {
'flatpages': FlatPageSitemap,
'blog': GenericSitemap(posts, priority=0.6, changefreq='monthly'),
#'tag': GenericSitemap(tags, priority=0.5, changefreq='monthly'),
#'category': GenericSitemap(categories, priority=0.4, changefreq='yearly'),
}
urlpatterns = patterns('',
(r'^$', 'blog.views.list_post'),
(r'update/$', 'blog.views.update'),
(r'^about/$', 'blog.views.about'),
(r'^timeline/$', 'blog.views.timeline'),
(r'^events/$', 'blog.views.events'),
示例10: widgets
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import all [as 别名]
def widgets(context):
context['categories'] = Category.all()
context['tags'] = Tag.all()
context['archives'] = Post.getArchives()
context['settings'] = UserSettings.getByCurrentUser()
return context
示例11: items
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import all [as 别名]
def items(self):
return Category.all()