Example #1
0
    def get(self):

        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(g_blog.baseurl, changefreq='daily', priority=1)

        entries = Entry.all().filter('published =', True).order('-date').fetch(g_blog.sitemap_entries)

        for item in entries:
            loc = '%s/%s' % (g_blog.baseurl, item.link)
            addurl(loc, item.date, 'daily', 0.9)

        if g_blog.sitemap_include_category:
            cats = Category.all()
            for cat in cats:
                loc = '%s/category/%s' % (g_blog.baseurl, cat.slug)
                addurl(loc, None, 'weekly', 0.8)

        if g_blog.sitemap_include_tag:
            tags = Tag.all()
            for tag in tags:
                loc = '%s/tag/%s' % (g_blog.baseurl, urlencode(tag.tag))
                addurl(loc, None, 'weekly', 0.8)

        self.response.headers['Content-Type'] = 'text/xml; charset=utf-8'
        self.render2('views/sitemap.xml', {'urlset': urls})
Example #2
0
    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')
Example #3
0
    def POST(self,slug=None):
        useajax=self.param('useajax')=='1'
        logging.debug('+++++++++++++++++++++++1')
        name=self.param('author')
        email=self.param('email')
        url=self.param('url')

        key=self.param('key')
        content=self.param('comment')
        parent_id=self.paramint('parentid',0)
        reply_notify_mail=self.parambool('reply_notify_mail')

        sess=Session(self,timeout=180)
        if not self.is_login:
            #if not (self.request.cookies.get('comment_user', '')):
            #try:
            if 1:
                check_ret=True
                if self.blog.comment_check_type in (1,2)  :
                    checkret=self.param('checkret')
                    check_ret=(int(checkret) == sess['code'])
                elif self.blog.comment_check_type ==3:
                    import app.gbtools as gb
                    checknum=self.param('checknum')
                    checkret=self.param('checkret')
                    check_ret=eval(checknum)==int(gb.stringQ2B( checkret))

                if not check_ret:
                    if useajax:
                        self.write(simplejson.dumps((False,-102,_('Your check code is invalid .')),ensure_ascii = False))
                    else:
                        self.error(-102,_('Your check code is invalid .'))
                    return
            #except:
            if 0:
                if useajax:
                    self.write(simplejson.dumps((False,-102,_('Your check code is invalid .')),ensure_ascii = False))
                else:
                    self.error(-102,_('Your check code is invalid .'))
                return
        sess.invalidate()
        content=content.replace('\n','<br />')
        content=myfilter.do_filter(content)
        name=cgi.escape(name)[:20]
        url=cgi.escape(url)[:100]
        if not (name and email and content):
            if useajax:
                self.write(simplejson.dumps((False,-101,_('Please input name, email and comment .'))))
            else:
                self.error(-101,_('Please input name, email and comment .'))
        else:
            comment=Comment(author=name,
                            content=content,
                            email=email,
                            reply_notify_mail=reply_notify_mail,
                            entry=Entry.get(key))
            if url:
                try:
                    if not url.lower().startswith(('http://','https://')):
                        url = 'http://' + url
                    comment.weburl=url
                except:
                    comment.weburl=None

            #name=name.decode('utf8').encode('gb2312')


            info_str='#@#'.join([urlencode(name),urlencode(email),urlencode(url)])

             #info_str='#@#'.join([name,email,url.encode('utf8')])
            cookiestr='comment_user=%s;expires=%s;path=/;'%( info_str,
                       (datetime.now()+timedelta(days=100)).strftime("%a, %d-%b-%Y %H:%M:%S GMT")
                       
                       )
            comment.ip=self.request.remote_addr

            if parent_id:
                comment.parent=Comment.get_by_id(parent_id)

            comment.no=comment.entry.commentcount+1
            #try:
            if 1:
                comment.save()
                memcache.delete("/"+comment.entry.link)

                self.response.headers.add_header( 'Set-Cookie', cookiestr)
                if useajax:
                    comment_c=self.get_render('comment',{'comment':comment})
                    self.write(simplejson.dumps((True,comment_c.decode('utf8')),ensure_ascii = False))
                else:
                    self.redirect(self.referer+"#comment-"+str(comment.key().id()))

                comment.entry.removecache()
                memcache.delete("/feed/comments")
            #except:
            if 0:
                if useajax:
                    self.write(simplejson.dumps((False,-102,_('Comment not allowed.'))))
                else:
                    self.error(-102,_('Comment not allowed .'))
