def process_article_edit(handler, permalink): # For http PUT, the parameters are passed in URIencoded string in body body = handler.request.body params = cgi.parse_qs(body) for key,value in params.iteritems(): params[key] = value[0] property_hash = restful.get_sent_properties(params.get, ['title', ('body', get_sanitizer_func(handler, trusted_source=True)), ('format', get_format), ('updated', get_datetime), ('tags', get_tags), ('html', get_html, 'body', 'format')]) if property_hash: if 'tags' in property_hash: property_hash['tag_keys'] = [get_tag_key(name) for name in property_hash['tags']] article = db.Query(models.blog.Article).filter('permalink =', permalink).get() before_tags = set(article.tag_keys) for key,value in property_hash.iteritems(): setattr(article, key, value) after_tags = set(article.tag_keys) for removed_tag in before_tags - after_tags: db.get(removed_tag).counter.decrement() for added_tag in after_tags - before_tags: db.get(added_tag).counter.increment() process_embedded_code(article) article.put() restful.send_successful_response(handler, '/' + article.permalink) view.invalidate_cache() else: handler.error(400)
def process_article_edit(handler, permalink): # For http PUT, the parameters are passed in URIencoded string in body body = handler.request.body params = cgi.parse_qs(body) for key, value in params.iteritems(): params[key] = value[0] property_hash = restful.get_sent_properties(params.get, [ 'title', ('body', get_sanitizer_func(handler, trusted_source=True)), ('format', get_format), ('updated', get_datetime), ('tags', get_tags), ('html', get_html, 'body', 'format') ]) if property_hash: if 'tags' in property_hash: property_hash['tag_keys'] = [ get_tag_key(name) for name in property_hash['tags'] ] article = db.Query(models.blog.Article).filter('permalink =', permalink).get() before_tags = set(article.tag_keys) for key, value in property_hash.iteritems(): setattr(article, key, value) after_tags = set(article.tag_keys) for removed_tag in before_tags - after_tags: db.get(removed_tag).counter.decrement() for added_tag in after_tags - before_tags: db.get(added_tag).counter.increment() process_embedded_code(article) article.put() restful.send_successful_response(handler, '/' + article.permalink) view.invalidate_cache() else: handler.error(400)
def process_article_submission(handler, article_type): property_hash = restful.get_sent_properties(handler.request.get, ['title', ('body', get_sanitizer_func(handler, trusted_source=True)), 'legacy_id', ('format', get_format), ('published', get_datetime), ('updated', get_datetime), ('tags', get_tags), ('html', get_html, 'body', 'format'), ('permalink', permalink_funcs[article_type], 'title', 'published')]) if property_hash: if 'tags' in property_hash: property_hash['tag_keys'] = [get_tag_key(name) for name in property_hash['tags']] property_hash['format'] = 'html' # For now, convert all to HTML property_hash['article_type'] = article_type article = models.blog.Article(**property_hash) article.set_associated_data( {'relevant_links': handler.request.get('relevant_links'), 'amazon_items': handler.request.get('amazon_items')}) process_embedded_code(article) article.put() for key in article.tag_keys: db.get(key).counter.increment() do_sitemap_ping() restful.send_successful_response(handler, '/' + article.permalink) view.invalidate_cache() else: handler.error(400)
def process_article_submission(handler, article_type): property_hash = restful.get_sent_properties(handler.request.get, [ 'title', ('body', get_sanitizer_func(handler, trusted_source=True)), 'legacy_id', ('format', get_format), ('published', get_datetime), ('updated', get_datetime), ('tags', get_tags), ('html', get_html, 'body', 'format'), ('permalink', permalink_funcs[article_type], 'title', 'published') ]) if property_hash: if 'tags' in property_hash: property_hash['tag_keys'] = [ get_tag_key(name) for name in property_hash['tags'] ] property_hash['format'] = 'html' # For now, convert all to HTML property_hash['article_type'] = article_type article = models.blog.Article(**property_hash) article.set_associated_data({ 'relevant_links': handler.request.get('relevant_links'), 'amazon_items': handler.request.get('amazon_items') }) process_embedded_code(article) article.put() # Ensure there is a year entity for this entry's year models.blog.Year.get_or_insert('Y%d' % (article.published.year, )) # Update tags for key in article.tag_keys: db.get(key).counter.increment() do_sitemap_ping() restful.send_successful_response(handler, '/' + article.permalink) view.invalidate_cache() else: handler.error(400)
def delete(self, device_name): logging.info("deleteHandler#(%s)", device_name) device = get_device_by_name(device_name) logging.info("deleteHandler#(%s)", device_name) if device: logging.info("dele#(%s)", device_name) db.delete(device) restful.send_successful_response(self, device_name)
def get(self): # get list of devices connected query = db.Query(ledomatic.Device) results = query.fetch(limit=5) dev_lst=[] for device in results: dev_lst.append(device.name) restful.send_successful_response(self, "result=" + ",".join(dev_lst))
def post(self, device_name): if not get_device_by_name(device_name): # login the device into DB device = ledomatic.Device() device.name = device_name device.put() # login device into list of device, if OK get the name back restful.send_successful_response(self, device_name)
def delete(self, comment_id): logging.info("Deleting comment %s", comment_id) comment = models.blog.Comment.get(db.Key(comment_id)) article = comment.article article.num_comments -= 1 article.put() comment.delete() view.invalidate_cache(article.permalink) restful.send_successful_response(self, "/")
def delete(self, year, month, perm_stem): permalink = 'blog/' + year + '/' + month + '/' + day + '/' + perm_stem logging.debug("Deleting blog entry %s", permalink) article = db.Query(models.blog.Article). \ filter('permalink =', permalink).get() for key in article.tag_keys: db.get(key).counter.decrement() article.delete() view.invalidate_cache() restful.send_successful_response(self, "/")
def delete(self, category, year, month, perm_stem): permalink = '/'.join((category, year, month, perm_stem)) logging.debug("Deleting %s entry %s" % (category, permalink)) article = db.Query(models.blog.Article). \ filter('permalink =', permalink).get() for key in article.tag_keys: db.get(key).counter.decrement() article.delete() view.invalidate_cache() restful.send_successful_response(self, "/")
def delete(self, year, month, perm_stem): permalink = year + '/' + month + '/' + perm_stem logging.debug("Deleting blog entry %s", permalink) article = db.Query(models.blog.Article). \ filter('permalink =', permalink).get() for key in article.tag_keys: db.get(key).counter.decrement() article.delete() view.invalidate_cache() restful.send_successful_response(self, "/")
def post(self, device_name): logging.debug("DevicesHandler#(%s)", device_name) query = ledomatic.Device.all() query.filter('name =', device_name) devices = query.fetch(limit=5) if not devices: device = ledomatic.Device() device.name = device_name device.put() # login device into list of device, if OK get the name back restful.send_successful_response(self, device_name)
def delete(self, path): logging.debug("Deleting article %s", path) if path=='article': # hack to pick out the 'top' article for bulk delete return delete_entity(self, models.blog.Article.all()) article = db.Query(models.blog.Article).filter('permalink =', path).get() if not article: return self.error(404) for key in article.tag_keys: db.get(key).counter.decrement() article.delete() view.invalidate_cache() restful.send_successful_response(self, "/")
def delete_entity(handler, query): target = query.get() if not target: return handler.response.set_status(204, 'No more entities') if hasattr(target, 'title'): title = target.title elif hasattr(target, 'name'): title = target.name else: title = '' logging.debug('Deleting %s', title) target.delete() handler.response.out.write('Deleted %s' % title) view.invalidate_cache() restful.send_successful_response(handler, "/")
def get(self, device_name, pin_id_str): # we pretends L1 is conencted query = ledomatic.Device.all() query.filter('name =', device_name) device = query.fetch(limit=5) if device: pins_value_str = device.pins_RGB if pins_value_str: values_lst = pins_value_str.split(',') restful.send_successful_response(self, 'result=',values_lst[0]) else: restful.send_successful_response(self, 'result=FFFFFF')
def delete_entity(handler, query): target = query.get() if not target: return handler.response.set_status(204, 'No more entities') if hasattr(target, 'title'): title = target.title elif hasattr(target, 'name'): title = target.name else: title = '' logging.debug('Deleting %s', title) target.delete() handler.response.out.write('Deleted %s' % title) view.invalidate_cache() restful.send_successful_response(handler, "/")
def delete(self, path): """ By using DELETE on /Article, /Comment, /Tag, you can delete the first entity of the desired kind. This is useful for writing utilities like clear_datastore.py. """ # TODO: Add DELETE for articles off root like blog entry DELETE. model_class = path.lower() aio.debug("blog.ArticleHandler#delete on %s", path) def delete_entity(query): targets = query.fetch(limit = 1) if len(targets) > 0: if hasattr(targets[0], 'title'): title = targets[0].title elif hasattr(targets[0], 'name'): title = targets[0].name else: title = '' aio.debug('Deleting %s %s', model_class, title) targets[0].delete() self.response.out.write('Deleted ' + model_class + ' ' + title) view.invalidate_cache(path) else: self.response.set_status(204, 'No more ' + model_class + ' entities') if model_class == 'article': query = models.blog.Article.all() delete_entity(query) elif model_class == 'comment': query = models.blog.Comment.all() delete_entity(query) elif model_class == 'tag': query = models.blog.Tag.all() delete_entity(query) else: article = db.Query(models.blog.Article). \ filter('permalink =', path).get() for key in article.tag_keys: tag = db.get(key) logging.debug("Decrementing tag %s with initial value %d", tag.name, tag.counter.count) tag.counter.decrement() if tag.counter.count == 0: logging.debug("Tag %s has count 0, removing tag", tag.name) tag.delete_counter() tag.delete() for comment in article.comments: comment.delete() article.delete() view.invalidate_cache(path) restful.send_successful_response(self, "/")
def delete(self, path): logging.debug("Deleting article %s", path) if path == 'article': # hack to pick out the 'top' article for bulk delete return delete_entity(self, models.blog.Article.all()) article = db.Query(models.blog.Article).filter('permalink =', path).get() if not article: return self.error(404) for key in article.tag_keys: db.get(key).counter.decrement() article.delete() view.invalidate_cache() restful.send_successful_response(self, "/")
def post(self, device_name): logging.debug("PinsHandler#post" + device_name) query = ledomatic.Device.all() query.filter('name =', device_name) device = query.fetch(limit=5) logging.debug("PinsHandler#post#body" + self.request.body) if device: # parse cmd # TO DO could be more generic key_value_lst = self.request.body.split('=') if key_value_lst[0] == 'color': memcache.delete("L1RGB0") setValueToPin(device[0], 'RGB', '0', key_value_lst[1]) restful.send_successful_response(self, '')
def delete(self, comment_id): if not comment_id: return delete_entity(self, models.blog.Comment.all()) logging.debug("Deleting comment %s", comment_id) comment = models.blog.Comment.get(db.Key(comment_id)) if not comment: return self.error(404) article = comment.article comment.delete() # TODO replace with counter? article.num_comments -= 1 # decrement comment count article.put() view.invalidate_cache(comment.article.permalink) restful.send_successful_response(self, "/")
def delete(self,comment_id): if not comment_id: return delete_entity( self, models.blog.Comment.all() ) logging.debug("Deleting comment %s", comment_id) comment = models.blog.Comment.get(db.Key(comment_id)) if not comment: return self.error(404) article = comment.article comment.delete() # TODO replace with counter? article.num_comments -=1 # decrement comment count article.put() view.invalidate_cache(comment.article.permalink) restful.send_successful_response(self, "/")
def get(self, device_name): # we pretends L1 is conencted data = memcache.get("L1RGB0") if data is not None: restful.send_successful_response(self, 'result=' + data) else: query = ledomatic.Device.all() query.filter('name =', device_name) device = query.fetch(limit=5) if device: pins_value_str = device[0].pins_RGB else: pins_value_str = 'FFFFFF,0' values_lst = pins_value_str.split(',') memcache.add("L1RGB0", values_lst[0], 30) restful.send_successful_response(self, 'result=' + values_lst[0])
def delete(self, path): """ By using DELETE on /Article, /Comment, /Tag, you can delete the first entity of the desired kind. This is useful for writing utilities like clear_datastore.py. """ # TODO: Add DELETE for articles off root like blog entry DELETE. model_class = path.lower() logging.debug("ArticleHandler#delete on %s", path) def delete_entity(query): targets = query.fetch(limit=1) if len(targets) > 0: if hasattr(targets[0], 'title'): title = targets[0].title elif hasattr(targets[0], 'name'): title = targets[0].name else: title = '' logging.debug('Deleting %s %s', model_class, title) targets[0].delete() self.response.out.write('Deleted ' + model_class + ' ' + title) view.invalidate_cache() else: self.response.set_status( 204, 'No more ' + model_class + ' entities') if model_class == 'article': query = models.blog.Article.all() delete_entity(query) elif model_class == 'comment': query = models.blog.Comment.all() delete_entity(query) elif model_class == 'tag': query = models.blog.Tag.all() delete_entity(query) else: article = db.Query(models.blog.Article). \ filter('permalink =', path).get() for key in article.tag_keys: db.get(key).counter.decrement() article.delete() view.invalidate_cache() restful.send_successful_response(self, "/")
def delete(self, year, month, permalink): perm_stem = [t for t in permalink.split("/") if len(t)][-1] permalink = year + '/' + month + '/' + perm_stem aio.debug("BlogEntryHandler. delete Deleting blog entry %s", permalink) article = db.Query(models.blog.Article).filter('permalink =', permalink).get() for key in article.tag_keys: tag = db.get(key) aio.debug("BlogEntryHandler.delete: Decrementing tag '%s' with current count %d", tag.name, tag.counter.count) tag.counter.decrement() if tag.counter.count == 0: aio.debug("Tag '%s' has count 0, removing tag", tag.name) tag.delete_counter() tag.delete() article.delete() view.invalidate_cache(perm_stem) restful.send_successful_response(self, "/")
def get(self, device_name, pin_type_name, pin_id_str): # we pretends L1 is conencted logging.info("aAA Hallo from cache common") query = ledomatic.Device.all() query.filter('name =', device_name) device = query.fetch(limit=5) if device: if pin_type_name == 'RGB': restful.send_successful_response(self, 'result=' + getValueFromPin(device[0], pin_type_name, pin_id_str)) else: if getValueFromPin(device[0], pin_type_name, pin_id_str) == "1": restful.send_successful_response(self, 'result=On') else: restful.send_successful_response(self, 'result=Off')
def process_article_edit(handler, postlink): # For HTTP PUT, the parameters are passed in URIencoded string in body body = handler.request.body params = cgi.parse_qs(body) for key, value in params.iteritems(): params[key] = value[0] if not isinstance(params[key], unicode): params[key] = params[key].decode(config.APP['charset']) aio.debug("blog.process_article_edit: params.keys: %s", params.keys()) # article_type = restful.get_sent_properties(params.get, [('postType', get_type)])['postType'] article_type = params['postType'] aio.debug("blog.process_article_edit article with postlink: %s, type: %s/%s", postlink, article_type, params['postFormat']) tmp_hash = restful.get_sent_properties(params.get, [ ('postTitle', cgi.escape), ('postBody', get_sanitizer_func(handler, trusted_source = True)), ('postFormat', get_format), ## markdown, html, text ('postType', get_type), ## draft, post, article ('postTags', get_tags), ('html', get_html, 'postBody', 'postFormat'), ('postPublished', get_datetime, 'postPublished'), ('permalink', permalink_funcs[article_type], 'postTitle', 'postPublished'), 'postThumb', # 'postPublished', ]) # aio.debug("blog.process_article_edit tmp_hash: %s", tmp_hash) property_hash = {} props = ( ("postTitle", "title"), ("postBody", "body"), ("postFormat", "format"), ("postPublished", "published"), ("postThumb", "thumb"), ("legacy_id", "legacy_id"), ("article_id", "article_id"), ("postType", "article_type"), ("postTags", "tags"), ("html", "html"), ("postPerma", "permalink") ) for pair in props : # aio.debug("PAIR: %s", pair) if pair is not None: if pair[0] in tmp_hash : # logging.info("COPY PAIR %s", pair) property_hash[pair[1]] = tmp_hash[pair[0]] else : pass # aio.debug("IGNORE %s from sent properties to %s in property hash", pair[0], pair[1]) else : aio.debug("ERROR '%s' with pair", pair) if property_hash: if 'tags' in property_hash: property_hash['tag_keys'] = [get_tag_key(name) for name in property_hash['tags'] if name != ""] aio.debug("blog.process_article_edit search article by postlink: %s", postlink) ## adjust dates property_hash['updated'] = datetime.datetime.utcnow() if property_hash['article_type'] == 'draft' : property_hash['published'] = None else : # property_hash['published'] = get_datetime(property_hash['published']) property_hash['published'] = property_hash['published'] aio.debug("blog.process_article_edit pub: %s: upd: %s", property_hash['published'], property_hash['updated']) article = db.Query(models.blog.Article).filter('permalink =', postlink).get() before_tags = set(article.tag_keys) for key, value in property_hash.iteritems(): # aio.debug("blog.process_article_edit: SAVE: " + key + " > " + aio.asciify(value)[:10]) ## utf errors setattr(article, key, value) after_tags = set(article.tag_keys) for removed_tag in before_tags - after_tags: tag = db.get(removed_tag) logging.debug("Decrementing tag '%s' with initial value %d", tag.name, tag.counter.count) tag.counter.decrement() if tag.counter.count == 0: logging.debug("Tag %s has count 0, removing tag", tag.name) tag.delete_counter() tag.delete() for added_tag in after_tags - before_tags: db.get(added_tag).counter.increment() process_embedded_code(article) article.put() # restful.send_successful_response(handler, '/' + article.permalink) restful.send_successful_response(handler, '/post/edit/' + str(article.key())) view.invalidate_cache(article.permalink) else: handler.error(400)
def get(self, device, pin): logging.debug(device + pin) # we pretends L1 is conencted restful.send_successful_response(self, 'L1')
def get(self, *path): logging.debug(path) # we pretends L1 is conencted restful.send_successful_response(self, 'L1')
def post(self): logging.debug("RootHandler#post") # login device into list of device, if OK get the name back restful.send_successful_response(self, 'L1')
def process_article_submission(handler, article_type): """ takes care of permalink """ aio.debug("blog.process_article_submission article_type: %s", article_type) tmp_hash = restful.get_sent_properties(handler.request.get, [ ('postTitle', get_sanitizer_func(handler, trusted_source = True)), ('postBody', get_sanitizer_func(handler, trusted_source = True)), ('postFormat', get_format), ('postType', get_type), ('postUpdated', get_datetime), ('postTags', get_tags), ('html', get_html, 'postBody', 'postFormat'), ('permalink', permalink_funcs[article_type], 'postTitle', 'postPublished'), 'postExcerpt', 'postThumb' ]) property_hash = {} props = ( ("key", "key"), ("postTitle", "title"), ("postBody", "body"), ("postExcerpt", "excerpt"), ("postThumb", "thumb"), ("postFormat", "format"), ("postType", "article_type"), ("postPublished", "published"), ("postUpdated", "updated"), ("article_id", "article_id"), ("permalink", "permalink"), ("html", "html"), ("postTags", "tags"), ) for pair in props: if pair[0] in tmp_hash: property_hash[pair[1]] = tmp_hash[pair[0]] if property_hash: if 'tags' in property_hash: property_hash['tag_keys'] = [get_tag_key(name) for name in property_hash['tags']] # property_hash['format'] = 'html' # For now, convert all to HTML # property_hash['article_type'] = article_type article = models.blog.Article(**property_hash) article.set_associated_data({'relevant_links': handler.request.get('relevant_links'), }) process_embedded_code(article) article.put() time.sleep(1) # Ensure there is a year entity for this entry's year if article.published : models.blog.Year.get_or_insert('Y%d' % (article.published.year, )) # Update tags for key in article.tag_keys: db.get(key).counter.increment() aio.debug("blog.process_article_submission perm: %s, key: %s", article.permalink, article.key()) # restful.send_successful_response(handler, '/' + article.permalink) restful.send_successful_response(handler, '/post/edit/' + str(article.key())) view.invalidate_cache(article.permalink) else: aio.debug("blog.process_article_submission no property_hash") handler.error(400)