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()
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()
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)
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()
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})
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()
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()
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)
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)
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()
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()
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()
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()
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)
def _get_reindex(self, par): q = Content.all() q.filter('status =', 'published') # date, author, content, title): search = BlogSearch() count = 0 for c in q: count = count + 1 search.insert_document(search.create_document( c.key().name(), c.sortdate, c.author.displayname, c.current.content, c.current.title, c.group.title )) self._respond(["reindex"], opt={"count":count})
def _post_new_content(self, par): user = User(self._req.sesh()) person = user.get_sesh_person() ut = Utils() key = ut.cleanUserName(self._req.par('cid')) # create the content record, by unique key - !important - replaces existing key - warn user? content = Content(key_name=key) content.status = 'draft' content.author = person groupname = self._req.par('cgroup') content.group = Group.get_by_key_name(groupname) # create a new version contentver = ContentVersion() # some defaults contentver.title = self._req.par('ctitle') contentver.content = '<p>Placeholder for the body of your Article</p>' contentver.summary = '<p>Placeholder for the article summary</p>' # have to put to get a reference contentver.put() # upate versions on this content content.current = contentver content.editing = contentver content.put() # link to my parent - in fact shouldnt I have used parents (but then sharding wont be an issue for a few, even 100's of, articles) contentver.mycontent = content contentver.put() # and redirect to the new content return self._req.redirect(path=self._conf.BLOG + '/' + groupname + '/' + key)
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()
def _get_blog(self, par, xml=False): """ all blog articles """ q = Content.all(); self._obj['title'] = self._conf.BLOG_TITLE self._get_blog_list(q, xml)
def _post_change_status(self, par): key = self._pl['id'] content = Content.get_by_key_name(key) content.status = self._pl['stat'] content.put()