Example #4
0
    def post(self,slug='post'):
        action=self.param("action")
        title=self.param("post_title")
        content=self.param('content')
        tags=self.param("tags")
        cats=self.request.get_all('cats')
        key=self.param('key')
        if self.param('publish')!='':
            published=True
        elif self.param('unpublish')!='':
            published=False
        else:
            published=self.param('published')=='True'

        allow_comment=self.parambool('allow_comment')
        allow_trackback=self.parambool('allow_trackback')
        entry_slug=self.param('slug')
        entry_parent=self.paramint('entry_parent')
        menu_order=self.paramint('menu_order')
        entry_excerpt=self.param('excerpt').replace('\n','<br />')
        password=self.param('password')
        sticky=self.parambool('sticky')

        is_external_page=self.parambool('is_external_page')
        target=self.param('target')
        external_page_address=self.param('external_page_address')

        def mapit(cat):
            return {'name':cat.name,'slug':cat.slug,'select':cat.slug in cats}

        vals={'action':action,'postback':True,'cats':Category.all(),'entrytype':slug,
              'cats':map(mapit,Category.all()),
              'entry':{ 'title':title,'content':content,'strtags':tags,'key':key,'published':published,
                         'allow_comment':allow_comment,
                         'allow_trackback':allow_trackback,
                        'slug':entry_slug,
                        'entry_parent':entry_parent,
                        'excerpt':entry_excerpt,
                        'menu_order':menu_order,
                        'is_external_page':is_external_page,
                        'target':target,
                        'external_page_address':external_page_address,
                        'password':password,
                        'sticky':sticky}
              }

        if not (title and (content or (is_external_page and external_page_address))):
            vals.update({'result':False, 'msg':_('Please input title and content.')})
            self.render2('views/admin/entry.html',vals)
        else:
            if action=='add':
                entry= Entry(title=title,content=content)
                entry.settags(tags)
                entry.entrytype=slug
                entry.slug=entry_slug.replace(" ","_")
                entry.entry_parent=entry_parent
                entry.menu_order=menu_order
                entry.excerpt=entry_excerpt
                entry.is_external_page=is_external_page
                entry.target=target
                entry.external_page_address=external_page_address
                newcates=[]
                entry.allow_comment=allow_comment
                entry.allow_trackback=allow_trackback
                entry.author=self.author.user
                entry.author_name=self.author.dispname
                entry.password=password
                entry.sticky=sticky
                if cats:

                    for cate in cats:
                        c=Category.all().filter('slug =',cate)
                        if c:
                            newcates.append(c[0].key())
                entry.categorie_keys=newcates;

                entry.save(published)
                if published:
                    smsg=_('Saved ok. <a href="/%(link)s" target="_blank">View it now!</a>')
                else:
                    smsg=_('Saved ok.')

                vals.update({'action':'edit','result':True,'msg':smsg%{'link':str(entry.link)},'entry':entry})
                self.render2('views/admin/entry.html',vals)
                if published and entry.allow_trackback and g_blog.allow_pingback:
                    try:
                        autoPingback(str(entry.fullurl),HTML=content)
                    except:
                        pass
            elif action=='edit':
                try:
                    entry=Entry.get(key)
                    entry.title=title
                    entry.content=content
                    entry.slug=entry_slug.replace(' ','-')
                    entry.entry_parent=entry_parent
                    entry.menu_order=menu_order
                    entry.excerpt=entry_excerpt
                    entry.is_external_page=is_external_page
                    entry.target=target
                    entry.external_page_address=external_page_address
                    entry.settags(tags)
                    entry.author=self.author.user
                    entry.author_name=self.author.dispname
                    entry.password=password
                    entry.sticky=sticky
                    newcates=[]

                    if cats:

                        for cate in cats:
                            c=Category.all().filter('slug =',cate)
                            if c:
                                newcates.append(c[0].key())
                    entry.categorie_keys=newcates;
                    entry.allow_comment=allow_comment
                    entry.allow_trackback=allow_trackback

                    entry.save(published)

                    if published:
                        smsg=_('Saved ok. <a href="/%(link)s" target="_blank">View it now!</a>')
                    else:
                        smsg=_('Saved ok.')
                    vals.update({'result':True,'msg':smsg%{'link':str(base.urlencode( entry.link))},'entry':entry})

                    self.render2('views/admin/entry.html',vals)
                    if published and entry.allow_trackback and g_blog.allow_pingback:
                        try:
                            autoPingback(entry.fullurl,HTML=content)
                        except:
                            pass

                except:
                    vals.update({'result':False,'msg':_('Error:Entry can''t been saved.')})
                    self.render2('views/admin/entry.html',vals)
