Exemplo n.º 1
0
    def get(self):


        key = self.request.get('key')
        item_type = self.request.get('item_type')
        if item_type == "entry":
            entry = Entry.get(key)
            form = EditEntryForm(instance=entry)
        else:
            entry = Country.get(key)
            form = EditCountryForm(instance=entry)

        if users.get_current_user():
            url = users.create_logout_url(self.request.uri)
            url_linktext = 'Logout'
        else:
            url = users.create_login_url(self.request.uri)
            url_linktext = 'Login'

        template_values = {
            'form': form,
            'item_type': item_type,
            'key': key,
            'url': url,
            'url_linktext': url_linktext,
        }

        path = os.path.join(os.path.dirname(__file__), 'templates/admin/edit.html')
        self.response.out.write(template.render(path, template_values))
Exemplo n.º 2
0
    def get(self):

        key = self.request.get('key')
        item_type = self.request.get('item_type')
        if item_type == "entry":
            entry = Entry.get(key)
            form = EditEntryForm(instance=entry)
        else:
            entry = Country.get(key)
            form = EditCountryForm(instance=entry)

        if users.get_current_user():
            url = users.create_logout_url(self.request.uri)
            url_linktext = 'Logout'
        else:
            url = users.create_login_url(self.request.uri)
            url_linktext = 'Login'

        template_values = {
            'form': form,
            'item_type': item_type,
            'key': key,
            'url': url,
            'url_linktext': url_linktext,
        }

        path = os.path.join(os.path.dirname(__file__),
                            'templates/admin/edit.html')
        self.response.out.write(template.render(path, template_values))
Exemplo n.º 3
0
    def POST(self,slug=None):
        try:
            linkcheck= self.request.get_all('checks')
            entrykeys=[]
            for key in linkcheck:

                comment=Comment.get(key)
                comment.delit()
                entrykeys.append(comment.entry.key())
            entrykeys=set(entrykeys)
            for key in entrykeys:
                e=Entry.get(key)
                e.update_commentno()
                e.removecache()
            memcache.delete("/feed/comments")
        finally:
            self.redirect(self.request.uri)
Exemplo n.º 4
0
    def GET(self,slug='post'):
        action=self.param("action")
        entry=None
        cats=Category.all()
        alltags=Tag.all()
        if action and  action=='edit':
                try:
                    key=self.param('key')
                    entry=Entry.get(key)

                except:
                    pass
        else:
            action='add'

        def mapit(cat):
            return {'name':cat.name,'slug':cat.slug,'select':entry and cat.key() in entry.categorie_keys}

        vals={'action':action,'entry':entry,'entrytype':slug,'cats':map(mapit,cats),'alltags':alltags}
        self.render2('views/admin/entry.html',vals)
Exemplo n.º 5
0
    def action_getcomments(self):
        key=self.param('key')
        entry=Entry.get(key)
        comments=Comment.all().filter(entry = key)

        commentuser=self.request.cookies.get('comment_user', '')
        if commentuser:
            commentuser=commentuser.split('#@#')
        else:
            commentuser=['','','']


        vals={
            'entry':entry,
            'comments':comments,
            'user_name':commentuser[0],
            'user_email':commentuser[1],
            'user_url':commentuser[2],
            'checknum1':random.randint(1,10),
            'checknum2':random.randint(1,10),
            }
        html=self.get_render('comments',vals)

        self.write(simplejson.dumps(html.decode('utf8')))
