Example #1
0
    def _get_blog_search(self, par, xml=False):
        """ all blog articles matching search result """
        self._curpage = int(self._req.par('p', default_value = 1))

        self._obj['title'] = "Search"

        search = BlogSearch()
        result = search.get(par[0])
        
        newest = datetime.datetime.fromtimestamp(0)
        self._obj['data'] = []

        count = 0
        for r in result:
            count = count + 1

            logging.debug(r.doc_id)

            c = Content.get_by_key_name(r.doc_id)
            d = self.copy_bits(c)

            self._obj['data'].append(d)
            
            if c.sortdate > newest:
                newest = c.sortdate

        # fill in all our widgets        
        self._build_widgets_list(count, None)


        self._respond(path='blog-search', obj=self._obj, xml=xml, search={"term":par[0], "count": count})
Example #2
0
    def _post_update_images(self, par):
        
        key = self._pl['key']
        which = self._pl['which']
        url = self._pl['url']
        parcontent = Content.get_by_key_name(key)
        content = parcontent.editing
        
        if which == "mainimage":
            image = Image.get_by_id(int(url))
            
            content.mainimage = image
            content.imagepath = None   # so reset the path    

            if content.thumb == None:
                content.thumb = images.get_serving_url(image.blob_key, 150)

        elif which == "thumb":
            content.thumb = url

        elif which == "reset_thumb":
            image = content.mainimage
            if image:
                content.thumb = images.get_serving_url(image.blob_key, 150) 
            
        content.put()
Example #3
0
    def _get_blog_single(self, par):

        ut = Utils()
        self._build_widgets_single()

        o = self._obj
        # if it is the single blog view and the user is an editor then load up the images for the image select box
        if self._req.sesh().can_edit():
            o['images'] = Image.all().order("-date").fetch(self._conf.IMAGES_VIEWER_COUNT)

        content = Content.get_by_key_name(par[1])
        if content:
            o['data'] = self.copy_bits(content)
        
            # versions for admin - perhaps optimise this out with a isAdmin clause
            o['data'].otherversions = content.contentversion_set
            ov = []
            for c in content.contentversion_set:
                c.nicetime = c.createtime.strftime('%e %b %Y - %H:%M:%S')
                ov.append(c)
            o['data'].otherversions = ov
            
            # what to put in the meta description - needed for singe blog post only
            if content.current.summary:
                o['data'].metadesc = ut.strip_tags(content.current.summary)
            else:
                o['data'].metadesc = o['data'].title
     
            # no paging controls - for a single blog
            o['page'] = {}
            
        else:
            return self._req.notfound()

        self._respond(path='blog-single', obj=self._obj)
Example #4
0
    def _post_update_images(self, par):

        key = self._pl["key"]
        which = self._pl["which"]
        url = self._pl["url"]
        parcontent = Content.get_by_key_name(key)
        content = parcontent.editing

        if which == "mainimage":
            image = Image.get_by_id(int(url))

            content.mainimage = image
            content.imagepath = None  # so reset the path

            if content.thumb == None:
                content.thumb = images.get_serving_url(image.blob_key, 150)

        elif which == "thumb":
            content.thumb = url

        elif which == "reset_thumb":
            image = content.mainimage
            if image:
                content.thumb = images.get_serving_url(image.blob_key, 150)

        elif which == "main_url":
            content.imagepath = url  # so reset the path

        elif which == "thumb_url":
            content.thumb = url  # so reset the path

        content.put()

        # respond with a good code
        self._req.draw_code()
Example #5
0
    def _post_raptor_save(self, par):

        for cid, cc in self._pl.items():
            logging.debug(cid)
            parcontent = Content.get_by_key_name(cid)
            content = parcontent.editing
            for eid, e in cc.items():
                ee = e.strip()
                logging.debug(eid)
                logging.debug(ee)
                if eid == 'ed_title':
                    content.title = ee
                if eid == 'ed_banner':

                    if ee =="":
                        content.banner = None
                    else:
                        content.banner = ee
                if eid == 'ed_content':
                    content.content = ee
                    if content.summary == "<p>Placeholder for the article summary</p>":             # still the default
                        paras = ee.split('<p>');
                        if len(paras) > 2:
                            content.summary = '<p>' + paras[1] + '<p>' + paras[2]
                        elif len(paras) > 1:
                            content.summary = '<p>' + paras[1]
                
                content.put()
        # respond with a good code
        self._req.draw_code()
Example #6
0
    def _post_change_current(self, par):
    
        key = self._pl['id']
        ver = int(self._pl['verid'])

        content = Content.get_by_key_name(key)
        contentver = ContentVersion.get_by_id(ver)

        content.current = contentver
        content.put()