Example #5
0
    def post(self, slug='post'):
        action = self.param("action")
        title = self.param("post_title")
        content = self.param('content')
        tags = self.param("tags")
        cats = self.request.get_all('cats')
        key = self.param('key')
        if self.param('publish') != '':
            published = True
        elif self.param('unpublish') != '':
            published = False
        else:
            published = self.param('published') == 'True'

        allow_comment = self.parambool('allow_comment')
        allow_trackback = self.parambool('allow_trackback')
        entry_slug = self.param('slug')
        entry_parent = self.paramint('entry_parent')
        menu_order = self.paramint('menu_order')
        entry_excerpt = self.param('excerpt').replace('\n', '<br />')
        password = self.param('password')
        sticky = self.parambool('sticky')

        is_external_page = self.parambool('is_external_page')
        target = self.param('target')
        external_page_address = self.param('external_page_address')

        def mapit(cat):
            return {
                'name': cat.name,
                'slug': cat.slug,
                'select': cat.slug in cats
            }

        vals = {
            'action': action,
            'postback': True,
            'cats': Category.all(),
            'entrytype': slug,
            'cats': map(mapit, Category.all()),
            'entry': {
                'title': title,
                'content': content,
                'strtags': tags,
                'key': key,
                'published': published,
                'allow_comment': allow_comment,
                'allow_trackback': allow_trackback,
                'slug': entry_slug,
                'entry_parent': entry_parent,
                'excerpt': entry_excerpt,
                'menu_order': menu_order,
                'is_external_page': is_external_page,
                'target': target,
                'external_page_address': external_page_address,
                'password': password,
                'sticky': sticky
            }
        }

        if not (title and (content or
                           (is_external_page and external_page_address))):
            vals.update({
                'result': False,
                'msg': _('Please input title and content.')
            })
            self.render2('views/admin/entry.html', vals)
        else:
            if action == 'add':
                entry = Entry(title=title, content=content)
                entry.settags(tags)
                entry.entrytype = slug
                entry.slug = entry_slug.replace(" ", "_")
                entry.entry_parent = entry_parent
                entry.menu_order = menu_order
                entry.excerpt = entry_excerpt
                entry.is_external_page = is_external_page
                entry.target = target
                entry.external_page_address = external_page_address
                newcates = []
                entry.allow_comment = allow_comment
                entry.allow_trackback = allow_trackback
                entry.author = self.author.user
                entry.author_name = self.author.dispname
                entry.password = password
                entry.sticky = sticky
                if cats:

                    for cate in cats:
                        c = Category.all().filter('slug =', cate)
                        if c:
                            newcates.append(c[0].key())
                entry.categorie_keys = newcates

                entry.save(published)
                if published:
                    smsg = _(
                        'Saved ok. <a href="/%(link)s" target="_blank">View it now!</a>'
                    )
                else:
                    smsg = _('Saved ok.')

                vals.update({
                    'action': 'edit',
                    'result': True,
                    'msg': smsg % {
                        'link': str(entry.link)
                    },
                    'entry': entry
                })
                self.render2('views/admin/entry.html', vals)
                if published and entry.allow_trackback and g_blog.allow_pingback:
                    try:
                        autoPingback(str(entry.fullurl), HTML=content)
                    except:
                        pass
            elif action == 'edit':
                try:
                    entry = Entry.get(key)
                    entry.title = title
                    entry.content = content
                    entry.slug = entry_slug.replace(' ', '-')
                    entry.entry_parent = entry_parent
                    entry.menu_order = menu_order
                    entry.excerpt = entry_excerpt
                    entry.is_external_page = is_external_page
                    entry.target = target
                    entry.external_page_address = external_page_address
                    entry.settags(tags)
                    entry.author = self.author.user
                    entry.author_name = self.author.dispname
                    entry.password = password
                    entry.sticky = sticky
                    newcates = []

                    if cats:

                        for cate in cats:
                            c = Category.all().filter('slug =', cate)
                            if c:
                                newcates.append(c[0].key())
                    entry.categorie_keys = newcates
                    entry.allow_comment = allow_comment
                    entry.allow_trackback = allow_trackback

                    entry.save(published)

                    if published:
                        smsg = _(
                            'Saved ok. <a href="/%(link)s" target="_blank">View it now!</a>'
                        )
                    else:
                        smsg = _('Saved ok.')
                    vals.update({
                        'result': True,
                        'msg': smsg % {
                            'link': str(base.urlencode(entry.link))
                        },
                        'entry': entry
                    })

                    self.render2('views/admin/entry.html', vals)
                    if published and entry.allow_trackback and g_blog.allow_pingback:
                        try:
                            autoPingback(entry.fullurl, HTML=content)
                        except:
                            pass

                except:
                    vals.update({
                        'result': False,
                        'msg': _('Error:Entry can'
                                 't been saved.')
                    })
                    self.render2('views/admin/entry.html', vals)