Exemplo n.º 6
0
    def post(self):
        self.response.out.write('<html><body>You wrote:<pre>')
        key = self.request.get('id_key')
        title = self.request.get('title')
        slug = str(slugify(title))
        item_type = self.request.get('item_type')
        tag_list = None


        if item_type == "entry":
            content = self.request.get('content')
            genre = self.request.get('genre')
            enable_comments = self.request.get('enable_comments')
            country = self.request.get('country')
            core_topic = self.request.get('core_topic')
            tags = self.request.get('tags')
            private = self.request.get('private')
            publish_date = self.request.get('publish_date')
 
            if publish_date:
                publish_date = datetime.strptime(publish_date, '%Y-%m-%d').date()
            else:
                publish_date = datetime.today().date()
                
            if genre == "blog":
                country_obj = Country.get(country)
            else:
                country_obj = None

            if key:
                entry = Entry.get(key)
            else:
                entry = Entry()
            entry.title = title
            entry.slug = slug
            entry.content = content
            entry.genre = genre
            entry.country = country_obj
            entry.publish_date = publish_date
            if len(core_topic):
                entry.core_topic = core_topic
            if private == "on":
                b = bool("1")
            else:
                b = bool("")
            entry.private = b
            entry.put()

            if len(tags) > 0:
                tag_list = shlex.split(str(tags))
                if tag_list:
                  for tag in tag_list:
                      tag_obj = Tag.get_or_insert(str(tag))
                      if tag_obj.name == None:
                          tag_obj.name = str(tag)
                          tag_obj.put()
                      entry.tags.append(tag_obj.key())
                  entry.put()
        else:
            map_url = self.request.get('map_url')
            if key:
                country = Country.get(key)
            else:
                country = Country()
            country.title = title
            country.slug = slug
            country.map_url = map_url
            country.put()

        self.response.out.write(str("Key: %s<br />" % key))
        self.response.out.write(str("Title: %s<br />" % title))
        self.response.out.write(str("Slug: %s<br />" % slug))
        self.response.out.write(str("Type: %s<br />" % item_type))
        if tag_list:
          self.response.out.write(str("Tags: %s<br />" % tags))
       
        self.response.out.write('</pre></body></html>')
Exemplo n.º 7
0
    def delete(self):
        key = get_key_from_body(self.request.body)

        if key:
            instance = Entry.get(db.Key(key))
            instance.delete()
Exemplo n.º 8
0
 def delete(self):
     key = get_key_from_body(self.request.body)
     
     if key:
         instance = Entry.get(db.Key(key))
         instance.delete()
Exemplo n.º 9
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 .'))
Exemplo n.º 10
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="/blog/%(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 self.blog.allow_pingback:
                    try:
                        autoPingback(str(entry.fullurl),HTML=content)
                    except:
                        pass
            elif action=='edit':
                #try:
                if 1:
                    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="/blog/%(link)s" target="_blank">View it now!</a>')
                    else:
                        smsg=_('Saved ok.')
                    vals.update({'result':True,'msg':smsg%{'link':str(entry.link)},'entry':entry})

                    self.render2('views/admin/entry.html',vals)

                #except:
                if 0:
                    vals.update({'result':False,'msg':_('Error:Entry can''t been saved.')})
                    self.render2('views/admin/entry.html',vals)
Exemplo n.º 11
0
    def post(self):
        self.response.out.write('<html><body>You wrote:<pre>')
        key = self.request.get('id_key')
        title = self.request.get('title')
        slug = str(slugify(title))
        item_type = self.request.get('item_type')
        tag_list = None

        if item_type == "entry":
            content = self.request.get('content')
            genre = self.request.get('genre')
            enable_comments = self.request.get('enable_comments')
            country = self.request.get('country')
            core_topic = self.request.get('core_topic')
            tags = self.request.get('tags')
            private = self.request.get('private')
            publish_date = self.request.get('publish_date')

            if publish_date:
                publish_date = datetime.strptime(publish_date,
                                                 '%Y-%m-%d').date()
            else:
                publish_date = datetime.today().date()

            if genre == "blog":
                country_obj = Country.get(country)
            else:
                country_obj = None

            if key:
                entry = Entry.get(key)
            else:
                entry = Entry()
            entry.title = title
            entry.slug = slug
            entry.content = content
            entry.genre = genre
            entry.country = country_obj
            entry.publish_date = publish_date
            if len(core_topic):
                entry.core_topic = core_topic
            if private == "on":
                b = bool("1")
            else:
                b = bool("")
            entry.private = b
            entry.put()

            if len(tags) > 0:
                tag_list = shlex.split(str(tags))
                if tag_list:
                    for tag in tag_list:
                        tag_obj = Tag.get_or_insert(str(tag))
                        if tag_obj.name == None:
                            tag_obj.name = str(tag)
                            tag_obj.put()
                        entry.tags.append(tag_obj.key())
                    entry.put()
        else:
            map_url = self.request.get('map_url')
            if key:
                country = Country.get(key)
            else:
                country = Country()
            country.title = title
            country.slug = slug
            country.map_url = map_url
            country.put()

        self.response.out.write(str("Key: %s<br />" % key))
        self.response.out.write(str("Title: %s<br />" % title))
        self.response.out.write(str("Slug: %s<br />" % slug))
        self.response.out.write(str("Type: %s<br />" % item_type))
        if tag_list:
            self.response.out.write(str("Tags: %s<br />" % tags))

        self.response.out.write('</pre></body></html>')