Example #7
0
    def popular(self):

        popular = {}
        pop = Content.get_by_key_name("popular-articles")
        if pop:
             
            popular['data'] = pop.current
            popular['articles'] = []
            
            try:
                popobj = json.loads(pop.current.content)
                for po in popobj:
                    po_cont = Content.get_by_key_name(po)
                    po_cont.current.group = po_cont.group
                    po_cont.current.keyname = po_cont.key().name()
                    popular['articles'].append(po_cont.current)

            except Exception, e:
                logging.error('popular problem')
                logging.exception(e)
Example #8
0
    def _post_createdate(self, par):

        content = Content.get_by_key_name(self._pl["id"])
        logging.debug(self._pl["createdate"])
        content.sortdate = datetime.datetime.strptime(self._pl["createdate"], "%m/%d/%Y")
        content.put()

        #  send back the new formatted date
        obj = {"createdate": content.sortdate.strftime("%e %b %Y")}

        self._req.draw_code(obj=obj)
Example #9
0
    def _post_new_version(self, par):
        
        key = self._pl['id']
        content = Content.get_by_key_name(key)

        new = clone_entity(content.current)
        new.before_put()
        new.put()
        
        content.editing = new
        content.put()
Example #10
0
    def _post_change_current(self, par):

        key = self._pl["id"]
        ver = int(self._pl["verid"])

        content = Content.get_by_key_name(key)
        contentver = ContentVersion.get_by_id(ver)

        content.current = contentver
        content.put()

        # respond with a good code
        self._req.draw_code()
Example #11
0
    def _post_change_status(self, par):

        status = self._pl["stat"]

        key = self._pl["id"]
        content = Content.get_by_key_name(key)
        content.status = status
        content.put()

        if status == "published":
            self._update_search_index(content)

        # respond with a good code
        self._req.draw_code()
Example #12
0
    def _post_new_version(self, par):

        key = self._pl["id"]
        content = Content.get_by_key_name(key)

        new = clone_entity(content.current)
        new.before_put()
        new.put()

        content.editing = new
        content.put()

        # respond with a good code
        self._req.draw_code()
Example #13
0
    def _post_summary_save(self, par):

        for cid, cc in self._pl.items():
            logging.debug(cid)
            for eid, ee in cc.items():
                parcontent = Content.get_by_key_name(eid)
                content = parcontent.editing
                if cid == "ed_summary":
                    content.summary = ee

                content.put()

        # respond with a good code
        self._req.draw_code()
Example #14
0
    def _get_blog_single(self, par):

        ut = Utils()
        self._build_widgets_single()

        o = self._obj
        # if it is the single blog view and the user is an editor then load up the images for the image select box
        if self._req.sesh().can_edit():
            o['images'] = Image.all().order("-date").fetch(self._conf.IMAGES_VIEWER_COUNT)

        content = Content.get_by_key_name(par[1])
        if content:
            if self._req.sesh().can_edit():
                o['data'] = content.editing
            else:
                o['data'] = content.current

            o['data'].ctype = content.ctype
            o['data'].status = content.status
            o['data'].otherversions = content.contentversion_set
            ov = []
            for c in content.contentversion_set:
                c.nicetime = c.createtime.strftime('%e %b %Y - %H:%M:%S')
                ov.append(c)

            o['data'].otherversions = ov
            o['data'].keyname = content.key().name()
            o['data'].group = content.group
     
            # what to put in the meta description 
            if content.current.summary:
                o['data'].metadesc = ut.strip_tags(content.current.summary)
            else:
                o['data'].metadesc = o['data'].title
     
            o['data'].nicedate = content.sortdate.strftime('%e %b %Y')

            # use hard coded imagepath, or the mainimage's url
            if not o['data'].imagepath:
                if o['data'].mainimage:
                    o['data'].imagepath = o['data'].mainimage.serving_url

            # no paging controls - for a single blog
            o['page'] = {}
            
        else:
            return self._req.notfound()

        self._respond(path='blog-single', obj=self._obj)
Example #15
0
    def _post_raptor_save(self, par):

        search = BlogSearch()

        for cid, cc in self._pl.items():
            logging.debug(cid)
            parcontent = Content.get_by_key_name(cid)
            content = parcontent.editing

            for eid, e in cc.items():
                ee = e.strip()
                logging.debug(eid)
                logging.debug(ee)

                if eid == "ed_title":
                    content.title = ee
                if eid == "ed_banner":

                    if ee == "":
                        content.banner = None
                    else:
                        content.banner = ee
                if eid == "ed_content":
                    content.content = ee
                    if content.summary == "<p>Placeholder for the article summary</p>":  # still the default
                        paras = ee.split("<p>")
                        if len(paras) > 2:
                            content.summary = "<p>" + paras[1] + "<p>" + paras[2]
                        elif len(paras) > 1:
                            content.summary = "<p>" + paras[1]

                content.put()

                # add the update if published to search index
                if parcontent.status == "published":
                    self._update_search_index(parcontent)

        # respond with a good code
        self._req.draw_code()
Example #16
0
    def _post_change_status(self, par):

        key = self._pl['id']
        content = Content.get_by_key_name(key)
        content.status = self._pl['stat']
        content.put()